vibespot 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +130 -125
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/ui/chat.js +15 -6
- package/ui/index.html +5 -1
- package/ui/styles.css +1 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var Rl=Object.defineProperty;var j=(e,t)=>()=>(e&&(t=e(e=0)),t);var nt=(e,t)=>{for(var n in t)Rl(e,n,{get:t[n],enumerable:!0})};import rm from"path";import{fileURLToPath as lm}from"url";var g=j(()=>{"use strict"});import{readFileSync as Ts,writeFileSync as Fl,mkdirSync as Vo,existsSync as Sn}from"fs";import{dirname as jl,join as Ve}from"path";function A(e){return Ts(e,"utf-8")}function H(e,t){Vo(jl(e),{recursive:!0}),Fl(e,t,"utf-8")}function b(e){return Sn(e)}function Ae(e){Vo(e,{recursive:!0})}function vn(e){let t=[Ve(import.meta.dirname,"../../assets",e),Ve(import.meta.dirname,"../assets",e),Ve(process.cwd(),"assets",e)];for(let n of t)if(Sn(n))return n;throw new Error(`Asset not found: ${e}`)}function wt(){if(xt)return xt;let e=[Ve(import.meta.dirname,"../../package.json"),Ve(import.meta.dirname,"../package.json"),Ve(process.cwd(),"package.json")];for(let t of e)if(Sn(t))try{let n=JSON.parse(Ts(t,"utf-8"));if(n.name==="vibespot"&&n.version)return xt=n.version,xt}catch{}return xt="dev",xt}function Ko(){if(bn)return bn;let e=[Ve(import.meta.dirname,"../../CHANGELOG.md"),Ve(import.meta.dirname,"../CHANGELOG.md"),Ve(process.cwd(),"CHANGELOG.md")];for(let t of e)if(Sn(t))try{return bn=Ts(t,"utf-8"),bn}catch{}return""}var xt,bn,Q=j(()=>{"use strict";g();xt="";bn=""});import{execSync as Yo}from"child_process";function $(e,t={}){try{return{stdout:Yo(e,{encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:12e4,...t}).trim(),stderr:"",success:!0}}catch(n){let s=n,o=(s.stdout??"").toString().trim(),i=(s.stderr??"").toString().trim();return{stdout:o,stderr:i,success:!1}}}function zo(e,t={}){try{return Yo(e,{stdio:"inherit",timeout:3e5,...t}),!0}catch{return!1}}var ut=j(()=>{"use strict";g()});var Qo={};nt(Qo,{addHubSpotAccount:()=>Jt,getActiveHubSpotAccount:()=>st,getApiKeyForEngine:()=>ge,getConfigDir:()=>Hl,getHubSpotPak:()=>he,isCliToolEnabled:()=>Dt,loadConfig:()=>_,maskApiKey:()=>wn,removeHubSpotAccount:()=>$s,saveConfig:()=>K,setActiveHubSpotAccount:()=>Es,setCliToolEnabled:()=>_s});import{join as qo}from"path";import{homedir as Jl}from"os";import{chmodSync as Dl}from"fs";function _(){if(!b(xn))return{};try{let e=JSON.parse(A(xn));return e.aiEngine==="api"&&(e.aiEngine="anthropic-api"),e}catch{return{}}}function ge(e,t){let n=t||_();switch(e){case"anthropic-api":case"api":return n.anthropicApiKey||process.env.ANTHROPIC_API_KEY;case"openai-api":return n.openaiApiKey||process.env.OPENAI_API_KEY;case"gemini-api":return n.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY;default:return}}function wn(e){return e.length<=12?"***":e.slice(0,7)+"..."+e.slice(-4)}function K(e){let n={..._(),...e};if(H(xn,JSON.stringify(n,null,2)),process.platform!=="win32")try{Dl(xn,384)}catch{}}function Hl(){return Xo}function st(){let e=_();if(!e.hubspotAccounts?.length)return null;let t=e.activeHubSpotAccount;if(t){let n=e.hubspotAccounts.find(s=>s.portalId===t);if(n)return n}return e.hubspotAccounts[0]||null}function Jt(e,t,n,s){let i=_().hubspotAccounts||[],a=i.findIndex(l=>l.portalId===t),r={portalId:t,portalName:n,personalAccessKey:e,dataCenter:s,addedAt:new Date().toISOString()};a>=0?i[a]=r:i.push(r),K({hubspotAccounts:i,activeHubSpotAccount:t})}function $s(e){let t=_(),n=(t.hubspotAccounts||[]).filter(o=>o.portalId!==e),s={hubspotAccounts:n};t.activeHubSpotAccount===e&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),K(s)}function Es(e){K({activeHubSpotAccount:e})}function he(){return st()?.personalAccessKey||null}function Dt(e){return _().enabledCLITools?.includes(e)??!1}function _s(e,t){let n=_(),s=new Set(n.enabledCLITools||[]);t?s.add(e):s.delete(e),K({enabledCLITools:[...s]})}var Xo,xn,Z=j(()=>{"use strict";g();Q();Xo=qo(Jl(),".vibespot"),xn=qo(Xo,"config.json")});var Os={};nt(Os,{OAUTH_EXTRA_HEADERS:()=>Ht,OAUTH_SYSTEM_PREFIX:()=>At,clearOAuthTokens:()=>kn,getOAuthTokenInfo:()=>Lt,getValidAccessToken:()=>Ms,hasValidOAuthToken:()=>Re,saveInitialToken:()=>Ps});import{join as Ll}from"path";import{homedir as Gl}from"os";import{chmodSync as Ul,unlinkSync as Bl}from"fs";function An(){if(!b(Ct))return null;try{return JSON.parse(A(Ct))}catch{return null}}function Zo(e){if(H(Ct,JSON.stringify(e,null,2)),process.platform!=="win32")try{Ul(Ct,384)}catch{}}async function Yl(e){let t=await fetch(Vl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:e,client_id:Wl})});if(!t.ok)throw kn(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await t.json();Zo({access_token:n.access_token,refresh_token:n.refresh_token||e,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function Ps(e,t=""){Zo({access_token:e,refresh_token:t,expires_at:Date.now()+28800*1e3})}function Re(){let e=An();return e?e.expires_at>Date.now():!1}async function Ms(){let e=An();if(!e)return null;if(e.expires_at-Date.now()>Kl)return e.access_token;if(e.refresh_token){Cn||(Cn=Yl(e.refresh_token).finally(()=>{Cn=null}));try{await Cn}catch{return null}return An()?.access_token??null}return e.access_token}function Lt(){let e=An();return e?{expiresAt:new Date(e.expires_at).toISOString()}:null}function kn(){if(b(Ct))try{Bl(Ct)}catch{}}var Wl,Vl,Ct,Kl,Ht,At,Cn,Ke=j(()=>{"use strict";g();Q();Wl="9d1c250a-e61b-44d9-88ed-5944d1962f5e",Vl="https://console.anthropic.com/v1/oauth/token",Ct=Ll(Gl(),".vibespot","claude-oauth.json"),Kl=300*1e3,Ht={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},At="You are Claude Code, Anthropic's official CLI for Claude.";Cn=null});import{readFileSync as Xl}from"fs";import{basename as Ql}from"path";async function oi(e){let t=si.get(e);if(t&&t.expiresAt-Date.now()>tc)return t;let n=await fetch(`${Ye}/localdevauth/v1/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({encodedOAuthRefreshToken:e})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(n.status===401||n.status===403?"Invalid or expired Personal Access Key":`Token exchange failed (${n.status}): ${i.slice(0,200)}`)}let s=await n.json(),o={accessToken:s.oauthAccessToken,expiresAt:s.expiresAtMillis,hubId:s.hubId,hubName:s.hubName||""};return si.set(e,o),o}async function kt(e){let{accessToken:t}=await oi(e);return{Authorization:`Bearer ${t}`}}function Pn(e){return e.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function nc(e){return e.startsWith("pat-eu1-")?"eu1":e.startsWith("pat-na1-")?"na1":e.startsWith("CiRldTE")?"eu1":"na1"}function sc(e){return new Promise(t=>setTimeout(t,e))}async function Yt(e,t){let n=`HTTP ${e.status}`,s,o;try{let i=await e.json();if(i.message&&typeof i.message=="string"&&(n=i.message),i.category&&typeof i.category=="string"&&(s=i.category),i.errors&&Array.isArray(i.errors)&&i.errors.length>0){let a=i.errors[0];o=a.message||JSON.stringify(a)}}catch{try{let i=await e.text();i&&(n=i.slice(0,500))}catch{}}return{status:e.status,message:t?`${n} (${t})`:n,category:s,detail:o}}async function zt(e,t,n=Zl){for(let s=0;s<=n;s++){let o=await fetch(e,t);if(o.status===429||o.status>=500&&s<n){let i=ec*Math.pow(2,s);await sc(i);continue}return o}return fetch(e,t)}async function Mn(e){let t=await oi(e),n=`${Ye}/account-info/v3/details`,s=await zt(n,{headers:await kt(e)});if(!s.ok){let r=await Yt(s);throw new Error(`Failed to get account info: ${r.message}`)}let o=await s.json(),i=String(o.portalId||t.hubId||""),a=t.hubName||o.uiDomain||i;return{portalId:i,portalName:a,dataCenter:nc(e)}}async function ii(e,t,n){let s=Xl(n),o=Ql(n),i=new FormData,a=new Blob([s]);i.append("file",a,o);let r=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,l=await zt(r,{method:"PUT",headers:await kt(e),body:i});if(!l.ok){let c=await Yt(l,t);return{success:!1,path:t,error:c}}return{success:!0,path:t}}async function js(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"DELETE",headers:await kt(e)});if(!s.ok&&s.status!==404){let o=await Yt(s,t);throw new Error(`Failed to delete ${t}: ${o.message}`)}}async function ri(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(!s.ok){let i=await Yt(s,t);throw new Error(`Failed to download ${t}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function On(e,t){let n=`${Ye}/cms/v3/source-code/published/metadata/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(s.status===404)return null;if(!s.ok){let o=await Yt(s,t);throw new Error(`Failed to get metadata for ${t}: ${o.message}`)}return await s.json()}async function ai(e){let t=await kt(e),n=[`${Ye}/cms/v3/source-code/published/metadata`,`${Ye}/cms/v3/source-code/published/metadata/`,`${Ye}/designmanager/v1/portals/content/listing`];for(let s of n)try{let o=await fetch(s,{method:"GET",headers:t});if(o.ok){let i=await o.json(),a=i.children||i.objects||(Array.isArray(i)?i:null);if(a&&a.length>0)return a.filter(r=>r.folder)}}catch{}return[]}var Ye,Zl,ec,tc,si,pt=j(()=>{"use strict";g();Ye="https://api.hubapi.com",Zl=3,ec=1e3,tc=300*1e3,si=new Map});var pi={};nt(pi,{fetchTheme:()=>qt});import{mkdirSync as mi,writeFileSync as ac}from"fs";import{join as lc,dirname as cc}from"path";async function Ls(e,t){let n=await On(e,t);if(!n)return[];if(!n.folder)return[n.path||t];let s=[],o=n.children||[];for(let i of o){let a=typeof i=="string"?i:i.name;if(!a)continue;let r=`${t}/${a}`;if(typeof i=="string")s.push(...await Ls(e,r));else{let l=i;l.folder?s.push(...await Ls(e,l.path||r)):s.push(l.path||r)}}return s}async function dc(e,t,n){let s=0;async function o(){for(;s<e.length;){let a=s++;await n(e[a])}}let i=Array.from({length:Math.min(t,e.length)},()=>o());await Promise.all(i)}async function qt(e,t,n,s={}){let o=s.concurrency??5,i=await Ls(e,t);if(i.length===0)throw new Error(`Theme "${t}" not found on HubSpot or is empty`);mi(n,{recursive:!0}),await dc(i,o,async a=>{let r=a.startsWith(t+"/")?a.slice(t.length+1):a,l=lc(n,r);mi(cc(l),{recursive:!0});let c=await ri(e,a);ac(l,c),s.onFile?.(r)})}var Jn=j(()=>{"use strict";g();pt()});function Tt(e){let t=fi.get(e);if(t!==void 0)return t;try{t=A(vn(e))}catch{t=""}return fi.set(e,t),t}function oe(){return Tt("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function Gs(){return Tt("design-guide.md")}function Us(){return Tt("content-guide.md")}function Ee(){return Tt("hubspot-rules.md")}function Bs(){return Tt("humanify-guide.md")}function Ws(e){let t=Tt("page-types.md");if(!t)return"";let s={landing_page:"## Landing Page",blog_post:"## Blog Post",website_page:"## Website Page",module_only:"## Module Only"}[e];if(!s)return"";let o=t.indexOf(s);if(o<0)return"";let i=t.indexOf(`
|
|
2
|
-
## `,o+s.length);return i>=0?t.slice(o,i).trim():t.slice(o).trim()}function
|
|
1
|
+
var jl=Object.defineProperty;var D=(e,t)=>()=>(e&&(t=e(e=0)),t);var nt=(e,t)=>{for(var n in t)jl(e,n,{get:t[n],enumerable:!0})};import cm from"path";import{fileURLToPath as um}from"url";var g=D(()=>{"use strict"});import{readFileSync as Ts,writeFileSync as Fl,mkdirSync as Ko,existsSync as Sn}from"fs";import{dirname as Jl,join as Ve}from"path";function k(e){return Ts(e,"utf-8")}function U(e,t){Ko(Jl(e),{recursive:!0}),Fl(e,t,"utf-8")}function b(e){return Sn(e)}function Ae(e){Ko(e,{recursive:!0})}function vn(e){let t=[Ve(import.meta.dirname,"../../assets",e),Ve(import.meta.dirname,"../assets",e),Ve(process.cwd(),"assets",e)];for(let n of t)if(Sn(n))return n;throw new Error(`Asset not found: ${e}`)}function wt(){if(xt)return xt;let e=[Ve(import.meta.dirname,"../../package.json"),Ve(import.meta.dirname,"../package.json"),Ve(process.cwd(),"package.json")];for(let t of e)if(Sn(t))try{let n=JSON.parse(Ts(t,"utf-8"));if(n.name==="vibespot"&&n.version)return xt=n.version,xt}catch{}return xt="dev",xt}function Yo(){if(bn)return bn;let e=[Ve(import.meta.dirname,"../../CHANGELOG.md"),Ve(import.meta.dirname,"../CHANGELOG.md"),Ve(process.cwd(),"CHANGELOG.md")];for(let t of e)if(Sn(t))try{return bn=Ts(t,"utf-8"),bn}catch{}return""}var xt,bn,Q=D(()=>{"use strict";g();xt="";bn=""});import{execSync as zo}from"child_process";function E(e,t={}){try{return{stdout:zo(e,{encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:12e4,...t}).trim(),stderr:"",success:!0}}catch(n){let s=n,o=(s.stdout??"").toString().trim(),i=(s.stderr??"").toString().trim();return{stdout:o,stderr:i,success:!1}}}function qo(e,t={}){try{return zo(e,{stdio:"inherit",timeout:3e5,...t}),!0}catch{return!1}}var ut=D(()=>{"use strict";g()});var Zo={};nt(Zo,{addHubSpotAccount:()=>Jt,getActiveHubSpotAccount:()=>st,getApiKeyForEngine:()=>ge,getConfigDir:()=>Ll,getHubSpotPak:()=>he,isCliToolEnabled:()=>Dt,loadConfig:()=>_,maskApiKey:()=>wn,removeHubSpotAccount:()=>$s,saveConfig:()=>K,setActiveHubSpotAccount:()=>Es,setCliToolEnabled:()=>_s});import{join as Xo}from"path";import{homedir as Dl}from"os";import{chmodSync as Hl}from"fs";function _(){if(!b(xn))return{};try{let e=JSON.parse(k(xn));return e.aiEngine==="api"&&(e.aiEngine="anthropic-api"),e}catch{return{}}}function ge(e,t){let n=t||_();switch(e){case"anthropic-api":case"api":return n.anthropicApiKey||process.env.ANTHROPIC_API_KEY;case"openai-api":return n.openaiApiKey||process.env.OPENAI_API_KEY;case"gemini-api":return n.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY;default:return}}function wn(e){return e.length<=12?"***":e.slice(0,7)+"..."+e.slice(-4)}function K(e){let n={..._(),...e};if(U(xn,JSON.stringify(n,null,2)),process.platform!=="win32")try{Hl(xn,384)}catch{}}function Ll(){return Qo}function st(){let e=_();if(!e.hubspotAccounts?.length)return null;let t=e.activeHubSpotAccount;if(t){let n=e.hubspotAccounts.find(s=>s.portalId===t);if(n)return n}return e.hubspotAccounts[0]||null}function Jt(e,t,n,s){let i=_().hubspotAccounts||[],a=i.findIndex(l=>l.portalId===t),r={portalId:t,portalName:n,personalAccessKey:e,dataCenter:s,addedAt:new Date().toISOString()};a>=0?i[a]=r:i.push(r),K({hubspotAccounts:i,activeHubSpotAccount:t})}function $s(e){let t=_(),n=(t.hubspotAccounts||[]).filter(o=>o.portalId!==e),s={hubspotAccounts:n};t.activeHubSpotAccount===e&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),K(s)}function Es(e){K({activeHubSpotAccount:e})}function he(){return st()?.personalAccessKey||null}function Dt(e){return _().enabledCLITools?.includes(e)??!1}function _s(e,t){let n=_(),s=new Set(n.enabledCLITools||[]);t?s.add(e):s.delete(e),K({enabledCLITools:[...s]})}var Qo,xn,Z=D(()=>{"use strict";g();Q();Qo=Xo(Dl(),".vibespot"),xn=Xo(Qo,"config.json")});var Os={};nt(Os,{OAUTH_EXTRA_HEADERS:()=>Ht,OAUTH_SYSTEM_PREFIX:()=>At,clearOAuthTokens:()=>kn,getOAuthTokenInfo:()=>Lt,getValidAccessToken:()=>Ms,hasValidOAuthToken:()=>Re,saveInitialToken:()=>Ps});import{join as Ul}from"path";import{homedir as Gl}from"os";import{chmodSync as Bl,unlinkSync as Wl}from"fs";function An(){if(!b(Ct))return null;try{return JSON.parse(k(Ct))}catch{return null}}function ei(e){if(U(Ct,JSON.stringify(e,null,2)),process.platform!=="win32")try{Bl(Ct,384)}catch{}}async function zl(e){let t=await fetch(Kl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:e,client_id:Vl})});if(!t.ok)throw kn(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await t.json();ei({access_token:n.access_token,refresh_token:n.refresh_token||e,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function Ps(e,t=""){ei({access_token:e,refresh_token:t,expires_at:Date.now()+28800*1e3})}function Re(){let e=An();return e?e.expires_at>Date.now():!1}async function Ms(){let e=An();if(!e)return null;if(e.expires_at-Date.now()>Yl)return e.access_token;if(e.refresh_token){Cn||(Cn=zl(e.refresh_token).finally(()=>{Cn=null}));try{await Cn}catch{return null}return An()?.access_token??null}return e.access_token}function Lt(){let e=An();return e?{expiresAt:new Date(e.expires_at).toISOString()}:null}function kn(){if(b(Ct))try{Wl(Ct)}catch{}}var Vl,Kl,Ct,Yl,Ht,At,Cn,Ke=D(()=>{"use strict";g();Q();Vl="9d1c250a-e61b-44d9-88ed-5944d1962f5e",Kl="https://console.anthropic.com/v1/oauth/token",Ct=Ul(Gl(),".vibespot","claude-oauth.json"),Yl=300*1e3,Ht={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},At="You are Claude Code, Anthropic's official CLI for Claude.";Cn=null});import{readFileSync as Ql}from"fs";import{basename as Zl}from"path";async function ii(e){let t=oi.get(e);if(t&&t.expiresAt-Date.now()>nc)return t;let n=await fetch(`${Ye}/localdevauth/v1/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({encodedOAuthRefreshToken:e})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(n.status===401||n.status===403?"Invalid or expired Personal Access Key":`Token exchange failed (${n.status}): ${i.slice(0,200)}`)}let s=await n.json(),o={accessToken:s.oauthAccessToken,expiresAt:s.expiresAtMillis,hubId:s.hubId,hubName:s.hubName||""};return oi.set(e,o),o}async function kt(e){let{accessToken:t}=await ii(e);return{Authorization:`Bearer ${t}`}}function Pn(e){return e.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function sc(e){return e.startsWith("pat-eu1-")?"eu1":e.startsWith("pat-na1-")?"na1":e.startsWith("CiRldTE")?"eu1":"na1"}function oc(e){return new Promise(t=>setTimeout(t,e))}async function Yt(e,t){let n=`HTTP ${e.status}`,s,o;try{let i=await e.json();if(i.message&&typeof i.message=="string"&&(n=i.message),i.category&&typeof i.category=="string"&&(s=i.category),i.errors&&Array.isArray(i.errors)&&i.errors.length>0){let a=i.errors[0];o=a.message||JSON.stringify(a)}}catch{try{let i=await e.text();i&&(n=i.slice(0,500))}catch{}}return{status:e.status,message:t?`${n} (${t})`:n,category:s,detail:o}}async function zt(e,t,n=ec){for(let s=0;s<=n;s++){let o=await fetch(e,t);if(o.status===429||o.status>=500&&s<n){let i=tc*Math.pow(2,s);await oc(i);continue}return o}return fetch(e,t)}async function Mn(e){let t=await ii(e),n=`${Ye}/account-info/v3/details`,s=await zt(n,{headers:await kt(e)});if(!s.ok){let r=await Yt(s);throw new Error(`Failed to get account info: ${r.message}`)}let o=await s.json(),i=String(o.portalId||t.hubId||""),a=t.hubName||o.uiDomain||i;return{portalId:i,portalName:a,dataCenter:sc(e)}}async function ri(e,t,n){let s=Ql(n),o=Zl(n),i=new FormData,a=new Blob([s]);i.append("file",a,o);let r=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,l=await zt(r,{method:"PUT",headers:await kt(e),body:i});if(!l.ok){let c=await Yt(l,t);return{success:!1,path:t,error:c}}return{success:!0,path:t}}async function Fs(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"DELETE",headers:await kt(e)});if(!s.ok&&s.status!==404){let o=await Yt(s,t);throw new Error(`Failed to delete ${t}: ${o.message}`)}}async function ai(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(!s.ok){let i=await Yt(s,t);throw new Error(`Failed to download ${t}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function On(e,t){let n=`${Ye}/cms/v3/source-code/published/metadata/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(s.status===404)return null;if(!s.ok){let o=await Yt(s,t);throw new Error(`Failed to get metadata for ${t}: ${o.message}`)}return await s.json()}async function li(e){let t=await kt(e),n=[`${Ye}/cms/v3/source-code/published/metadata`,`${Ye}/cms/v3/source-code/published/metadata/`,`${Ye}/designmanager/v1/portals/content/listing`];for(let s of n)try{let o=await fetch(s,{method:"GET",headers:t});if(o.ok){let i=await o.json(),a=i.children||i.objects||(Array.isArray(i)?i:null);if(a&&a.length>0)return a.filter(r=>r.folder)}}catch{}return[]}var Ye,ec,tc,nc,oi,pt=D(()=>{"use strict";g();Ye="https://api.hubapi.com",ec=3,tc=1e3,nc=300*1e3,oi=new Map});var fi={};nt(fi,{fetchTheme:()=>qt});import{mkdirSync as pi,writeFileSync as lc}from"fs";import{join as cc,dirname as dc}from"path";async function Ls(e,t){let n=await On(e,t);if(!n)return[];if(!n.folder)return[n.path||t];let s=[],o=n.children||[];for(let i of o){let a=typeof i=="string"?i:i.name;if(!a)continue;let r=`${t}/${a}`;if(typeof i=="string")s.push(...await Ls(e,r));else{let l=i;l.folder?s.push(...await Ls(e,l.path||r)):s.push(l.path||r)}}return s}async function uc(e,t,n){let s=0;async function o(){for(;s<e.length;){let a=s++;await n(e[a])}}let i=Array.from({length:Math.min(t,e.length)},()=>o());await Promise.all(i)}async function qt(e,t,n,s={}){let o=s.concurrency??5,i=await Ls(e,t);if(i.length===0)throw new Error(`Theme "${t}" not found on HubSpot or is empty`);pi(n,{recursive:!0}),await uc(i,o,async a=>{let r=a.startsWith(t+"/")?a.slice(t.length+1):a,l=cc(n,r);pi(dc(l),{recursive:!0});let c=await ai(e,a);lc(l,c),s.onFile?.(r)})}var Jn=D(()=>{"use strict";g();pt()});function Tt(e){let t=gi.get(e);if(t!==void 0)return t;try{t=k(vn(e))}catch{t=""}return gi.set(e,t),t}function oe(){return Tt("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function Us(){return Tt("design-guide.md")}function Gs(){return Tt("content-guide.md")}function Ee(){return Tt("hubspot-rules.md")}function Bs(){return Tt("humanify-guide.md")}function Ws(e){let t=Tt("page-types.md");if(!t)return"";let s={landing_page:"## Landing Page",blog_post:"## Blog Post",website_page:"## Website Page",module_only:"## Module Only"}[e];if(!s)return"";let o=t.indexOf(s);if(o<0)return"";let i=t.indexOf(`
|
|
2
|
+
## `,o+s.length);return i>=0?t.slice(o,i).trim():t.slice(o).trim()}function hi(e){return`You are a HubSpot CMS expert converting React/Tailwind pages to native HubSpot modules.
|
|
3
3
|
|
|
4
4
|
## Rules
|
|
5
5
|
Follow the conversion guide below EXACTLY. Key rules:
|
|
@@ -19,7 +19,7 @@ Follow the conversion guide below EXACTLY. Key rules:
|
|
|
19
19
|
${Ee()}
|
|
20
20
|
|
|
21
21
|
## Conversion Guide
|
|
22
|
-
${e}`}function
|
|
22
|
+
${e}`}function yi(e,t,n){return`Convert this React component to a HubSpot module named "${t}".
|
|
23
23
|
|
|
24
24
|
Return a JSON object with these keys:
|
|
25
25
|
- fieldsJson: complete fields.json content (as JSON string)
|
|
@@ -34,7 +34,7 @@ ${n}
|
|
|
34
34
|
React component source:
|
|
35
35
|
${e}
|
|
36
36
|
|
|
37
|
-
Return ONLY valid JSON, no markdown fences.`}function
|
|
37
|
+
Return ONLY valid JSON, no markdown fences.`}function bi(e,t,n){return`Create a shared CSS file for a HubSpot CMS landing page.
|
|
38
38
|
|
|
39
39
|
Extract the design system from the source CSS and Tailwind config below.
|
|
40
40
|
Use the class prefix ".${n}-" for all custom classes.
|
|
@@ -58,7 +58,7 @@ ${e}
|
|
|
58
58
|
Tailwind config:
|
|
59
59
|
${t}
|
|
60
60
|
|
|
61
|
-
Return ONLY the CSS content, no markdown fences.`}function
|
|
61
|
+
Return ONLY the CSS content, no markdown fences.`}function Si(e,t,n){return`Create a shared vanilla JS file for a HubSpot CMS landing page.
|
|
62
62
|
|
|
63
63
|
Convert the React hooks and interactive components below to plain JavaScript.
|
|
64
64
|
Use the class prefix "${n}-" to match the CSS.
|
|
@@ -76,7 +76,7 @@ ${e}
|
|
|
76
76
|
Interactive component sources:
|
|
77
77
|
${t}
|
|
78
78
|
|
|
79
|
-
Return ONLY the JavaScript content, no markdown fences.`}function
|
|
79
|
+
Return ONLY the JavaScript content, no markdown fences.`}function vi(e,t,n){return`Create a HubSpot page template that assembles these modules:
|
|
80
80
|
|
|
81
81
|
${e.map((s,o)=>`${o+1}. ${s}.module`).join(`
|
|
82
82
|
`)}
|
|
@@ -91,21 +91,21 @@ Template requirements:
|
|
|
91
91
|
- Each module in its own dnd_section with padding zeroed and full_width=true
|
|
92
92
|
- dnd_area label: "${t} Landing Page"
|
|
93
93
|
|
|
94
|
-
Return ONLY the template HTML content, no markdown fences.`}var
|
|
95
|
-
`),"utf-8")}function Ks(e,t){if(!_e()||!Qe(He(e,".git"))||(
|
|
96
|
-
`)){let i=o.split("|");if(i.length<4)continue;let a=parseInt(i[3],10)*1e3;s.push({hash:i[0],fullHash:i[1],message:i[2],timestamp:a,date:new Date(a).toISOString()})}return s}function
|
|
97
|
-
`)){let r=a.split("|");if(r.length<4)continue;let l=parseInt(r[3],10)*1e3;i.push({hash:r[0],fullHash:r[1],message:r[2],timestamp:l,date:new Date(l).toISOString()})}return i}function zi(e,t){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(t))return{success:!1,error:"Invalid commit hash"};let n=$(`git cat-file -t ${t}`,{cwd:e});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${t} not found`};let s=$(`git log --format="%s" -1 ${t}`,{cwd:e}),o=s.success?s.stdout:t,i=$(`git checkout ${t} -- .`,{cwd:e});if(!i.success)return{success:!1,error:`Checkout failed: ${i.stderr}`};let a=`Rollback to: ${o}`.slice(0,72);return $(`git commit -m "${a.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}function qi(e,t,n,s){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(n))return{success:!1,error:"Invalid commit hash"};let o=$(`git cat-file -t ${n}`,{cwd:e});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=$(`git log --format="%s" -1 ${n}`,{cwd:e}),a=i.success?i.stdout:n,r=0;for(let d of s)$(`git checkout ${n} -- "${d}"`,{cwd:e}).success&&r++;if(r===0)return{success:!1,error:"No files could be restored from that commit"};$("git add -A",{cwd:e});let c=`${`[${t}] `}Rollback to: ${a}`.slice(0,72);return $(`git commit -m "${c.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}var Xn,Zt=j(()=>{"use strict";g();ut();Xn=null});import{readFileSync as Lc,existsSync as Xi,writeFileSync as Gc,mkdirSync as Uc,rmSync as Bc}from"fs";import{join as Zn}from"path";function ft(e){let t=S();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function it(){let e=S();if(!e)return;let t=Ce();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function rt(e,t,n){let s=S();if(!s)return;let o={role:e,content:t,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),it(),Wc()}function Qi(e){let t=S();t&&(t.assets||(t.assets=[]),t.assets.push(e),t.updatedAt=Date.now(),D())}function Le(e){let t=S();if(t){if(e.sharedCss!==void 0&&(t.sharedCss=e.sharedCss),e.sharedJs!==void 0&&(t.sharedJs=e.sharedJs),e.template!==void 0&&(t.template=e.template),e.modules)for(let n of e.modules){let s=n.moduleName.toLowerCase(),o=t.modules.findIndex(i=>i.moduleName.toLowerCase()===s);o>=0?t.modules[o]=n:(t.modules.push(n),t.moduleOrder.some(i=>i.toLowerCase()===s)||t.moduleOrder.push(n.moduleName))}t.updatedAt=Date.now(),it()}}function Et(e){let t=S();t&&(t.moduleOrder=e,t.updatedAt=Date.now(),it())}function Zi(e){let t=S();if(t){t.modules=t.modules.filter(n=>n.moduleName!==e),t.moduleOrder=t.moduleOrder.filter(n=>n!==e);for(let n of t.templates)n.modules=n.modules.filter(s=>s.moduleName!==e),n.moduleOrder=n.moduleOrder.filter(s=>s!==e);if(t.themePath){let n=Zn(t.themePath,"modules",`${e}.module`);Xi(n)&&Bc(n,{recursive:!0,force:!0})}t.updatedAt=Date.now(),it()}}function er(e){let t=S();t&&(t.moduleOrder=t.moduleOrder.filter(n=>n!==e),t.updatedAt=Date.now(),it())}function tr(e,t,n){let s=S();if(!s)return;let o=s.modules.find(i=>i.moduleName===e);if(o)try{let i=JSON.parse(o.fieldsJson);sr(i,t,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),it()}catch{}}function me(){let e=S();if(!e)return[];let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function Wc(){let e=S();if(e)try{let t=Zn(e.themePath,".vibespot");Uc(t,{recursive:!0});let n={sessionId:e.id,themeName:e.themeName,messages:e.messages,updatedAt:Date.now()};Gc(Zn(t,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function nr(e){let t=Zn(e,".vibespot","chat.json");if(!Xi(t))return[];try{let n=JSON.parse(Lc(t,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function sr(e,t,n){let s=t.split("."),o=s[0],i=e.find(a=>a.name===o);i&&(s.length===1?i.default=n:i.children&&sr(i.children,s.slice(1).join("."),n))}var es=j(()=>{"use strict";g();tn();en()});import{existsSync as Ys,rmSync as zs}from"fs";import{join as nn}from"path";function ts(e){if(e.templates&&e.templates.length>0)return;if(!e.modules||e.modules.length===0){e.templates=[],e.activeTemplateId="";return}let t=`lp-${e.themeName}`,n={id:t,label:`${e.themeName} Landing Page`,pageType:"landing_page",templateFile:`templates/lp-${e.themeName}.html`,modules:[...e.modules],moduleOrder:[...e.moduleOrder],sharedCss:e.sharedCss||"",sharedJs:e.sharedJs||"",template:e.template||"",messages:[...e.messages]};e.templates=[n],e.activeTemplateId=t}function Ce(){let e=S();return!e||!e.activeTemplateId||!e.templates?.length?null:e.templates.find(t=>t.id===e.activeTemplateId)||null}function qs(e){let t=S();if(!t)return!1;let n=t.templates.find(s=>s.id===e);return n?(t.activeTemplateId=e,ft(n),t.updatedAt=Date.now(),!0):!1}function or(e,t){let n=S();if(!n)throw new Error("No active session");let s=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),i=`${e==="blog_post"?"bp":e==="website_page"?"wp":e==="module_only"?"mo":"lp"}-${s}`,a={id:i,label:t,pageType:e,templateFile:e==="module_only"?"":`templates/${i}.html`,modules:[],moduleOrder:[],sharedCss:"",sharedJs:"",template:"",messages:[]};return n.templates.push(a),n.activeTemplateId=i,ft(a),n.updatedAt=Date.now(),a}function ir(e,t){let n=S();if(!n)return null;let s=n.templates.find(c=>c.id===e);if(!s)return null;let o=t||`${s.label} (Copy)`,i=o.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),r=`${s.pageType==="blog_post"?"bp":s.pageType==="website_page"?"wp":s.pageType==="module_only"?"mo":"lp"}-${i}`,l={id:r,label:o,pageType:s.pageType,templateFile:s.pageType==="module_only"?"":`templates/${r}.html`,modules:s.modules.map(c=>({...c})),moduleOrder:[...s.moduleOrder],sharedCss:s.sharedCss,sharedJs:s.sharedJs,template:s.template,messages:[]};return n.templates.push(l),n.activeTemplateId=r,ft(l),n.updatedAt=Date.now(),l}function rr(e,t){let n=S();if(!n)return!1;let s=n.templates.find(o=>o.id===e);return s?(s.label=t,n.updatedAt=Date.now(),!0):!1}function ar(e,t=!1){let n=S();if(!n)return!1;let s=n.templates.findIndex(i=>i.id===e);if(s<0)return!1;let o=n.templates.splice(s,1)[0];if(n.themePath){let i=nn(n.themePath,"templates"),a=`${o.id}.html`,r=nn(i,a);if(Ys(r)&&zs(r,{force:!0}),o.pageType==="blog_post"){let l=nn(i,`${o.id}-listing.html`);Ys(l)&&zs(l,{force:!0})}}if(t&&o.modules.length>0){let i=new Set;for(let r of n.templates)for(let l of r.modules)i.add(l.moduleName);for(let r of n.modules)i.add(r.moduleName);let a=o.modules.map(r=>r.moduleName).filter(r=>!i.has(r));if(n.themePath&&a.length>0){let r=nn(n.themePath,"modules");for(let l of a){let c=nn(r,`${l}.module`);Ys(c)&&zs(c,{recursive:!0,force:!0})}}}return n.activeTemplateId===e&&(n.templates.length>0?qs(n.templates[0].id):(n.activeTemplateId="",n.modules=[],n.moduleOrder=[],n.sharedCss="",n.sharedJs="",n.template="",n.messages=[])),n.updatedAt=Date.now(),!0}function at(){let e=S();if(!e)return[];let t=new Map;for(let n of e.templates)for(let s of n.modules){let o=t.get(s.moduleName);o?o.usedIn.push(n.label):t.set(s.moduleName,{module:s,usedIn:[n.label]})}return Array.from(t.values())}var en=j(()=>{"use strict";g();tn();es()});import{readFileSync as Ze,readdirSync as to,existsSync as ye,writeFileSync as ns,mkdirSync as lr,rmSync as Xs,renameSync as Qs}from"fs";import{join as re,dirname as Vc}from"path";import{homedir as Kc}from"os";function ss(){if(_t)return _t;try{return ye(Zs)?(_t=JSON.parse(Ze(Zs,"utf-8")),_t):eo()}catch{return eo()}}function os(e){_t=e;try{lr(ne,{recursive:!0}),ns(Zs,JSON.stringify(e),"utf-8")}catch{}}function eo(){if(!ye(ne))return[];let e=[];for(let t of to(ne).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(Ze(re(ne,t),"utf-8")),s=n.templates||[];e.push({id:n.id,themeName:n.themeName,updatedAt:n.updatedAt,moduleCount:s.reduce((o,i)=>o+(i.modules?.length||0),0),templateCount:s.length})}catch{}return _t=e,os(e),e}function Yc(e){let t=ss(),n=e.templates||[],s={id:e.id,themeName:e.themeName,updatedAt:e.updatedAt,moduleCount:n.reduce((i,a)=>i+(a.modules?.length||0),0),templateCount:n.length},o=t.findIndex(i=>i.id===e.id);o>=0?t[o]=s:t.push(s),os(t)}function zc(e){let t=ss().filter(n=>n.id!==e);os(t)}function qc(e){let t=ss().filter(n=>n.themeName!==e);os(t)}function S(){return be}function Xc(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function sn(e,t){let n={id:Xc(),themePath:e,themeName:t,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return be=n,Qn(e),n}function D(){if(!be)return;lr(ne,{recursive:!0});let e=re(ne,`${be.id}.json`);ns(e,JSON.stringify(be,null,2),"utf-8"),Yc(be)}function is(e){let t=re(ne,e+".json");if(!ye(t))return null;try{let n=JSON.parse(Ze(t,"utf-8"));return n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),ts(n),be=n,n}catch{return null}}function Pt(){return ye(ne)?ss():[]}function cr(e,t=!1){let n=re(ne,e+".json"),s="";if(t)try{let o=JSON.parse(Ze(n,"utf-8"));s=o.themeName||"",o.themePath&&ye(o.themePath)&&Xs(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(Ze(n,"utf-8")).themeName||""}catch{}try{ye(n)&&Xs(n)}catch{}if(s&&ye(ne)){for(let o of to(ne).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(Ze(re(ne,o),"utf-8")).themeName===s&&Xs(re(ne,o))}catch{}qc(s)}else zc(e);be?.id===e&&(be=null)}function dr(e,t){let n=re(ne,e+".json");if(!ye(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(Ze(n,"utf-8"))}catch{return{ok:!1,error:"Failed to read session"}}let o=s.themeName;if(o===t)return{ok:!0};let i=s.themePath,a=re(Vc(i),t);if(ye(i)){if(ye(a))return{ok:!1,error:"A project with that name already exists"};try{Qs(i,a)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let r=re(a,"css",`${o}-theme.css`),l=re(a,"css",`${t}-theme.css`);if(ye(r))try{Qs(r,l)}catch{}let c=re(a,"js",`${o}-animations.js`),d=re(a,"js",`${t}-animations.js`);if(ye(c))try{Qs(c,d)}catch{}let u=re(a,"theme.json");if(ye(u))try{let m=JSON.parse(Ze(u,"utf-8"));m.label=t,m.name=t,ns(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if(ye(ne))for(let r of to(ne).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(Ze(re(ne,r),"utf-8"));l.themeName===o&&(l.themeName=t,l.themePath=a,l.updatedAt=Date.now(),ns(re(ne,r),JSON.stringify(l,null,2),"utf-8"))}catch{}return be&&be.themeName===o&&(be.themeName=t,be.themePath=a,be.updatedAt=Date.now()),eo(),{ok:!0}}var ne,Zs,_t,be,tn=j(()=>{"use strict";g();Zt();en();ne=re(Kc(),".vibespot","sessions"),Zs=re(ne,"_index.json"),_t=null;be=null});import{readFileSync as no,readdirSync as rn,existsSync as pe,writeFileSync as Ie,mkdirSync as on,rmSync as ur}from"fs";import{join as M}from"path";function ae(e){try{return no(e,"utf-8")}catch{return""}}function Qc(e){let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function Zc(e,t){let n=ae(e);if(!n||t==="home.html"||t.endsWith("-listing.html"))return null;let s=t.replace(/\.html$/,""),o="landing_page";s.startsWith("bp-")?o="blog_post":s.startsWith("wp-")?o="website_page":s.startsWith("mo-")&&(o="module_only");let i=s,a=n.match(/<!--[\s\S]*?label:\s*"?([^"\n]+)"?\s*[\s\S]*?-->/);a&&(i=a[1].trim());let r=/dnd_module\s+path=["']\.\.\/modules\/(.+?)\.module["']/g,l=[],c;for(;(c=r.exec(n))!==null;)l.push(c[1]);return{id:s,label:i,pageType:o,moduleNames:l,templateContent:n,filename:t}}function ed(e,t,n,s,o){if(!pe(e))return[];let i=[],a=rn(e).filter(r=>r.endsWith(".html")&&r!=="home.html");for(let r of a){let l=M(e,r),c=Zc(l,r);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let f=t.get(m);f&&(d.push(f),u.push(m))}i.push({id:c.id,label:c.label,pageType:c.pageType,templateFile:`templates/${c.filename}`,modules:d,moduleOrder:u,sharedCss:n,sharedJs:s,template:c.templateContent,messages:i.length===0?[...o]:[]})}return i}function an(e){let t=S();if(!t)return;let n=nr(e);n.length>0&&t.messages.length===0&&(t.messages=n),Qn(e);let s=M(e,"modules");if(!pe(s))return;let o=rn(s,{withFileTypes:!0});for(let y of o){if(!y.isDirectory()||!y.name.endsWith(".module"))continue;let v=M(s,y.name),C=y.name.replace(/\.module$/,""),k={moduleName:C,fieldsJson:ae(M(v,"fields.json")),metaJson:ae(M(v,"meta.json")),moduleHtml:ae(M(v,"module.html")),moduleCss:ae(M(v,"module.css")),moduleJs:ae(M(v,"module.js"))||void 0};k.fieldsJson&&k.moduleHtml&&(t.modules.push(k),t.moduleOrder.push(C))}let i=M(e,"css"),a=M(e,"js"),r="",l="";if(pe(i)){let y=rn(i).filter(v=>v.endsWith("-theme.css"));y.length>0&&(r=ae(M(i,y[0])),t.sharedCss=r)}if(pe(a)){let y=rn(a).filter(v=>v.endsWith("-animations.js"));y.length>0&&(l=ae(M(a,y[0])),t.sharedJs=l)}let c=M(e,".vibespot","styleguide.md"),d=M(e,".vibespot","brandvoice.md"),u=M(e,".vibespot","theme-context.md");(pe(c)||pe(d)||pe(u))&&(t.brandAssets||(t.brandAssets={}),pe(c)&&(t.brandAssets.styleguide=ae(c)),pe(d)&&(t.brandAssets.brandvoice=ae(d)),pe(u)&&(t.brandAssets.themeContext=ae(u)));let m=M(e,"templates"),f=new Map(t.modules.map(y=>[y.moduleName,y])),h=ed(m,f,r,l,t.messages);if(h.length>0){t.templates=h,t.activeTemplateId=h[0].id;let y=h[0].moduleOrder;if(y.length>0){let v=new Set(t.moduleOrder),C=y.filter(k=>v.has(k));for(let k of t.moduleOrder)C.includes(k)||C.push(k);t.moduleOrder=C}ft(h[0])}else t.templates||(t.templates=[]),t.activeTemplateId||(t.activeTemplateId=""),ts(t)}function lt(){let e=S();if(!e)return;let t=e.themePath,n=new Map;if(e.templates.length>0)for(let l of e.templates)for(let c of l.modules)n.set(c.moduleName,c);for(let l of e.modules)n.set(l.moduleName,l);let s=M(t,"modules");on(s,{recursive:!0});for(let l of n.values())on(M(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=M(s,`${l.moduleName}.module`);Ie(M(c,"fields.json"),l.fieldsJson,"utf-8"),Ie(M(c,"meta.json"),l.metaJson,"utf-8"),Ie(M(c,"module.html"),l.moduleHtml,"utf-8"),Ie(M(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ie(M(c,"module.js"),l.moduleJs,"utf-8")}if(e.sharedCss){let l=M(t,"css");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-theme.css`),e.sharedCss,"utf-8")}if(e.sharedJs){let l=M(t,"js");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-animations.js`),e.sharedJs,"utf-8")}let o=M(t,"templates");on(o,{recursive:!0});let i=M(o,"home.html");(e.templates.length>0||e.modules.length>0)&&pe(i)&&ur(i,{force:!0});let r=new Set;if(e.templates.length>0)for(let l of e.templates){if(l.pageType==="module_only"||l.modules.length===0)continue;let c=l.template||sd(l),d=mr(c,l.label,l.pageType),u=`${l.id}.html`;Ie(M(o,u),d,"utf-8"),r.add(u),l.pageType==="blog_post"&&(od(o,l),r.add(`${l.id}-listing.html`))}else if(e.modules.length>0){let l=e.template||id(),c=mr(l,`${e.themeName} Landing Page`),d=`lp-${e.themeName}.html`;Ie(M(o,d),c,"utf-8"),r.add(d)}try{for(let l of rn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!r.has(l)&&ur(M(o,l),{force:!0})}catch{}td(),nd()}function pr(){let e=S();e&&(e.modules=[],e.moduleOrder=[],e.sharedCss="",e.sharedJs="",e.template="",an(e.themePath),e.updatedAt=Date.now(),it())}function fr(){let e=S();if(!e)return;let t=Ce();if(!t)return;let n=e.themePath,s=M(n,"modules");t.modules=[];for(let o of t.moduleOrder){let i=M(s,`${o}.module`);if(!pe(i))continue;let a={moduleName:o,fieldsJson:ae(M(i,"fields.json")),metaJson:ae(M(i,"meta.json")),moduleHtml:ae(M(i,"module.html")),moduleCss:ae(M(i,"module.css")),moduleJs:ae(M(i,"module.js"))||void 0};a.fieldsJson&&a.moduleHtml&&t.modules.push(a)}if(t.templateFile){let o=M(n,t.templateFile);pe(o)&&(t.template=ae(o))}ft(t),e.updatedAt=Date.now()}function td(){let e=S();if(!e)return;let t=M(e.themePath,"templates","layouts","base.html");if(pe(t))try{let n=no(t,"utf-8");if(n.includes("template_js"))return;let s='{{ require_js(get_asset_url("../../js/main.js")) }}';n.includes(s)?n=n.replace(s,s+`
|
|
94
|
+
Return ONLY the template HTML content, no markdown fences.`}var gi,qe=D(()=>{"use strict";g();Q();gi=new Map});var Bi=D(()=>{"use strict";g()});import{existsSync as Qe,writeFileSync as Dc,mkdirSync as Hc}from"fs";import{join as He}from"path";function Vi(e){return/^[0-9a-f]{4,40}$/i.test(e)}function _e(){return Xn!==null||(Xn=E("git --version").success),Xn}function Qn(e){if(!_e())return!1;if(Qe(He(e,".git")))return Wi(e),!0;let t=E("git init",{cwd:e});return t.success?(Lc(e),Wi(e),E("git add -A",{cwd:e}),E('git commit -m "Initial theme"',{cwd:e}),!0):(console.warn(`[project-git] git init failed in ${e}: ${t.stderr}`),!1)}function Wi(e){let t=He(e,".vibespot");Qe(t)||Hc(t,{recursive:!0})}function Lc(e){let t=He(e,".gitignore");Dc(t,[".vibespot/","node_modules/",""].join(`
|
|
95
|
+
`),"utf-8")}function Ks(e,t){if(!_e()||!Qe(He(e,".git"))||(E("git add -A",{cwd:e}),E("git diff --cached --quiet",{cwd:e}).success))return null;let s=t.length>72?t.slice(0,69)+"...":t,o=E(`git commit -m "${s.replace(/"/g,'\\"')}"`,{cwd:e});if(!o.success)return console.warn(`[project-git] commit failed: ${o.stderr}`),null;let i=E("git rev-parse --short HEAD",{cwd:e});return i.success?i.stdout:null}function Ki(e,t,n,s){if(!_e()||!Qe(He(e,".git")))return null;for(let u of s){let m=He(e,u);Qe(m)&&E(`git add "${u}"`,{cwd:e})}if(E("git diff --cached --quiet",{cwd:e}).success)return null;let i=`[${t}] `,a=72-i.length,r=n.length>a?n.slice(0,a-3)+"...":n,l=i+r,c=E(`git commit -m "${l.replace(/"/g,'\\"')}"`,{cwd:e});if(!c.success)return console.warn(`[project-git] template commit failed: ${c.stderr}`),null;let d=E("git rev-parse --short HEAD",{cwd:e});return d.success?d.stdout:null}function Yi(e,t=50){if(!_e())return[];if(!Qe(He(e,".git")))return[];let n=E(`git log --pretty=format:"%h|%H|%s|%at" -n ${t}`,{cwd:e});if(!n.success||!n.stdout.trim())return[];let s=[];for(let o of n.stdout.split(`
|
|
96
|
+
`)){let i=o.split("|");if(i.length<4)continue;let a=parseInt(i[3],10)*1e3;s.push({hash:i[0],fullHash:i[1],message:i[2],timestamp:a,date:new Date(a).toISOString()})}return s}function zi(e,t,n=50){if(!_e())return[];if(!Qe(He(e,".git")))return[];let s=t.replace(/[[\]\\]/g,"\\$&"),o=E(`git log --grep="\\[${s}\\]" --pretty=format:"%h|%H|%s|%at" -n ${n}`,{cwd:e});if(!o.success||!o.stdout.trim())return[];let i=[];for(let a of o.stdout.split(`
|
|
97
|
+
`)){let r=a.split("|");if(r.length<4)continue;let l=parseInt(r[3],10)*1e3;i.push({hash:r[0],fullHash:r[1],message:r[2],timestamp:l,date:new Date(l).toISOString()})}return i}function qi(e,t){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Vi(t))return{success:!1,error:"Invalid commit hash"};let n=E(`git cat-file -t ${t}`,{cwd:e});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${t} not found`};let s=E(`git log --format="%s" -1 ${t}`,{cwd:e}),o=s.success?s.stdout:t,i=E(`git checkout ${t} -- .`,{cwd:e});if(!i.success)return{success:!1,error:`Checkout failed: ${i.stderr}`};let a=`Rollback to: ${o}`.slice(0,72);return E(`git commit -m "${a.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}function Xi(e,t,n,s){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Vi(n))return{success:!1,error:"Invalid commit hash"};let o=E(`git cat-file -t ${n}`,{cwd:e});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=E(`git log --format="%s" -1 ${n}`,{cwd:e}),a=i.success?i.stdout:n,r=0;for(let d of s)E(`git checkout ${n} -- "${d}"`,{cwd:e}).success&&r++;if(r===0)return{success:!1,error:"No files could be restored from that commit"};E("git add -A",{cwd:e});let c=`${`[${t}] `}Rollback to: ${a}`.slice(0,72);return E(`git commit -m "${c.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}var Xn,Zt=D(()=>{"use strict";g();ut();Xn=null});import{readFileSync as Uc,existsSync as Qi,writeFileSync as Gc,mkdirSync as Bc,rmSync as Wc}from"fs";import{join as Zn}from"path";function ft(e){let t=v();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function it(){let e=v();if(!e)return;let t=Ce();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function rt(e,t,n){let s=v();if(!s)return;let o={role:e,content:t,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),it(),Vc()}function Zi(e){let t=v();t&&(t.assets||(t.assets=[]),t.assets.push(e),t.updatedAt=Date.now(),L())}function Le(e){let t=v();if(t){if(e.sharedCss!==void 0&&(t.sharedCss=e.sharedCss),e.sharedJs!==void 0&&(t.sharedJs=e.sharedJs),e.template!==void 0&&(t.template=e.template),e.modules)for(let n of e.modules){let s=n.moduleName.toLowerCase(),o=t.modules.findIndex(i=>i.moduleName.toLowerCase()===s);o>=0?t.modules[o]=n:(t.modules.push(n),t.moduleOrder.some(i=>i.toLowerCase()===s)||t.moduleOrder.push(n.moduleName))}t.updatedAt=Date.now(),it()}}function Et(e){let t=v();t&&(t.moduleOrder=e,t.updatedAt=Date.now(),it())}function er(e){let t=v();if(t){t.modules=t.modules.filter(n=>n.moduleName!==e),t.moduleOrder=t.moduleOrder.filter(n=>n!==e);for(let n of t.templates)n.modules=n.modules.filter(s=>s.moduleName!==e),n.moduleOrder=n.moduleOrder.filter(s=>s!==e);if(t.themePath){let n=Zn(t.themePath,"modules",`${e}.module`);Qi(n)&&Wc(n,{recursive:!0,force:!0})}t.updatedAt=Date.now(),it()}}function tr(e){let t=v();t&&(t.moduleOrder=t.moduleOrder.filter(n=>n!==e),t.updatedAt=Date.now(),it())}function nr(e,t,n){let s=v();if(!s)return;let o=s.modules.find(i=>i.moduleName===e);if(o)try{let i=JSON.parse(o.fieldsJson);or(i,t,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),it()}catch{}}function me(){let e=v();if(!e)return[];let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function Vc(){let e=v();if(e)try{let t=Zn(e.themePath,".vibespot");Bc(t,{recursive:!0});let n={sessionId:e.id,themeName:e.themeName,messages:e.messages,updatedAt:Date.now()};Gc(Zn(t,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function sr(e){let t=Zn(e,".vibespot","chat.json");if(!Qi(t))return[];try{let n=JSON.parse(Uc(t,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function or(e,t,n){let s=t.split("."),o=s[0],i=e.find(a=>a.name===o);i&&(s.length===1?i.default=n:i.children&&or(i.children,s.slice(1).join("."),n))}var es=D(()=>{"use strict";g();tn();en()});import{existsSync as Ys,rmSync as zs}from"fs";import{join as nn}from"path";function ts(e){if(e.templates&&e.templates.length>0)return;if(!e.modules||e.modules.length===0){e.templates=[],e.activeTemplateId="";return}let t=`lp-${e.themeName}`,n={id:t,label:`${e.themeName} Landing Page`,pageType:"landing_page",templateFile:`templates/lp-${e.themeName}.html`,modules:[...e.modules],moduleOrder:[...e.moduleOrder],sharedCss:e.sharedCss||"",sharedJs:e.sharedJs||"",template:e.template||"",messages:[...e.messages]};e.templates=[n],e.activeTemplateId=t}function Ce(){let e=v();return!e||!e.activeTemplateId||!e.templates?.length?null:e.templates.find(t=>t.id===e.activeTemplateId)||null}function qs(e){let t=v();if(!t)return!1;let n=t.templates.find(s=>s.id===e);return n?(t.activeTemplateId=e,ft(n),t.updatedAt=Date.now(),!0):!1}function ir(e,t){let n=v();if(!n)throw new Error("No active session");let s=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),i=`${e==="blog_post"?"bp":e==="website_page"?"wp":e==="module_only"?"mo":"lp"}-${s}`,a={id:i,label:t,pageType:e,templateFile:e==="module_only"?"":`templates/${i}.html`,modules:[],moduleOrder:[],sharedCss:"",sharedJs:"",template:"",messages:[]};return n.templates.push(a),n.activeTemplateId=i,ft(a),n.updatedAt=Date.now(),a}function rr(e,t){let n=v();if(!n)return null;let s=n.templates.find(c=>c.id===e);if(!s)return null;let o=t||`${s.label} (Copy)`,i=o.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),r=`${s.pageType==="blog_post"?"bp":s.pageType==="website_page"?"wp":s.pageType==="module_only"?"mo":"lp"}-${i}`,l={id:r,label:o,pageType:s.pageType,templateFile:s.pageType==="module_only"?"":`templates/${r}.html`,modules:s.modules.map(c=>({...c})),moduleOrder:[...s.moduleOrder],sharedCss:s.sharedCss,sharedJs:s.sharedJs,template:s.template,messages:[]};return n.templates.push(l),n.activeTemplateId=r,ft(l),n.updatedAt=Date.now(),l}function ar(e,t){let n=v();if(!n)return!1;let s=n.templates.find(o=>o.id===e);return s?(s.label=t,n.updatedAt=Date.now(),!0):!1}function lr(e,t=!1){let n=v();if(!n)return!1;let s=n.templates.findIndex(i=>i.id===e);if(s<0)return!1;let o=n.templates.splice(s,1)[0];if(n.themePath){let i=nn(n.themePath,"templates"),a=`${o.id}.html`,r=nn(i,a);if(Ys(r)&&zs(r,{force:!0}),o.pageType==="blog_post"){let l=nn(i,`${o.id}-listing.html`);Ys(l)&&zs(l,{force:!0})}}if(t&&o.modules.length>0){let i=new Set;for(let r of n.templates)for(let l of r.modules)i.add(l.moduleName);for(let r of n.modules)i.add(r.moduleName);let a=o.modules.map(r=>r.moduleName).filter(r=>!i.has(r));if(n.themePath&&a.length>0){let r=nn(n.themePath,"modules");for(let l of a){let c=nn(r,`${l}.module`);Ys(c)&&zs(c,{recursive:!0,force:!0})}}}return n.activeTemplateId===e&&(n.templates.length>0?qs(n.templates[0].id):(n.activeTemplateId="",n.modules=[],n.moduleOrder=[],n.sharedCss="",n.sharedJs="",n.template="",n.messages=[])),n.updatedAt=Date.now(),!0}function at(){let e=v();if(!e)return[];let t=new Map;for(let n of e.templates)for(let s of n.modules){let o=t.get(s.moduleName);o?o.usedIn.push(n.label):t.set(s.moduleName,{module:s,usedIn:[n.label]})}return Array.from(t.values())}var en=D(()=>{"use strict";g();tn();es()});import{readFileSync as Ze,readdirSync as to,existsSync as ye,writeFileSync as ns,mkdirSync as cr,rmSync as Xs,renameSync as Qs}from"fs";import{join as re,dirname as Kc}from"path";import{homedir as Yc}from"os";function ss(){if(_t)return _t;try{return ye(Zs)?(_t=JSON.parse(Ze(Zs,"utf-8")),_t):eo()}catch{return eo()}}function os(e){_t=e;try{cr(ne,{recursive:!0}),ns(Zs,JSON.stringify(e),"utf-8")}catch{}}function eo(){if(!ye(ne))return[];let e=[];for(let t of to(ne).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(Ze(re(ne,t),"utf-8")),s=n.templates||[];e.push({id:n.id,themeName:n.themeName,updatedAt:n.updatedAt,moduleCount:s.reduce((o,i)=>o+(i.modules?.length||0),0),templateCount:s.length})}catch{}return _t=e,os(e),e}function zc(e){let t=ss(),n=e.templates||[],s={id:e.id,themeName:e.themeName,updatedAt:e.updatedAt,moduleCount:n.reduce((i,a)=>i+(a.modules?.length||0),0),templateCount:n.length},o=t.findIndex(i=>i.id===e.id);o>=0?t[o]=s:t.push(s),os(t)}function qc(e){let t=ss().filter(n=>n.id!==e);os(t)}function Xc(e){let t=ss().filter(n=>n.themeName!==e);os(t)}function v(){return be}function Qc(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function sn(e,t){let n={id:Qc(),themePath:e,themeName:t,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return be=n,Qn(e),n}function L(){if(!be)return;cr(ne,{recursive:!0});let e=re(ne,`${be.id}.json`);ns(e,JSON.stringify(be,null,2),"utf-8"),zc(be)}function is(e){let t=re(ne,e+".json");if(!ye(t))return null;try{let n=JSON.parse(Ze(t,"utf-8"));return n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),ts(n),be=n,n}catch{return null}}function Pt(){return ye(ne)?ss():[]}function dr(e,t=!1){let n=re(ne,e+".json"),s="";if(t)try{let o=JSON.parse(Ze(n,"utf-8"));s=o.themeName||"",o.themePath&&ye(o.themePath)&&Xs(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(Ze(n,"utf-8")).themeName||""}catch{}try{ye(n)&&Xs(n)}catch{}if(s&&ye(ne)){for(let o of to(ne).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(Ze(re(ne,o),"utf-8")).themeName===s&&Xs(re(ne,o))}catch{}Xc(s)}else qc(e);be?.id===e&&(be=null)}function ur(e,t){let n=re(ne,e+".json");if(!ye(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(Ze(n,"utf-8"))}catch{return{ok:!1,error:"Failed to read session"}}let o=s.themeName;if(o===t)return{ok:!0};let i=s.themePath,a=re(Kc(i),t);if(ye(i)){if(ye(a))return{ok:!1,error:"A project with that name already exists"};try{Qs(i,a)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let r=re(a,"css",`${o}-theme.css`),l=re(a,"css",`${t}-theme.css`);if(ye(r))try{Qs(r,l)}catch{}let c=re(a,"js",`${o}-animations.js`),d=re(a,"js",`${t}-animations.js`);if(ye(c))try{Qs(c,d)}catch{}let u=re(a,"theme.json");if(ye(u))try{let m=JSON.parse(Ze(u,"utf-8"));m.label=t,m.name=t,ns(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if(ye(ne))for(let r of to(ne).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(Ze(re(ne,r),"utf-8"));l.themeName===o&&(l.themeName=t,l.themePath=a,l.updatedAt=Date.now(),ns(re(ne,r),JSON.stringify(l,null,2),"utf-8"))}catch{}return be&&be.themeName===o&&(be.themeName=t,be.themePath=a,be.updatedAt=Date.now()),eo(),{ok:!0}}var ne,Zs,_t,be,tn=D(()=>{"use strict";g();Zt();en();ne=re(Yc(),".vibespot","sessions"),Zs=re(ne,"_index.json"),_t=null;be=null});import{readFileSync as no,readdirSync as rn,existsSync as pe,writeFileSync as Ie,mkdirSync as on,rmSync as mr}from"fs";import{join as M}from"path";function ae(e){try{return no(e,"utf-8")}catch{return""}}function Zc(e){let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function ed(e,t){let n=ae(e);if(!n||t==="home.html"||t.endsWith("-listing.html"))return null;let s=t.replace(/\.html$/,""),o="landing_page";s.startsWith("bp-")?o="blog_post":s.startsWith("wp-")?o="website_page":s.startsWith("mo-")&&(o="module_only");let i=s,a=n.match(/<!--[\s\S]*?label:\s*"?([^"\n]+)"?\s*[\s\S]*?-->/);a&&(i=a[1].trim());let r=/dnd_module\s+path=["']\.\.\/modules\/(.+?)\.module["']/g,l=[],c;for(;(c=r.exec(n))!==null;)l.push(c[1]);return{id:s,label:i,pageType:o,moduleNames:l,templateContent:n,filename:t}}function td(e,t,n,s,o){if(!pe(e))return[];let i=[],a=rn(e).filter(r=>r.endsWith(".html")&&r!=="home.html");for(let r of a){let l=M(e,r),c=ed(l,r);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let f=t.get(m);f&&(d.push(f),u.push(m))}i.push({id:c.id,label:c.label,pageType:c.pageType,templateFile:`templates/${c.filename}`,modules:d,moduleOrder:u,sharedCss:n,sharedJs:s,template:c.templateContent,messages:i.length===0?[...o]:[]})}return i}function an(e){let t=v();if(!t)return;let n=sr(e);n.length>0&&t.messages.length===0&&(t.messages=n),Qn(e);let s=M(e,"modules");if(!pe(s))return;let o=rn(s,{withFileTypes:!0});for(let y of o){if(!y.isDirectory()||!y.name.endsWith(".module"))continue;let w=M(s,y.name),x=y.name.replace(/\.module$/,""),S={moduleName:x,fieldsJson:ae(M(w,"fields.json")),metaJson:ae(M(w,"meta.json")),moduleHtml:ae(M(w,"module.html")),moduleCss:ae(M(w,"module.css")),moduleJs:ae(M(w,"module.js"))||void 0};S.fieldsJson&&S.moduleHtml&&(t.modules.push(S),t.moduleOrder.push(x))}let i=M(e,"css"),a=M(e,"js"),r="",l="";if(pe(i)){let y=rn(i).filter(w=>w.endsWith("-theme.css"));y.length>0&&(r=ae(M(i,y[0])),t.sharedCss=r)}if(pe(a)){let y=rn(a).filter(w=>w.endsWith("-animations.js"));y.length>0&&(l=ae(M(a,y[0])),t.sharedJs=l)}let c=M(e,".vibespot","styleguide.md"),d=M(e,".vibespot","brandvoice.md"),u=M(e,".vibespot","theme-context.md");(pe(c)||pe(d)||pe(u))&&(t.brandAssets||(t.brandAssets={}),pe(c)&&(t.brandAssets.styleguide=ae(c)),pe(d)&&(t.brandAssets.brandvoice=ae(d)),pe(u)&&(t.brandAssets.themeContext=ae(u)));let m=M(e,"templates"),f=new Map(t.modules.map(y=>[y.moduleName,y])),h=td(m,f,r,l,t.messages);if(h.length>0){t.templates=h,t.activeTemplateId=h[0].id;let y=h[0].moduleOrder;if(y.length>0){let w=new Set(t.moduleOrder),x=y.filter(S=>w.has(S));for(let S of t.moduleOrder)x.includes(S)||x.push(S);t.moduleOrder=x}ft(h[0])}else t.templates||(t.templates=[]),t.activeTemplateId||(t.activeTemplateId=""),ts(t)}function lt(){let e=v();if(!e)return;let t=e.themePath,n=new Map;if(e.templates.length>0)for(let l of e.templates)for(let c of l.modules)n.set(c.moduleName,c);for(let l of e.modules)n.set(l.moduleName,l);let s=M(t,"modules");on(s,{recursive:!0});for(let l of n.values())on(M(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=M(s,`${l.moduleName}.module`);Ie(M(c,"fields.json"),l.fieldsJson,"utf-8"),Ie(M(c,"meta.json"),l.metaJson,"utf-8"),Ie(M(c,"module.html"),l.moduleHtml,"utf-8"),Ie(M(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ie(M(c,"module.js"),l.moduleJs,"utf-8")}if(e.sharedCss){let l=M(t,"css");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-theme.css`),e.sharedCss,"utf-8")}if(e.sharedJs){let l=M(t,"js");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-animations.js`),e.sharedJs,"utf-8")}let o=M(t,"templates");on(o,{recursive:!0});let i=M(o,"home.html");(e.templates.length>0||e.modules.length>0)&&pe(i)&&mr(i,{force:!0});let r=new Set;if(e.templates.length>0)for(let l of e.templates){if(l.pageType==="module_only"||l.modules.length===0)continue;let c=l.template||od(l),d=pr(c,l.label,l.pageType),u=`${l.id}.html`;Ie(M(o,u),d,"utf-8"),r.add(u),l.pageType==="blog_post"&&(id(o,l),r.add(`${l.id}-listing.html`))}else if(e.modules.length>0){let l=e.template||rd(),c=pr(l,`${e.themeName} Landing Page`),d=`lp-${e.themeName}.html`;Ie(M(o,d),c,"utf-8"),r.add(d)}try{for(let l of rn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!r.has(l)&&mr(M(o,l),{force:!0})}catch{}nd(),sd()}function fr(){let e=v();e&&(e.modules=[],e.moduleOrder=[],e.sharedCss="",e.sharedJs="",e.template="",an(e.themePath),e.updatedAt=Date.now(),it())}function gr(){let e=v();if(!e)return;let t=Ce();if(!t)return;let n=e.themePath,s=M(n,"modules");t.modules=[];for(let o of t.moduleOrder){let i=M(s,`${o}.module`);if(!pe(i))continue;let a={moduleName:o,fieldsJson:ae(M(i,"fields.json")),metaJson:ae(M(i,"meta.json")),moduleHtml:ae(M(i,"module.html")),moduleCss:ae(M(i,"module.css")),moduleJs:ae(M(i,"module.js"))||void 0};a.fieldsJson&&a.moduleHtml&&t.modules.push(a)}if(t.templateFile){let o=M(n,t.templateFile);pe(o)&&(t.template=ae(o))}ft(t),e.updatedAt=Date.now()}function nd(){let e=v();if(!e)return;let t=M(e.themePath,"templates","layouts","base.html");if(pe(t))try{let n=no(t,"utf-8");if(n.includes("template_js"))return;let s='{{ require_js(get_asset_url("../../js/main.js")) }}';n.includes(s)?n=n.replace(s,s+`
|
|
98
98
|
{% if template_js %}
|
|
99
99
|
{{ require_js(get_asset_url(template_js)) }}
|
|
100
100
|
{% endif %}`):n=n.replace("{{ standard_footer_includes }}",`{% if template_js %}
|
|
101
101
|
{{ require_js(get_asset_url(template_js)) }}
|
|
102
102
|
{% endif %}
|
|
103
|
-
{{ standard_footer_includes }}`),Ie(t,n,"utf-8")}catch{}}function
|
|
103
|
+
{{ standard_footer_includes }}`),Ie(t,n,"utf-8")}catch{}}function sd(){let e=v();if(!e)return;let t=M(e.themePath,"theme.json");if(pe(t))try{let n=JSON.parse(no(t,"utf-8"));n.label=e.themeName,n.name=e.themeName,Ie(t,JSON.stringify(n,null,2),"utf-8")}catch{}}function pr(e,t,n="landing_page"){return e.includes("templateType")?e:`<!--
|
|
104
104
|
templateType: ${n==="blog_post"?"blog_post":"page"}
|
|
105
105
|
isAvailableForNewContent: true
|
|
106
106
|
label: "${t}"
|
|
107
107
|
-->
|
|
108
|
-
`+e}function
|
|
108
|
+
`+e}function od(e){if(e.modules.length===0)return"";let n=v().themeName,o=Zc(e).map(a=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
|
|
109
109
|
{% dnd_module path="../modules/${a.moduleName}.module" %}
|
|
110
110
|
{% end_dnd_module %}
|
|
111
111
|
{% end_dnd_section %}`).join(`
|
|
@@ -136,7 +136,7 @@ ${o}
|
|
|
136
136
|
|
|
137
137
|
{% block footer %}
|
|
138
138
|
{% endblock footer %}
|
|
139
|
-
`}function
|
|
139
|
+
`}function id(e,t){let n=`<!--
|
|
140
140
|
templateType: blog_listing
|
|
141
141
|
isAvailableForNewContent: true
|
|
142
142
|
label: "${t.label} - Listing"
|
|
@@ -161,7 +161,7 @@ ${o}
|
|
|
161
161
|
{% endif %}
|
|
162
162
|
</div>
|
|
163
163
|
{% endblock body %}
|
|
164
|
-
`;Ie(M(e,`${t.id}-listing.html`),n,"utf-8")}function
|
|
164
|
+
`;Ie(M(e,`${t.id}-listing.html`),n,"utf-8")}function rd(){let e=v();if(!e||e.modules.length===0)return"";let t=e.themeName,s=me().map(o=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
|
|
165
165
|
{% dnd_module path="../modules/${o.moduleName}.module" %}
|
|
166
166
|
{% end_dnd_module %}
|
|
167
167
|
{% end_dnd_section %}`).join(`
|
|
@@ -192,7 +192,7 @@ ${s}
|
|
|
192
192
|
|
|
193
193
|
{% block footer %}
|
|
194
194
|
{% endblock footer %}
|
|
195
|
-
`}var
|
|
195
|
+
`}var hr=D(()=>{"use strict";g();tn();es();en();Zt()});var yr=D(()=>{"use strict";g();Bi();tn();es();hr();en()});var Se=D(()=>{"use strict";g();yr()});function rs(e){let t={};for(let n of e)n.type==="group"&&n.occurrence&&Array.isArray(n.default)?t[n.name]=n.default:n.type==="group"&&n.children?t[n.name]=rs(n.children):t[n.name]=n.default??"";return t}function oo(e,t){let n=e;return n=gd(n),n=xr(n,t),n=wr(n,t),n=Cr(n,t),n=yd(n),n}function io(e){let t=[e.sharedCss||"",...e.moduleCssArray].filter(Boolean).map(o=>`<style>${o}</style>`).join(`
|
|
196
196
|
`),n=[e.sharedJs||"",...e.moduleJsArray].filter(Boolean).map(o=>`<script>${o}</script>`).join(`
|
|
197
197
|
`),s=e.renderedModules.join(`
|
|
198
198
|
`);return`<!DOCTYPE html>
|
|
@@ -239,11 +239,11 @@ document.querySelectorAll('img').forEach(function(img){
|
|
|
239
239
|
});
|
|
240
240
|
</script>
|
|
241
241
|
</body>
|
|
242
|
-
</html>`}function
|
|
242
|
+
</html>`}function gd(e){return e=e.replace(ad,""),e=e.replace(ld,""),e=e.replace(cd,""),br.lastIndex=0,e=e.replace(br,(t,n)=>`/theme-assets/${n}`),Sr.lastIndex=0,e=e.replace(Sr,""),e=e.replace(dd,""),e=e.replace(ud,""),e=e.replace(md,""),e=e.replace(pd,""),e=e.replace(fd,""),e}function xr(e,t){let n=e,s=0;for(;s<30;){s++;let o=hd(n);if(!o)break;let{varName:i,iterExpr:a,body:r,start:l,end:c}=o,d=bd(a,t),u="";Array.isArray(d)&&(u=d.map((m,f)=>{let h={...t,[i]:m,loop:{index:f+1,index0:f,first:f===0,last:f===d.length-1,length:d.length}},y=xr(r,h);return y=wr(y,h),y=Cr(y,h),y}).join("")),n=n.slice(0,l)+u+n.slice(c)}return n}function hd(e){let t=/\{%[-\s]*for\s+(\w+)\s+in\s+([\w.]+(?:\([^)]*\))?(?:\|[\w(),"' ]+)*)\s*-?%\}/g,n=/\{%[-\s]*(for\s|endfor)\s*.*?-?%\}/g,s=t.exec(e);if(!s)return null;let o=s[1],i=s[2],a=s.index+s[0].length;n.lastIndex=a;let r=1,l;for(;(l=n.exec(e))!==null;)if(l[1].startsWith("for"))r++;else if(r--,r===0){let c=e.slice(a,l.index);return{varName:o,iterExpr:i,body:c,start:s.index,end:l.index+l[0].length}}return null}function wr(e,t){let n=e,s=0;for(;so.test(n)&&s<50;)s++,n=n.replace(so,(o,i,a)=>{let r=a.split(/\{%[-\s]*else\s*-?%\}/),l=r[0],c=r[1]||"",d=l.split(/\{%[-\s]*elif\s+(.*?)\s*-?%\}/);if(d.length>1){if(Mt(i,t))return d[0];for(let u=1;u<d.length;u+=2){let m=d[u],f=d[u+1]||"";if(Mt(m,t))return f}return c}return Mt(i,t)?l:c}),so.lastIndex=0;return n}function Cr(e,t){return e.replace(/\{\{[-\s]*(.*?)[-\s]*\}\}/g,(n,s)=>{let i=s.trim().split("|"),a=i[0].trim(),r=gt(t,a);for(let c=1;c<i.length;c++)r=kr(r,i[c].trim());if(r==null)return"";if(typeof r=="object")return JSON.stringify(r);let l=String(r);return l=l.replace(/\\n/g," ").replace(/\n/g," "),l})}function yd(e){return e=e.replace(/\{%.*?%\}/gs,""),e=e.replace(/\{\{.*?\}\}/gs,""),e}function bd(e,t){let n=e.match(/^range\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);if(n){let o=vr(n[1],t),i=vr(n[2],t),a=[];for(let r=o;r<i;r++)a.push(r);return a}let s=e.match(/^(.+?)\|split\(['"](.+?)['"]\)$/);if(s){let o=gt(t,s[1].trim());return typeof o=="string"?o.split(s[2]):[]}return gt(t,e)}function vr(e,t){let s=e.trim().split("|"),o=s[0].trim();if(!isNaN(Number(o)))return Number(o);let i=gt(t,o);for(let a=1;a<s.length;a++)i=kr(i,s[a].trim());return Number(i)||0}function gt(e,t){let n=t.split("."),s=e;for(let o of n){if(s==null||typeof s!="object")return;s=s[o]}return s}function Mt(e,t){let n=e.trim();if(n.startsWith("not "))return!Mt(n.slice(4),t);if(n.includes(" and "))return n.split(" and ").every(i=>Mt(i,t));if(n.includes(" or "))return n.split(" or ").some(i=>Mt(i,t));let s=n.match(/^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);if(s){let i=gt(t,s[1].trim()),a=s[2],r=s[3].trim();switch(typeof r=="string"&&r.startsWith('"')&&r.endsWith('"')||typeof r=="string"&&r.startsWith("'")&&r.endsWith("'")?r=r.slice(1,-1):isNaN(Number(r))?r=gt(t,r):r=Number(r),a){case"==":return i==r;case"!=":return i!=r;case">":return Number(i)>Number(r);case"<":return Number(i)<Number(r);case">=":return Number(i)>=Number(r);case"<=":return Number(i)<=Number(r)}}let o=gt(t,n);return Ar(o)}function Ar(e){return!(e==null||e===""||e===0||e===!1||Array.isArray(e)&&e.length===0)}function kr(e,t){let n=e==null?"":String(e),s=t.match(/^(\w+)\((.*)\)$/),o=s?s[1]:t,i=s?s[2].replace(/^["']|["']$/g,""):void 0;switch(o){case"escape":case"e":return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");case"lower":return n.toLowerCase();case"upper":return n.toUpperCase();case"capitalize":return n.charAt(0).toUpperCase()+n.slice(1);case"trim":return n.trim();case"truncate":if(i){let a=parseInt(i,10);return n.length>a?n.slice(0,a)+"...":n}return n;case"default":return Ar(e)?e:i??"";case"length":return Array.isArray(e)?e.length:n.length;case"join":return Array.isArray(e)?e.join(i??", "):n;case"int":case"float":return Number(n)||0;case"abs":return Math.abs(Number(n));case"round":return Math.round(Number(n));default:return e}}var ad,ld,cd,br,Sr,dd,ud,md,pd,fd,so,Ir=D(()=>{"use strict";g();ad=/\{%[-\s]*require_(css|js)\b.*?%\}/gs,ld=/\{%[-\s]*end_require_(css|js)\s*%\}/gs,cd=/\{\{[-\s]*require_(css|js)\(.*?\)\s*\}\}/gs,br=/\{\{[-\s]*get_asset_url\(["'](?:[^"'\/]+\/)?assets\/(.*?)["']\)\s*\}\}/gs,Sr=/\{\{[-\s]*get_asset_url\(.*?\)\s*\}\}/gs,dd=/\{%[-\s]*(end_)?(dnd_area|dnd_section|dnd_column|dnd_row|dnd_module)\b.*?%\}/gs,ud=/\{%[-\s]*module\b.*?%\}/gs,md=/\{%[-\s]*(extends|block|endblock|set)\b.*?%\}/gs,pd=/\{#.*?#\}/gs,fd=/\{\{[-\s]*content\.\w+.*?\}\}/gs,so=/\{%[-\s]*if\s+(.*?)\s*-?%\}((?:(?!\{%[-\s]*if\s)[\s\S])*?)\{%[-\s]*endif\s*-?%\}/g});var lo={};nt(lo,{buildModulePreviewHtml:()=>ao,buildPreviewHtml:()=>ro});function Sd(e){if(!e)return{bg:"#0f0f14",surface:"#1a1a20",text:"#ffffff",textMuted:"#666",border:"#333"};let t=(r,l)=>{for(let c of r){let d=new RegExp(`${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*:\\s*([^;})]+)`,"i"),u=e.match(d);if(u)return u[1].trim()}return l},n=t(["--bg","--background","--color-bg","--bg-primary","--body-bg"],"#0f0f14"),s=t(["--surface","--bg-secondary","--card-bg","--color-surface"],n),o=t(["--text","--color-text","--text-primary","--fg","--foreground"],"#ffffff"),i=t(["--text-muted","--text-secondary","--muted","--color-text-muted"],"#666"),a=t(["--border","--border-color","--color-border"],"#333");return{bg:n,surface:s,text:o,textMuted:i,border:a}}function ro(){let e=v();if(!e)return Tr();let t=me(),n=e.moduleOrder||[];if(t.length===0&&n.length===0)return Tr();let s=[],o=[],i=[],a=new Set;for(let c of t){if(c.moduleHtml.includes("dnd_area")||c.moduleHtml.includes("extends "))continue;let d;try{let f=JSON.parse(c.fieldsJson);d={module:rs(f)}}catch{d={module:{}}}let u=oo(c.moduleHtml,d),m=c.moduleName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module" id="${m}" data-module="${c.moduleName}">${u}</div>`),a.add(c.moduleName),c.moduleCss&&o.push(c.moduleCss),c.moduleJs&&i.push(c.moduleJs)}let r=Sd(e.sharedCss);for(let c of n)if(!a.has(c)){let d=c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module vibespot-module--pending" id="${d}" data-module="${c}">
|
|
243
243
|
<div class="vibespot-placeholder">
|
|
244
244
|
<div class="vibespot-placeholder__name">${c}</div>
|
|
245
245
|
</div>
|
|
246
|
-
</div>`)}let l=`body{background:${r.bg}}.vibespot-placeholder{display:flex;align-items:center;justify-content:center;min-height:200px;padding:3rem;background:${r.surface};border:1px dashed ${r.border};border-radius:12px;margin:1rem 0}.vibespot-placeholder__name{font-size:1.5rem;font-weight:600;font-family:system-ui,sans-serif;color:${r.textMuted};letter-spacing:.5px;animation:vp-fade 2s ease-in-out infinite}@keyframes vp-fade{0%,100%{opacity:.3}50%{opacity:.8}}`;return io({renderedModules:s,sharedCss:e.sharedCss,moduleCssArray:[l,...o],sharedJs:e.sharedJs,moduleJsArray:i})}function
|
|
246
|
+
</div>`)}let l=`body{background:${r.bg}}.vibespot-placeholder{display:flex;align-items:center;justify-content:center;min-height:200px;padding:3rem;background:${r.surface};border:1px dashed ${r.border};border-radius:12px;margin:1rem 0}.vibespot-placeholder__name{font-size:1.5rem;font-weight:600;font-family:system-ui,sans-serif;color:${r.textMuted};letter-spacing:.5px;animation:vp-fade 2s ease-in-out infinite}@keyframes vp-fade{0%,100%{opacity:.3}50%{opacity:.8}}`;return io({renderedModules:s,sharedCss:e.sharedCss,moduleCssArray:[l,...o],sharedJs:e.sharedJs,moduleJsArray:i})}function Tr(){return`<!DOCTYPE html>
|
|
247
247
|
<html lang="en">
|
|
248
248
|
<head>
|
|
249
249
|
<meta charset="utf-8">
|
|
@@ -294,8 +294,8 @@ document.querySelectorAll('img').forEach(function(img){
|
|
|
294
294
|
<div class="welcome__sub">Build Something Great</div>
|
|
295
295
|
</div>
|
|
296
296
|
</body>
|
|
297
|
-
</html>`}function ao(e){let t=
|
|
298
|
-
`)}catch{}}}var ls,
|
|
297
|
+
</html>`}function ao(e){let t=v();if(!t)return"";let n;for(let i of t.templates)if(n=i.modules.find(a=>a.moduleName===e),n)break;if(n||(n=t.modules.find(i=>i.moduleName===e)),!n)return"";let s;try{let i=JSON.parse(n.fieldsJson);s={module:rs(i)}}catch{s={module:{}}}let o=oo(n.moduleHtml,s);return io({renderedModules:[`<div class="vibespot-module" data-module="${n.moduleName}">${o}</div>`],sharedCss:t.sharedCss,moduleCssArray:n.moduleCss?[n.moduleCss]:[],sharedJs:t.sharedJs,moduleJsArray:n.moduleJs?[n.moduleJs]:[]})}var as=D(()=>{"use strict";g();Ir();Se()});import{appendFileSync as vd,mkdirSync as xd,readdirSync as wd,unlinkSync as Cd}from"fs";import{join as po}from"path";import{homedir as Ad}from"os";function Id(){if(!uo)try{xd(ls,{recursive:!0}),uo=!0}catch{}}function Td(){if(!mo){mo=!0;try{let e=Date.now()-kd*864e5;for(let t of wd(ls)){if(!t.startsWith("vibespot-")||!t.endsWith(".log"))continue;let n=t.slice(9,19),s=new Date(n).getTime();if(s&&s<e)try{Cd(po(ls,t))}catch{}}}catch{}}}function $d(){let t=new Date().toISOString().slice(0,10);return po(ls,`vibespot-${t}.log`)}function Ed(){return new Date().toISOString().slice(11,23)}function co(e,t){if(Id(),!!uo){mo||Td();try{vd($d(),`${Ed()} ${e} ${t}
|
|
298
|
+
`)}catch{}}}var ls,kd,uo,mo,$,ve=D(()=>{"use strict";g();ls=po(Ad(),".vibespot","logs"),kd=7,uo=!1,mo=!1;$={info(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.log(s),co("INFO",s)},warn(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.warn(s),co("WARN",s)},error(e,t,n){let s=n instanceof Error?n.message:n?String(n):"",o=s?`[${e}] ${t}: ${s}`:`[${e}] ${t}`;console.error(o),co("ERROR",o)}}});function Ue(e){try{return JSON.parse(e)}catch{}let t=e,n=-1;for(let s=0;s<20;s++)try{return JSON.parse(t)}catch(o){if(!(o instanceof SyntaxError))return null;let i=/position (\d+)/.exec(o.message);if(!i)return null;let a=parseInt(i[1],10);if(a<=n)return null;n=a;let r=Math.max(0,a-5),c=t.slice(r,a+1).lastIndexOf('"');if(c===-1)return null;let d=r+c;if(d>0&&t[d-1]==="\\")return null;t=t.slice(0,d)+'\\"'+t.slice(d+1)}return null}function ln(e){let t=e.indexOf('"modules"');if(t===-1)return null;let n=e.indexOf("[",t);if(n===-1)return null;let s=-1,o=0,i=!1,a=!1;for(let d=n+1;d<e.length;d++){let u=e[d];if(a){a=!1;continue}if(u==="\\"){a=!0;continue}if(u==='"'){i=!i;continue}i||(u==="{"&&o++,u==="}"&&(o--,o===0&&(s=d)))}if(s===-1)return null;let l=e.slice(0,s+1)+"]}",c=l.trimStart().startsWith("{")?l:"{"+l;return Ue(c)}function fo(e){return{moduleName:String(e.moduleName||""),fieldsJson:typeof e.fieldsJson=="string"?e.fieldsJson:JSON.stringify(e.fieldsJson,null,2),metaJson:typeof e.metaJson=="string"?e.metaJson:JSON.stringify(e.metaJson,null,2),moduleHtml:String(e.moduleHtml||""),moduleCss:String(e.moduleCss||""),moduleJs:e.moduleJs?String(e.moduleJs):void 0}}function $r(e,t){let n=!1,s,o=/```vibespot-modules\s*\n?([\s\S]*?)```/g;for(;(s=o.exec(e))!==null;)try{$.info("parse","Found vibespot-modules block",{length:s[1].length});let i=Ue(s[1]);if(!i||typeof i!="object")throw $.warn("parse","tryParseJSON returned non-object",{result:typeof i}),new Error("Invalid JSON after repair");let a=i;a.modules&&Array.isArray(a.modules)&&(Le({modules:a.modules.map(r=>fo(r)),sharedCss:a.sharedCss!==void 0?String(a.sharedCss):void 0,sharedJs:a.sharedJs!==void 0?String(a.sharedJs):void 0}),n=!0)}catch(i){$.warn("parse","Failed to parse vibespot-modules block",{error:i instanceof Error?i.message:String(i)})}if(!n){let i=/```(?:json)?\s*\n([\s\S]*?)```/g;for(;(s=i.exec(e))!==null;)if(s[1].includes('"modules"'))try{let a=Ue(s[1]);if(!a||typeof a!="object")throw new Error("Invalid JSON after repair");let r=a;r.modules&&Array.isArray(r.modules)&&(Le({modules:r.modules.map(l=>fo(l)),sharedCss:r.sharedCss!==void 0?String(r.sharedCss):void 0,sharedJs:r.sharedJs!==void 0?String(r.sharedJs):void 0}),n=!0)}catch(a){$.warn("parse","Failed to parse JSON module block",{error:a instanceof Error?a.message:String(a)})}}if(!n&&(e.match(/```/g)||[]).length%2!==0&&e.includes('"modules"')){$.info("parse","Detected truncated response (odd fence count), attempting salvage");let a=e.lastIndexOf("```"),r=e.slice(a+3);r=r.replace(/^[\w-]*\s*\n?/,"");let l=ln(r);if(l){let c=l;c.modules&&Array.isArray(c.modules)&&c.modules.length>0&&($.info("parse","Salvaged modules from truncated response",{count:c.modules.length}),Le({modules:c.modules.map(d=>fo(d)),sharedCss:c.sharedCss!==void 0?String(c.sharedCss):void 0,sharedJs:c.sharedJs!==void 0?String(c.sharedJs):void 0}),n=!0,t&&t("Response was truncated \u2014 some modules may be incomplete. Try sending your request again for the full set."))}}if(!n){$.info("parse","No modules applied",{responseLength:e.length,hasVibespot:e.includes("vibespot-modules"),hasModules:e.includes('"modules"'),fenceCount:(e.match(/```/g)||[]).length});let i=e.includes("vibespot-modules")||e.includes('"modules"'),a=/\bmodule|modul/i.test(e)&&(/\bcreated?\b|\berstellt\b|\bgenerat/i.test(e)||/\|.*\|.*\|/m.test(e));if(i||a){let r=i?"Module changes could not be applied \u2014 the AI response contained invalid JSON. Try sending your request again.":"The AI described modules but did not include the required structured data. Try sending your request again.";$.warn("parse",r),t&&t(r)}}}var cs=D(()=>{"use strict";g();Se();ve()});function Ot(){let e=v();return e?{pageType:Ce()?.pageType,brandAssets:e.brandAssets}:{}}function Er(e,t,n=!1,s,o){let a=[{type:"text",text:Pd(t,n)}];if(n){let l=`## HubSpot CMS Rules
|
|
299
299
|
${Ee()}
|
|
300
300
|
|
|
301
301
|
## Conversion Guide Reference
|
|
@@ -322,22 +322,22 @@ When using scroll-animate classes (opacity: 0 \u2192 visible), you MUST include
|
|
|
322
322
|
This makes elements appear after 3 seconds if JS never adds the .visible class. Once JS runs normally and adds .visible, the animation is cancelled.
|
|
323
323
|
|
|
324
324
|
## Design Guide
|
|
325
|
-
${
|
|
325
|
+
${Us()}
|
|
326
326
|
|
|
327
327
|
## Content & Copywriting Guide
|
|
328
|
-
${
|
|
328
|
+
${Gs()}
|
|
329
329
|
|
|
330
330
|
## HubSpot CMS Rules
|
|
331
331
|
${Ee()}
|
|
332
332
|
|
|
333
333
|
## Conversion Guide Reference
|
|
334
|
-
${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let r=
|
|
334
|
+
${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let r=_d(s,o);return r&&a.push({type:"text",text:r}),a.push({type:"text",text:"## REMINDER \u2014 Output Format (CRITICAL)\nYour response MUST contain a ```vibespot-modules code block with the full JSON. Without this block, no modules will be created. Do NOT respond with only text, tables, or descriptions. The JSON block is mandatory."}),a}function _d(e,t){let n=[];if(e){let s=Ws(e);s&&n.push(`## Page Type Context
|
|
335
335
|
${s}`)}if(t?.styleguide&&n.push(`## Brand Style Guide
|
|
336
336
|
${t.styleguide}`),t?.brandvoice&&n.push(`## Brand Voice
|
|
337
337
|
${t.brandvoice}`),t?.humanify!==!1){let s=Bs();s&&n.push(`## Anti-AI Copy Rules (Humanify)
|
|
338
338
|
${s}`)}return n.join(`
|
|
339
339
|
|
|
340
|
-
`)}function
|
|
340
|
+
`)}function Pd(e,t){return`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
|
|
341
341
|
|
|
342
342
|
## Your Role
|
|
343
343
|
You generate native HubSpot CMS modules directly from user descriptions. Every module you create is immediately compatible with HubSpot's drag-and-drop page editor.
|
|
@@ -538,16 +538,16 @@ When using scroll-animate classes (opacity: 0 \u2192 visible), you MUST include
|
|
|
538
538
|
This makes elements appear after 3 seconds if JS never adds the .visible class. Once JS runs normally and adds .visible, the animation is cancelled.
|
|
539
539
|
|
|
540
540
|
## Design Guide
|
|
541
|
-
${
|
|
541
|
+
${Us()}
|
|
542
542
|
|
|
543
543
|
## Content & Copywriting Guide
|
|
544
|
-
${
|
|
544
|
+
${Gs()}
|
|
545
545
|
|
|
546
546
|
## HubSpot CMS Rules
|
|
547
547
|
${Ee()}
|
|
548
548
|
|
|
549
549
|
## Conversion Guide Reference
|
|
550
|
-
${e}`+c}function dn(){let e=
|
|
550
|
+
${e}`+c}function dn(){let e=v(),t=[],n=e.modules,s=n.length;if(s>0){t.push(`
|
|
551
551
|
|
|
552
552
|
## Page Narrative (module sequence)
|
|
553
553
|
`),t.push(`This template has ${s} module${s===1?"":"s"} in this order:
|
|
@@ -590,7 +590,7 @@ ${e.sharedJs}
|
|
|
590
590
|
`);for(let r of a)t.push(`- ${r.module.moduleName} (used in: ${r.usedIn.join(", ")})
|
|
591
591
|
`);t.push(`
|
|
592
592
|
The user can ask to reuse any of these modules by name.
|
|
593
|
-
`)}return t.join("")}function go(e,t){let n=
|
|
593
|
+
`)}return t.join("")}function go(e,t){let n=v(),s=n.messages.slice(-20);s.length>0&&s[s.length-1].role==="user"&&s[s.length-1].content===e&&(s=s.slice(0,-1));let o=s.map(d=>({role:d.role,content:d.content})),i=dn(),a="";if(n.assets?.length){let d=n.assets.filter(u=>u.type==="image"&&u.usage==="asset");d.length>0&&(a=`
|
|
594
594
|
|
|
595
595
|
## Available Theme Assets
|
|
596
596
|
These images are in the theme's assets/ folder. Reference them with get_asset_url("${n.themeName}/assets/filename"):
|
|
@@ -604,44 +604,44 @@ ${i}`),a&&(r+=a),r+="\n\n---\nRemember: respond with a ```vibespot-modules JSON
|
|
|
604
604
|
[Attached document: ${d.originalName}]
|
|
605
605
|
${d.extractedText}`),d.type==="image"&&d.usage==="asset"&&d.assetPath&&(r+=`
|
|
606
606
|
|
|
607
|
-
[Uploaded image: ${d.originalName} \u2192 available as get_asset_url("${d.assetPath}")]`);let c=l?t.filter(d=>d.type==="image"&&d.base64):[];if(c.length>0){let d=[];for(let u of c)d.push({type:"image",source:{type:"base64",media_type:u.mimeType,data:u.base64}});d.push({type:"text",text:r}),o.push({role:"user",content:d})}else o.push({role:"user",content:r});return o}var
|
|
607
|
+
[Uploaded image: ${d.originalName} \u2192 available as get_asset_url("${d.assetPath}")]`);let c=l?t.filter(d=>d.type==="image"&&d.base64):[];if(c.length>0){let d=[];for(let u of c)d.push({type:"image",source:{type:"base64",media_type:u.mimeType,data:u.base64}});d.push({type:"text",text:r}),o.push({role:"user",content:d})}else o.push({role:"user",content:r});return o}var _r=D(()=>{"use strict";g();qe();Se()});import{spawn as Md}from"child_process";async function Pr(){return ho||(ho=(await import("@anthropic-ai/sdk")).default),ho}function Mr(e){if(!e?.length)return"";let t=[];for(let n of e)n.type==="image"&&n.usage==="asset"&&n.assetPath&&t.push(`
|
|
608
608
|
[Uploaded image: ${n.originalName} \u2192 use get_asset_url("${n.assetPath}")]`),n.type==="document"&&n.extractedText&&t.push(`
|
|
609
609
|
|
|
610
610
|
---
|
|
611
611
|
[Attached document: ${n.originalName}]
|
|
612
|
-
${n.extractedText}`);return t.join("")}async function
|
|
613
|
-
`);
|
|
612
|
+
${n.extractedText}`);return t.join("")}async function Or(e,t,n,s,o,i,a){for(let r=0;;r++)try{let l="",c=0,d=i||(()=>{});d(fe[0]);let u=setInterval(()=>{c++,d(fe[Math.min(c,fe.length-1)])},6e3);try{let m=e.messages.stream({model:s,max_tokens:48e3,system:t,messages:n});for await(let f of m)if(f.type==="content_block_delta"&&f.delta.type==="text_delta"){let h=f.delta.text;l+=h,o(h)}}finally{clearInterval(u)}a&&a(l);return}catch(l){let c=l.status,d=l.error?.type;if(!(c===429||d==="rate_limit_error"||l instanceof Error&&l.message.includes("429"))||r>=yo.length)throw l;let m=yo[r];$.warn("ai-engine",`Rate limited (429), attempt ${r+1}/${yo.length} \u2014 waiting ${m}s`),i&&i(`Rate limited by Anthropic API \u2014 retrying in ${m}s...`),await new Promise(f=>setTimeout(f,m*1e3)),i&&i("Retrying...")}}function Nr(e,t,n){let s=oe(),i=v().modules.length>0,a=go(e,n),r=Ot(),l=Er(s,t,i,r.pageType,r.brandAssets);return{messages:a,systemBlocks:l,conversionGuide:s,editMode:i}}async function Rr(e,t,n,s,o,i,a,r){let l=await Pr(),c=new l({apiKey:t}),{messages:d,systemBlocks:u}=Nr(e,n,r);$.info("anthropic","API call",{model:s,systemBlockCount:u.length,cachedBlocks:u.filter(m=>m.cache_control).length,messageCount:d.length}),await Or(c,u,d,s,o,i,a)}async function jr(e,t,n,s,o,i,a){let r=await Ms();if(!r)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let l=await Pr(),c=new l({authToken:r,defaultHeaders:Ht}),{messages:d,systemBlocks:u}=Nr(e,t,a),m=[{type:"text",text:At},...u];$.info("anthropic-oauth","API call",{model:n,systemBlockCount:m.length,cachedBlocks:m.filter(f=>f.cache_control).length,messageCount:d.length}),await Or(c,m,d,n,s,o,i)}async function Fr(e,t,n,s,o,i,a,r){let l=oe(),c=v().modules.length>0,d=go(e,r),u=Ot(),m=d.map(G=>typeof G.content=="string"?G:{role:G.role,content:G.content.map(T=>T.type==="text"?{type:"text",text:T.text}:{type:"image_url",image_url:{url:`data:${T.source.media_type};base64,${T.source.data}`}})}),f=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({model:s,max_tokens:48e3,stream:!0,messages:[{role:"system",content:cn(l,n,c,u.pageType,u.brandAssets)},...m]})});if(!f.ok){let G=await f.text();throw new Error(`OpenAI API error (${f.status}): ${G}`)}let h=0,y=i||(()=>{});y(fe[0]);let w=setInterval(()=>{h++,y(fe[Math.min(h,fe.length-1)])},6e3),x="",S=f.body.getReader(),P=new TextDecoder,j="";try{for(;;){let{done:G,value:T}=await S.read();if(G)break;j+=P.decode(T,{stream:!0});let V=j.split(`
|
|
613
|
+
`);j=V.pop()||"";for(let N of V){if(!N.startsWith("data: "))continue;let O=N.slice(6).trim();if(O==="[DONE]")break;try{let F=JSON.parse(O).choices?.[0]?.delta?.content;F&&(x+=F,o(F))}catch{}}}}finally{clearInterval(w)}a&&a(x)}async function Jr(e,t,n,s,o,i,a){let r=oe(),l=v(),c=l.modules.length>0,d=dn(),u=Ot(),m=[];for(let O of l.messages.slice(-20))m.push({role:O.role==="assistant"?"model":"user",parts:[{text:O.content}]});let f=d?`${e}
|
|
614
614
|
|
|
615
615
|
---
|
|
616
|
-
${d}`:e;if(a?.length)for(let
|
|
616
|
+
${d}`:e;if(a?.length)for(let O of a)O.type==="document"&&O.extractedText&&(f+=`
|
|
617
617
|
|
|
618
618
|
---
|
|
619
|
-
[Attached document: ${
|
|
620
|
-
${
|
|
619
|
+
[Attached document: ${O.originalName}]
|
|
620
|
+
${O.extractedText}`),O.type==="image"&&O.usage==="asset"&&O.assetPath&&(f+=`
|
|
621
621
|
|
|
622
|
-
[Uploaded image: ${
|
|
623
|
-
`);
|
|
624
|
-
`+(
|
|
625
|
-
`:"")+(
|
|
626
|
-
`+(
|
|
627
|
-
`:"")+`Partial output (${
|
|
622
|
+
[Uploaded image: ${O.originalName} \u2192 available as get_asset_url("${O.assetPath}")]`);let h=[];if(a?.length)for(let O of a)O.type==="image"&&O.base64&&h.push({inlineData:{mimeType:O.mimeType,data:O.base64}});h.push({text:f}),m.push({role:"user",parts:h});let w=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=${t}`,x=await fetch(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({systemInstruction:{parts:[{text:cn(r,n,c,u.pageType,u.brandAssets)}]},contents:m,generationConfig:{maxOutputTokens:48e3}})});if(!x.ok){let O=await x.text();throw new Error(`Gemini API error (${x.status}): ${O}`)}let S=0,P=o||(()=>{});P(fe[0]);let j=setInterval(()=>{S++,P(fe[Math.min(S,fe.length-1)])},6e3),G="",T=x.body.getReader(),V=new TextDecoder,N="";try{for(;;){let{done:O,value:J}=await T.read();if(O)break;N+=V.decode(J,{stream:!0});let F=N.split(`
|
|
623
|
+
`);N=F.pop()||"";for(let X of F){if(!X.startsWith("data: "))continue;let le=X.slice(6).trim();try{let Ft=JSON.parse(le).candidates?.[0]?.content?.parts?.[0]?.text;Ft&&(G+=Ft,s(Ft))}catch{}}}}finally{clearInterval(j)}i&&i(G)}function ds(e,t,n,s,o){return new Promise((i,a)=>{let r={...process.env};delete r.CLAUDECODE;let l=Md(e,t,{stdio:["pipe","pipe","pipe"],env:r}),c="",d="",u=!1,m=x=>{u||(u=!0,x())};l.stdout.on("data",x=>{let S=x.toString();c+=S,s&&s(S)}),l.stderr.on("data",x=>{d+=x.toString()}),l.on("error",x=>m(()=>a(new Error(`${e} failed to start: ${x.message}`)))),l.on("close",x=>{m(()=>{x!==0?a(new Error(`${e} exited with code ${x}.
|
|
624
|
+
`+(d?`Stderr: ${d.slice(0,500)}
|
|
625
|
+
`:"")+(c?`Output: ${c.slice(0,500)}`:"No output"))):i(c)})}),l.stdin.on("error",()=>{}),l.stdin.write(n)?l.stdin.end():l.stdin.once("drain",()=>l.stdin.end());let h=o||6e5,y=Math.round(h/6e4),w=setTimeout(()=>{l.kill(),m(()=>a(new Error(`${e} timed out after ${y} minutes.
|
|
626
|
+
`+(d?`Stderr: ${d.slice(0,500)}
|
|
627
|
+
`:"")+`Partial output (${c.length} chars): ${c.slice(0,500)}`)))},h);l.on("close",()=>clearTimeout(w))})}async function Dr(e,t,n,s,o,i){let a=oe(),r=_(),l=v().modules.length>0,c=Ot(),d=cn(a,t,l,c.pageType,c.brandAssets);d+=`
|
|
628
628
|
|
|
629
629
|
## User Request
|
|
630
|
-
`+e,d+=dn(),d+=
|
|
630
|
+
`+e,d+=dn(),d+=Mr(i),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u=["--print"];r.claudeCodeModel&&u.push("--model",r.claudeCodeModel);let m=0,f=s||(()=>{});f(fe[0]);let h=setInterval(()=>{m++;let y=fe[Math.min(m,fe.length-1)];f(y)},6e3);try{let y=await ds("claude",u,d,w=>{n(w)});o&&o(y)}finally{clearInterval(h)}}async function bo(e,t,n,s,o,i,a){let r=oe(),l=v().modules.length>0,c=Ot(),d=cn(r,n,l,c.pageType,c.brandAssets);d+=`
|
|
631
631
|
|
|
632
632
|
## User Request
|
|
633
|
-
`+t,d+=dn(),d+=Pr(a),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u,m;e==="gemini"?(u="gemini",m=[]):(u="codex",m=["exec","--full-auto"]);let f=0,h=o||(()=>{});h(fe[0]);let y=setInterval(()=>{f++;let v=fe[Math.min(f,fe.length-1)];h(v)},6e3);try{let v=await ds(u,m,d,C=>{s(C)});i&&i(v)}finally{clearInterval(y)}}var ho,fe,yo,So=j(()=>{"use strict";g();qe();Z();Ke();Se();Er();ve();ho=null;fe=["Analyzing your request...","Reading the conversion guide...","Planning module structure...","Generating HTML templates...","Writing CSS styles...","Creating field definitions...","Building module metadata...","Assembling theme assets...","Polishing the output...","Almost there \u2014 hang tight..."],yo=[10,20,40,60,120]});function p(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n))}function N(e,t){let n=[];e.on("data",s=>n.push(s)),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))}function vo(e,t,n){N(e,s=>{try{n(JSON.parse(s||"{}"))}catch{p(t,400,{error:"Invalid JSON in request body"})}})}var et=j(()=>{"use strict";g()});import{createWriteStream as Md,mkdirSync as Dr,existsSync as xo,readFileSync as wo}from"fs";import{join as ht,extname as Od}from"path";import{randomUUID as Nd}from"crypto";import Rd from"busboy";function Dd(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Hd(e,t){if(!xo(ht(e,t)))return t;let n=Od(t),s=t.slice(0,-n.length||void 0),o=1;for(;xo(ht(e,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function Ld(e){let t=(await import("pdf-parse")).default,n=wo(e);return(await t(n)).text}async function Gd(e){return(await(await import("mammoth")).extractRawText({path:e})).value}function Ud(e){return wo(e,"utf-8")}function Lr(e,t){let n=S();if(!n){p(t,400,{error:"No active session"});return}if(!(e.headers["content-type"]||"").includes("multipart/form-data")){p(t,400,{error:"Expected multipart/form-data"});return}let o=[],i=[],a=0,r=[],l=Rd({headers:e.headers,limits:{fileSize:Fd,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:f}=u;if(a++,!Jd.has(f)){i.push(`Unsupported file type: ${m} (${f})`),d.resume();return}let h=Hr.has(f),y=Dd(m),v=Nd(),C,k;h?(C=ht(n.themePath,"assets"),Dr(C,{recursive:!0}),k=Hd(C,y)):(C=ht(n.themePath,".vibespot","uploads"),Dr(C,{recursive:!0}),k=`${v}-${y}`);let P=ht(C,k),O=Md(P),G=0,E=!1;d.on("data",R=>{G+=R.length}),d.on("limit",()=>{E=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(O),r.push(new Promise(R=>{O.on("finish",()=>{if(!E){let W={id:v,filename:k,originalName:m,type:h?"image":"document",usage:h?"asset":"context",mimeType:f,size:G,addedAt:new Date().toISOString()};o.push(W),Qi(W)}R()}),O.on("error",()=>{i.push(`Failed to write: ${m}`),R()})}))}),l.on("finish",async()=>{await Promise.all(r);for(let c of o)if(c.type==="document"){let d=ht(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await Ld(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await Gd(d):c.extractedText=Ud(d),T.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){T.warn("upload",`Failed to extract text from ${c.originalName}: ${u}`),c.extractedText=`[Could not extract text from ${c.originalName}]`}}if(a===0){p(t,400,{error:"No files uploaded"});return}p(t,200,{files:o.map(c=>({id:c.id,filename:c.filename,originalName:c.originalName,type:c.type,usage:c.usage,size:c.size})),errors:i.length>0?i:void 0})}),l.on("error",c=>{T.error("upload",`Busboy error: ${c}`),p(t,500,{error:"Upload failed"})}),e.pipe(l)}function Gr(e){let t=S();return t?.assets?e.map(n=>{let s=t.assets.find(i=>i.id===n);if(!s)return null;let o={id:s.id,filename:s.filename,originalName:s.originalName,type:s.type,usage:s.usage,mimeType:s.mimeType};if(s.type==="image"){let i=ht(t.themePath,"assets",s.filename);xo(i)&&(o.base64=wo(i).toString("base64")),o.assetPath=`${t.themeName}/assets/${s.filename}`}else s.type==="document"&&(o.extractedText=s.extractedText);return o}).filter(n=>n!==null):[]}var Fd,Hr,jd,Jd,Co=j(()=>{"use strict";g();et();Se();ve();Fd=10*1024*1024,Hr=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),jd=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),Jd=new Set([...Hr,...jd])});async function us(e,t){for(let n=0;;n++)try{return await e()}catch(s){let o=s.status,i=s.error?.type;if(!(o===429||i==="rate_limit_error"||s instanceof Error&&s.message.includes("429"))||n>=Ao.length)throw s;let r=Ao[n];T.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${Ao.length} \u2014 waiting ${r}s`),t&&t(`Rate limited \u2014 retrying in ${r}s...`),await new Promise(l=>setTimeout(l,r*1e3)),t&&t("Retrying...")}}function un(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t=e;for(let n of["fieldsJson","metaJson"])t[n]&&typeof t[n]=="object"&&(t[n]=JSON.stringify(t[n]))}return e}async function Ur(){return ko||(ko=(await import("@anthropic-ai/sdk")).default),ko}async function Bd(e,t,n,s,o){let i=await Ur(),a=new i({apiKey:e,...s?{defaultHeaders:s}:{}}),r=n.messages,l=n.systemPrompt;if(n.systemBlocks?l=o?[{type:"text",text:o},...n.systemBlocks]:n.systemBlocks:o&&(l=[{type:"text",text:o},{type:"text",text:n.systemPrompt}]),n.structuredOutput){let c={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema};return us(async()=>{let d=await a.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r,tools:[c],tool_choice:{type:"tool",name:n.structuredOutput.name}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:un(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return us(async()=>{let c="",d=a.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r});for await(let u of d)u.type==="content_block_delta"&&u.delta.type==="text_delta"&&(c+=u.delta.text,n.onChunk&&n.onChunk(u.delta.text));return{type:"text",text:c}},n.onStatus)}async function Wd(e,t,n){let s=await Ur(),o=new s({authToken:e,defaultHeaders:Ht}),i=n.messages,a;if(n.systemBlocks?a=[{type:"text",text:At},...n.systemBlocks]:a=[{type:"text",text:At},{type:"text",text:n.systemPrompt}],n.structuredOutput){let r={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema};return us(async()=>{let l=await o.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i,tools:[r],tool_choice:{type:"tool",name:n.structuredOutput.name}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:un(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return us(async()=>{let r="",l=o.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i});for await(let c of l)c.type==="content_block_delta"&&c.delta.type==="text_delta"&&(r+=c.delta.text,n.onChunk&&n.onChunk(c.delta.text));return{type:"text",text:r}},n.onStatus)}function Io(e){let t={...e};if(t.type==="object"&&(t.additionalProperties=!1,t.properties&&typeof t.properties=="object")){let n={};for(let[s,o]of Object.entries(t.properties))n[s]=o&&typeof o=="object"?Io(o):o;t.properties=n}return t.items&&typeof t.items=="object"&&(t.items=Io(t.items)),t}async function Vd(e,t,n){let s=[{role:"system",content:n.systemPrompt},...n.messages.map(l=>({role:l.role,content:typeof l.content=="string"?l.content:l.content.map(c=>({type:"text",text:c.text}))}))],o={model:t,max_tokens:n.maxTokens||16e3,messages:s};n.structuredOutput&&(o.response_format={type:"json_schema",json_schema:{name:n.structuredOutput.name,strict:!0,schema:Io(n.structuredOutput.schema)}});let i=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(o)});if(!i.ok){let l=await i.text(),c=i.status;if(c===429){let d=new Error(`OpenAI rate limit: ${l}`);throw d.status=429,d}throw new Error(`OpenAI API error (${c}): ${l}`)}let r=(await i.json()).choices?.[0]?.message?.content||"";if(n.structuredOutput)try{return{type:"structured",data:un(JSON.parse(r))}}catch{return T.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:r}}return{type:"text",text:r}}async function Kd(e,t,n){let s=t||"gemini-2.5-flash",o=n.messages.map(d=>({role:d.role==="assistant"?"model":"user",parts:typeof d.content=="string"?[{text:d.content}]:d.content.map(u=>({text:u.text}))})),i={systemInstruction:{parts:[{text:n.systemPrompt}]},contents:o,generationConfig:{maxOutputTokens:n.maxTokens||16e3,...n.structuredOutput?{responseMimeType:"application/json",responseSchema:n.structuredOutput.schema}:{}}},a=`https://generativelanguage.googleapis.com/v1beta/models/${s}:generateContent?key=${e}`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok){let d=await r.text(),u=r.status;if(u===429){let m=new Error(`Gemini rate limit: ${d}`);throw m.status=429,m}throw new Error(`Gemini API error (${u}): ${d}`)}let c=(await r.json()).candidates?.[0]?.content?.parts?.[0]?.text||"";if(n.structuredOutput)try{return{type:"structured",data:un(JSON.parse(c))}}catch{return T.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function Yd(e){switch(e){case"claude-code":{let t=_(),n=["--print"];return t.claudeCodeModel&&n.push("--model",t.claudeCodeModel),{bin:"claude",args:n}}case"gemini-cli":return{bin:"gemini",args:[]};case"codex-cli":return{bin:"codex",args:["exec","--full-auto"]};default:throw new Error(`Not a CLI engine: ${e}`)}}function zd(e){let t=[e.systemPrompt];for(let n of e.messages){let s=n.role==="user"?"User":"Assistant",o=typeof n.content=="string"?n.content:n.content.map(i=>i.text).join(`
|
|
633
|
+
`+t,d+=dn(),d+=Mr(a),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u,m;e==="gemini"?(u="gemini",m=[]):(u="codex",m=["exec","--full-auto"]);let f=0,h=o||(()=>{});h(fe[0]);let y=setInterval(()=>{f++;let w=fe[Math.min(f,fe.length-1)];h(w)},6e3);try{let w=await ds(u,m,d,x=>{s(x)});i&&i(w)}finally{clearInterval(y)}}var ho,fe,yo,So=D(()=>{"use strict";g();qe();Z();Ke();Se();_r();ve();ho=null;fe=["Analyzing your request...","Reading the conversion guide...","Planning module structure...","Generating HTML templates...","Writing CSS styles...","Creating field definitions...","Building module metadata...","Assembling theme assets...","Polishing the output...","Almost there \u2014 hang tight..."],yo=[10,20,40,60,120]});function p(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n))}function R(e,t){let n=[];e.on("data",s=>n.push(s)),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))}function vo(e,t,n){R(e,s=>{try{n(JSON.parse(s||"{}"))}catch{p(t,400,{error:"Invalid JSON in request body"})}})}var et=D(()=>{"use strict";g()});import{createWriteStream as Od,mkdirSync as Hr,existsSync as xo,readFileSync as wo}from"fs";import{join as ht,extname as Nd}from"path";import{randomUUID as Rd}from"crypto";import jd from"busboy";function Hd(e,t){if(Ur.has(t))return t;let n=e.slice(e.lastIndexOf(".")).toLowerCase();return Dd[n]??t}function Ld(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Ud(e,t){if(!xo(ht(e,t)))return t;let n=Nd(t),s=t.slice(0,-n.length||void 0),o=1;for(;xo(ht(e,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function Gd(e){let t=(await import("pdf-parse")).default,n=wo(e);return(await t(n)).text}async function Bd(e){return(await(await import("mammoth")).extractRawText({path:e})).value}function Wd(e){return wo(e,"utf-8")}function Gr(e,t){let n=v();if(!n){p(t,400,{error:"No active session"});return}if(!(e.headers["content-type"]||"").includes("multipart/form-data")){p(t,400,{error:"Expected multipart/form-data"});return}let o=[],i=[],a=0,r=[],l=jd({headers:e.headers,limits:{fileSize:Fd,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:f}=u;a++;let h=Hd(m,f);if(!Ur.has(h)){i.push(`Unsupported file type: ${m} (${f})`),d.resume();return}let y=Lr.has(h),w=Ld(m),x=Rd(),S,P;y?(S=ht(n.themePath,"assets"),Hr(S,{recursive:!0}),P=Ud(S,w)):(S=ht(n.themePath,".vibespot","uploads"),Hr(S,{recursive:!0}),P=`${x}-${w}`);let j=ht(S,P),G=Od(j),T=0,V=!1;d.on("data",N=>{T+=N.length}),d.on("limit",()=>{V=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(G),r.push(new Promise(N=>{G.on("finish",()=>{if(!V){let O={id:x,filename:P,originalName:m,type:y?"image":"document",usage:y?"asset":"context",mimeType:h,size:T,addedAt:new Date().toISOString()};o.push(O),Zi(O)}N()}),G.on("error",()=>{i.push(`Failed to write: ${m}`),N()})}))}),l.on("finish",async()=>{await Promise.all(r);for(let c of o)if(c.type==="document"){let d=ht(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await Gd(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await Bd(d):c.extractedText=Wd(d),$.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){$.warn("upload",`Failed to extract text from ${c.originalName}: ${u}`),c.extractedText=`[Could not extract text from ${c.originalName}]`}}if(a===0){p(t,400,{error:"No files uploaded"});return}p(t,200,{files:o.map(c=>({id:c.id,filename:c.filename,originalName:c.originalName,type:c.type,usage:c.usage,size:c.size})),errors:i.length>0?i:void 0})}),l.on("error",c=>{$.error("upload",`Busboy error: ${c}`),p(t,500,{error:"Upload failed"})}),e.pipe(l)}function Co(e){let t=v();return t?.assets?e.map(n=>{let s=t.assets.find(i=>i.id===n);if(!s)return null;let o={id:s.id,filename:s.filename,originalName:s.originalName,type:s.type,usage:s.usage,mimeType:s.mimeType};if(s.type==="image"){let i=ht(t.themePath,"assets",s.filename);xo(i)&&(o.base64=wo(i).toString("base64")),o.assetPath=`${t.themeName}/assets/${s.filename}`}else s.type==="document"&&(o.extractedText=s.extractedText);return o}).filter(n=>n!==null):[]}var Fd,Lr,Jd,Ur,Dd,Ao=D(()=>{"use strict";g();et();Se();ve();Fd=10*1024*1024,Lr=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),Jd=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),Ur=new Set([...Lr,...Jd]),Dd={".md":"text/markdown",".txt":"text/plain",".markdown":"text/markdown"}});async function us(e,t){for(let n=0;;n++)try{return await e()}catch(s){let o=s.status,i=s.error?.type;if(!(o===429||i==="rate_limit_error"||s instanceof Error&&s.message.includes("429"))||n>=ko.length)throw s;let r=ko[n];$.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${ko.length} \u2014 waiting ${r}s`),t&&t(`Rate limited \u2014 retrying in ${r}s...`),await new Promise(l=>setTimeout(l,r*1e3)),t&&t("Retrying...")}}function un(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t=e;for(let n of["fieldsJson","metaJson"])t[n]&&typeof t[n]=="object"&&(t[n]=JSON.stringify(t[n]))}return e}async function Br(){return Io||(Io=(await import("@anthropic-ai/sdk")).default),Io}async function Vd(e,t,n,s,o){let i=await Br(),a=new i({apiKey:e,...s?{defaultHeaders:s}:{}}),r=n.messages,l=n.systemPrompt;if(n.systemBlocks?l=o?[{type:"text",text:o},...n.systemBlocks]:n.systemBlocks:o&&(l=[{type:"text",text:o},{type:"text",text:n.systemPrompt}]),n.structuredOutput){let c={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema};return us(async()=>{let d=await a.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r,tools:[c],tool_choice:{type:"tool",name:n.structuredOutput.name}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:un(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return us(async()=>{let c="",d=a.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r});for await(let u of d)u.type==="content_block_delta"&&u.delta.type==="text_delta"&&(c+=u.delta.text,n.onChunk&&n.onChunk(u.delta.text));return{type:"text",text:c}},n.onStatus)}async function Kd(e,t,n){let s=await Br(),o=new s({authToken:e,defaultHeaders:Ht}),i=n.messages,a;if(n.systemBlocks?a=[{type:"text",text:At},...n.systemBlocks]:a=[{type:"text",text:At},{type:"text",text:n.systemPrompt}],n.structuredOutput){let r={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema};return us(async()=>{let l=await o.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i,tools:[r],tool_choice:{type:"tool",name:n.structuredOutput.name}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:un(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return us(async()=>{let r="",l=o.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i});for await(let c of l)c.type==="content_block_delta"&&c.delta.type==="text_delta"&&(r+=c.delta.text,n.onChunk&&n.onChunk(c.delta.text));return{type:"text",text:r}},n.onStatus)}function To(e){let t={...e};if(t.type==="object"&&(t.additionalProperties=!1,t.properties&&typeof t.properties=="object")){let n={};for(let[s,o]of Object.entries(t.properties))n[s]=o&&typeof o=="object"?To(o):o;t.properties=n}return t.items&&typeof t.items=="object"&&(t.items=To(t.items)),t}async function Yd(e,t,n){let s=[{role:"system",content:n.systemPrompt},...n.messages.map(l=>({role:l.role,content:typeof l.content=="string"?l.content:l.content.map(c=>({type:"text",text:c.text}))}))],o={model:t,max_tokens:n.maxTokens||16e3,messages:s};n.structuredOutput&&(o.response_format={type:"json_schema",json_schema:{name:n.structuredOutput.name,strict:!0,schema:To(n.structuredOutput.schema)}});let i=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(o)});if(!i.ok){let l=await i.text(),c=i.status;if(c===429){let d=new Error(`OpenAI rate limit: ${l}`);throw d.status=429,d}throw new Error(`OpenAI API error (${c}): ${l}`)}let r=(await i.json()).choices?.[0]?.message?.content||"";if(n.structuredOutput)try{return{type:"structured",data:un(JSON.parse(r))}}catch{return $.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:r}}return{type:"text",text:r}}async function zd(e,t,n){let s=t||"gemini-2.5-flash",o=n.messages.map(d=>({role:d.role==="assistant"?"model":"user",parts:typeof d.content=="string"?[{text:d.content}]:d.content.map(u=>({text:u.text}))})),i={systemInstruction:{parts:[{text:n.systemPrompt}]},contents:o,generationConfig:{maxOutputTokens:n.maxTokens||16e3,...n.structuredOutput?{responseMimeType:"application/json",responseSchema:n.structuredOutput.schema}:{}}},a=`https://generativelanguage.googleapis.com/v1beta/models/${s}:generateContent?key=${e}`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok){let d=await r.text(),u=r.status;if(u===429){let m=new Error(`Gemini rate limit: ${d}`);throw m.status=429,m}throw new Error(`Gemini API error (${u}): ${d}`)}let c=(await r.json()).candidates?.[0]?.content?.parts?.[0]?.text||"";if(n.structuredOutput)try{return{type:"structured",data:un(JSON.parse(c))}}catch{return $.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function qd(e){switch(e){case"claude-code":{let t=_(),n=["--print"];return t.claudeCodeModel&&n.push("--model",t.claudeCodeModel),{bin:"claude",args:n}}case"gemini-cli":return{bin:"gemini",args:[]};case"codex-cli":return{bin:"codex",args:["exec","--full-auto"]};default:throw new Error(`Not a CLI engine: ${e}`)}}function Xd(e){let t=[e.systemPrompt];for(let n of e.messages){let s=n.role==="user"?"User":"Assistant",o=typeof n.content=="string"?n.content:n.content.map(i=>i.text).join(`
|
|
634
634
|
`);t.push(`
|
|
635
635
|
|
|
636
636
|
## ${s}
|
|
637
|
-
${o}`)}if(e.structuredOutput){let n=
|
|
637
|
+
${o}`)}if(e.structuredOutput){let n=Wr(e.structuredOutput.schema);t.push(`
|
|
638
638
|
|
|
639
639
|
## Output Format \u2014 CRITICAL
|
|
640
640
|
Respond with a JSON code block. Wrap your JSON in \`\`\`json fences. No prose or explanation before or after the code block.
|
|
641
641
|
|
|
642
642
|
The JSON must match this structure:
|
|
643
|
-
${n}`)}return t.join("")}function
|
|
644
|
-
`)}function
|
|
643
|
+
${n}`)}return t.join("")}function Wr(e,t=0){let n=" ".repeat(t),s=e.properties,o=e.required||[];if(!s)return`${n}${JSON.stringify(e)}`;let i=["{"];for(let[a,r]of Object.entries(s)){let l=o.includes(a)?" (required)":"",c=r.type||"any",d=r.description?` \u2014 ${r.description}`:"",u=r.enum?` [${r.enum.join(", ")}]`:"";if(c==="array"&&r.items){let m=r.items.type||"object";i.push(`${n} "${a}": ${c}<${m}>${l}${d}${u}`)}else c==="object"&&r.properties?i.push(`${n} "${a}": ${Wr(r,t+1)}${l}${d}`):i.push(`${n} "${a}": ${c}${l}${d}${u}`)}return i.push(`${n}}`),i.join(`
|
|
644
|
+
`)}function Qd(e){let t=e.trim(),n=Ue(t);if(n&&typeof n=="object")return n;let s=t.match(/```(?:json|vibespot-modules)?\s*\n([\s\S]*?)```/i);if(s){let r=s[1].trim(),l=Ue(r);if(l&&typeof l=="object")return l;let c=ln(r);if(c&&typeof c=="object")return c}let o=t.indexOf("{"),i=t.lastIndexOf("}");if(o!==-1&&i>o){let r=t.slice(o,i+1),l=Ue(r);if(l&&typeof l=="object")return l;let c=ln(r);if(c&&typeof c=="object")return c}let a=ln(t);return a&&typeof a=="object"?a:null}async function Zd(e,t,n){let{bin:s,args:o}=qd(e),i=Xd(n),a=await ds(s,o,i,n.onChunk);if(!n.structuredOutput)return{type:"text",text:a};let r=Qd(a);return r?{type:"structured",data:un(r)}:($.warn("agent-cli",`${e}: failed to parse structured output, returning text`,{outputPreview:a.slice(0,500),outputLength:a.length}),{type:"text",text:a})}async function tu(e,t,n,s){switch($.info("agent-adapter",`${e} API call`,{model:n,structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),e){case"anthropic-api":return Vd(t,n,s);case"claude-oauth":{let{getValidAccessToken:o}=await Promise.resolve().then(()=>(Ke(),Os)),i=await o();if(!i)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");return Kd(i,n,s)}case"openai-api":return Yd(t,n,s);case"gemini-api":return zd(t,n,s);default:throw new Error(`Unsupported API engine: ${e}`)}}async function Pe(e,t,n,s){return eu.has(e)?tu(e,t,n,s):($.info("agent-adapter",`${e} CLI call`,{structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),Zd(e,n,s))}function ms(e){return e==="anthropic-api"||e==="claude-oauth"||e==="openai-api"||e==="gemini-api"||e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}function mn(e){return e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}var ko,Io,eu,ct=D(()=>{"use strict";g();So();cs();Z();Ke();ve();ko=[10,20,40,60,120];Io=null;eu=new Set(["anthropic-api","claude-oauth","openai-api","gemini-api"])});function Vr(e,t,n,s){let o=t.length>0?`Current template modules (in page order):
|
|
645
645
|
${t.map((r,l)=>`${l+1}. ${r}`).join(`
|
|
646
646
|
`)}`:"No modules yet (new page).",i=n.length>0?`
|
|
647
647
|
|
|
@@ -697,7 +697,7 @@ CRITICAL: When the user corrects a misclassification (e.g., "I was referencing t
|
|
|
697
697
|
If the user asks for multiple things (e.g., "make hero taller AND add testimonials"), capture ALL parts:
|
|
698
698
|
- Affected existing modules in \`affectedModules\`
|
|
699
699
|
- New modules in \`newModules\`
|
|
700
|
-
- Set the broadest applicable intent (prefer "modify" + newModules over splitting)`}var
|
|
700
|
+
- Set the broadest applicable intent (prefer "modify" + newModules over splitting)`}var Kr,Yr=D(()=>{"use strict";g();Kr={type:"object",properties:{intent:{type:"string",enum:["create","modify","add","remove","rearrange","style_change","question"]},affectedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that need changes"},unchangedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that stay as-is"},newModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},description:{type:"string"},position:{type:"number"}},required:["name","description","position"]},description:"New modules to create"},reuseModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},sourceTemplate:{type:"string"},position:{type:"number"}},required:["name","sourceTemplate","position"]},description:"Modules to copy from the library (immutable structure)"},guidesNeeded:{type:"array",items:{type:"string",enum:["design","content","conversion","hubspot_rules","humanify"]}},designSystemChanges:{type:"boolean",description:"True if shared CSS / design system needs regeneration"},answer:{type:"string",description:'For "question" intent only \u2014 the answer to return directly'}},required:["intent","affectedModules","unchangedModules","newModules","guidesNeeded","designSystemChanges"]}});async function zr(e,t,n,s,o,i,a){i({type:"agent_step",step:"analyzing",label:"Analyzing your request..."});let r=t.modules.map(f=>f.moduleName),l=Vr(t.themeName,r,a,t.brandAssets?.themeContext),c=[],d=t.messages.slice(-6);for(let f of d)if(f.role==="user"||f.role==="assistant"){let h=f.role==="assistant"&&f.content.length>300?f.content.slice(0,300)+"...":f.content;c.push({role:f.role,content:h})}c.push({role:"user",content:e});let u=await Pe(n,s,o,{systemPrompt:l,messages:c,structuredOutput:{schema:Kr,name:"pipeline_plan"},maxTokens:2e3});if(u.type!=="structured"){$.warn("intent-analyzer","Did not get structured output, falling back");let f=t.modules.length===0;return{intent:f?"create":"modify",affectedModules:f?[]:r,unchangedModules:[],newModules:[],guidesNeeded:["design","content","conversion","hubspot_rules","humanify"],designSystemChanges:f}}let m=u.data;return m.affectedModules=m.affectedModules||[],m.unchangedModules=m.unchangedModules||[],m.newModules=m.newModules||[],m.guidesNeeded=m.guidesNeeded||[],$.info("intent-analyzer","Plan",{intent:m.intent,affected:m.affectedModules.length,unchanged:m.unchangedModules.length,new:m.newModules.length,reuse:m.reuseModules?.length||0,designSystem:m.designSystemChanges}),i({type:"agent_decision",step:"analyzing",decision:nu(m)}),m}function nu(e){let t=[`Intent: ${e.intent}`];return e.affectedModules.length>0&&t.push(`Modifying: ${e.affectedModules.join(", ")}`),e.unchangedModules.length>0&&t.push(`Unchanged: ${e.unchangedModules.join(", ")}`),e.newModules.length>0&&t.push(`New: ${e.newModules.map(n=>n.name).join(", ")}`),e.reuseModules?.length&&t.push(`Reuse: ${e.reuseModules.map(n=>`${n.name} from ${n.sourceTemplate}`).join(", ")}`),e.designSystemChanges&&t.push("Design system changes: yes"),t.join(" | ")}var qr=D(()=>{"use strict";g();ct();Yr();ve()});function $o(e,t){let n=[];return n.push(`You are the Design System Architect for vibeSpot, a HubSpot CMS page builder.
|
|
701
701
|
|
|
702
702
|
Your job: create a complete, production-ready CSS design system for a landing page theme. You produce the :root custom properties, shared utility/component CSS, and optional shared JS (scroll animations). Downstream agents will use YOUR CSS classes and variables to build individual modules.
|
|
703
703
|
|
|
@@ -784,21 +784,22 @@ Good system font stacks by style:
|
|
|
784
784
|
| Geometric | Futura, "Century Gothic", "Trebuchet MS", sans-serif | system-ui, sans-serif |`),n.push(`
|
|
785
785
|
|
|
786
786
|
## Design Guide
|
|
787
|
-
${
|
|
787
|
+
${ta()}`),t?.styleguide&&n.push(`
|
|
788
788
|
|
|
789
789
|
## Brand Style Guide
|
|
790
790
|
${t.styleguide}`),t?.themeContext&&n.push(`
|
|
791
791
|
|
|
792
792
|
## Product Context
|
|
793
|
-
${t.themeContext}`),n.join("")}function
|
|
793
|
+
${t.themeContext}`),n.join("")}function Xr(e,t){let n=$o(e),o=n.indexOf(`
|
|
794
794
|
|
|
795
795
|
## Design Guide
|
|
796
796
|
`);if(o===-1)return[{type:"text",text:n}];let i=n.slice(0,o),a=`## Design Guide
|
|
797
|
-
${
|
|
797
|
+
${ta()}`,r=[{type:"text",text:i},{type:"text",text:a,cache_control:{type:"ephemeral"}}],l=[];return t?.styleguide&&l.push(`## Brand Style Guide
|
|
798
798
|
${t.styleguide}`),t?.themeContext&&l.push(`## Product Context
|
|
799
799
|
${t.themeContext}`),l.length>0&&r.push({type:"text",text:l.join(`
|
|
800
800
|
|
|
801
|
-
`)}),r}function
|
|
801
|
+
`)}),r}function su(e){let t=[...new Set([...e.matchAll(/\.([a-zA-Z][\w-]*)/g)].map(i=>`.${i[1]}`))],n=[...new Set([...e.matchAll(/(--[\w-]+)\s*:/g)].map(i=>i[1]))],s=[...new Set([...e.matchAll(/@media\s*\([^)]+\)/g)].map(i=>i[0]))],o=[];return n.length>0&&o.push(`CSS Variables: ${n.join(", ")}`),t.length>0&&o.push(`CSS Classes: ${t.join(", ")}`),s.length>0&&o.push(`Breakpoints: ${s.join(", ")}`),o.join(`
|
|
802
|
+
`)}function Zr(e,t,n,s){let o=[],i=su(t);return o.push(`You are the Module Planner for vibeSpot, a HubSpot CMS page builder.
|
|
802
803
|
|
|
803
804
|
Your job: plan the modules for a landing page. You define what each module contains (content brief) and how it should be laid out. You do NOT write module code \u2014 downstream Module Developers handle that.
|
|
804
805
|
|
|
@@ -806,12 +807,10 @@ The Design System has already been created. Your module plans MUST reference the
|
|
|
806
807
|
|
|
807
808
|
## Theme: "${e}"
|
|
808
809
|
|
|
809
|
-
## Available CSS Classes
|
|
810
|
-
|
|
810
|
+
## Available CSS Classes & Variables
|
|
811
|
+
Reference these in your layoutNotes:
|
|
811
812
|
|
|
812
|
-
|
|
813
|
-
${t}
|
|
814
|
-
\`\`\`
|
|
813
|
+
${i}
|
|
815
814
|
|
|
816
815
|
## Output Rules
|
|
817
816
|
- Module names: descriptive, title-case (e.g., "Hero Banner", "Pricing Cards")
|
|
@@ -821,7 +820,7 @@ ${t}
|
|
|
821
820
|
- moduleOrder: list module names in the order they should appear on the page`),(!s||s.includes("content"))&&o.push(`
|
|
822
821
|
|
|
823
822
|
## Content & Copywriting Guide
|
|
824
|
-
${
|
|
823
|
+
${ou()}`),n?.brandvoice&&o.push(`
|
|
825
824
|
|
|
826
825
|
## Brand Voice
|
|
827
826
|
${n.brandvoice}`),n?.themeContext&&o.push(`
|
|
@@ -830,7 +829,7 @@ ${n.brandvoice}`),n?.themeContext&&o.push(`
|
|
|
830
829
|
${n.themeContext}`),n?.humanify!==!1&&s?.includes("humanify")&&o.push(`
|
|
831
830
|
|
|
832
831
|
## Anti-AI Copy Rules
|
|
833
|
-
${
|
|
832
|
+
${iu()}`),o.join("")}function ta(){return`### Design Philosophy
|
|
834
833
|
You are a senior UI designer. Every page must look professionally designed, not like AI output.
|
|
835
834
|
Avoid "AI slop": purple gradients on white, cookie-cutter card grids, no personality.
|
|
836
835
|
|
|
@@ -933,7 +932,7 @@ Include these in shared CSS:
|
|
|
933
932
|
| All animations same speed | Stagger with increasing delays |
|
|
934
933
|
| Skip hover/focus states | Every interactive element needs feedback |
|
|
935
934
|
| Use \`<br>\` tags for spacing | Use proper margin/padding |
|
|
936
|
-
| Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function
|
|
935
|
+
| Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function ou(){return`### Mandatory Page Sections (generate all)
|
|
937
936
|
1. **Navigation Bar** \u2014 Logo, 4-5 nav links, CTA button, sticky on scroll
|
|
938
937
|
2. **Hero** \u2014 Badge/pill, primary headline, subheadline, primary + secondary CTA, trust signals, visual element
|
|
939
938
|
3. **Social Proof Bar** \u2014 Logo strip of 4-6 clients OR stats bar (compact, py-8)
|
|
@@ -1021,7 +1020,7 @@ Alternate backgrounds every 2-3 sections to create visual "chapters." Sprinkle t
|
|
|
1021
1020
|
- Invent plausible specifics: neighborhood names, "48 hours" not "quickly", "\u20AC49" not "affordable"
|
|
1022
1021
|
- Keep paragraphs to 2-3 sentences max
|
|
1023
1022
|
- Aim for 6th-grade reading level
|
|
1024
|
-
- Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function
|
|
1023
|
+
- Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function iu(){return`### Banned Punctuation
|
|
1025
1024
|
- **Em dashes (\u2014)**: NEVER use. Biggest AI tell. Replace with periods, commas, or parentheses.
|
|
1026
1025
|
- **Semicolons**: Feel academic, not conversational. Use periods instead.
|
|
1027
1026
|
- **Exclamation marks**: One per page maximum. Zero is ideal for B2B.
|
|
@@ -1051,28 +1050,28 @@ seamless, cutting-edge, groundbreaking, game-changer, revolutionary, transformat
|
|
|
1051
1050
|
- Use plain short words: use > utilize, start > commence, help > facilitate
|
|
1052
1051
|
- Vary sentence length aggressively: mix 3-word, 12-word, and 25-word sentences
|
|
1053
1052
|
- Front-load the benefit in the first 5 words
|
|
1054
|
-
- Write like you'd explain it in a bar \u2014 if you wouldn't say it holding a beer, rewrite it`}var
|
|
1053
|
+
- Write like you'd explain it in a bar \u2014 if you wouldn't say it holding a beer, rewrite it`}var Qr,ea,na=D(()=>{"use strict";g();Qr={type:"object",properties:{cssVariables:{type:"object",description:"CSS custom property name \u2192 value map. Every var() used in sharedCss must be defined here."},sharedCss:{type:"string",description:"Complete shared CSS file. MUST start with :root {} block defining all cssVariables, followed by reset, typography, layout, components, animations, and responsive styles."},sharedJs:{type:"string",description:"Optional shared JS for scroll animations (IntersectionObserver). Wrap in IIFE. Empty string if not needed."},aesthetic:{type:"string",description:"Brief description of the chosen aesthetic direction (e.g., 'dark luxury with warm gold accents')"}},required:["cssVariables","sharedCss","aesthetic"]};ea={type:"object",properties:{modules:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Module name in title-case"},description:{type:"string",description:"What this module does"},contentBrief:{type:"string",description:"Specific content: headlines, body copy, stats, CTAs"},layoutNotes:{type:"string",description:"Visual layout approach referencing shared CSS classes"}},required:["name","description","contentBrief","layoutNotes"]}},moduleOrder:{type:"array",items:{type:"string"},description:"Module names in page display order"},narrative:{type:"string",description:"Brief description of the page story/flow"}},required:["modules","moduleOrder","narrative"]}});async function sa(e,t,n,s,o,i,a){a({type:"agent_step",step:"designing",label:"Creating design system..."});let r=s==="anthropic-api"||s==="claude-oauth",l=$o(n.themeName,n.brandAssets),c=r?Xr(n.themeName,n.brandAssets):void 0,d=`## User Request
|
|
1055
1054
|
${e}`;n.modules.length>0&&t.designSystemChanges&&(d+=`
|
|
1056
1055
|
|
|
1057
1056
|
## Current Shared CSS (update this)
|
|
1058
1057
|
\`\`\`css
|
|
1059
1058
|
${n.sharedCss}
|
|
1060
|
-
\`\`\``);let u=await Pe(s,o,i,{systemPrompt:l,systemBlocks:c,messages:[{role:"user",content:d}],structuredOutput:{schema:
|
|
1061
|
-
${Object.entries(h).map(([
|
|
1059
|
+
\`\`\``);let u=await Pe(s,o,i,{systemPrompt:l,systemBlocks:c,messages:[{role:"user",content:d}],structuredOutput:{schema:Qr,name:"design_system"},maxTokens:16e3}),m;u.type!=="structured"?($.warn("page-architect","Design system: did not get structured output, using fallback"),m={cssVariables:{},sharedCss:n.sharedCss||"",sharedJs:n.sharedJs||"",aesthetic:"default"}):(m=u.data,$.info("page-architect","Design system created",{aesthetic:m.aesthetic,varCount:Object.keys(m.cssVariables||{}).length,cssLength:m.sharedCss?.length||0}));let f=m.sharedCss||"",h=m.cssVariables;h&&typeof h=="object"&&Object.keys(h).length>0&&(f.includes(":root")||(f=`:root {
|
|
1060
|
+
${Object.entries(h).map(([O,J])=>` ${O.startsWith("--")?O:`--${O}`}: ${J};`).join(`
|
|
1062
1061
|
`)}
|
|
1063
1062
|
}
|
|
1064
1063
|
|
|
1065
|
-
${f}`));let y=[],
|
|
1066
|
-
`)}),a({type:"design_system_ready",sharedCss:f,sharedJs:m.sharedJs||"",aesthetic:m.aesthetic||""}),a({type:"agent_step",step:"designing",label:"Planning modules..."});let P=
|
|
1067
|
-
${e}`;t.newModules.length>0&&(
|
|
1064
|
+
${f}`));let y=[],w=/\b(Montserrat|Inter|Poppins|Raleway|Playfair|Lato|Roboto|Open\s?Sans|Nunito|Merriweather|Oswald|Source\s?Sans|Fira\s?Sans|Work\s?Sans|Manrope|Plus\s?Jakarta)\b/gi,x=[...new Set((e.match(w)||[]).map(N=>N.trim()))];if(x.length>0){let N=x.filter(J=>f.toLowerCase().includes(J.toLowerCase())),O=x.filter(J=>!N.includes(J));O.length>0&&y.push(`Note: ${O.join(", ")} not available \u2014 HubSpot modules use system font stacks (no external font imports allowed)`)}let S=[`Design system: ${m.aesthetic||"created"} | ${Object.keys(h||{}).length} variables, ${f.length} chars CSS`,...y];a({type:"agent_decision",step:"designing",decision:S.join(`
|
|
1065
|
+
`)}),a({type:"design_system_ready",sharedCss:f,sharedJs:m.sharedJs||"",aesthetic:m.aesthetic||""}),a({type:"agent_step",step:"designing",label:"Planning modules..."});let P=Zr(n.themeName,f,n.brandAssets,t.guidesNeeded),j=`## User Request
|
|
1066
|
+
${e}`;t.newModules.length>0&&(j+=`
|
|
1068
1067
|
|
|
1069
1068
|
## Planned Modules
|
|
1070
|
-
${t.newModules.map((
|
|
1071
|
-
`)}`),n.modules.length>0&&!t.designSystemChanges&&(
|
|
1069
|
+
${t.newModules.map((N,O)=>`${O+1}. **${N.name}** \u2014 ${N.description}`).join(`
|
|
1070
|
+
`)}`),n.modules.length>0&&!t.designSystemChanges&&(j+=`
|
|
1072
1071
|
|
|
1073
1072
|
## Existing Modules (keeping)
|
|
1074
|
-
${n.modules.map(
|
|
1075
|
-
`)}`);let G=await Pe(s,o,i,{systemPrompt:P,messages:[{role:"user",content:
|
|
1073
|
+
${n.modules.map(N=>`- ${N.moduleName}`).join(`
|
|
1074
|
+
`)}`);let G=await Pe(s,o,i,{systemPrompt:P,messages:[{role:"user",content:j}],structuredOutput:{schema:ea,name:"module_plan"},maxTokens:8e3}),T,V={modules:t.newModules.map(N=>({name:N.name,description:N.description,contentBrief:"Generate appropriate content",layoutNotes:"Use responsive layout"})),moduleOrder:t.newModules.map(N=>N.name),narrative:"Page generated from user request"};if(G.type!=="structured")$.warn("page-architect","Module planner: did not get structured output, using fallback"),T=V;else{let N=G.data;Array.isArray(N?.modules)&&N.modules.length>0?(T=N,T.moduleOrder=T.moduleOrder||T.modules.map(O=>O.name),T.narrative=T.narrative||"Page generated from user request"):($.warn("page-architect","Module planner: structured output missing 'modules' array, using fallback",{keys:N?Object.keys(N):[]}),T=V),$.info("page-architect","Module plan",{moduleCount:T.modules.length})}return a({type:"agent_decision",step:"designing",decision:`Page: ${T.narrative} | ${T.modules.length} modules planned`}),{designSystem:{cssVariables:m.cssVariables||{},sharedCss:f,sharedJs:m.sharedJs},modules:T.modules,moduleOrder:T.moduleOrder,narrative:T.narrative}}var oa=D(()=>{"use strict";g();ct();na();ve()});function ia(e){let t=0,n=[];return async function(o){t>=e&&await new Promise(i=>n.push(i)),t++;try{return await o()}finally{t--,n.length>0&&n.shift()()}}}var ra=D(()=>{"use strict";g()});function Eo(e,t,n,s){let o=[];return o.push(`You are a Module Developer for vibeSpot, a HubSpot CMS page builder.
|
|
1076
1075
|
|
|
1077
1076
|
Your job: generate ONE HubSpot CMS module. You receive a module specification and must produce the complete module code.
|
|
1078
1077
|
|
|
@@ -1133,7 +1132,7 @@ ${oe()}`),s?.themeContext&&o.push(`
|
|
|
1133
1132
|
${s.themeContext}`),s?.humanify!==!1&&n?.includes("humanify")&&o.push(`
|
|
1134
1133
|
|
|
1135
1134
|
## Anti-AI Copy Rules
|
|
1136
|
-
${
|
|
1135
|
+
${la()}`),o.join("")}function aa(e,t,n,s){let o=[],i=Eo(e,"",[],s?{...s,humanify:!1}:void 0);t&&(i+=`
|
|
1137
1136
|
|
|
1138
1137
|
## Theme Shared CSS (use these custom properties)
|
|
1139
1138
|
\`\`\`css
|
|
@@ -1144,9 +1143,9 @@ ${oe()}`),a.length>0&&o.push({type:"text",text:a.join(`
|
|
|
1144
1143
|
|
|
1145
1144
|
`),cache_control:{type:"ephemeral"}});let r=[];return s?.themeContext&&r.push(`## Product Context
|
|
1146
1145
|
${s.themeContext}`),s?.humanify!==!1&&n?.includes("humanify")&&r.push(`## Anti-AI Copy Rules
|
|
1147
|
-
${
|
|
1146
|
+
${la()}`),r.length>0&&o.push({type:"text",text:r.join(`
|
|
1148
1147
|
|
|
1149
|
-
`)}),o}function
|
|
1148
|
+
`)}),o}function la(){return`### Banned Punctuation
|
|
1150
1149
|
- **Em dashes (\u2014)**: NEVER use. Replace with periods, commas, or parentheses. Hyphens for compounds fine.
|
|
1151
1150
|
- **Semicolons**: Use periods instead in marketing copy.
|
|
1152
1151
|
- **Exclamation marks**: One per page max. Zero ideal for B2B.
|
|
@@ -1185,7 +1184,7 @@ Never end with: "The future of [X] is here", "Your journey starts here", "Join t
|
|
|
1185
1184
|
- Keep slightly imperfect (fragments OK, mild hedging like "honestly didn't think")
|
|
1186
1185
|
- Full names, specific roles (not "John D., CEO")
|
|
1187
1186
|
- Never start with "This product is..." \u2014 start with the person's situation
|
|
1188
|
-
- Vary length and voice across testimonials`}function
|
|
1187
|
+
- Vary length and voice across testimonials`}function ca(e,t,n){let s=[];return s.push(`## User Request
|
|
1189
1188
|
${e}`),s.push(`
|
|
1190
1189
|
|
|
1191
1190
|
## Module Specification
|
|
@@ -1212,33 +1211,39 @@ ${n.moduleCss}
|
|
|
1212
1211
|
**module.js:**
|
|
1213
1212
|
\`\`\`js
|
|
1214
1213
|
${n.moduleJs}
|
|
1215
|
-
\`\`\``)),s.join("")}var
|
|
1214
|
+
\`\`\``)),s.join("")}var da,ua=D(()=>{"use strict";g();qe();da={type:"object",properties:{moduleName:{type:"string"},fieldsJson:{type:"string",description:"Complete fields.json content as a JSON string"},metaJson:{type:"string",description:"Complete meta.json content as a JSON string"},moduleHtml:{type:"string",description:"Complete module.html HubL template content"},moduleCss:{type:"string",description:"Complete module.css vanilla CSS content"},moduleJs:{type:"string",description:"Optional module.js vanilla JS content, or empty string if not needed"}},required:["moduleName","fieldsJson","metaJson","moduleHtml","moduleCss"]}});async function ma(e,t,n,s,o,i,a,r,l,c,d){l({type:"agent_step",step:"developing",label:`Generating ${t.length} module${t.length===1?"":"s"}...`});let u=o==="anthropic-api"||o==="claude-oauth",m=Eo(s,n,c,d),f=u?aa(s,n,c,d):void 0,h=ia(r),y=t.length,w=t.map((S,P)=>h(async()=>{l({type:"module_progress",module:S.name,status:"generating",current:P+1,total:y});let j="";for(let G=0;G<2;G++)try{G>0&&($.warn("module-developer",`${S.name}: retrying after failure (attempt ${G+1})`),l({type:"module_progress",module:S.name,status:"retrying",current:P+1,total:y}));let T=await pa(e,S,m,o,i,a,0,f);return l({type:"module_progress",module:S.name,status:"complete",current:P+1,total:y,moduleFiles:T}),{moduleName:S.name,module:T}}catch(T){j=T instanceof Error?T.message:typeof T=="object"&&T!==null?JSON.stringify(T):String(T),$.error("module-developer",`Failed: ${S.name} (attempt ${G+1})`,{error:j})}return l({type:"module_progress",module:S.name,status:"failed",current:P+1,total:y}),{moduleName:S.name,error:j}}));return(await Promise.allSettled(w)).map(S=>S.status==="fulfilled"?S.value:{moduleName:"unknown",error:S.reason instanceof Error?S.reason.message:String(S.reason)})}async function pa(e,t,n,s,o,i,a=0,r){let l=ca(e,t,t.existingCode),c=await Pe(s,o,i,{systemPrompt:n,systemBlocks:r,messages:[{role:"user",content:l}],structuredOutput:{schema:da,name:"module_output"},maxTokens:16e3});if(c.type!=="structured"){if(a<2)return $.warn("module-developer",`${t.name}: no structured output, retry ${a+1}`),pa(e,t,n,s,o,i,a+1,r);throw new Error(`Module "${t.name}" failed to produce structured output after ${a+1} attempts`)}let d=c.data,u=typeof d.fieldsJson=="string"?d.fieldsJson:JSON.stringify(d.fieldsJson,null,2),m=typeof d.metaJson=="string"?d.metaJson:JSON.stringify(d.metaJson,null,2);return{moduleName:t.name,fieldsJson:u,metaJson:m,moduleHtml:String(d.moduleHtml||""),moduleCss:String(d.moduleCss||""),moduleJs:d.moduleJs?String(d.moduleJs):void 0}}var fa=D(()=>{"use strict";g();ct();ra();ua();ve()});function ha(e,t,n){return n({type:"agent_step",step:"quality_check",label:"Quality check..."}),e.map(s=>{let o=[],i={...s};i.fieldsJson=ga(i.fieldsJson,i.moduleName,"fieldsJson",o),i.metaJson=ga(i.metaJson,i.moduleName,"metaJson",o),i.fieldsJson=ru(i.fieldsJson,i.moduleName,o),i.fieldsJson=au(i.fieldsJson,i.moduleName,o),i.moduleCss=lu(i.moduleCss,i.moduleName,"moduleCss",o),i.moduleCss=du(i.moduleCss,i.moduleName,t,o),i.moduleHtml=uu(i.moduleHtml,i.moduleName,t,o),i.moduleHtml=pu(i.moduleHtml,i.moduleName,o),i.metaJson=fu(i.metaJson,i.moduleName,o);let a=o.every(r=>r.autoFixed);return o.length>0&&$.info("validator",`${i.moduleName}: ${o.length} issues`,{autoFixed:o.filter(r=>r.autoFixed).length,unfixed:o.filter(r=>!r.autoFixed).length}),{module:i,issues:o,valid:a}})}function ga(e,t,n,s){return!e||e.trim()===""?(s.push({module:t,field:n,message:`Empty ${n}`,autoFixed:n==="metaJson"}),n==="metaJson"?JSON.stringify({host_template_types:["PAGE"],is_available_for_new_content:!0}):e):(Ue(e)===null&&s.push({module:t,field:n,message:`Invalid JSON in ${n}`,autoFixed:!1}),e)}function ru(e,t,n){let s=e;return/"name"\s*:\s*"name"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"name" is a reserved field name \u2192 renamed to "item_name"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"name"/g,'"name": "item_name"')),/"name"\s*:\s*"label"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"label" is a reserved field name \u2192 renamed to "section_label"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"label"/g,'"name": "section_label"')),s}function au(e,t,n){let s=e;return/"type"\s*:\s*"textarea"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"textarea" is deprecated \u2192 changed to "text"',autoFixed:!0}),s=s.replace(/"type"\s*:\s*"textarea"/g,'"type": "text"')),s}function lu(e,t,n,s){if(!e)return e;let o=e,i=/@import\s+url\([^)]*(?:fonts\.googleapis|cdnjs|unpkg|jsdelivr)[^)]*\)\s*;?/gi;return i.test(o)&&(s.push({module:t,field:n,message:"CDN @import removed (external imports not allowed)",autoFixed:!0}),o=o.replace(i,"/* CDN import removed */")),o}function ya(e){return cu.has(e)||e.startsWith("body-wrapper")||e.startsWith("dnd-")||e.startsWith("row-")||e.startsWith("hs-")||e.startsWith("hs_")}function du(e,t,n,s){if(!e)return e;let o=n+"-",i=/\.([a-zA-Z][\w-]*)/g,a=new Set,r;for(;(r=i.exec(e))!==null;){let c=r[1];!c.startsWith(o)&&!ya(c)&&a.add(c)}if(a.size<=3)return e;let l=e;for(let c of a){let d=new RegExp(`\\.${mu(c)}(?=[\\s,{:+~>\\[\\]])`,"g");l=l.replace(d,`.${o}${c}`)}return l!==e&&s.push({module:t,field:"moduleCss",message:`${a.size} CSS classes auto-prefixed with "${o}"`,autoFixed:!0}),l}function uu(e,t,n,s){if(!e)return e;let o=n+"-",i=/class="([^"]*)"/g,a=!1,r=e.replace(i,(l,c)=>{let d=c.split(/\s+/),u=!1,m=d.map(f=>f&&!f.startsWith(o)&&!ya(f)&&/^[a-zA-Z][\w-]*$/.test(f)?(u=!0,o+f):f);return u?(a=!0,`class="${m.join(" ")}"`):l});return a&&s.push({module:t,field:"moduleHtml",message:`HTML class references auto-prefixed with "${o}"`,autoFixed:!0}),r}function mu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function pu(e,t,n){if(!e)return e;let s=e,o=/\{%[-~]?\s*(if|for|block|macro|endif|endfor|endblock|endmacro)\b[^%]*%\}/g,i=[],a;for(;(a=o.exec(s))!==null;){let c=a[1],d=!c.startsWith("end"),u=d?c:c.replace("end","");i.push({tag:c,isOpen:d,baseTag:u,start:a.index,end:a.index+a[0].length})}let r=[],l=[];for(let c=0;c<i.length;c++)if(i[c].isOpen)r.push(c);else{let d=-1;for(let u=r.length-1;u>=0;u--)if(i[r[u]].baseTag===i[c].baseTag){d=u;break}d!==-1?r.splice(d,1):l.push(c)}if(l.length>0){for(let c=l.length-1;c>=0;c--){let d=i[l[c]];s=s.slice(0,d.start)+`<!-- removed orphan {% ${d.tag} %} -->`+s.slice(d.end)}n.push({module:t,field:"moduleHtml",message:`Removed ${l.length} orphan closing tag${l.length===1?"":"s"} with no matching opener`,autoFixed:!0})}if(r.length>0){let c=r.map(u=>i[u].baseTag),d=c.reverse().map(u=>`{% end${u} %}`).join(`
|
|
1216
1215
|
`);s=`${s}
|
|
1217
|
-
${d}`,n.push({module:t,field:"moduleHtml",message:`Added ${c.length} missing closing tag${c.length===1?"":"s"}: ${c.map(u=>`{% end${u} %}`).join(", ")}`,autoFixed:!0})}return/\bnow\(\)/.test(s)&&(s=s.replace(/\bnow\(\)/g,"local_dt"),n.push({module:t,field:"moduleHtml",message:"Replaced now() with local_dt (now() is not valid HubL)",autoFixed:!0})),s}function
|
|
1218
|
-
`);a({type:"agent_decision",step:"quality_check",decision:`${
|
|
1219
|
-
${X}`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let P=
|
|
1216
|
+
${d}`,n.push({module:t,field:"moduleHtml",message:`Added ${c.length} missing closing tag${c.length===1?"":"s"}: ${c.map(u=>`{% end${u} %}`).join(", ")}`,autoFixed:!0})}return/\bnow\(\)/.test(s)&&(s=s.replace(/\bnow\(\)/g,"local_dt"),n.push({module:t,field:"moduleHtml",message:"Replaced now() with local_dt (now() is not valid HubL)",autoFixed:!0})),s}function fu(e,t,n){let s=Ue(e);if(!s||typeof s!="object")return e;let o=s,i=!1;return o.host_template_types||(o.host_template_types=["PAGE"],i=!0),o.is_available_for_new_content===void 0&&(o.is_available_for_new_content=!0,i=!0),i?(n.push({module:t,field:"metaJson",message:"Added missing meta.json required fields",autoFixed:!0}),JSON.stringify(o,null,2)):e}var cu,ba=D(()=>{"use strict";g();cs();ve();cu=new Set(["visible","active","scroll-animate","hidden","open","closed","fade-in","fade-out","is-active","is-open","is-visible"])});import{execSync as gu}from"child_process";async function Sa(e,t,n,s,o,i,a,r){let l=Date.now(),c=i;if(mn(n)){let F={"claude-code":"claude","gemini-cli":"gemini","codex-cli":"codex"}[n];if(F)try{gu(`command -v ${F}`,{stdio:"ignore"})}catch{throw new Error(`CLI engine "${n}" requires "${F}" to be installed and on your PATH.`)}}let d=await zr(e,t,n,s,o,a,r);if(d.intent==="question"&&d.answer){let J=Date.now()-l;return a({type:"pipeline_complete",modulesGenerated:0,modulesUnchanged:t.modules.length,durationMs:J,answer:d.answer}),{modules:[...t.modules],moduleOrder:t.moduleOrder,sharedCss:t.sharedCss,sharedJs:t.sharedJs,assistantMessage:d.answer,stats:{modulesGenerated:0,modulesUnchanged:t.modules.length,modulesFailed:0,durationMs:J}}}let u=null,m=t.sharedCss,f=t.sharedJs;(d.intent==="create"||d.designSystemChanges)&&(u=await sa(e,d,t,n,s,o,a),m=u.designSystem.sharedCss||m,f=u.designSystem.sharedJs||f,a({type:"blueprint_ready",moduleOrder:u.moduleOrder,sharedCss:m,sharedJs:f}));let y=[];if(u)for(let J of u.modules)y.push({name:J.name,description:J.description,contentBrief:J.contentBrief,layoutNotes:J.layoutNotes});else{for(let J of d.newModules)y.push({name:J.name,description:J.description,contentBrief:"Generate appropriate content based on the user request",layoutNotes:"Use responsive layout matching the existing design system"});for(let J of d.affectedModules){let F=t.modules.find(X=>X.moduleName===J);F&&y.push({name:J,description:`Modify existing module: ${J}`,contentBrief:"Apply the user's requested changes",layoutNotes:"Preserve existing layout unless changes are requested",existingCode:F})}}let w=[],x=[];if(y.length>0){let J=await ma(e,y,m,t.themeName,n,s,o,c,a,d.guidesNeeded,t.brandAssets);for(let F of J)F.module?w.push(F.module):x.push(F.moduleName)}let S=null;if(w.length>0){S=ha(w,t.themeName,a),w=S.map(F=>F.module);let J=S.reduce((F,X)=>F+X.issues.length,0);if(J>0){let F=S.reduce((le,Wo)=>le+Wo.issues.filter(Ft=>Ft.autoFixed).length,0);$.info("pipeline",`Quality check: ${J} issues, ${F} auto-fixed`);let X=S.flatMap(le=>le.issues).map(le=>`${le.autoFixed?"\u2713":"\u26A0"} ${le.module}: ${le.message}`).join(`
|
|
1217
|
+
`);a({type:"agent_decision",step:"quality_check",decision:`${J} issues found, ${F} auto-fixed
|
|
1218
|
+
${X}`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let P=hu(t,d,w,u,r),j=yu(t,d,u,P);if(u?.moduleOrder?.length){let J=new Set(u.moduleOrder),F=P.filter(X=>!J.has(X.moduleName)).map(X=>X.moduleName);F.length>0&&a({type:"agent_decision",step:"quality_check",decision:`\u26A0 ${F.length} module${F.length===1?"":"s"} missing from page order \u2014 auto-inserted: ${F.join(", ")}`})}let G=Date.now()-l,T=w.length,V=d.unchangedModules.length,N=S?S.flatMap(J=>J.issues):[],O=bu(d,T,V,x,G,u,N);return x.length>0?a({type:"pipeline_partial",succeeded:w.map(J=>J.moduleName),failed:x,durationMs:G}):a({type:"pipeline_complete",modulesGenerated:T,modulesUnchanged:V,durationMs:G}),{modules:P,moduleOrder:j,sharedCss:m,sharedJs:f,assistantMessage:O,stats:{modulesGenerated:T,modulesUnchanged:V,modulesFailed:x.length,durationMs:G}}}function hu(e,t,n,s,o){let i=[],a=new Set;for(let r of n)i.push(r),a.add(r.moduleName);for(let r of t.unchangedModules){if(a.has(r))continue;let l=e.modules.find(c=>c.moduleName===r);l&&(i.push(l),a.add(r))}if(t.reuseModules)for(let r of t.reuseModules){if(a.has(r.name))continue;let l=o.find(c=>c.name===r.name&&c.module);l&&l.module&&(i.push(l.module),a.add(r.name))}return i}function yu(e,t,n,s){if(n?.moduleOrder?.length){let r=[...n.moduleOrder],l=new Set(r);for(let c of s)if(!l.has(c.moduleName)){let d=r.findIndex(u=>u.toLowerCase().includes("footer"));d!==-1?r.splice(d,0,c.moduleName):r.push(c.moduleName),l.add(c.moduleName),$.warn("pipeline",`Module "${c.moduleName}" missing from blueprint order \u2014 inserted`)}return r}if(t.intent==="create")return s.map(r=>r.moduleName);let o=[...e.moduleOrder],i=[...t.newModules.map(r=>({name:r.name,position:r.position})),...(t.reuseModules||[]).map(r=>({name:r.name,position:r.position}))].sort((r,l)=>r.position-l.position);for(let r of i){let l=Math.min(r.position,o.length);o.splice(l,0,r.name)}let a=new Set(s.map(r=>r.moduleName));return o.filter(r=>a.has(r))}function bu(e,t,n,s,o,i,a){let r=Math.round(o/1e3),l=[];if(e.intent==="create")l.push(`Created ${t} module${t===1?"":"s"} in ${r}s.`);else if(e.intent==="modify"||e.intent==="style_change")l.push(`Updated ${t} module${t===1?"":"s"} in ${r}s.`),n>0&&l.push(`${n} module${n===1?"":"s"} unchanged.`);else if(e.intent==="add"){let u=e.newModules.map(m=>m.name).join(", ");l.push(`Added ${u} in ${r}s.`)}else e.intent==="remove"?l.push(`Removed modules in ${r}s.`):e.intent==="rearrange"&&l.push(`Rearranged modules in ${r}s.`);i?.narrative&&l.push(`
|
|
1220
1219
|
|
|
1221
1220
|
${i.narrative}`),s.length>0&&l.push(`
|
|
1222
1221
|
|
|
1223
1222
|
**Failed:** ${s.join(", ")}. You can retry these individually.`);let c=a.filter(u=>!u.autoFixed),d=a.filter(u=>u.autoFixed);if(d.length>0||c.length>0){let u=[];d.length>0&&u.push(`**Auto-fixed:** ${d.map(m=>`${m.module}: ${m.message}`).join(", ")}`),c.length>0&&u.push(`**Warnings:** ${c.map(m=>`${m.module}: ${m.message}`).join(", ")}`),l.push(`
|
|
1224
1223
|
|
|
1225
1224
|
${u.join(`
|
|
1226
|
-
`)}`)}return l.join("")}var
|
|
1225
|
+
`)}`)}return l.join("")}var va=D(()=>{"use strict";g();ct();qr();oa();fa();ba();ve();ct()});var xa={};nt(xa,{applyPipelineResult:()=>Ro,handleAgenticGenerate:()=>No,handleGenerate:()=>Su,handleGenerateStream:()=>pn,isGenerating:()=>Nt,resolveAgenticEngine:()=>ps,setParseWarningCallback:()=>Mo,shouldUseAgenticMode:()=>jo});import{execSync as _o}from"child_process";function Mo(e){Po=e}function Nt(){return bt!==null}function yt(e){if(bt){let t=v();if(!t||t.id!==bt){$.warn("ai-handler","Session changed during generation \u2014 discarding AI output");return}}rt("assistant",e),$r(e,Po||void 0),L()}async function pn(e,t,n,s){let o=v();if(!o)throw new Error("No active session");bt=o.id;let a=s?.length?Co(s):void 0;try{let r=_(),l=r.aiEngine||Oo();switch(l){case"anthropic-api":case"api":{let c=ge("anthropic-api",r);if(!c)throw new Error("Anthropic API key not configured. Open Settings to add one.");await Rr(e,c,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"claude-oauth":{await jr(e,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"openai-api":{let c=ge("openai-api",r);if(!c)throw new Error("OpenAI API key not configured. Open Settings to add one.");await Fr(e,c,o.themeName,r.openaiApiModel||"gpt-4o",t,n,yt,a);break}case"gemini-api":{let c=ge("gemini-api",r);if(!c)throw new Error("Gemini API key not configured. Open Settings to add one.");await Jr(e,c,o.themeName,t,n,yt,a);break}case"claude-code":await Dr(e,o.themeName,t,n,yt,a);break;case"gemini-cli":await bo("gemini",e,o.themeName,t,n,yt,a);break;case"codex-cli":await bo("codex",e,o.themeName,t,n,yt,a);break;default:throw new Error(`Unknown AI engine: ${l}. Open Settings to configure one.`)}}finally{bt=null,Po=null}}function Oo(){let e=_();if(Re())return"claude-oauth";if(e.anthropicApiKey||process.env.ANTHROPIC_API_KEY)return"anthropic-api";if(e.openaiApiKey||process.env.OPENAI_API_KEY)return"openai-api";if(e.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY)return"gemini-api";try{return _o("claude --version",{stdio:"pipe"}),"claude-code"}catch{}try{return _o("gemini --version",{stdio:"pipe"}),"gemini-cli"}catch{}try{return _o("codex --version",{stdio:"pipe"}),"codex-cli"}catch{}throw new Error("No AI engine available. Open Settings to configure one.")}async function Su(e){let t="";return await pn(e,n=>{t+=n}),t}function vu(){let e=v(),t=Ce(),n=t?[...t.modules]:[...e.modules],s=t?[...t.moduleOrder]:[...e.moduleOrder];return{modules:n,moduleOrder:s,sharedCss:t?.sharedCss||e.sharedCss,sharedJs:t?.sharedJs||e.sharedJs,messages:[...e.messages],themeName:e.themeName,themePath:e.themePath,brandAssets:e.brandAssets?{...e.brandAssets}:void 0}}function ps(e){let t=e.aiEngine||Oo();if(!ms(t))throw new Error("Agentic pipeline is not available for this engine.");if(mn(t)){let o="";return t==="claude-code"&&(o=e.claudeCodeModel||""),{engine:t,apiKey:"",model:o}}let n;if(t==="claude-oauth"){if(!Re())throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");n="oauth"}else n=ge(t,e);if(!n)throw new Error(`API key not configured for ${t}. Open Settings to add one.`);let s;switch(t){case"anthropic-api":case"claude-oauth":s=e.anthropicApiModel||"claude-sonnet-4-6";break;case"openai-api":s=e.openaiApiModel||"gpt-4o";break;case"gemini-api":s="gemini-2.5-flash";break;default:s=""}return{engine:t,apiKey:n,model:s}}async function No(e,t,n){let s=v();if(!s)throw new Error("No active session");let o=s.id;bt=o;try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),c=i.agenticConcurrency||20,d=vu(),u=n?.length?Co(n):void 0,m=e;if(u?.length)for(let S of u)S.type==="document"&&S.extractedText&&(m+=`
|
|
1226
|
+
|
|
1227
|
+
---
|
|
1228
|
+
[Attached document: ${S.originalName}]
|
|
1229
|
+
${S.extractedText}`),S.type==="image"&&S.usage==="asset"&&S.assetPath&&(m+=`
|
|
1230
|
+
|
|
1231
|
+
[Uploaded image: ${S.originalName} \u2192 available as get_asset_url("${S.assetPath}")]`);let f=at(),h=new Set(d.modules.map(S=>S.moduleName)),y=f.filter(S=>!h.has(S.module.moduleName)).map(S=>({name:S.module.moduleName,usedIn:S.usedIn})),w=await Sa(m,d,a,r,l,c,t,y),x=v();if(!x||x.id!==o)throw $.warn("ai-handler","Session changed during agentic generation \u2014 discarding output"),new Error("Session changed during generation");return w}finally{bt=null}}function Ro(e,t){Le({modules:e.modules,sharedCss:e.sharedCss,sharedJs:e.sharedJs}),Et(e.moduleOrder),rt("assistant",e.assistantMessage,t),L()}function jo(){let e=_(),t=e.aiEngine||Oo();return ms(t)?e.agenticMode===void 0?{useAgentic:!1,needsPrompt:!0}:{useAgentic:e.agenticMode,needsPrompt:!1}:{useAgentic:!1,needsPrompt:!1,reason:"Agentic pipeline is not available for this engine."}}var Po,bt,fs=D(()=>{"use strict";g();Z();Se();cs();ve();So();Ke();Ao();va();Po=null;bt=null});var ws={};nt(ws,{collectThemeFiles:()=>il,extractDesignContext:()=>Lu});import{existsSync as Ss,readdirSync as vs,readFileSync as Fu}from"fs";import{join as Ge}from"path";import{spawn as Ju}from"child_process";async function ol(){return Jo||(Jo=(await import("@anthropic-ai/sdk")).default),Jo}function hn(e){try{return Fu(e,"utf-8")}catch{return""}}function il(e){let t=[],n=0;function s(r,l){if(!l.trim())return!0;let c=`
|
|
1227
1232
|
### ${r}
|
|
1228
1233
|
\`\`\`
|
|
1229
1234
|
${l}
|
|
1230
1235
|
\`\`\`
|
|
1231
|
-
`;return n+c.length>
|
|
1232
|
-
${n}`;t?.({status:"Analyzing design patterns..."});let i=_(),a=i.aiEngine||"anthropic-api",r="";switch(a){case"anthropic-api":case"api":{let l=ge("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await
|
|
1236
|
+
`;return n+c.length>Du?!1:(t.push(c),n+=c.length,!0)}let o=hn(Ge(e,"theme.json"));o&&s("theme.json",o);let i=Ge(e,"css");if(Ss(i)){for(let r of vs(i).filter(l=>l.endsWith(".css")))if(!s(`css/${r}`,hn(Ge(i,r))))break}let a=Ge(e,"modules");if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ge(a,r),c=hn(Ge(l,"module.css"));if(c&&!s(`modules/${r}/module.css`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ge(a,r),c=hn(Ge(l,"module.html"));if(c&&!s(`modules/${r}/module.html`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ge(a,r),c=hn(Ge(l,"fields.json"));if(c&&!s(`modules/${r}/fields.json`,c))break}return t.join("")}function Hu(){if(!xs)try{xs=k(vn("extraction-prompt.md"))}catch{xs=""}return xs}function Do(e,t,n){return new Promise((s,o)=>{let i={...process.env};delete i.CLAUDECODE;let a=Ju(e,t,{stdio:["pipe","pipe","pipe"],env:i,shell:!0}),r="",l="";a.stdout.on("data",c=>{r+=c.toString()}),a.stderr.on("data",c=>{l+=c.toString()}),a.on("error",c=>o(new Error(`${e} failed to start: ${c.message}`))),a.on("close",c=>{c===0||r.trim()?s(r.trim()):o(new Error(`${e} exited with code ${c}: ${l.trim()}`))}),a.stdin.write(n),a.stdin.end()})}async function Lu(e,t){t?.({status:"Collecting theme files..."});let n=il(e);if(!n.trim())throw new Error("No CSS, HTML, or fields.json files found in theme.");let s=Hu();if(!s)throw new Error("Extraction prompt not found (assets/extraction-prompt.md).");let o=`Analyze this HubSpot CMS theme and extract the design system:
|
|
1237
|
+
${n}`;t?.({status:"Analyzing design patterns..."});let i=_(),a=i.aiEngine||"anthropic-api",r="";switch(a){case"anthropic-api":case"api":{let l=ge("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await ol();r=(await new c({apiKey:l}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:s,messages:[{role:"user",content:o}]})).content.filter(m=>m.type==="text").map(m=>m.text).join("");break}case"claude-oauth":{let{getValidAccessToken:l,OAUTH_EXTRA_HEADERS:c,OAUTH_SYSTEM_PREFIX:d}=await Promise.resolve().then(()=>(Ke(),Os)),u=await l();if(!u)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let m=await ol();r=(await new m({authToken:u,defaultHeaders:c}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:[{type:"text",text:d},{type:"text",text:s}],messages:[{role:"user",content:o}]})).content.filter(y=>y.type==="text").map(y=>y.text).join("");break}case"openai-api":{let l=ge("openai-api");if(!l)throw new Error("OpenAI API key not configured. Open Settings to add one.");let c=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},body:JSON.stringify({model:i.openaiApiModel||"gpt-4o",max_tokens:8e3,messages:[{role:"system",content:s},{role:"user",content:o}]})});if(!c.ok)throw new Error(`OpenAI API error: ${c.status} ${await c.text()}`);r=(await c.json()).choices?.[0]?.message?.content||"";break}case"gemini-api":{let l=ge("gemini-api");if(!l)throw new Error("Gemini API key not configured. Open Settings to add one.");let c=i.geminiApiModel||"gemini-2.5-flash",d=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${c}:generateContent?key=${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({system_instruction:{parts:[{text:s}]},contents:[{role:"user",parts:[{text:o}]}],generationConfig:{maxOutputTokens:8e3}})});if(!d.ok)throw new Error(`Gemini API error: ${d.status} ${await d.text()}`);r=(await d.json()).candidates?.[0]?.content?.parts?.map(m=>m.text).join("")||"";break}case"claude-code":{let l=`${s}
|
|
1233
1238
|
|
|
1234
1239
|
## User Request
|
|
1235
|
-
${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),r=await
|
|
1240
|
+
${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),r=await Do("claude",c,l);break}case"gemini-cli":{let l=`${s}
|
|
1236
1241
|
|
|
1237
1242
|
## User Request
|
|
1238
|
-
${o}`;r=await
|
|
1243
|
+
${o}`;r=await Do("gemini",[],l);break}case"codex-cli":{let l=`${s}
|
|
1239
1244
|
|
|
1240
1245
|
## User Request
|
|
1241
|
-
${o}`;r=await
|
|
1246
|
+
${o}`;r=await Do("codex",[],l);break}default:throw new Error(`Unknown AI engine: ${a}. Open Settings to configure one.`)}if(!r.trim())throw new Error("AI returned empty response.");return t?.({status:"Design extraction complete."}),r}var Jo,Du,xs,Cs=D(()=>{"use strict";g();Q();Z();Jo=null;Du=8e4;xs=""});var rl={};nt(rl,{extractBrandvoice:()=>Uu});async function Uu(e,t,n,s){if(!e||e.length<50)return null;let o=`You are a brand strategist. Analyze the rendered landing page HTML below and extract a concise brand voice guide. The HTML contains the actual text content with all template variables resolved to their default values.
|
|
1242
1247
|
|
|
1243
1248
|
Return a markdown document with these sections (skip any section where the content provides no signal):
|
|
1244
1249
|
|
|
@@ -1258,7 +1263,7 @@ Typical sentence length, structure, use of questions, imperatives, etc.
|
|
|
1258
1263
|
## Dos and Don'ts
|
|
1259
1264
|
3-4 practical rules for writing in this voice (e.g., "Do: Lead with benefits, not features", "Don't: Use jargon without context").
|
|
1260
1265
|
|
|
1261
|
-
Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await Pe(t,n,s,{systemPrompt:o,messages:[{role:"user",content:e}],maxTokens:1e3}),a=i.type==="text"?i.text:JSON.stringify(i.data);return!a||a.trim().length<20?null:(
|
|
1266
|
+
Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await Pe(t,n,s,{systemPrompt:o,messages:[{role:"user",content:e}],maxTokens:1e3}),a=i.type==="text"?i.text:JSON.stringify(i.data);return!a||a.trim().length<20?null:($.info("brandvoice-extractor",`Extracted brand voice (${a.length} chars)`),a.trim())}catch(i){let a=i instanceof Error?i.message:String(i);return $.warn("brandvoice-extractor",`Brand voice extraction failed: ${a}`),null}}var al=D(()=>{"use strict";g();ct();ve()});var Ho={};nt(Ho,{extractThemeContext:()=>Gu});async function Gu(e,t,n,s,o){if(!e||e.length<50)return null;let a=`You are a content analyst. Extract a concise product/company brief from the rendered landing page HTML below. The HTML contains the actual text content (headings, paragraphs, button labels, image alt text, etc.) with all template variables resolved to their default values.
|
|
1262
1267
|
|
|
1263
1268
|
Return a markdown document with these sections (skip any section where the content provides no information):
|
|
1264
1269
|
|
|
@@ -1280,11 +1285,11 @@ Specific terms, product names, or branded language used consistently.
|
|
|
1280
1285
|
Keep it concise \u2014 this brief is used as context for AI-generated content on other pages in the same theme.${t?`
|
|
1281
1286
|
|
|
1282
1287
|
Existing product context (update if the new content adds info, keep what's still accurate):
|
|
1283
|
-
${t}`:""}`;try{let r=await Pe(n,s,o,{systemPrompt:a,messages:[{role:"user",content:e}],maxTokens:1e3}),l=r.type==="text"?r.text:JSON.stringify(r.data);return!l||l.trim().length<20?null:(
|
|
1284
|
-
`);for(let a of i){let r=a.match(/^\s*(.+?)\s+(\d{5,})\s+(.*)/);if(r&&!/Account ID/i.test(a)&&!/^-+$/.test(a.trim())&&!/^Name\s/i.test(a.trim())){let l=r[1].trim(),c=r[2].trim(),d=r[3]?.trim()||"unknown";t.push({name:l,portalId:c,authType:d,isDefault:c===s})}}return o?{authenticated:!0,portalName:n,portalId:s,accounts:t}:t.length>0?{authenticated:!0,portalName:t[0].name,portalId:t[0].portalId,accounts:t}:{authenticated:e.stdout.length>0,portalName:"",portalId:"",accounts:[]}}function Vt(){let e
|
|
1285
|
-
`)[0]?.replace("gh version ","").split(" ")[0]||"",path
|
|
1288
|
+
${t}`:""}`;try{let r=await Pe(n,s,o,{systemPrompt:a,messages:[{role:"user",content:e}],maxTokens:1e3}),l=r.type==="text"?r.text:JSON.stringify(r.data);return!l||l.trim().length<20?null:($.info("context-extractor",`Extracted theme context (${l.length} chars)`),l.trim())}catch(r){let l=r instanceof Error?r.message:String(r);return $.warn("context-extractor",`Theme context extraction failed: ${l}`),null}}var Lo=D(()=>{"use strict";g();ct();ve()});g();g();import{Command as im}from"commander";g();g();g();import vt from"chalk";var Oe={accent:"#FF7A59",accentBright:"#FF9A7A",success:"#00BDA5",info:"#0066FF",warn:"#FFB020",error:"#E23D2D",muted:"#8B8D91",vibes:"#00BDD6"},Vo=!!process.env.NO_COLOR;function We(e){return Vo?vt:vt.hex(e)}var I={accent:We(Oe.accent),accentBright:We(Oe.accentBright),success:We(Oe.success),info:We(Oe.info),warn:We(Oe.warn),error:We(Oe.error),muted:We(Oe.muted),vibes:We(Oe.vibes),heading:Vo?vt.bold:vt.bold.hex(Oe.accent),command:We(Oe.accentBright),dim:vt.dim,bold:vt.bold};Q();function Ne(){let e=I.vibes,t=I.accent,n=I.muted,s=[`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584\u2584")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2584\u2584\u2584\u2584\u2584 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584 \u2580\u2580\u2588\u2588\u2580\u2580")}`,`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B ")}${t("\u2580\u2580\u2580\u2584 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e(" \u2588\u2584\u2584\u2588\u2580 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${t(" \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e(" \u2580\u2580\u2580 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2580\u2580\u2580\u2580\u2580")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2580\u2580\u2580\u2580 \u2588\u2588 \u2580\u2580\u2580\u2580 \u2588\u2588 ")}`];console.log();for(let o of s)console.log(` ${o}`);console.log(),console.log(` ${n("AI-powered HubSpot Landing Pages")} ${I.dim(`v${wt()}`)}`),console.log()}g();g();ut();Z();Ke();import{join as In}from"path";import{homedir as Tn}from"os";import{readFileSync as ti,existsSync as $n,readdirSync as ql}from"fs";var mt=process.platform==="win32"?"where":"which";function Ut(){let e=E("node --version");return{name:"Node.js",found:e.success,version:e.stdout.replace(/^v/,""),path:E(`${mt} node`).stdout}}function Gt(){let e=E("git --version");return{name:"Git",found:e.success,version:e.stdout.replace("git version ",""),path:E(`${mt} git`).stdout}}function je(){let e=E("hs --version");return{name:"HubSpot CLI",found:e.success,version:e.stdout,path:E(`${mt} hs`).stdout}}function Bt(){let e=E("claude --version");if(!e.success)return{name:"Claude Code",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=In(Tn(),".claude"),n=!1,s="Not signed in \u2014 run `claude` to authenticate";try{if($n(t)){let o=ql(t);(o.some(a=>a.includes("credentials")||a.includes("auth")||a.includes("token")||a===".credentials.json")||o.length>2)&&(n=!0,s="Authenticated")}}catch{}return{name:"Claude Code",found:!0,version:e.stdout,path:E(`${mt} claude`).stdout,authenticated:n,authDetail:s}}function Wt(e){try{let t=In(Tn(),".hscli","config.yml");if(!$n(t))return"na1";let n=ti(t,"utf-8"),s=n.indexOf(`accountId: ${e}`);if(s===-1)return"na1";let o=n.indexOf("personalAccessKey:",s);if(o===-1)return"na1";let a=n.slice(o,o+300).match(/personalAccessKey:[\s>-]*\n\s+(\S+)/);if(!a)return"na1";if(a[1].startsWith("CiRldTE"))return"eu1"}catch{}return"na1"}function Fe(){let e=E("hs accounts list");if(!e.success||!e.stdout)return{authenticated:!1,portalName:"",portalId:"",accounts:[]};let t=[],n="",s="",o=e.stdout.match(/Account:\s*(.+?)\s*\((\d+)\)/);o&&(n=o[1].trim(),s=o[2].trim());let i=e.stdout.split(`
|
|
1289
|
+
`);for(let a of i){let r=a.match(/^\s*(.+?)\s+(\d{5,})\s+(.*)/);if(r&&!/Account ID/i.test(a)&&!/^-+$/.test(a.trim())&&!/^Name\s/i.test(a.trim())){let l=r[1].trim(),c=r[2].trim(),d=r[3]?.trim()||"unknown";t.push({name:l,portalId:c,authType:d,isDefault:c===s})}}return o?{authenticated:!0,portalName:n,portalId:s,accounts:t}:t.length>0?{authenticated:!0,portalName:t[0].name,portalId:t[0].portalId,accounts:t}:{authenticated:e.stdout.length>0,portalName:"",portalId:"",accounts:[]}}function Vt(){let e=E("gemini --version");if(!e.success)return{name:"Gemini CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=In(Tn(),".config","gcloud","application_default_credentials.json"),n=$n(t),s=!!(process.env.GEMINI_API_KEY||process.env.GOOGLE_API_KEY||process.env.GOOGLE_AI_API_KEY),o=n||s;return{name:"Gemini CLI",found:!0,version:e.stdout,path:E(`${mt} gemini`).stdout,authenticated:o,authDetail:o?"Authenticated":"Run `gemini` to sign in with Google"}}function Kt(){let e=E("codex --version");if(!e.success)return{name:"OpenAI Codex CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=!!process.env.OPENAI_API_KEY,n=!1;try{let i=In(Tn(),".codex","auth.json");$n(i)&&(n=ti(i,"utf-8").length>10)}catch{}let s=t||n,o=n?"Authenticated (OAuth)":t?"Authenticated (API key)":"Not authenticated";return{name:"OpenAI Codex CLI",found:!0,version:e.stdout,path:E(`${mt} codex`).stdout,authenticated:s,authDetail:o}}function Rs(){let e=E("gh --version");return{name:"GitHub CLI",found:e.success,version:e.stdout.split(`
|
|
1290
|
+
`)[0]?.replace("gh version ","").split(" ")[0]||"",path:E(`${mt} gh`).stdout}}function js(){let e=E("gh auth status 2>&1");if(!e.success&&!e.stdout)return{authenticated:!1,username:""};let t=e.stdout||e.stderr||"",n=t.match(/Logged in to github\.com.*account\s+(\S+)/);if(n)return{authenticated:!0,username:n[1]};let s=t.match(/account\s+(\S+)/);return s&&t.includes("Logged in")?{authenticated:!0,username:s[1]}:{authenticated:t.includes("Logged in"),username:""}}function ni(){return!!process.env.ANTHROPIC_API_KEY}function En(e){return parseInt(e.split(".")[0],10)>=18}function si(e){let t=parseInt(e.split(".")[0],10);return!isNaN(t)&&t>=8}function Xl(){let e=_(),t=e.hubspotUploadMode||"api",n=e.hubspotAccounts||[],s=n.map(i=>({name:i.portalName,portalId:i.portalId,authType:"personalaccesskey",isDefault:i.portalId===(e.activeHubSpotAccount||n[0]?.portalId)})),o=st();return{authenticated:!!o,portalName:o?.portalName||"",portalId:o?.portalId||"",dataCenter:o?o.dataCenter:"na1",accounts:s,uploadMode:t}}var Ns={name:"",found:!1,version:"",path:"",authenticated:!1,authDetail:"Disabled"};function _n(){let e=_(),t=Ut(),n=Gt(),s=e.hubspotUploadMode||"api",o;if(s==="cli"){let x=je(),S=x.found?Fe():{authenticated:!1,portalName:"",portalId:"",accounts:[]},P=S.portalId?Wt(S.portalId):"na1";o={...x,...S,dataCenter:P,uploadMode:"cli"}}else o={name:"HubSpot API",found:!0,version:"v3",path:"",...Xl()};let i=Rs(),a=i.found?js():{authenticated:!1,username:""},r={authenticated:Re(),expiresAt:Lt()?.expiresAt},l=e.enabledCLITools||[],c=Dt("claude-code")?Bt():{...Ns,name:"Claude Code"},d=Dt("gemini-cli")?Vt():{...Ns,name:"Gemini CLI"},u=Dt("codex-cli")?Kt():{...Ns,name:"OpenAI Codex CLI"};function m(x,...S){if(x)return{configured:!0,masked:wn(x),source:"config"};for(let P of S)if(process.env[P])return{configured:!0,masked:wn(process.env[P]),source:"env"};return{configured:!1,masked:"",source:null}}let f=m(e.anthropicApiKey,"ANTHROPIC_API_KEY"),h=m(e.openaiApiKey,"OPENAI_API_KEY"),y=m(e.geminiApiKey,"GEMINI_API_KEY","GOOGLE_AI_API_KEY"),w=[];return c.found&&c.authenticated&&w.push("claude-code"),r.authenticated&&w.push("claude-oauth"),f.configured&&w.push("anthropic-api"),h.configured&&w.push("openai-api"),d.found&&d.authenticated&&w.push("gemini-cli"),y.configured&&w.push("gemini-api"),u.found&&u.authenticated&&w.push("codex-cli"),{tools:{node:t,git:n,hubspot:o,github:{...i,...a},claudeCode:c,claudeOAuth:r,geminiCli:d,codexCli:u},apiKeys:{anthropic:f,openai:h,gemini:y},activeEngine:e.aiEngine||null,availableEngines:w,enabledCLITools:l}}Ke();ut();Z();pt();g();import*as Y from"@clack/prompts";function Js(e){Y.isCancel(e)&&(Y.cancel(I.muted("Operation cancelled.")),process.exit(0))}async function ce(e){Y.intro(I.heading(e))}async function de(e){Y.outro(I.success(e))}async function Je(e,t){Y.note(e,t?I.heading(t):void 0)}async function Te(e){let t=await Y.text({message:I.accent(e.message),placeholder:e.placeholder,defaultValue:e.defaultValue,validate:e.validate});return Js(t),t}async function se(e){let t=await Y.confirm({message:I.accent(e.message),initialValue:e.initialValue??!0});return Js(t),t}async function It(e){let t=await Y.select({message:I.accent(e.message),options:e.options});return Js(t),t}async function ue(){let e=Y.spinner();return{start:t=>e.start(I.muted(t)),stop:t=>e.stop(I.success(t)),message:t=>e.message(I.muted(t))}}function ee(e){Y.log.info(e)}function H(e){Y.log.success(I.success(e))}function z(e){Y.log.warn(I.warn(e))}function B(e){Y.log.error(I.error(e))}async function Nn(){await ce("Checking your environment");let e=Ut();e.found||(B("Node.js not found. Install it from https://nodejs.org"),process.exit(1)),En(e.version)||(B(`Node.js ${e.version} is too old. Version 18+ required. Update at https://nodejs.org`),process.exit(1)),H(`Node.js v${e.version}`);let t=Gt();t.found||(B("Git not found. Install it from https://git-scm.com"),process.exit(1)),H(`Git ${t.version}`);let n=_(),s=n.hubspotUploadMode!=="cli",o="",i="";if(s){let w=he(),x=st();if(w)o=x?.portalId||"",i=x?.portalName||"",H(`HubSpot${i?`: ${i}`:""}${o?` (${o})`:""} \u2014 API mode`);else{z("No HubSpot account connected"),await Je(`You need a Personal Access Key to deploy themes.
|
|
1286
1291
|
Create one at: https://app.hubspot.com/l/personal-access-key
|
|
1287
|
-
Make sure the Content scope is enabled.`,"HubSpot connection required");let
|
|
1292
|
+
Make sure the Content scope is enabled.`,"HubSpot connection required");let S=await Te({message:"Paste your Personal Access Key:",placeholder:"pat-na1-...",validate:j=>j.trim()?void 0:"Key is required"}),P=await ue();P.start("Validating key...");try{let j=await Mn(S);Jt(S,j.portalId,j.portalName,j.dataCenter),w=S,o=j.portalId,i=j.portalName,P.stop(`Connected to ${j.portalName} (${j.portalId})`)}catch(j){P.stop("Validation failed"),B(`Invalid key: ${j instanceof Error?j.message:String(j)}`),process.exit(1)}}}else{let w=je();if(w.found)H(`HubSpot CLI v${w.version}`);else{z("HubSpot CLI not found"),await se({message:"Install HubSpot CLI globally?"})||(B("HubSpot CLI is required in CLI mode. Install: npm install -g @hubspot/cli"),process.exit(1));let P=await ue();P.start("Installing HubSpot CLI..."),E("npm install -g @hubspot/cli").success||(P.stop("Failed"),B("Try: npm install -g @hubspot/cli"),process.exit(1)),w=je(),P.stop(`HubSpot CLI v${w.version} installed`)}let x=Fe();if(x.authenticated)H(`HubSpot portal${x.portalName?`: ${x.portalName}`:""} (ID: ${x.portalId})`);else{z("HubSpot not authenticated"),await se({message:"Run `hs init` now?"})||(B("Run `hs init` manually."),process.exit(1));let P=await ue();P.start("Waiting for HubSpot authentication..."),qo("hs init")||(P.stop("Authentication failed"),process.exit(1)),x=Fe(),P.stop(`Connected to portal${x.portalName?`: ${x.portalName}`:""} (ID: ${x.portalId})`)}o=x.portalId,i=x.portalName}let a=Bt(),r=Vt(),l=Kt(),c=ni(),d={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"},u=Re(),m,f=n.aiEngine,h=[];if(a.found&&h.push({value:"claude-code",label:"Claude Code",hint:f==="claude-code"?"last used \u2014 recommended":"uses your existing Claude subscription \u2014 recommended"}),u&&h.push({value:"claude-oauth",label:"Claude (OAuth)",hint:f==="claude-oauth"?"last used":"uses your Claude Pro/Max subscription via OAuth"}),r.found&&h.push({value:"gemini-cli",label:"Gemini CLI",hint:f==="gemini-cli"?"last used":"uses your existing Gemini setup"}),l.found&&h.push({value:"codex-cli",label:"OpenAI Codex",hint:f==="codex-cli"?"last used":"uses your existing OpenAI setup"}),c&&h.push({value:"api",label:"Anthropic API",hint:f==="api"?"last used":"uses your API key"}),f&&h.sort((w,x)=>w.value===f?-1:x.value===f?1:0),h.length===1)m=h[0].value,H(`AI engine: ${d[m]} (auto-detected)`);else if(h.length>1)m=await It({message:"Choose your AI engine:",options:h});else if(await Je(`You need an AI coding assistant to power the conversion.
|
|
1288
1293
|
|
|
1289
1294
|
${I.bold("Option 1:")} Install Claude Code ${I.muted("(recommended)")}
|
|
1290
1295
|
https://claude.ai/code
|
|
@@ -1297,13 +1302,13 @@ ${I.bold("Option 3:")} Install OpenAI Codex
|
|
|
1297
1302
|
|
|
1298
1303
|
${I.bold("Option 4:")} Set an Anthropic API key
|
|
1299
1304
|
export ANTHROPIC_API_KEY=sk-ant-...
|
|
1300
|
-
(get one at https://console.anthropic.com)`,"AI engine required"),m=await It({message:"Which will you set up?",options:[{value:"claude-code",label:"Claude Code",hint:"I'll install it now"},{value:"gemini-cli",label:"Gemini CLI",hint:"I'll install it now"},{value:"codex-cli",label:"OpenAI Codex",hint:"I'll install it now"},{value:"api",label:"Anthropic API",hint:"I'll enter my key"}]}),m==="api"){let
|
|
1305
|
+
(get one at https://console.anthropic.com)`,"AI engine required"),m=await It({message:"Which will you set up?",options:[{value:"claude-code",label:"Claude Code",hint:"I'll install it now"},{value:"gemini-cli",label:"Gemini CLI",hint:"I'll install it now"},{value:"codex-cli",label:"OpenAI Codex",hint:"I'll install it now"},{value:"api",label:"Anthropic API",hint:"I'll enter my key"}]}),m==="api"){let w=await Te({message:"Enter your Anthropic API key:",placeholder:"sk-ant-api03-...",validate:x=>x.startsWith("sk-ant-")?void 0:"Key should start with sk-ant-"});process.env.ANTHROPIC_API_KEY=w,K({anthropicApiKey:w})}let y;return m==="claude-code"&&(y=await It({message:"Which model?",options:[{value:"sonnet",label:"Sonnet",hint:"fast, recommended"},{value:"opus",label:"Opus",hint:"most capable"},{value:"haiku",label:"Haiku",hint:"fastest, cheapest"}]})),K({aiEngine:m}),await de("Environment ready!"),{aiEngine:m,model:y,portalId:o,portalName:i}}g();ut();Q();import{readdirSync as Ds,statSync as ic}from"fs";import{join as te,basename as Hs,extname as rc}from"path";function ci(e){let t=[],n=[te(e,"src/components/landing"),te(e,"src/components/sections"),te(e,"src/components"),te(e,"src/pages"),te(e,"app/components"),te(e,"components")];for(let s of n)if(b(s))try{let o=Ds(s);for(let i of o){let a=te(s,i);if(!ic(a).isFile())continue;let l=rc(i);if(![".tsx",".jsx"].includes(l))continue;let c=Hs(i,l);if(c.startsWith("ui")||c==="index")continue;let d=k(a),u=ac(c,d);t.push({name:c,path:a,description:u})}}catch{}return t}function ac(e,t){let n=[];return/carousel|slider|swiper|embla/i.test(t)&&n.push("carousel"),/accordion|collapsible|expand/i.test(t)&&n.push("accordion"),/form|submit|input.*email/i.test(t)&&n.push("form"),/nav|navigation|menu/i.test(t)&&n.push("navigation"),/hero|headline|tagline/i.test(t)&&n.push("hero"),/footer|copyright/i.test(t)&&n.push("footer"),/testimonial|quote|review/i.test(t)&&n.push("testimonials"),/pricing|plan|tier/i.test(t)&&n.push("pricing"),/faq|question.*answer/i.test(t)&&n.push("FAQ"),/feature|benefit|advantage/i.test(t)&&n.push("features"),/contact|get.in.touch/i.test(t)&&n.push("contact"),/cta|call.to.action/i.test(t)&&n.push("CTA"),/team|member|bio/i.test(t)&&n.push("team"),n.length===0?e.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim():n.join(", ")}function di(e){let t=[te(e,"src/index.css"),te(e,"src/globals.css"),te(e,"src/app/globals.css"),te(e,"app/globals.css")],n=0,s=[];for(let o of t){if(!b(o))continue;let i=k(o),a=i.match(/--[\w-]+:/g);a&&(n+=a.length);let r=i.match(/font-family:\s*['"]([^'"]+)['"]/g);if(r)for(let c of r){let d=c.match(/['"]([^'"]+)['"]/)?.[1];d&&!s.includes(d)&&s.push(d)}let l=i.match(/@import\s+url\([^)]*fonts\.googleapis\.com[^)]*family=([^&)]+)/g);if(l)for(let c of l){let d=c.match(/family=([^&)]+)/)?.[1]?.replace(/\+/g," ");d&&!s.includes(d)&&s.push(d)}}return{varCount:n,fonts:s}}function ui(e){let t=[],n=te(e,"src/hooks");if(b(n))try{let o=Ds(n);for(let i of o)/scroll/i.test(i)&&t.push("Scroll animations"),/intersection/i.test(i)&&t.push("Scroll animations")}catch{}let s=te(e,"src/components/landing");if(b(s))try{let o=Ds(s);for(let i of o){if(!i.endsWith(".tsx")&&!i.endsWith(".jsx"))continue;let a=k(te(s,i));/carousel|embla|swiper/i.test(a)&&!t.includes("Carousel")&&t.push("Carousel"),/accordion|collapsible/i.test(a)&&!t.includes("Accordion")&&t.push("Accordion"),/typing|typewriter/i.test(a)&&!t.includes("Typing animation")&&t.push("Typing animation"),/parallax|requestAnimationFrame/i.test(a)&&!t.includes("Parallax")&&t.push("Parallax")}}catch{}return t.length===0&&t.push("Scroll animations"),t}function mi(e){let t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let l=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",l),!b(t)){let c=E(`git clone --depth 1 "${e}" "${t}"`);if(!c.success)throw new Error(`Failed to clone ${e}: ${c.stderr}`)}}else if(t=e,!b(t))throw new Error(`Directory not found: ${t}`);let s=ci(t),o=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:i,fonts:a}=di(t),r=ui(t);return{sourceDir:t,wasCloned:n,components:s,hasTailwind:o,cssVarCount:i,fonts:a,interactions:r}}async function Rn(){await ce("Source Project");let e=await Te({message:"GitHub URL or local path to your React project:",placeholder:"https://github.com/user/my-lovable-page",validate:h=>{if(!h.trim())return"Please enter a URL or path"}}),t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let h=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",h),b(t))H(`Using existing clone: ${I.dim(t)}`);else{let y=await ue();y.start("Cloning repository..."),E(`git clone --depth 1 "${e}" "${t}"`).success||(y.stop("Clone failed"),B(`Failed to clone ${e}. Check the URL and your access permissions.`),process.exit(1)),y.stop(`Cloned to ${I.dim(t)}`)}}else t=e,b(t)||(B(`Directory not found: ${t}`),process.exit(1)),H(`Using local source: ${I.dim(t)}`);let s=await ue();s.start("Analyzing project structure...");let o=ci(t),i=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:a,fonts:r}=di(t),l=ui(t);s.stop(`Found ${o.length} landing page components`),o.length===0&&(z("No components found. Make sure the React source has .tsx/.jsx files in src/components/"),process.exit(1));let c=o.map((h,y)=>` ${I.dim(`${y+1}.`)} ${I.bold(h.name)} ${I.muted(`\u2014 ${h.description}`)}`).join(`
|
|
1301
1306
|
`),d=i?`Tailwind + custom CSS (${a} variables)`:`Custom CSS (${a} variables)`,u=r.length>0?r.join(", "):"System fonts",m=l.join(", ");return await Je(`${c}
|
|
1302
1307
|
|
|
1303
1308
|
CSS: ${d}
|
|
1304
1309
|
JS: ${m}
|
|
1305
|
-
Font: ${u}`,`${o.length} components detected`),await se({message:"Does this look right?"})||(B("Please adjust your source directory and try again."),process.exit(0)),await de("Source analyzed!"),{sourceDir:t,wasCloned:n,components:o,hasTailwind:i,cssVarCount:a,fonts:r,interactions:l}}g();ut();Q();import{join as Xt}from"path";Z();g();import{mkdirSync as ot,writeFileSync as
|
|
1306
|
-
`),
|
|
1310
|
+
Font: ${u}`,`${o.length} components detected`),await se({message:"Does this look right?"})||(B("Please adjust your source directory and try again."),process.exit(0)),await de("Source analyzed!"),{sourceDir:t,wasCloned:n,components:o,hasTailwind:i,cssVarCount:a,fonts:r,interactions:l}}g();ut();Q();import{join as Xt}from"path";Z();g();import{mkdirSync as ot,writeFileSync as jn}from"fs";import{join as $e}from"path";function Fn(e,t){ot(e,{recursive:!0}),ot($e(e,"templates"),{recursive:!0}),ot($e(e,"modules"),{recursive:!0}),ot($e(e,"css"),{recursive:!0}),ot($e(e,"js"),{recursive:!0}),ot($e(e,"images"),{recursive:!0}),ot($e(e,"assets"),{recursive:!0});let n={label:t,preview_path:"./templates/home.html",screenshot_path:"./images/template-previews/home.png",enable_domain_stylesheets:!1,version:"1.0.0",author:{name:"vibeSpot",url:"https://github.com/borismichel/vibespot"}};jn($e(e,"theme.json"),JSON.stringify(n,null,2)+`
|
|
1311
|
+
`),jn($e(e,"fields.json"),`[]
|
|
1307
1312
|
`);let s=`<!--
|
|
1308
1313
|
templateType: page
|
|
1309
1314
|
isAvailableForNewContent: false
|
|
@@ -1319,7 +1324,7 @@ ${I.bold("Option 4:")} Set an Anthropic API key
|
|
|
1319
1324
|
%}
|
|
1320
1325
|
{% end_dnd_area %}
|
|
1321
1326
|
{% endblock body %}
|
|
1322
|
-
`;
|
|
1327
|
+
`;jn($e(e,"templates","home.html"),s);let o=`<!--
|
|
1323
1328
|
templateType: none
|
|
1324
1329
|
isAvailableForNewContent: false
|
|
1325
1330
|
label: Base Layout
|
|
@@ -1342,12 +1347,12 @@ ${I.bold("Option 4:")} Set an Anthropic API key
|
|
|
1342
1347
|
{{ standard_footer_includes }}
|
|
1343
1348
|
</body>
|
|
1344
1349
|
</html>
|
|
1345
|
-
`;ot($e(e,"templates","layouts"),{recursive:!0}),
|
|
1350
|
+
`;ot($e(e,"templates","layouts"),{recursive:!0}),jn($e(e,"templates","layouts","base.html"),o)}Jn();async function Dn(){await ce("HubSpot Theme Setup");let e=await It({message:"Do you have an existing HubSpot theme?",options:[{value:"fetch",label:"Fetch my existing theme from HubSpot",hint:"downloads your current theme"},{value:"create",label:"Start fresh (HubSpot Boilerplate)",hint:"creates a new starter theme"}]}),t,n,s=Xt(process.cwd(),"workspace");if(Ae(s),e==="fetch"){t=await Te({message:"What's your theme name in HubSpot?",placeholder:"My-Company-Theme",validate:u=>u.trim()?void 0:"Theme name is required"}),n=Xt(s,t);let l=await ue();l.start("Fetching theme from HubSpot...");let c=_(),d=he();if(c.hubspotUploadMode==="cli"||!d)E(`hs cms fetch "${t}" "${n}"`).success||(l.stop("Fetch failed"),B(`Could not fetch theme "${t}". Check the name in HubSpot Design Manager.`),process.exit(1));else try{await qt(d,t,n)}catch(u){l.stop("Fetch failed"),B(`Could not fetch theme "${t}": ${u instanceof Error?u.message:String(u)}`),process.exit(1)}l.stop(`Theme fetched: ${I.dim(n)}`)}else{t=await Te({message:"Name for your new theme:",placeholder:"my-theme",defaultValue:"my-theme"}),n=Xt(s,t);let l=await ue();l.start("Creating theme...");try{Fn(n,t)}catch(c){l.stop("Creation failed"),B(`Could not create theme "${t}": ${c instanceof Error?c.message:String(c)}`),process.exit(1)}l.stop(`Theme created: ${I.dim(n)}`)}await ce("Checking theme compatibility");let o=Xt(n,"templates/layouts/base.html");b(o)||(B(`base.html not found at ${o}. Your theme may have a different structure.`),process.exit(1)),H("base.html found");let i=k(o),a=!1;if(i.includes("template_css"))H("template_css support");else{z("Missing template_css support in base.html");let l=i.indexOf("theme-overrides.css")!==-1?i.indexOf("{{",i.lastIndexOf(`
|
|
1346
1351
|
`,i.indexOf("theme-overrides.css"))):i.lastIndexOf("require_css");if(l>0){let c=i.lastIndexOf(`
|
|
1347
1352
|
`,l);i=i.slice(0,c)+`
|
|
1348
1353
|
{% if template_css %}
|
|
1349
1354
|
{{ require_css(get_asset_url(template_css)) }}
|
|
1350
|
-
{% endif %}`+i.slice(c),a=!0}}if(i.includes("template_js"))
|
|
1355
|
+
{% endif %}`+i.slice(c),a=!0}}if(i.includes("template_js"))H("template_js support");else{z("Missing template_js support in base.html");let l=i.indexOf("require_js");if(l>0){let c=i.indexOf(`
|
|
1351
1356
|
`,l),d=i.indexOf(`
|
|
1352
1357
|
`,c+1),u=`
|
|
1353
1358
|
{% if template_js %}
|
|
@@ -1355,17 +1360,17 @@ ${I.bold("Option 4:")} Set an Anthropic API key
|
|
|
1355
1360
|
{% endif %}`,m=i.indexOf("}}",l)+2+i.slice(i.indexOf("}}",l)+2).indexOf(`
|
|
1356
1361
|
`)+1;i=i.slice(0,i.indexOf(`
|
|
1357
1362
|
`,i.indexOf("}}",l)+2))+u+i.slice(i.indexOf(`
|
|
1358
|
-
`,i.indexOf("}}",l)+2)),a=!0}}if(a){let l=await ue();l.start("Patching base.html..."),
|
|
1363
|
+
`,i.indexOf("}}",l)+2)),a=!0}}if(a){let l=await ue();l.start("Patching base.html..."),U(o,i),l.stop("base.html patched with template_css/template_js support")}let r=Xt(n,".hsignore");if(b(r)){let l=k(r);l.includes("docs/")||(U(r,l+`
|
|
1359
1364
|
docs/
|
|
1360
|
-
`),
|
|
1365
|
+
`),H("Added docs/ to .hsignore"))}else U(r,`docs/
|
|
1361
1366
|
*.md
|
|
1362
1367
|
node_modules/
|
|
1363
1368
|
.git
|
|
1364
|
-
`),
|
|
1369
|
+
`),H("Created .hsignore");return await de("Theme ready!"),{themePath:n,themeName:t}}g();import{join as ke}from"path";import{readdirSync as Qt,rmSync as Ci}from"fs";g();qe();Q();import{spawn as mc}from"child_process";import{join as W,basename as pc}from"path";import{readdirSync as De,statSync as xi,writeFileSync as fc}from"fs";var gc=new Set(["about.html","blog-index.html","blog-post.html","contact.html","home.html","hubdb.html","landing-page.html","pricing.html","qa-test.html","base.html"]),Hn=class{model;reported=new Set;moduleCount=0;expectedModules=0;constructor(t){this.model=t}async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe();this.reported.clear(),this.moduleCount=0,this.expectedModules=0;let a=this.countSourceComponents(n),r=this.listModules(s),l=this.listDir(W(s,"css")),c=this.listDir(W(s,"js")),d=this.listDir(W(s,"templates")),u=this.buildFullPrompt(n,s,i);o("convert",`Starting Claude Code (${a} source components found)...`);let m="",f="",h=setInterval(()=>{this.reportProgress(s,r,l,c,d,o)},3e3);try{await new Promise((S,P)=>{let j={...process.env};delete j.CLAUDECODE;let G=["--print","--max-turns","50","--allowedTools","Read,Glob,Grep,Write,Edit,Bash"];this.model&&G.push("--model",this.model);let T=mc("claude",G,{cwd:s,stdio:["pipe","pipe","pipe"],env:j,shell:!0});T.stdout.on("data",V=>{m+=V.toString()}),T.stderr.on("data",V=>{f+=V.toString()}),T.on("error",V=>P(new Error(`Claude Code failed to start: ${V.message}`))),T.on("close",V=>{V!==0?P(new Error(`Claude Code exited with code ${V}.
|
|
1365
1370
|
`+(f?`Stderr: ${f.slice(0,500)}
|
|
1366
|
-
`:"")+(m?`Output: ${m.slice(0,500)}`:"No output"))):
|
|
1371
|
+
`:"")+(m?`Output: ${m.slice(0,500)}`:"No output"))):S()}),T.stdin.on("error",()=>{}),T.stdin.write(u),T.stdin.end(),setTimeout(()=>{T.kill(),P(new Error("Claude Code timed out after 30 minutes"))},18e5)})}finally{clearInterval(h)}let y=W(s,"..","vibespot-conversion.log");try{let P=["=== vibeSpot Conversion Log ===",`Timestamp: ${new Date().toISOString()}`,`Source: ${n}`,`Theme: ${s}`,`Model: ${this.model||"default"}`,"","=== PROMPT SENT ===",u.slice(0,500)+`
|
|
1367
1372
|
... (truncated, full guide follows)`,"","=== CLAUDE CODE STDOUT ===",m||"(empty)","","=== CLAUDE CODE STDERR ===",f||"(empty)",""].join(`
|
|
1368
|
-
`);
|
|
1373
|
+
`);fc(y,P,"utf-8"),o("status",`Log written to ${pc(y)}`)}catch{}o("scan","Scanning generated files...");let w=this.scanGeneratedFiles(s);if(w.modules.filter(S=>!r.has(S.moduleName+".module")).length===0){let S=m.slice(0,1500)||"(no output)",P=f.slice(0,500);throw new Error(`Claude Code did not create any new module files.
|
|
1369
1374
|
|
|
1370
1375
|
This usually means the model described the conversion instead of using Write tool to create files.
|
|
1371
1376
|
|
|
@@ -1381,7 +1386,7 @@ Stderr:
|
|
|
1381
1386
|
${P}
|
|
1382
1387
|
`:"")+`
|
|
1383
1388
|
Claude output:
|
|
1384
|
-
${
|
|
1389
|
+
${S}`)}return w}reportProgress(t,n,s,o,i,a){let r=0,l=this.listDir(W(t,"css"));for(let m of l){if(s.has(m)||!m.endsWith(".css"))continue;let f=`css:${m}`;this.reported.has(f)||(this.reported.add(f),a("created",`Shared CSS (${m})`),r++)}let c=this.listDir(W(t,"js"));for(let m of c){if(o.has(m)||!m.endsWith(".js"))continue;let f=`js:${m}`;this.reported.has(f)||(this.reported.add(f),a("created",`Shared JS (${m})`),r++)}this.expectedModules===0&&(this.expectedModules=this.detectExpectedModules(t,i));let d=this.listModules(t);for(let m of d){if(n.has(m))continue;let f=`module:${m}`;if(!this.reported.has(f)){this.reported.add(f),this.moduleCount++;let h=this.expectedModules>0?`[${this.moduleCount}/${this.expectedModules}]`:`[${this.moduleCount}]`;a("created",`Module ${h}: ${m.replace(".module","")}`),r++}}let u=this.listDir(W(t,"templates"));for(let m of u){if(i.has(m)||!m.endsWith(".html"))continue;let f=`template:${m}`;this.reported.has(f)||(this.reported.add(f),a("created",`Page template (${m})`),r++)}if(r===0)if(this.moduleCount>0){let m=this.expectedModules>0?`/${this.expectedModules}`:"";a("status",`${this.moduleCount}${m} modules created, conversion continuing...`)}else this.reported.size>0?a("status","Shared assets created, building modules..."):a("status","Claude Code is analyzing source files...")}buildFullPrompt(t,n,s){return`You are converting a React landing page to native HubSpot CMS modules.
|
|
1385
1390
|
|
|
1386
1391
|
SOURCE DIRECTORY: ${t}
|
|
1387
1392
|
THEME DIRECTORY: ${n}
|
|
@@ -1427,13 +1432,13 @@ HUBSPOT CMS RULES:
|
|
|
1427
1432
|
${Ee()}
|
|
1428
1433
|
|
|
1429
1434
|
CONVERSION GUIDE:
|
|
1430
|
-
${s}`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=
|
|
1431
|
-
${
|
|
1435
|
+
${s}`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=W(t,"css");if(b(s)){for(let r of De(s))if(r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=k(W(s,r));break}}let o=W(t,"js");if(b(o)){for(let r of De(o))if(r.endsWith(".js")&&r!=="main.js"){n.sharedJs=k(W(o,r));break}}let i=W(t,"templates");if(b(i)){for(let r of De(i))if(r.startsWith("lp-")&&r.endsWith(".html")){n.template=k(W(i,r));break}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!gc.has(r)&&!r.startsWith("system")){let l=k(W(i,r));if(l.includes("dnd_area")){n.template=l;break}}}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=k(W(i,r));if(l.includes("dnd_area")){n.template=l;break}}}}let a=W(t,"modules");if(b(a))for(let r of De(a)){if(!r.endsWith(".module"))continue;let l=W(a,r);if(!xi(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=W(l,"fields.json");b(d)&&(c.fieldsJson=k(d));let u=W(l,"meta.json");b(u)&&(c.metaJson=k(u));let m=W(l,"module.html");b(m)&&(c.moduleHtml=k(m));let f=W(l,"module.css");b(f)&&(c.moduleCss=k(f));let h=W(l,"module.js");b(h)&&(c.moduleJs=k(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}listModules(t){let n=W(t,"modules");return b(n)?new Set(De(n).filter(s=>s.endsWith(".module"))):new Set}listDir(t){return b(t)?new Set(De(t)):new Set}detectExpectedModules(t,n){let s=W(t,"templates");if(!b(s))return 0;for(let o of De(s))if(!n.has(o)&&!(!o.endsWith(".html")||o==="base.html"||o.startsWith("system")))try{let i=k(W(s,o));if(i.includes("dnd_area")){let a=i.match(/dnd_module/g);return a?a.length:0}}catch{}return 0}countSourceComponents(t){let n=W(t,"src");return b(n)?this.countComponentsRecursive(n):0}countComponentsRecursive(t){let n=0;for(let s of De(t)){let o=W(t,s);try{xi(o).isDirectory()&&s!=="node_modules"&&s!==".git"?n+=this.countComponentsRecursive(o):/\.(tsx|jsx)$/.test(s)&&!s.includes(".test.")&&!s.includes(".spec.")&&n++}catch{}}return n}};g();qe();Q();import hc from"@anthropic-ai/sdk";import{join as q,basename as yc}from"path";import{readdirSync as wi}from"fs";var Ln=class{client;model="claude-sonnet-4-6";constructor(t){this.client=new hc({apiKey:t||process.env.ANTHROPIC_API_KEY})}async convert(t){let{sourceDir:n,themePath:s,conversionGuide:o,onProgress:i}=t,a=hi(o),r=yc(n)||"page",l=r.toLowerCase().replace(/[^a-z0-9]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,15);i("css","Analyzing design system...");let c=this.findAndReadCSS(n),d=this.findAndReadTailwind(n),u=await this.complete(a,bi(c,d,l)),m=q(s,"css",`${l}-theme.css`);U(m,u),i("css-done",`Created css/${l}-theme.css`),i("js","Creating shared JavaScript...");let f=this.findAndReadHooks(n),h=this.findInteractiveComponents(n),y=await this.complete(a,Si(f,h,l)),w=q(s,"js",`${l}-animations.js`);U(w,y),i("js-done",`Created js/${l}-animations.js`),i("modules","Building modules...");let x=this.findComponents(n),S=[];for(let T=0;T<x.length;T++){let V=x[T],N=V.name.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim();i("module",`Building ${N}.module (${T+1}/${x.length})...`);let O=k(V.path),J=await this.complete(a,yi(O,N,`See css/${l}-theme.css`));try{let F=JSON.parse(J),X={moduleName:N,fieldsJson:typeof F.fieldsJson=="string"?F.fieldsJson:JSON.stringify(F.fieldsJson,null,2),metaJson:typeof F.metaJson=="string"?F.metaJson:JSON.stringify(F.metaJson,null,2),moduleHtml:F.moduleHtml||"",moduleCss:F.moduleCss||"",moduleJs:F.moduleJs||void 0},le=q(s,"modules",`${N}.module`);Ae(le),U(q(le,"fields.json"),X.fieldsJson),U(q(le,"meta.json"),X.metaJson),U(q(le,"module.html"),X.moduleHtml),U(q(le,"module.css"),X.moduleCss),X.moduleJs&&U(q(le,"module.js"),X.moduleJs),S.push(X),i("module-done",`${N}.module (${this.countFiles(X)} files)`)}catch{i("module-error",`Failed to parse ${N} \u2014 skipping`)}}i("template","Creating page template...");let P=S.map(T=>T.moduleName),j=await this.complete(a,vi(P,r,l)),G=q(s,"templates",`lp-${l}.html`);return U(G,j),i("template-done",`Created templates/lp-${l}.html`),{sharedCss:u,sharedJs:y,template:j,modules:S}}async complete(t,n){return(await this.client.messages.create({model:this.model,max_tokens:8192,system:t,messages:[{role:"user",content:n}]})).content.find(i=>i.type==="text")?.text||""}findAndReadCSS(t){let n=[q(t,"src/index.css"),q(t,"src/globals.css"),q(t,"src/app/globals.css"),q(t,"app/globals.css")];for(let s of n)if(b(s))return k(s);return""}findAndReadTailwind(t){let n=[q(t,"tailwind.config.ts"),q(t,"tailwind.config.js"),q(t,"tailwind.config.mjs")];for(let s of n)if(b(s))return k(s);return""}findAndReadHooks(t){let n=q(t,"src/hooks");if(!b(n))return"";try{return wi(n).filter(s=>s.endsWith(".ts")||s.endsWith(".tsx")).map(s=>`// ${s}
|
|
1436
|
+
${k(q(n,s))}`).join(`
|
|
1432
1437
|
|
|
1433
|
-
`)}catch{return""}}findInteractiveComponents(t){let n=this.findComponents(t),s=[];for(let o of n){let i=
|
|
1438
|
+
`)}catch{return""}}findInteractiveComponents(t){let n=this.findComponents(t),s=[];for(let o of n){let i=k(o.path);/carousel|accordion|typing|parallax|embla|swiper|collapsible/i.test(i)&&s.push(`// ${o.name}
|
|
1434
1439
|
${i}`)}return s.join(`
|
|
1435
1440
|
|
|
1436
|
-
`)}findComponents(t){let n=[q(t,"src/components/landing"),q(t,"src/components/sections"),q(t,"src/components")];for(let s of n)if(b(s))try{return
|
|
1441
|
+
`)}findComponents(t){let n=[q(t,"src/components/landing"),q(t,"src/components/sections"),q(t,"src/components")];for(let s of n)if(b(s))try{return wi(s).filter(o=>(o.endsWith(".tsx")||o.endsWith(".jsx"))&&!o.startsWith("ui")&&o!=="index.tsx"&&o!=="index.jsx").map(o=>({name:o.replace(/\.(tsx|jsx)$/,""),path:q(s,o)}))}catch{continue}return[]}countFiles(t){let n=3;return t.moduleCss&&n++,t.moduleJs&&n++,n}};g();qe();Q();import{spawn as bc}from"child_process";import{join as xe}from"path";import{readdirSync as Un,statSync as Sc}from"fs";var Gn=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),a=this.buildFullPrompt(n,s,i);return o("convert","Running Gemini CLI (this may take a few minutes)..."),await new Promise((r,l)=>{let c=bc("gemini",["-p",a],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Gemini CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Gemini CLI failed: ${u}`)):r()}),setTimeout(()=>{c.kill(),l(new Error("Gemini CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(t,n,s){return`Read the conversion guide below, then convert the React landing page at ${t} into native HubSpot CMS modules for the theme at ${n}.
|
|
1437
1442
|
|
|
1438
1443
|
INSTRUCTIONS:
|
|
1439
1444
|
1. Analyze all .tsx/.jsx components in the React source
|
|
@@ -1448,7 +1453,7 @@ CONVERSION GUIDE:
|
|
|
1448
1453
|
${s}
|
|
1449
1454
|
|
|
1450
1455
|
Do NOT run hs upload \u2014 I will handle that separately.
|
|
1451
|
-
Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=xe(t,"css");if(b(s)){for(let r of
|
|
1456
|
+
Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=xe(t,"css");if(b(s)){for(let r of Un(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=k(xe(s,r));break}}let o=xe(t,"js");if(b(o)){for(let r of Un(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=k(xe(o,r));break}}let i=xe(t,"templates");if(b(i)){for(let r of Un(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=k(xe(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=xe(t,"modules");if(b(a))for(let r of Un(a)){if(!r.endsWith(".module"))continue;let l=xe(a,r);if(!Sc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=xe(l,"fields.json");b(d)&&(c.fieldsJson=k(d));let u=xe(l,"meta.json");b(u)&&(c.metaJson=k(u));let m=xe(l,"module.html");b(m)&&(c.moduleHtml=k(m));let f=xe(l,"module.css");b(f)&&(c.moduleCss=k(f));let h=xe(l,"module.js");b(h)&&(c.moduleJs=k(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};g();qe();Q();import{spawn as vc}from"child_process";import{join as we}from"path";import{readdirSync as Bn,statSync as xc}from"fs";var Wn=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),a=this.buildFullPrompt(n,s,i);return o("convert","Running OpenAI Codex (this may take a few minutes)..."),await new Promise((r,l)=>{let c=vc("codex",["exec","--full-auto",a],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Codex CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Codex CLI failed: ${u}`)):r()}),setTimeout(()=>{c.kill(),l(new Error("Codex CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(t,n,s){return`Read the conversion guide below, then convert the React landing page at ${t} into native HubSpot CMS modules for the theme at ${n}.
|
|
1452
1457
|
|
|
1453
1458
|
INSTRUCTIONS:
|
|
1454
1459
|
1. Analyze all .tsx/.jsx components in the React source
|
|
@@ -1463,15 +1468,15 @@ CONVERSION GUIDE:
|
|
|
1463
1468
|
${s}
|
|
1464
1469
|
|
|
1465
1470
|
Do NOT run hs upload \u2014 I will handle that separately.
|
|
1466
|
-
Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=we(t,"css");if(b(s)){for(let r of Bn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=
|
|
1467
|
-
HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let t=
|
|
1471
|
+
Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=we(t,"css");if(b(s)){for(let r of Bn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=k(we(s,r));break}}let o=we(t,"js");if(b(o)){for(let r of Bn(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=k(we(o,r));break}}let i=we(t,"templates");if(b(i)){for(let r of Bn(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=k(we(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=we(t,"modules");if(b(a))for(let r of Bn(a)){if(!r.endsWith(".module"))continue;let l=we(a,r);if(!xc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=we(l,"fields.json");b(d)&&(c.fieldsJson=k(d));let u=we(l,"meta.json");b(u)&&(c.metaJson=k(u));let m=we(l,"module.html");b(m)&&(c.moduleHtml=k(m));let f=we(l,"module.css");b(f)&&(c.moduleCss=k(f));let h=we(l,"module.js");b(h)&&(c.moduleJs=k(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};qe();Q();function wc(e,t){switch(e){case"claude-code":return new Hn(t);case"gemini-cli":return new Gn;case"codex-cli":return new Wn;case"api":return new Ln}}async function Vn(e){await ce("Converting React to HubSpot Modules"),await Je(`AI will now analyze your React code and create
|
|
1472
|
+
HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let t=wc(e.aiEngine,e.model),n=oe(),s=await ue();s.start("Starting AI conversion...");let o=Date.now(),i=await t.convert({sourceDir:e.sourceDir,themePath:e.themePath,conversionGuide:n,onProgress:(h,y)=>{h==="created"?H(y):s.message(y)}}),a=((Date.now()-o)/1e3).toFixed(0);s.stop(`AI conversion complete (${a}s)`);let r=Cc(e.themePath);for(let h of r)H(`Auto-fixed: ${h}`);let l=Ac(e.themePath,i),c=[];for(let h of l){let y=h.passed?"\u2705":"\u274C",w=h.passed?"":h.critical?" (CRITICAL)":" (cosmetic)";c.push(`${y} ${h.label}${w}`)}let d=l.filter(h=>h.passed).length;c.push(`
|
|
1468
1473
|
${d}/${l.length} checks passed`),await Je(c.join(`
|
|
1469
1474
|
`),"Conversion Checklist");let u=l.filter(h=>!h.passed&&h.critical),m=l.filter(h=>!h.passed&&!h.critical);if(u.length>0){if(B(`${u.length} critical issue(s) \u2014 upload will likely fail:
|
|
1470
1475
|
`+u.map(y=>` - ${y.label}`).join(`
|
|
1471
1476
|
`)),!await se({message:"Continue with upload anyway?",initialValue:!1}))throw new Error("Conversion aborted due to critical checklist failures.")}else m.length>0&&z(`${m.length} non-critical issue(s) \u2014 page will work but may look incomplete:
|
|
1472
1477
|
`+m.map(h=>` - ${h.label}`).join(`
|
|
1473
|
-
`));let f=ke(e.themePath,"..","vibespot-conversion.log");return b(f)&&(await se({message:"Keep conversion log file for debugging?",initialValue:!1})?
|
|
1474
|
-
`,l=!0)}catch{t.push(`${a}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&
|
|
1478
|
+
`));let f=ke(e.themePath,"..","vibespot-conversion.log");return b(f)&&(await se({message:"Keep conversion log file for debugging?",initialValue:!1})?H(`Log saved: ${f}`):Ci(f)),await de("Files ready for upload!"),i}function Cc(e){let t=[];kc(e),Ic(e);let n=ke(e,"modules");if(b(n))for(let o of Qt(n)){if(!o.endsWith(".module"))continue;let i=ke(n,o,"fields.json");if(!b(i))continue;let a=o.replace(".module",""),r=k(i),l=!1;r.includes('"textarea"')&&(r=r.replace(/"textarea"/g,'"text"'),l=!0,t.push(`${a}: "textarea" \u2192 "text"`)),/"name":\s*"name"/.test(r)&&(r=r.replace(/"name":\s*"name"/g,'"name": "item_name"'),l=!0,t.push(`${a}: reserved field name "name" \u2192 "item_name"`));try{let d=JSON.parse(r),u=!1;Ai(d)&&(u=!0,t.push(`${a}: fixed choice field format`)),ki(d)&&(u=!0,t.push(`${a}: fixed link field default value`)),u&&(r=JSON.stringify(d,null,2)+`
|
|
1479
|
+
`,l=!0)}catch{t.push(`${a}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&U(i,r);let c=ke(n,o,"module.html");if(b(c)){let d=k(c);d.includes("now()")&&(d=d.replace(/now\(\)/g,"local_dt"),U(c,d),t.push(`${a}: now() \u2192 local_dt`))}}let s=ke(e,"templates");if(b(s))for(let o of Qt(s)){if(!o.endsWith(".html"))continue;let i=ke(s,o),a=k(i);(a.includes("hubdb_table")||a.includes("hubdb_table_rows"))&&(Ci(i),t.push(`Removed ${o} (HubDB requires CMS Hub Pro/Enterprise)`))}return t}function Ai(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;s.type==="choice"&&Array.isArray(s.choices)&&s.choices.some(i=>typeof i=="string")&&(s.choices=s.choices.map(i=>{if(typeof i=="string"){let a=i.charAt(0).toUpperCase()+i.slice(1);return[i,a]}return i}),t=!0),Array.isArray(s.children)&&Ai(s.children)&&(t=!0)}return t}function ki(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let a=typeof o=="string"?o:"";s.default={url:{href:a,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},t=!0}}Array.isArray(s.children)&&ki(s.children)&&(t=!0)}return t}function Ac(e,t){let n=[],s=t.modules.length;n.push({label:`Modules created (${s})`,passed:s>0,critical:!0});let o=!0;for(let u of t.modules)if(u.fieldsJson.includes('"textarea"')||/"name":\s*"name"/.test(u.fieldsJson)){o=!1;break}n.push({label:"fields.json valid (no textarea, no reserved names)",passed:s>0&&o,critical:!0});let i=t.modules.every(u=>u.moduleHtml.length>0);n.push({label:"module.html created for each module",passed:s>0&&i,critical:!0});let a=t.modules.filter(u=>!u.moduleCss).map(u=>u.moduleName),r=a.length===0;n.push({label:r?"module.css created for each module":`module.css missing for: ${a.join(", ")}`,passed:s>0&&r,critical:!1});let l=t.modules.some(u=>u.fieldsJson.includes('"STYLE"'));n.push({label:"Style tab fields (color pickers)",passed:l,critical:!1}),n.push({label:"Shared CSS with design system variables",passed:t.sharedCss.length>50,critical:!1}),n.push({label:"Shared JS for scroll animations",passed:t.sharedJs.length>50,critical:!1}),n.push({label:"Page template with dnd_area",passed:t.template.length>0&&t.template.includes("dnd_area"),critical:!0});let c=ke(e,"templates"),d=!1;if(b(c))for(let u of Qt(c)){if(!u.endsWith(".html")||u==="base.html"||u.startsWith("system"))continue;let m=k(ke(c,u));if(m.includes("dnd_area")&&/templateType\s*:\s*page/i.test(m)){d=!0;break}}return n.push({label:"Template annotations (templateType: page)",passed:d,critical:!0}),n}function kc(e){let t=ke(e,"templates");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".html")||n==="base.html"||n.startsWith("system"))continue;let s=ke(t,n),o=k(s);if(!o.includes("dnd_area")&&!o.includes("extends"))continue;let i=/templateType\s*:\s*page/i.test(o),a=/isAvailableForNewContent\s*:\s*true/i.test(o);if(i&&a)continue;let r=n.replace(".html","").replace(/[-_]/g," ").replace(/\b\w/g,l=>l.toUpperCase());if(o.includes("<!--")&&o.indexOf("-->")<200){let l=o.indexOf("-->"),c=o.slice(0,l);i||(c+=`
|
|
1475
1480
|
templateType: page`),a||(c+=`
|
|
1476
1481
|
isAvailableForNewContent: true`),/label\s*:/i.test(c)||(c+=`
|
|
1477
1482
|
label: ${r}`),o=c+o.slice(l)}else o=`<!--
|
|
@@ -1479,13 +1484,13 @@ ${d}/${l.length} checks passed`),await Je(c.join(`
|
|
|
1479
1484
|
isAvailableForNewContent: true
|
|
1480
1485
|
label: ${r}
|
|
1481
1486
|
-->
|
|
1482
|
-
`+o;
|
|
1483
|
-
`)}catch{}}}g();ut();import{join as
|
|
1484
|
-
`),t=!0)}catch{}}return t}function
|
|
1485
|
-
`),t=!0)}catch{}}return t}function
|
|
1487
|
+
`+o;U(s,o),H(`Template "${n}" \u2014 annotations verified`)}}function Ic(e){let t=ke(e,"modules");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".module"))continue;let s=ke(t,n,"meta.json");if(b(s))try{let o=JSON.parse(k(s)),i=!1;(!o.host_template_types||!o.host_template_types.includes("PAGE"))&&(o.host_template_types=["PAGE"],i=!0),o.is_available_for_new_content||(o.is_available_for_new_content=!0,i=!0),i&&U(s,JSON.stringify(o,null,2)+`
|
|
1488
|
+
`)}catch{}}}g();ut();import{join as ji,basename as jc}from"path";g();Q();import{join as ie}from"path";import{readdirSync as Xe,rmSync as Tc}from"fs";function Kn(e){let t=[];for(let n of e){let s=`${n.message}${n.detail?` \u2014 ${n.detail}`:""}`,o=!1;/textarea|unknown.*field.*type/i.test(s)&&(o=!0),/reserved.*name|missing field name|field null/i.test(s)&&(o=!0),/could not resolve.*now/i.test(s)&&(o=!0),/hubdb|do not have access/i.test(s)&&(o=!0),/invalid default value|link.*invalid|deserializ/i.test(s)&&(o=!0),/color.*invalid/i.test(s)&&(o=!0),t.push({file:n.file||"unknown",message:s,fixable:o})}return t}function Yn(e){let t=[];if(/textarea.*not.*valid|unknown.*field.*type/i.test(e)){let n=e.match(/(?:in|file:?)\s+(\S+fields\.json)/i);t.push({file:n?.[1]||"fields.json",message:'"textarea" is not a valid field type',fixable:!0})}if(/missing field name|field null/i.test(e)){let n=e.match(/(?:in|file:?)\s+(\S+fields\.json)/i);t.push({file:n?.[1]||"fields.json",message:'"name" is a reserved field name',fixable:!0})}if(/could not resolve.*now/i.test(e)&&t.push({file:"module.html",message:"now() is not a valid HubL function",fixable:!0}),/hubdb|do not have access to hubdb/i.test(e)&&t.push({file:"templates",message:"HubDB requires CMS Hub Pro/Enterprise",fixable:!0}),/invalid default value|link.*field.*invalid/i.test(e)){let n=e.match(/field.*?(\w+)\s+has an invalid/i);t.push({file:n?.[1]||"fields.json",message:"Link field has invalid default value",fixable:!0})}if(/failed to deserialize/i.test(e)){let n=e.match(/file '([^']+)'/i);t.push({file:n?.[1]||"fields.json",message:"fields.json deserialization error",fixable:!0})}return/format for the color value is invalid/i.test(e)&&t.push({file:"fields.json",message:"Color field has invalid format (rgba/rgb/named \u2014 must be hex)",fixable:!0}),t}function zn(e){let t=[];return Ti(e)&&t.push("textarea \u2192 text"),$i(e)&&t.push("name \u2192 item_name"),Ei(e)&&t.push("now() \u2192 local_dt"),_i(e)&&t.push("Removed HubDB templates"),Pi(e)&&t.push("Fixed link field defaults"),Mi(e)&&t.push("Fixed rgba/invalid color values \u2192 hex"),$c(e)&&t.push("Stripped CDN @import statements"),t}function Ii(e,t){return t.message.includes("textarea")?Ti(e):t.message.includes("reserved field name")?$i(e):t.message.includes("now()")?Ei(e):t.message.includes("HubDB")?_i(e):t.message.includes("invalid default value")||t.message.includes("deserialization")?Pi(e):t.message.includes("invalid format")&&t.message.includes("color")?Mi(e):!1}function Ti(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=k(o);i.includes('"textarea"')&&(i=i.replace(/"textarea"/g,'"text"'),U(o,i),t=!0)}return t}function $i(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=k(o);/"name":\s*"name"/g.test(i)&&(i=i.replace(/"name":\s*"name"/g,'"name": "item_name"'),U(o,i),t=!0)}return t}function Ei(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"module.html");if(!b(o))continue;let i=k(o);i.includes("now()")&&(i=i.replace(/now\(\)/g,"local_dt"),U(o,i),t=!0)}return t}function _i(e){let t=!1,n=ie(e,"templates");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".html"))continue;let o=ie(n,s),i=k(o);(i.includes("hubdb_table")||i.includes("hubdb_table_rows"))&&(Tc(o),t=!0)}return t}function Pi(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(k(o));Ni(i)&&(U(o,JSON.stringify(i,null,2)+`
|
|
1489
|
+
`),t=!0)}catch{}}return t}function $c(e){let t=!1,n=ie(e,"css");if(b(n))for(let o of Xe(n)){if(!o.endsWith(".css"))continue;let i=ie(n,o),a=k(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(U(i,r),t=!0)}let s=ie(e,"modules");if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.css");if(!b(i))continue;let a=k(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(U(i,r),t=!0)}if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.html");if(!b(i))continue;let a=k(i),r=a.replace(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,"");r!==a&&(U(i,r),t=!0)}return t}function Mi(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(k(o));Oi(i)&&(U(o,JSON.stringify(i,null,2)+`
|
|
1490
|
+
`),t=!0)}catch{}}return t}function Oi(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="color"&&s.default&&typeof s.default=="object"){let o=s.default,i=o.color;if(typeof i=="string"&&!Ec(i)){let a=_c(i);a&&(o.color=a.hex,a.opacity!==void 0&&(o.opacity=a.opacity),t=!0)}}Array.isArray(s.children)&&Oi(s.children)&&(t=!0)}return t}function Ec(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function _c(e){let t=e.match(/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/);if(t)return{hex:`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`};let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/i);if(n){let i=Math.min(255,parseInt(n[1])),a=Math.min(255,parseInt(n[2])),r=Math.min(255,parseInt(n[3])),l=`#${i.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`,c=n[4]!==void 0?Math.round(parseFloat(n[4])*100):void 0;return{hex:l,opacity:c}}let s={white:"#ffffff",black:"#000000",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",purple:"#800080",gray:"#808080",grey:"#808080",transparent:"#000000"},o=e.toLowerCase().trim();return s[o]?{hex:s[o],opacity:o==="transparent"?0:void 0}:null}function Ni(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let a=typeof o=="string"?o:"";s.default={url:{href:a,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},t=!0}}Array.isArray(s.children)&&Ni(s.children)&&(t=!0)}return t}Z();g();pt();pt();import{readdirSync as Pc}from"fs";import{join as Mc,relative as Oc}from"path";var Nc=new Set([".git","node_modules",".vibespot",".DS_Store"]);function Ri(e){let t=[];for(let n of Pc(e,{withFileTypes:!0})){if(Nc.has(n.name)||n.name.startsWith(".")&&n.name!==".gitkeep")continue;let s=Mc(e,n.name);n.isDirectory()?t.push(...Ri(s)):n.isFile()&&t.push(s)}return t}async function Rc(e,t,n){let s=0;async function o(){for(;s<e.length;){let a=s++;await n(e[a])}}let i=Array.from({length:Math.min(t,e.length)},()=>o());await Promise.all(i)}async function qn(e,t,n,s={}){let o=s.concurrency??5,i=Ri(t),a=i.length,r=0,l=0,c=[];return await Rc(i,o,async d=>{let u=Oc(t,d).replace(/\\/g,"/"),m=`${n}/${u}`;s.onFileStart?.(u);let f=await ri(e,m,d);if(f.success)r++,s.onFileComplete?.(u);else{l++;let h={file:u,status:f.error?.status||0,message:f.error?.message||"Unknown error",category:f.error?.category,detail:f.error?.detail};c.push(h),s.onFileError?.(u,h)}s.onProgress?.(r+l,a)}),{success:l===0,uploaded:r,failed:l,total:a,errors:c}}function Fc(e){return(e.match(/^Uploaded file /gm)||[]).length}async function $t(e){await ce("Uploading to HubSpot");let t=jc(e)||e,n=_(),s=he(),o=n.hubspotUploadMode!=="cli"&&!!s,i=await ue(),a=3;for(let r=1;r<=a;r++){i.start(r===1?"Uploading theme...":`Retrying upload (attempt ${r}/${a})...`);let l=[],c=0,d=!1;if(o){let m=await qn(s,e,t,{onFileComplete:()=>{c++}});d=m.success,d?c=m.uploaded:l=Kn(m.errors)}else{let m=E(`hs cms upload "${e}" "${t}"`,{cwd:ji(e,"..")}),f=[m.stdout,m.stderr].filter(Boolean).join(`
|
|
1486
1491
|
`);c=Fc(f),d=m.success,d||(l=Yn(f))}if(d)return i.stop(`All files uploaded! (${c} files)`),await de("Upload complete!"),!0;if(c>0?i.stop(`${c} files uploaded, but some errors occurred`):i.stop("Upload failed"),l.length===0){if(B("Upload failed with unknown error."),c>0&&(z(`Most files uploaded successfully. The theme may already be usable in HubSpot.
|
|
1487
|
-
You can check your HubSpot Design Manager to verify.`),await se({message:"Continue anyway (theme is likely uploaded)?",initialValue:!0})))return!0;if(r<a){if(!await se({message:"Try uploading again?"}))break;continue}break}let u=!1;for(let m of l)m.fixable?
|
|
1488
|
-
The theme may work \u2014 check HubSpot Design Manager.`),await se({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await
|
|
1492
|
+
You can check your HubSpot Design Manager to verify.`),await se({message:"Continue anyway (theme is likely uploaded)?",initialValue:!0})))return!0;if(r<a){if(!await se({message:"Try uploading again?"}))break;continue}break}let u=!1;for(let m of l)m.fixable?Ii(e,m)?(H(`Auto-fixed: ${m.message}`),u=!0):z(`Could not auto-fix: ${m.message}`):B(m.message);if(!(u&&r<a)){if(c>0&&(z(`${c} files uploaded successfully despite errors.
|
|
1493
|
+
The theme may work \u2014 check HubSpot Design Manager.`),await se({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await Fs(s,`${t}/modules`)}catch{}else E(`hs cms delete "${t}/modules"`,{cwd:ji(e,"..")});i.stop("Cleaned up modules, retrying...")}}}return B("Upload failed after multiple attempts."),!1}g();import{execFileSync as Vs}from"child_process";import{rmSync as Jc}from"fs";import{basename as Fi}from"path";Q();async function Ji(e){let{portalId:t,sourceDir:n,themePath:s,wasCloned:o}=e;await ce("You're all set!");let a=Wt(t)==="eu1"?"app-eu1.hubspot.com":"app.hubspot.com";if(await Je(`Your React page has been converted and uploaded to HubSpot.
|
|
1489
1494
|
The theme and modules are now in your account, but you still
|
|
1490
1495
|
need to ${I.bold("create a new landing page")} that uses them.
|
|
1491
1496
|
|
|
@@ -1497,14 +1502,14 @@ Next steps:
|
|
|
1497
1502
|
${I.bold("4.")} Your converted modules will appear \u2014 drag them onto the page
|
|
1498
1503
|
${I.bold("5.")} Click each section to edit text, images, and colors
|
|
1499
1504
|
${I.bold("6.")} Upload images via File Manager ${I.muted("(Settings \u2192 Files)")}
|
|
1500
|
-
${I.bold("7.")} Preview and publish!`,"What's next"),await se({message:"Open HubSpot Landing Pages in your browser?"})){let c=t?`https://${a}/page-ui/${t}/management/pages/landing`:`https://${a}`;try{let d=process.platform;d==="darwin"?Vs("open",[c],{stdio:"ignore"}):d==="win32"?Vs("cmd",["/c","start","",c],{stdio:"ignore"}):Vs("xdg-open",[c],{stdio:"ignore"}),
|
|
1505
|
+
${I.bold("7.")} Preview and publish!`,"What's next"),await se({message:"Open HubSpot Landing Pages in your browser?"})){let c=t?`https://${a}/page-ui/${t}/management/pages/landing`:`https://${a}`;try{let d=process.platform;d==="darwin"?Vs("open",[c],{stdio:"ignore"}):d==="win32"?Vs("cmd",["/c","start","",c],{stdio:"ignore"}):Vs("xdg-open",[c],{stdio:"ignore"}),H("Opening HubSpot Landing Pages...")}catch{ee(`Open this URL in your browser: ${I.info(c)}`)}}let l=[];if(o&&b(n)&&l.push({path:n,label:`Cloned source (${Fi(n)})`}),b(s)&&l.push({path:s,label:`Theme directory (${Fi(s)})`}),l.length>0&&await se({message:"Clean up local working directories?"}))for(let d of l)try{Jc(d.path,{recursive:!0,force:!0}),H(`Removed ${d.label}`)}catch{z(`Could not remove ${d.label} \u2014 delete manually if needed.`)}await de(`Thanks for using hub${I.vibes("Vibes")}! ${I.vibes("~")}`)}Z();async function Di(){Ne();let e=await Nn(),t=await Rn();K({lastSourcePath:t.sourceDir});let n=await Dn();K({lastThemePath:n.themePath}),await Vn({aiEngine:e.aiEngine,model:e.model,sourceDir:t.sourceDir,themePath:n.themePath}),await $t(n.themePath),await Ji({portalId:e.portalId,sourceDir:t.sourceDir,themePath:n.themePath,wasCloned:t.wasCloned})}g();async function Hi(){Ne(),await Nn()}g();Z();async function Li(){Ne();let e=_();e.aiEngine||(B("AI engine not configured. Run `vibespot init` first or use the full wizard with `vibespot`."),process.exit(1));let t=await Rn(),n=await Dn();await Vn({aiEngine:e.aiEngine,sourceDir:t.sourceDir,themePath:n.themePath})}g();Z();async function Ui(){Ne();let e=_();if(e.lastThemePath)if(await se({message:`Upload from ${e.lastThemePath}?`}))await $t(e.lastThemePath);else{let n=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme"});await $t(n)}else{let t=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:n=>n.trim()?void 0:"Path is required"});await $t(t)}}g();Z();async function Gi(){Ne(),await ce("Environment Diagnostics");let e=0,t=Ut();t.found?En(t.version)?H(`Node.js v${t.version}`):(z(`Node.js v${t.version} \u2014 too old (need 18+)`),ee(" Update at https://nodejs.org"),e++):(B("Node.js \u2014 not installed"),ee(" Install from https://nodejs.org"),e++);let n=Gt();n.found?H(`Git ${n.version}`):(B("Git \u2014 not installed"),ee(" Install from https://git-scm.com"),e++);let s=je();if(!s.found)z("HubSpot CLI \u2014 not installed (only needed for deployment)"),ee(" Install: npm install -g @hubspot/cli");else if(!si(s.version))z(`HubSpot CLI v${s.version} \u2014 too old (need v8+)`),ee(" Update: npm install -g @hubspot/cli@latest"),e++;else{H(`HubSpot CLI v${s.version}`);let m=Fe();m.authenticated?H(`HubSpot portal${m.portalName?`: ${m.portalName}`:""} (ID: ${m.portalId})`):(z("HubSpot \u2014 not authenticated"),ee(" Run: hs init"))}let o=Bt();o.found?H(`Claude Code ${o.version} at ${o.path}`):ee(I.muted("Claude Code \u2014 not installed"));let i=Vt();i.found?H(`Gemini CLI ${i.version} at ${i.path}`):ee(I.muted("Gemini CLI \u2014 not installed"));let a=Kt();a.found?H(`OpenAI Codex ${a.version} at ${a.path}`):ee(I.muted("OpenAI Codex \u2014 not installed"));let r=_(),l=!!(r.anthropicApiKey||process.env.ANTHROPIC_API_KEY),c=!!(r.openaiApiKey||process.env.OPENAI_API_KEY),d=!!(r.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY);l?H("Anthropic API key configured"):ee(I.muted("Anthropic API key \u2014 not set")),c?H("OpenAI API key configured"):ee(I.muted("OpenAI API key \u2014 not set")),d?H("Google AI API key configured"):ee(I.muted("Google AI API key \u2014 not set"));let u={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"};r.aiEngine&&H(`AI engine: ${u[r.aiEngine]||r.aiEngine}`),r.lastThemePath&&ee(I.muted(`Last theme: ${r.lastThemePath}`)),!o.found&&!i.found&&!a.found&&!l&&!c&&!d&&(z("No AI engine available"),ee(" Fastest: Set an API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)"),ee(" Or install: Claude Code \u2014 https://claude.ai/code"),ee(" Gemini CLI \u2014 https://github.com/google-gemini/gemini-cli"),ee(" Codex CLI \u2014 https://github.com/openai/codex"),e++),console.log(),e===0?await de("Everything looks good!"):await de(I.warn(`${e} issue${e>1?"s":""} found \u2014 see above`))}g();import{join as ks}from"path";import{existsSync as nm}from"fs";import{execFileSync as Bo}from"child_process";import Is from"chalk";g();Se();Zt();as();fs();Z();import{createServer as zu}from"http";import{readFileSync as Go,existsSync as yn}from"fs";import{join as tt,extname as Pl}from"path";import{createHash as qu}from"crypto";import{WebSocketServer as Xu}from"ws";g();import{spawn as Fo}from"child_process";var dt=new Map;function wa(e,t,n){e.stdout?.on("data",o=>{t.output+=o.toString()}),e.stderr?.on("data",o=>{t.output+=o.toString()}),e.on("close",o=>{t.status=o===0?"completed":"failed",t.exitCode=o,t.completedAt=Date.now()}),e.on("error",o=>{t.status="failed",t.output+=`
|
|
1501
1506
|
Process error: ${o.message}`,t.completedAt=Date.now()}),setTimeout(()=>{t.status==="running"&&(e.kill(),t.status="failed",t.output+=`
|
|
1502
|
-
Process timed out`,t.completedAt=Date.now())},n||3e5)}function fn(e,t,n,s){let o=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,i={id:o,command:`${e} ${t.join(" ")}`,description:n,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};dt.set(o,i);let a=Fo(e,t,{cwd:s?.cwd,stdio:[s?.stdin?"pipe":"ignore","pipe","pipe"],env:{...process.env,...s?.env},shell:process.platform==="win32"});return s?.stdin&&a.stdin&&(a.stdin.write(s.stdin),a.stdin.end()),
|
|
1507
|
+
Process timed out`,t.completedAt=Date.now())},n||3e5)}function fn(e,t,n,s){let o=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,i={id:o,command:`${e} ${t.join(" ")}`,description:n,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};dt.set(o,i);let a=Fo(e,t,{cwd:s?.cwd,stdio:[s?.stdin?"pipe":"ignore","pipe","pipe"],env:{...process.env,...s?.env},shell:process.platform==="win32"});return s?.stdin&&a.stdin&&(a.stdin.write(s.stdin),a.stdin.end()),wa(a,i,s?.timeout),o}function St(e,t,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:e,description:t,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};dt.set(s,o);let i=e.split(" "),a=Fo(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0});return wa(a,o,n?.timeout),s}function gs(e){return dt.get(e)}function xu(){let e=Date.now()-18e5;for(let[t,n]of dt)n.completedAt&&n.completedAt<e&&dt.delete(t)}setInterval(xu,600*1e3);function hs(e,t,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:e,description:t,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null,listeners:new Set};dt.set(s,o);let i=e.split(" "),a=Fo(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0}),r=c=>{for(let d of o.listeners)try{d(c)}catch{}};a.stdout?.on("data",c=>{let d=c.toString();o.output+=d,r(d)}),a.stderr?.on("data",c=>{let d=c.toString();o.output+=d,r(d)}),a.on("close",c=>{o.status=c===0?"completed":"failed",o.exitCode=c,o.completedAt=Date.now(),o.listeners.clear()}),a.on("error",c=>{o.status="failed",o.output+=`
|
|
1503
1508
|
Process error: ${c.message}`,o.completedAt=Date.now(),o.listeners.clear()});let l=n?.timeout||3e5;return setTimeout(()=>{o.status==="running"&&(a.kill(),o.status="failed",o.output+=`
|
|
1504
|
-
Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function wa(e,t){let n=dt.get(e);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{t(s.output)}catch{}s.listeners.add(t)}function Ca(e,t){let n=dt.get(e);!n||!("listeners"in n)||n.listeners.delete(t)}et();Q();g();et();Z();import{existsSync as Rt,readdirSync as Aa,rmSync as Su}from"fs";import{join as Ft,basename as vu}from"path";import{homedir as xu}from"os";import{execFileSync as ka}from"child_process";Jn();pt();Se();fs();Z();Q();var Ia=process.platform==="win32"?{shell:!0}:{},Me=Ft(xu(),"vibespot-themes"),ys=null,wu=5e3;function bs(){if(ys&&Date.now()-ys.ts<wu)return ys.data;let e=[];if(Rt(Me))try{for(let t of Aa(Me,{withFileTypes:!0}))if(t.isDirectory()){let n=Ft(Me,t.name,"theme.json");if(Rt(n)){let s=0,o=Ft(Me,t.name,"modules");if(Rt(o))try{s=Aa(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}e.push({name:t.name,moduleCount:s})}}}catch{}return ys={data:e,ts:Date.now()},e}function Ta(e){let t=S(),n=_n(),s=!1;try{ka("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...Ia}),s=!0}catch{}let o=Pt().sort((a,r)=>r.updatedAt-a.updatedAt).slice(0,10),i=bs();p(e,200,{hasActiveSession:!!t,activeSession:t?{id:t.id,themeName:t.themeName,moduleCount:t.modules.length}:null,hsInstalled:s,aiAvailable:n.availableEngines.length>0,availableEngines:n.availableEngines,activeEngine:n.activeEngine,sessions:o,localThemes:i})}function $a(e,t){N(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),i=Ft(Me,o);Ae(Me),Rt(i)&&Su(i,{recursive:!0,force:!0}),jn(i,o),sn(i,o),D(),p(t,200,{ok:!0,themeName:o,themePath:i})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ea(e,t){N(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.replace(/^\/+|\/+$/g,"");if(!o){p(t,400,{error:"Theme name is required"});return}let i=he(),a=_(),r=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=Ft(Me,r);Ae(Me),a.hubspotUploadMode==="cli"||!i?(ka("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...Ia}),sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.modules.length||0})):qt(i,o,l).then(()=>{sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.modules.length||0})}).catch(c=>{p(t,500,{error:c instanceof Error?c.message:String(c)})})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function _a(e,t){N(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{path:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme path is required"});return}let o=s;if(Rt(o)||(o=Ft(Me,s)),!Rt(o)){p(t,400,{error:`Theme folder not found: ${s}`});return}let i=vu(o);sn(o,i),an(o),D(),p(t,200,{ok:!0,themeName:i,themePath:o,moduleCount:S()?.modules.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Pa(e,t){N(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{sessionId:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Session ID is required"});return}let o=is(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath,moduleCount:o.modules.length,messageCount:o.messages.length})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ma(e,t){N(e,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"API key is required"});return}K({anthropicApiKey:s}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Oa(e){let t=he();if(!t){p(e,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await ai(t);if(n.length===0){p(e,200,{themes:[]});return}let s=[],o=n.map(async r=>{let l=r.path||r.name;try{let c=await On(t,`${l}/theme.json`);c&&!c.folder&&s.push({name:r.name,path:l})}catch{}});await Promise.all(o),s.sort((r,l)=>r.name.localeCompare(l.name));let i=bs(),a=new Set(i.map(r=>r.name));p(e,200,{themes:s.map(r=>({...r,existsLocally:a.has(r.name)}))})})().catch(n=>{p(e,200,{themes:[],error:n instanceof Error?n.message:String(n)})})}g();et();Z();Se();import{existsSync as Cu,readFileSync as Au,appendFileSync as ku}from"fs";import{join as Na}from"path";import{homedir as Ra}from"os";pt();Q();var gn={data:{},ts:0},Iu=600*1e3,Fa={"claude-code":[{id:"sonnet",label:"Claude Sonnet (default)"},{id:"opus",label:"Claude Opus"},{id:"haiku",label:"Claude Haiku"}],"codex-cli":[{id:"o4-mini",label:"o4 Mini (default)"},{id:"o3",label:"o3"},{id:"gpt-4o",label:"GPT-4o"}]};async function Tu(e){let t=await fetch("https://api.anthropic.com/v1/models",{headers:{"x-api-key":e,"anthropic-version":"2023-06-01"}});return t.ok?(await t.json()).data.filter(s=>!s.id.startsWith("claude-3-")&&!s.id.startsWith("claude-2")).map(s=>({id:s.id,label:s.display_name})):[]}async function $u(e){let t=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)return[];let n=await t.json(),s=/^(gpt-4o|gpt-4o-mini|o[1-4](-mini)?|o[1-4]-pro)$/;return n.data.filter(o=>s.test(o.id)).sort((o,i)=>o.id.localeCompare(i.id)).map(o=>({id:o.id,label:o.id}))}async function Eu(e){let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${e}`);return t.ok?(await t.json()).models.filter(s=>s.name.includes("gemini-2")).map(s=>({id:s.name.replace("models/",""),label:s.displayName})):[]}async function _u(){if(Date.now()-gn.ts<Iu&&Object.keys(gn.data).length>0)return gn.data;let e=_(),t={...Fa},n=[],s=ge("anthropic-api",e);s&&n.push(Tu(s).then(a=>{a.length&&(t["anthropic-api"]=a,t["claude-oauth"]=a)}).catch(()=>{}));let o=ge("openai-api",e);o&&n.push($u(o).then(a=>{a.length&&(t["openai-api"]=a)}).catch(()=>{}));let i=ge("gemini-api",e);return i&&n.push(Eu(i).then(a=>{a.length&&(t["gemini-api"]=a,t["gemini-cli"]=a)}).catch(()=>{})),await Promise.all(n),gn.data=t,gn.ts=Date.now(),t}function ja(e){let t=_n(),n=_(),s={aiEngine:n.aiEngine||null,claudeCodeModel:n.claudeCodeModel||null,anthropicApiModel:n.anthropicApiModel||null,openaiApiModel:n.openaiApiModel||null,hubspotUploadMode:n.hubspotUploadMode||"api",hubspotAccounts:(n.hubspotAccounts||[]).map(r=>({portalId:r.portalId,portalName:r.portalName,dataCenter:r.dataCenter})),activeHubSpotAccount:n.activeHubSpotAccount||null,enabledCLITools:n.enabledCLITools||[],agenticMode:n.agenticMode,agenticConcurrency:n.agenticConcurrency},o=Pt().length,i=bs().length,a=wt();_u().then(r=>{p(e,200,{version:a,environment:t,config:s,models:r,sessionCount:o,localThemeCount:i})}).catch(()=>{p(e,200,{version:a,environment:t,config:s,models:Fa,sessionCount:o,localThemeCount:i})})}function Ja(e,t){N(e,n=>{try{let{engine:s,model:o}=JSON.parse(n);if(!["claude-code","anthropic-api","claude-oauth","openai-api","gemini-cli","gemini-api","codex-cli"].includes(s)){p(t,400,{error:`Invalid engine: ${s}`});return}let a={aiEngine:s};if(o)switch(s){case"claude-code":a.claudeCodeModel=o;break;case"anthropic-api":case"claude-oauth":a.anthropicApiModel=o;break;case"openai-api":a.openaiApiModel=o;break}K(a),p(t,200,{ok:!0,engine:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Da(e,t){N(e,n=>{try{let{provider:s,apiKey:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"provider is required"});return}if(!o){let l={};switch(s){case"anthropic":l.anthropicApiKey="";break;case"openai":l.openaiApiKey="";break;case"gemini":l.geminiApiKey="";break;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(l),p(t,200,{ok:!0,provider:s,deleted:!0});return}let i={};switch(s){case"anthropic":i.anthropicApiKey=o;break;case"openai":i.openaiApiKey=o;break;case"gemini":i.geminiApiKey=o;break;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(i);let a=null;if(!_().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(K({aiEngine:c}),a=c)}p(t,200,{ok:!0,provider:s,autoSelectedEngine:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ha(e,t){N(e,n=>{try{let{tool:s}=JSON.parse(n),o={hubspot:{cmd:"npm install -g @hubspot/cli",desc:"Installing HubSpot CLI"},claude:{cmd:"npm install -g @anthropic-ai/claude-code",desc:"Installing Claude Code"},gemini:{cmd:"npm install -g @google/gemini-cli",desc:"Installing Gemini CLI"},codex:{cmd:process.platform==="darwin"?"brew install --cask codex":"npm install -g @openai/codex",desc:"Installing OpenAI Codex"},gh:{cmd:process.platform==="darwin"?"brew install gh":"npm install -g @cli/gh",desc:"Installing GitHub CLI"}},i=o[s];if(!i){p(t,400,{error:`Unknown tool: ${s}. Valid: ${Object.keys(o).join(", ")}`});return}let a=St(i.cmd,i.desc,{timeout:12e4});p(t,200,{ok:!0,jobId:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function La(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}"),o=_(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){Mn(s.personalAccessKey).then(a=>{Jt(s.personalAccessKey,a.portalId,a.portalName,a.dataCenter),p(t,200,{ok:!0,portalName:a.portalName,portalId:a.portalId,dataCenter:a.dataCenter})}).catch(a=>{p(t,400,{error:a instanceof Error?a.message:String(a)})});return}else{if(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=fn("hs",["auth",`--pak=${s.personalAccessKey}`],"Authenticating with HubSpot",{timeout:3e4});p(t,200,{ok:!0,jobId:r});return}if(i==="api"){let a=o.hubspotAccounts||[];if(a.length>0&&!s.force){let r=a.find(l=>l.portalId===o.activeHubSpotAccount)||a[0];p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}else{if(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=je();if(r.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}p(t,200,{needsKey:!0,instructions:"Create a personal access key in HubSpot",url:"https://app.hubspot.com/portal-recommend/l?slug=personal-access-key",steps:["Click the link above to open HubSpot","Select your account","Create a Personal Access Key with CMS permissions","Copy the key and paste it below"]})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ga(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}");if(!Rs().found){p(t,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=Fs();if(i.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let r=fn("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(t,200,{ok:!0,jobId:r});return}let a=St("gh auth login --web --git-protocol https","GitHub authentication (check your browser)",{timeout:3e5});p(t,200,{ok:!0,jobId:a,browserAuthRequired:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ua(e,t){N(e,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((_().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){$s(s),p(t,200,{ok:!0});return}if(s){Es(s),p(t,200,{ok:!0});return}}else{if(!Fe().found){p(t,400,{error:"HubSpot CLI not installed"});return}let l=String(s).replace(/[^0-9]/g,"");if(!l){p(t,400,{error:"Invalid portalId"});return}if(o==="remove"){let c=fn("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}if(l){let c=fn("hs",["accounts","use",l],`Switching to HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}}p(t,400,{error:"portalId required"})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ba(e){let t=St("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(e,200,{ok:!0,jobId:t})}function Wa(e,t){N(e,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=St("CLAUDECODE= claude --print -p 'reply OK'","Authenticating Claude Code (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Claude Code opens a browser window, complete the sign-in there."});break}case"gemini":{let i=St("gemini -p 'reply OK'","Authenticating Gemini CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Gemini opens a browser window, complete the sign-in there."});break}case"codex":{if(o&&o.trim()){let i=o.trim();if(process.env.OPENAI_API_KEY=i,K({openaiApiKey:i}),process.platform!=="win32"){let a=/^[A-Za-z0-9_\-.:]+$/.test(i)?i:"";if(a){let r=`export OPENAI_API_KEY="${a}"`,l=process.env.SHELL?.includes("zsh")?Na(Ra(),".zshrc"):Na(Ra(),".bashrc");try{(Cu(l)?Au(l,"utf-8"):"").includes("OPENAI_API_KEY")||ku(l,`
|
|
1509
|
+
Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function Ca(e,t){let n=dt.get(e);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{t(s.output)}catch{}s.listeners.add(t)}function Aa(e,t){let n=dt.get(e);!n||!("listeners"in n)||n.listeners.delete(t)}et();Q();g();et();Z();import{existsSync as Rt,readdirSync as ka,rmSync as wu}from"fs";import{join as jt,basename as Cu}from"path";import{homedir as Au}from"os";import{execFileSync as Ia}from"child_process";Jn();pt();Se();fs();Z();Q();var Ta=process.platform==="win32"?{shell:!0}:{},Me=jt(Au(),"vibespot-themes"),ys=null,ku=5e3;function bs(){if(ys&&Date.now()-ys.ts<ku)return ys.data;let e=[];if(Rt(Me))try{for(let t of ka(Me,{withFileTypes:!0}))if(t.isDirectory()){let n=jt(Me,t.name,"theme.json");if(Rt(n)){let s=0,o=jt(Me,t.name,"modules");if(Rt(o))try{s=ka(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}e.push({name:t.name,moduleCount:s})}}}catch{}return ys={data:e,ts:Date.now()},e}function $a(e){let t=v(),n=_n(),s=!1;try{Ia("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...Ta}),s=!0}catch{}let o=Pt().sort((a,r)=>r.updatedAt-a.updatedAt).slice(0,10),i=bs();p(e,200,{hasActiveSession:!!t,activeSession:t?{id:t.id,themeName:t.themeName,moduleCount:t.modules.length}:null,hsInstalled:s,aiAvailable:n.availableEngines.length>0,availableEngines:n.availableEngines,activeEngine:n.activeEngine,sessions:o,localThemes:i})}function Ea(e,t){R(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),i=jt(Me,o);Ae(Me),Rt(i)&&wu(i,{recursive:!0,force:!0}),Fn(i,o),sn(i,o),L(),p(t,200,{ok:!0,themeName:o,themePath:i})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function _a(e,t){R(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.replace(/^\/+|\/+$/g,"");if(!o){p(t,400,{error:"Theme name is required"});return}let i=he(),a=_(),r=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=jt(Me,r);Ae(Me),a.hubspotUploadMode==="cli"||!i?(Ia("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...Ta}),sn(l,r),an(l),L(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:v()?.modules.length||0})):qt(i,o,l).then(()=>{sn(l,r),an(l),L(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:v()?.modules.length||0})}).catch(c=>{p(t,500,{error:c instanceof Error?c.message:String(c)})})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Pa(e,t){R(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{path:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme path is required"});return}let o=s;if(Rt(o)||(o=jt(Me,s)),!Rt(o)){p(t,400,{error:`Theme folder not found: ${s}`});return}let i=Cu(o);sn(o,i),an(o),L(),p(t,200,{ok:!0,themeName:i,themePath:o,moduleCount:v()?.modules.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ma(e,t){R(e,n=>{try{if(Nt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{sessionId:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Session ID is required"});return}let o=is(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath,moduleCount:o.modules.length,messageCount:o.messages.length})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Oa(e,t){R(e,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"API key is required"});return}K({anthropicApiKey:s}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Na(e){let t=he();if(!t){p(e,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await li(t);if(n.length===0){p(e,200,{themes:[]});return}let s=[],o=n.map(async r=>{let l=r.path||r.name;try{let c=await On(t,`${l}/theme.json`);c&&!c.folder&&s.push({name:r.name,path:l})}catch{}});await Promise.all(o),s.sort((r,l)=>r.name.localeCompare(l.name));let i=bs(),a=new Set(i.map(r=>r.name));p(e,200,{themes:s.map(r=>({...r,existsLocally:a.has(r.name)}))})})().catch(n=>{p(e,200,{themes:[],error:n instanceof Error?n.message:String(n)})})}g();et();Z();Se();import{existsSync as Iu,readFileSync as Tu,appendFileSync as $u}from"fs";import{join as Ra}from"path";import{homedir as ja}from"os";pt();Q();var gn={data:{},ts:0},Eu=600*1e3,Fa={"claude-code":[{id:"sonnet",label:"Claude Sonnet (default)"},{id:"opus",label:"Claude Opus"},{id:"haiku",label:"Claude Haiku"}],"codex-cli":[{id:"o4-mini",label:"o4 Mini (default)"},{id:"o3",label:"o3"},{id:"gpt-4o",label:"GPT-4o"}]};async function _u(e){let t=await fetch("https://api.anthropic.com/v1/models",{headers:{"x-api-key":e,"anthropic-version":"2023-06-01"}});return t.ok?(await t.json()).data.filter(s=>!s.id.startsWith("claude-3-")&&!s.id.startsWith("claude-2")).map(s=>({id:s.id,label:s.display_name})):[]}async function Pu(e){let t=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)return[];let n=await t.json(),s=/^(gpt-4o|gpt-4o-mini|o[1-4](-mini)?|o[1-4]-pro)$/;return n.data.filter(o=>s.test(o.id)).sort((o,i)=>o.id.localeCompare(i.id)).map(o=>({id:o.id,label:o.id}))}async function Mu(e){let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${e}`);return t.ok?(await t.json()).models.filter(s=>s.name.includes("gemini-2")).map(s=>({id:s.name.replace("models/",""),label:s.displayName})):[]}async function Ou(){if(Date.now()-gn.ts<Eu&&Object.keys(gn.data).length>0)return gn.data;let e=_(),t={...Fa},n=[],s=ge("anthropic-api",e);s&&n.push(_u(s).then(a=>{a.length&&(t["anthropic-api"]=a,t["claude-oauth"]=a)}).catch(()=>{}));let o=ge("openai-api",e);o&&n.push(Pu(o).then(a=>{a.length&&(t["openai-api"]=a)}).catch(()=>{}));let i=ge("gemini-api",e);return i&&n.push(Mu(i).then(a=>{a.length&&(t["gemini-api"]=a,t["gemini-cli"]=a)}).catch(()=>{})),await Promise.all(n),gn.data=t,gn.ts=Date.now(),t}function Ja(e){let t=_n(),n=_(),s={aiEngine:n.aiEngine||null,claudeCodeModel:n.claudeCodeModel||null,anthropicApiModel:n.anthropicApiModel||null,openaiApiModel:n.openaiApiModel||null,hubspotUploadMode:n.hubspotUploadMode||"api",hubspotAccounts:(n.hubspotAccounts||[]).map(r=>({portalId:r.portalId,portalName:r.portalName,dataCenter:r.dataCenter})),activeHubSpotAccount:n.activeHubSpotAccount||null,enabledCLITools:n.enabledCLITools||[],agenticMode:n.agenticMode,agenticConcurrency:n.agenticConcurrency},o=Pt().length,i=bs().length,a=wt();Ou().then(r=>{p(e,200,{version:a,environment:t,config:s,models:r,sessionCount:o,localThemeCount:i})}).catch(()=>{p(e,200,{version:a,environment:t,config:s,models:Fa,sessionCount:o,localThemeCount:i})})}function Da(e,t){R(e,n=>{try{let{engine:s,model:o}=JSON.parse(n);if(!["claude-code","anthropic-api","claude-oauth","openai-api","gemini-cli","gemini-api","codex-cli"].includes(s)){p(t,400,{error:`Invalid engine: ${s}`});return}let a={aiEngine:s};if(o)switch(s){case"claude-code":a.claudeCodeModel=o;break;case"anthropic-api":case"claude-oauth":a.anthropicApiModel=o;break;case"openai-api":a.openaiApiModel=o;break}K(a),p(t,200,{ok:!0,engine:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ha(e,t){R(e,n=>{try{let{provider:s,apiKey:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"provider is required"});return}if(!o){let l={};switch(s){case"anthropic":l.anthropicApiKey="";break;case"openai":l.openaiApiKey="";break;case"gemini":l.geminiApiKey="";break;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(l),p(t,200,{ok:!0,provider:s,deleted:!0});return}let i={};switch(s){case"anthropic":i.anthropicApiKey=o;break;case"openai":i.openaiApiKey=o;break;case"gemini":i.geminiApiKey=o;break;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(i);let a=null;if(!_().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(K({aiEngine:c}),a=c)}p(t,200,{ok:!0,provider:s,autoSelectedEngine:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function La(e,t){R(e,n=>{try{let{tool:s}=JSON.parse(n),o={hubspot:{cmd:"npm install -g @hubspot/cli",desc:"Installing HubSpot CLI"},claude:{cmd:"npm install -g @anthropic-ai/claude-code",desc:"Installing Claude Code"},gemini:{cmd:"npm install -g @google/gemini-cli",desc:"Installing Gemini CLI"},codex:{cmd:process.platform==="darwin"?"brew install --cask codex":"npm install -g @openai/codex",desc:"Installing OpenAI Codex"},gh:{cmd:process.platform==="darwin"?"brew install gh":"npm install -g @cli/gh",desc:"Installing GitHub CLI"}},i=o[s];if(!i){p(t,400,{error:`Unknown tool: ${s}. Valid: ${Object.keys(o).join(", ")}`});return}let a=St(i.cmd,i.desc,{timeout:12e4});p(t,200,{ok:!0,jobId:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ua(e,t){R(e,n=>{try{let s=JSON.parse(n||"{}"),o=_(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){Mn(s.personalAccessKey).then(a=>{Jt(s.personalAccessKey,a.portalId,a.portalName,a.dataCenter),p(t,200,{ok:!0,portalName:a.portalName,portalId:a.portalId,dataCenter:a.dataCenter})}).catch(a=>{p(t,400,{error:a instanceof Error?a.message:String(a)})});return}else{if(!je().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=fn("hs",["auth",`--pak=${s.personalAccessKey}`],"Authenticating with HubSpot",{timeout:3e4});p(t,200,{ok:!0,jobId:r});return}if(i==="api"){let a=o.hubspotAccounts||[];if(a.length>0&&!s.force){let r=a.find(l=>l.portalId===o.activeHubSpotAccount)||a[0];p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}else{if(!je().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=Fe();if(r.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}p(t,200,{needsKey:!0,instructions:"Create a personal access key in HubSpot",url:"https://app.hubspot.com/portal-recommend/l?slug=personal-access-key",steps:["Click the link above to open HubSpot","Select your account","Create a Personal Access Key with CMS permissions","Copy the key and paste it below"]})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ga(e,t){R(e,n=>{try{let s=JSON.parse(n||"{}");if(!Rs().found){p(t,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=js();if(i.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let r=fn("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(t,200,{ok:!0,jobId:r});return}let a=St("gh auth login --web --git-protocol https","GitHub authentication (check your browser)",{timeout:3e5});p(t,200,{ok:!0,jobId:a,browserAuthRequired:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ba(e,t){R(e,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((_().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){$s(s),p(t,200,{ok:!0});return}if(s){Es(s),p(t,200,{ok:!0});return}}else{if(!je().found){p(t,400,{error:"HubSpot CLI not installed"});return}let l=String(s).replace(/[^0-9]/g,"");if(!l){p(t,400,{error:"Invalid portalId"});return}if(o==="remove"){let c=fn("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}if(l){let c=fn("hs",["accounts","use",l],`Switching to HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}}p(t,400,{error:"portalId required"})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Wa(e){let t=St("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(e,200,{ok:!0,jobId:t})}function Va(e,t){R(e,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=St("CLAUDECODE= claude --print -p 'reply OK'","Authenticating Claude Code (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Claude Code opens a browser window, complete the sign-in there."});break}case"gemini":{let i=St("gemini -p 'reply OK'","Authenticating Gemini CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Gemini opens a browser window, complete the sign-in there."});break}case"codex":{if(o&&o.trim()){let i=o.trim();if(process.env.OPENAI_API_KEY=i,K({openaiApiKey:i}),process.platform!=="win32"){let a=/^[A-Za-z0-9_\-.:]+$/.test(i)?i:"";if(a){let r=`export OPENAI_API_KEY="${a}"`,l=process.env.SHELL?.includes("zsh")?Ra(ja(),".zshrc"):Ra(ja(),".bashrc");try{(Iu(l)?Tu(l,"utf-8"):"").includes("OPENAI_API_KEY")||$u(l,`
|
|
1505
1510
|
# Added by vibeSpot
|
|
1506
1511
|
${r}
|
|
1507
|
-
`)}catch{}}}p(t,200,{ok:!0,message:"API key saved"})}else{let i=St("codex login","Authenticating Codex CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"Complete the sign-in in your browser."})}break}default:p(t,400,{error:`Unknown CLI: ${s}`})}}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Va(e,t){N(e,n=>{try{let{mode:s}=JSON.parse(n);if(s!=="api"&&s!=="cli"){p(t,400,{error:`Invalid mode: ${s}. Must be "api" or "cli".`});return}K({hubspotUploadMode:s}),p(t,200,{ok:!0,mode:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ka(e,t){N(e,n=>{try{let{toolId:s,enabled:o}=JSON.parse(n);if(!s||typeof o!="boolean"){p(t,400,{error:"toolId (string) and enabled (boolean) required"});return}_s(s,o),p(t,200,{ok:!0,toolId:s,enabled:o})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ya(e,t){N(e,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency"],i={};for(let a of o)a in s&&(i[a]=s[a]);if(Object.keys(i).length===0){p(t,400,{error:"No valid settings fields provided"});return}K(i),p(t,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function za(e,t){let n=e.replace("/api/settings/job/","");if(!n){p(t,400,{error:"Job ID required"});return}let s=gs(n);if(!s){p(t,404,{error:"Job not found"});return}p(t,200,{id:s.id,status:s.status,description:s.description,output:s.output,exitCode:s.exitCode,startedAt:s.startedAt,completedAt:s.completedAt})}g();et();Z();Ke();function qa(e,t){N(e,n=>{try{let{access_token:s,refresh_token:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"access_token is required"});return}Ps(s.trim(),(o||"").trim());let i=_();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&K({aiEngine:"claude-oauth"}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Xa(e,t){let n=Re(),s=Lt();p(t,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function Qa(e,t){try{kn(),_().aiEngine==="claude-oauth"&&K({aiEngine:void 0}),p(t,200,{ok:!0})}catch(n){p(t,500,{error:n instanceof Error?n.message:String(n)})}}g();et();Se();import{existsSync as Pu,rmSync as Mu}from"fs";import{join as Ou}from"path";function Za(e,t,n){if(e==="GET"){let s=S(),o=Pt().sort((i,a)=>a.updatedAt-i.updatedAt);p(n,200,{activeTheme:s?{id:s.id,themeName:s.themeName}:null,sessions:o});return}if(e==="DELETE"){N(t,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);cr(o,i),p(n,200,{ok:!0})}catch(o){p(n,500,{error:o instanceof Error?o.message:String(o)})}});return}p(n,405,{error:"Method not allowed"})}function el(e,t){N(e,n=>{try{let{sessionId:s}=JSON.parse(n),o=is(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function tl(e,t){N(e,n=>{try{let{themeName:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=Ou(Me,s);if(!Pu(o)){p(t,404,{error:"Theme not found on disk"});return}Mu(o,{recursive:!0,force:!0}),p(t,200,{ok:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function nl(e,t){N(e,n=>{try{let{sessionId:s,newName:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"sessionId and newName are required"});return}let i=o.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/^-|-$/g,"").replace(/-{2,}/g,"-");if(!i){p(t,400,{error:"Invalid name"});return}let a=dr(s,i);a.ok?p(t,200,{ok:!0,newName:i}):p(t,400,{error:a.error})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}g();et();ve();Z();Se();Q();import{existsSync as As,readFileSync as Lu,rmSync as Lo}from"fs";import{join as Be,basename as Gu}from"path";import{execFileSync as Uu}from"child_process";var Bu=process.platform==="win32"?{shell:!0}:{};function cl(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}let n=at();p(e,200,{themeName:t.themeName,themePath:t.themePath,templates:t.templates.map(s=>({id:s.id,label:s.label,pageType:s.pageType,moduleCount:s.modules.length,messageCount:s.messages.length})),activeTemplateId:t.activeTemplateId,moduleLibrary:n.map(s=>({moduleName:s.module.moduleName,usedIn:s.usedIn})),brandAssets:{hasStyleguide:!!t.brandAssets?.styleguide,hasBrandvoice:!!t.brandAssets?.brandvoice,hasThemeContext:!!t.brandAssets?.themeContext,humanify:t.brandAssets?.humanify!==!1}})}function dl(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}let n=t.themePath;if(!As(n)){p(e,404,{error:"Theme directory not found"});return}let s=t.themeName||"theme",o=Be(n,".."),i=Gu(n);try{let a=`${s}.zip`,r=Be(o,a);As(r)&&Lo(r),Uu("zip",["-r",a,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...Bu});let l=Lu(r);Lo(r),e.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${a}"`,"Content-Length":l.length}),e.end(l)}catch(a){T.error("download-zip","Failed to create zip archive",a),p(e,500,{error:"Failed to create zip archive"})}}function ul(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{templates:s.templates.map(o=>({id:o.id,label:o.label,pageType:o.pageType,moduleCount:o.modules.length})),activeTemplateId:s.activeTemplateId});return}if(e==="POST"){N(t,o=>{try{let{pageType:i,label:a}=JSON.parse(o);if(!i||!a){p(n,400,{error:"pageType and label are required"});return}if(!["landing_page","blog_post","website_page","module_only"].includes(i)){p(n,400,{error:`Invalid pageType: ${i}`});return}let l=or(i,a);D(),p(n,200,{ok:!0,template:{id:l.id,label:l.label,pageType:l.pageType}})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){N(t,o=>{try{let{templateId:i,deleteModules:a}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!ar(i,!!a)){p(n,404,{error:"Template not found"});return}D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function ml(e,t){N(e,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}if(!qs(s)){p(t,404,{error:"Template not found"});return}D();let i=S();p(t,200,{ok:!0,modules:me().map(a=>a.moduleName),messageCount:i?.messages.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function pl(e,t){N(e,n=>{try{let{templateId:s,newLabel:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"templateId and newLabel are required"});return}if(!rr(s,o.trim())){p(t,404,{error:"Template not found"});return}D(),p(t,200,{ok:!0,newLabel:o.trim()})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function fl(e,t){N(e,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}let i=ir(s,o);if(!i){p(t,404,{error:"Template not found"});return}D(),p(t,200,{ok:!0,template:{id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function gl(e){let t=at();p(e,200,{modules:t.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function hl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}N(t,o=>{try{let{moduleName:i}=JSON.parse(o);if(!i){p(n,400,{error:"moduleName is required"});return}let r=at().find(d=>d.module.moduleName===i);if(!r){p(n,404,{error:`Module "${i}" not found in library`});return}let l={...r.module};s.modules.find(d=>d.moduleName===l.moduleName)||(s.modules.push(l),s.moduleOrder.push(l.moduleName),s.updatedAt=Date.now()),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function yl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{styleguide:s.brandAssets?.styleguide||null,brandvoice:s.brandAssets?.brandvoice||null,themeContext:s.brandAssets?.themeContext||null});return}if(e==="POST"){N(t,o=>{try{let{type:i,content:a}=JSON.parse(o);if(!i){p(n,400,{error:"type is required"});return}if(s.brandAssets||(s.brandAssets={}),i==="humanify"){s.brandAssets.humanify=a==="on",s.updatedAt=Date.now(),D(),p(n,200,{ok:!0});return}if(!a){p(n,400,{error:"content is required"});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}. Must be "styleguide", "brandvoice", or "themeContext"`});return}let r=i==="themeContext"?"theme-context.md":`${i}.md`;s.brandAssets[i]=a,s.updatedAt=Date.now();let l=Be(s.themePath,".vibespot");Ae(l),H(Be(l,r),a),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){N(t,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}s.brandAssets&&delete s.brandAssets[i],s.updatedAt=Date.now();let a=i==="themeContext"?"theme-context.md":`${i}.md`,r=Be(s.themePath,".vibespot",a);As(r)&&Lo(r),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function al(e,t,n){if(!e)return;e.brandAssets||(e.brandAssets={}),e.brandAssets[t]=n,e.updatedAt=Date.now();let s=t==="themeContext"?"theme-context.md":`${t}.md`,o=Be(e.themePath,".vibespot");Ae(o),H(Be(o,s),n)}async function ll(e,t,n){if(t==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(Cs(),ws));return m(n||e.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(fs(),va)),{loadConfig:o}=await Promise.resolve().then(()=>(Z(),Qo)),i=o(),{engine:a,apiKey:r,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return null;if(t==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(rl(),il));return m(d,a,r,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do));return u(d,e.brandAssets?.themeContext,a,r,l)}function bl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(e,s=>{(async()=>{try{let o=s?JSON.parse(s):{},i=o.type||"styleguide",a=o.sourcePath;if(i==="all"){let l=["styleguide","brandvoice","themeContext"],c=await Promise.allSettled(l.map(u=>ll(n,u,a))),d={};for(let u=0;u<l.length;u++){let m=c[u],f=m.status==="fulfilled"?m.value:null;f&&al(n,l[u],f),d[l[u]]=f}D(),p(t,200,{ok:!0,type:"all",extracted:d});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(t,400,{error:`Invalid type: ${i}`});return}let r=await ll(n,i,a);if(!r){p(t,200,{ok:!1,type:i,error:"No content to extract from"});return}al(n,i,r),D(),p(t,200,{ok:!0,type:i,content:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}function Sl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(e,s=>{(async()=>{try{let{source:o,themeName:i,localPath:a}=JSON.parse(s),r;if(o==="hubspot"){if(!i){p(t,400,{error:"themeName is required for HubSpot import"});return}let u=he();if(!u){p(t,400,{error:"No HubSpot account connected"});return}let m=i.replace(/^\/+|\/+$/g,"");if(!m){p(t,400,{error:"Invalid theme name"});return}let f=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:h}=await import("os"),y=Be(h(),"vibespot-themes",".references",f);Ae(y);let{fetchTheme:v}=await Promise.resolve().then(()=>(Jn(),pi));await v(u,m,y),r=y}else if(o==="local"){if(!a){p(t,400,{error:"localPath is required for local import"});return}if(!As(a)){p(t,400,{error:`Path not found: ${a}`});return}r=a}else{p(t,400,{error:"source must be 'hubspot' or 'local'"});return}let{extractDesignContext:l}=await Promise.resolve().then(()=>(Cs(),ws)),c=await l(r);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Be(n.themePath,".vibespot");Ae(d),H(Be(d,"styleguide.md"),c),D(),p(t,200,{ok:!0,styleguide:c,source:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}g();et();Se();import{join as Wu}from"path";Zt();function vl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}p(t,200,{id:n.id,themeName:n.themeName,themePath:n.themePath,messageCount:n.messages.length,moduleCount:n.modules.length,moduleOrder:n.moduleOrder})}function xl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){let o=me();p(n,200,{modules:o.map(i=>({moduleName:i.moduleName,fieldsJson:i.fieldsJson,moduleHtml:i.moduleHtml,moduleCss:i.moduleCss,moduleJs:i.moduleJs||null})),sharedCss:s.sharedCss,sharedJs:s.sharedJs});return}if(e==="DELETE"){vo(t,n,o=>{o.deleteEntirely?Zi(o.moduleName):er(o.moduleName),D(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function wl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(e,s=>{try{let o=JSON.parse(s);if(o.shared){if(o.shared==="css")n.sharedCss=o.content;else if(o.shared==="js")n.sharedJs=o.content;else{p(t,400,{error:"Invalid shared type"});return}let c=Ce();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),D(),lt(),p(t,200,{ok:!0});return}let{moduleName:i,fileType:a,content:r}=o;if(!i||!a){p(t,400,{error:"moduleName and fileType required"});return}let l=n.modules.find(c=>c.moduleName===i);if(!l){p(t,404,{error:`Module "${i}" not found`});return}switch(a){case"html":l.moduleHtml=r;break;case"css":l.moduleCss=r;break;case"js":l.moduleJs=r||void 0;break;case"fields":try{JSON.parse(r)}catch{p(t,400,{error:"Invalid JSON in fields.json"});return}l.fieldsJson=r;break;default:p(t,400,{error:`Invalid fileType: ${a}`});return}n.updatedAt=Date.now(),D(),lt(),p(t,200,{ok:!0})}catch(o){p(t,400,{error:String(o)})}})}function Cl(e,t){vo(e,t,n=>{Array.isArray(n.order)?(Et(n.order),D(),p(t,200,{ok:!0})):p(t,400,{error:"order must be an array"})})}async function Al(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}try{lt();let n=zn(t.themePath),s=hs(`hs cms upload "${t.themePath}" "${t.themeName}"`,"Uploading to HubSpot",{cwd:Wu(t.themePath,".."),timeout:18e4});p(e,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(e,500,{error:String(n)})}}function kl(e,t){N(e,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);tr(s,o,i),D(),p(t,200,{ok:!0})}catch(s){p(t,400,{error:String(s)})}})}function Il(e,t){N(e,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"url is required"});return}let o=ui(s),i=o.components.map(r=>`- ${r.name}: ${r.description}`).join(`
|
|
1512
|
+
`)}catch{}}}p(t,200,{ok:!0,message:"API key saved"})}else{let i=St("codex login","Authenticating Codex CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"Complete the sign-in in your browser."})}break}default:p(t,400,{error:`Unknown CLI: ${s}`})}}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ka(e,t){R(e,n=>{try{let{mode:s}=JSON.parse(n);if(s!=="api"&&s!=="cli"){p(t,400,{error:`Invalid mode: ${s}. Must be "api" or "cli".`});return}K({hubspotUploadMode:s}),p(t,200,{ok:!0,mode:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ya(e,t){R(e,n=>{try{let{toolId:s,enabled:o}=JSON.parse(n);if(!s||typeof o!="boolean"){p(t,400,{error:"toolId (string) and enabled (boolean) required"});return}_s(s,o),p(t,200,{ok:!0,toolId:s,enabled:o})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function za(e,t){R(e,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency"],i={};for(let a of o)a in s&&(i[a]=s[a]);if(Object.keys(i).length===0){p(t,400,{error:"No valid settings fields provided"});return}K(i),p(t,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function qa(e,t){let n=e.replace("/api/settings/job/","");if(!n){p(t,400,{error:"Job ID required"});return}let s=gs(n);if(!s){p(t,404,{error:"Job not found"});return}p(t,200,{id:s.id,status:s.status,description:s.description,output:s.output,exitCode:s.exitCode,startedAt:s.startedAt,completedAt:s.completedAt})}g();et();Z();Ke();function Xa(e,t){R(e,n=>{try{let{access_token:s,refresh_token:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"access_token is required"});return}Ps(s.trim(),(o||"").trim());let i=_();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&K({aiEngine:"claude-oauth"}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Qa(e,t){let n=Re(),s=Lt();p(t,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function Za(e,t){try{kn(),_().aiEngine==="claude-oauth"&&K({aiEngine:void 0}),p(t,200,{ok:!0})}catch(n){p(t,500,{error:n instanceof Error?n.message:String(n)})}}g();et();Se();import{existsSync as Nu,rmSync as Ru}from"fs";import{join as ju}from"path";function el(e,t,n){if(e==="GET"){let s=v(),o=Pt().sort((i,a)=>a.updatedAt-i.updatedAt);p(n,200,{activeTheme:s?{id:s.id,themeName:s.themeName}:null,sessions:o});return}if(e==="DELETE"){R(t,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);dr(o,i),p(n,200,{ok:!0})}catch(o){p(n,500,{error:o instanceof Error?o.message:String(o)})}});return}p(n,405,{error:"Method not allowed"})}function tl(e,t){R(e,n=>{try{let{sessionId:s}=JSON.parse(n),o=is(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function nl(e,t){R(e,n=>{try{let{themeName:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=ju(Me,s);if(!Nu(o)){p(t,404,{error:"Theme not found on disk"});return}Ru(o,{recursive:!0,force:!0}),p(t,200,{ok:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function sl(e,t){R(e,n=>{try{let{sessionId:s,newName:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"sessionId and newName are required"});return}let i=o.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/^-|-$/g,"").replace(/-{2,}/g,"-");if(!i){p(t,400,{error:"Invalid name"});return}let a=ur(s,i);a.ok?p(t,200,{ok:!0,newName:i}):p(t,400,{error:a.error})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}g();et();ve();Z();Se();Q();import{existsSync as As,readFileSync as Bu,rmSync as Uo}from"fs";import{join as Be,basename as Wu}from"path";import{execFileSync as Vu}from"child_process";var Ku=process.platform==="win32"?{shell:!0}:{};function dl(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}let n=at();p(e,200,{themeName:t.themeName,themePath:t.themePath,templates:t.templates.map(s=>({id:s.id,label:s.label,pageType:s.pageType,moduleCount:s.modules.length,messageCount:s.messages.length})),activeTemplateId:t.activeTemplateId,moduleLibrary:n.map(s=>({moduleName:s.module.moduleName,usedIn:s.usedIn})),brandAssets:{hasStyleguide:!!t.brandAssets?.styleguide,hasBrandvoice:!!t.brandAssets?.brandvoice,hasThemeContext:!!t.brandAssets?.themeContext,humanify:t.brandAssets?.humanify!==!1}})}function ul(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}let n=t.themePath;if(!As(n)){p(e,404,{error:"Theme directory not found"});return}let s=t.themeName||"theme",o=Be(n,".."),i=Wu(n);try{let a=`${s}.zip`,r=Be(o,a);As(r)&&Uo(r),Vu("zip",["-r",a,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...Ku});let l=Bu(r);Uo(r),e.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${a}"`,"Content-Length":l.length}),e.end(l)}catch(a){$.error("download-zip","Failed to create zip archive",a),p(e,500,{error:"Failed to create zip archive"})}}function ml(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{templates:s.templates.map(o=>({id:o.id,label:o.label,pageType:o.pageType,moduleCount:o.modules.length})),activeTemplateId:s.activeTemplateId});return}if(e==="POST"){R(t,o=>{try{let{pageType:i,label:a}=JSON.parse(o);if(!i||!a){p(n,400,{error:"pageType and label are required"});return}if(!["landing_page","blog_post","website_page","module_only"].includes(i)){p(n,400,{error:`Invalid pageType: ${i}`});return}let l=ir(i,a);L(),p(n,200,{ok:!0,template:{id:l.id,label:l.label,pageType:l.pageType}})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){R(t,o=>{try{let{templateId:i,deleteModules:a}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!lr(i,!!a)){p(n,404,{error:"Template not found"});return}L(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function pl(e,t){R(e,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}if(!qs(s)){p(t,404,{error:"Template not found"});return}L();let i=v();p(t,200,{ok:!0,modules:me().map(a=>a.moduleName),messageCount:i?.messages.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function fl(e,t){R(e,n=>{try{let{templateId:s,newLabel:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"templateId and newLabel are required"});return}if(!ar(s,o.trim())){p(t,404,{error:"Template not found"});return}L(),p(t,200,{ok:!0,newLabel:o.trim()})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function gl(e,t){R(e,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}let i=rr(s,o);if(!i){p(t,404,{error:"Template not found"});return}L(),p(t,200,{ok:!0,template:{id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function hl(e){let t=at();p(e,200,{modules:t.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function yl(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}R(t,o=>{try{let{moduleName:i}=JSON.parse(o);if(!i){p(n,400,{error:"moduleName is required"});return}let r=at().find(d=>d.module.moduleName===i);if(!r){p(n,404,{error:`Module "${i}" not found in library`});return}let l={...r.module};s.modules.find(d=>d.moduleName===l.moduleName)||(s.modules.push(l),s.moduleOrder.push(l.moduleName),s.updatedAt=Date.now()),L(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function bl(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{styleguide:s.brandAssets?.styleguide||null,brandvoice:s.brandAssets?.brandvoice||null,themeContext:s.brandAssets?.themeContext||null});return}if(e==="POST"){R(t,o=>{try{let{type:i,content:a}=JSON.parse(o);if(!i){p(n,400,{error:"type is required"});return}if(s.brandAssets||(s.brandAssets={}),i==="humanify"){s.brandAssets.humanify=a==="on",s.updatedAt=Date.now(),L(),p(n,200,{ok:!0});return}if(!a){p(n,400,{error:"content is required"});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}. Must be "styleguide", "brandvoice", or "themeContext"`});return}let r=i==="themeContext"?"theme-context.md":`${i}.md`;s.brandAssets[i]=a,s.updatedAt=Date.now();let l=Be(s.themePath,".vibespot");Ae(l),U(Be(l,r),a),L(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){R(t,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}s.brandAssets&&delete s.brandAssets[i],s.updatedAt=Date.now();let a=i==="themeContext"?"theme-context.md":`${i}.md`,r=Be(s.themePath,".vibespot",a);As(r)&&Uo(r),L(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function ll(e,t,n){if(!e)return;e.brandAssets||(e.brandAssets={}),e.brandAssets[t]=n,e.updatedAt=Date.now();let s=t==="themeContext"?"theme-context.md":`${t}.md`,o=Be(e.themePath,".vibespot");Ae(o),U(Be(o,s),n)}async function cl(e,t,n){if(t==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(Cs(),ws));return m(n||e.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(fs(),xa)),{loadConfig:o}=await Promise.resolve().then(()=>(Z(),Zo)),i=o(),{engine:a,apiKey:r,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return null;if(t==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(al(),rl));return m(d,a,r,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(Lo(),Ho));return u(d,e.brandAssets?.themeContext,a,r,l)}function Sl(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}R(e,s=>{(async()=>{try{let o=s?JSON.parse(s):{},i=o.type||"styleguide",a=o.sourcePath;if(i==="all"){let l=["styleguide","brandvoice","themeContext"],c=await Promise.allSettled(l.map(u=>cl(n,u,a))),d={};for(let u=0;u<l.length;u++){let m=c[u],f=m.status==="fulfilled"?m.value:null;f&&ll(n,l[u],f),d[l[u]]=f}L(),p(t,200,{ok:!0,type:"all",extracted:d});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(t,400,{error:`Invalid type: ${i}`});return}let r=await cl(n,i,a);if(!r){p(t,200,{ok:!1,type:i,error:"No content to extract from"});return}ll(n,i,r),L(),p(t,200,{ok:!0,type:i,content:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}function vl(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}R(e,s=>{(async()=>{try{let{source:o,themeName:i,localPath:a}=JSON.parse(s),r;if(o==="hubspot"){if(!i){p(t,400,{error:"themeName is required for HubSpot import"});return}let u=he();if(!u){p(t,400,{error:"No HubSpot account connected"});return}let m=i.replace(/^\/+|\/+$/g,"");if(!m){p(t,400,{error:"Invalid theme name"});return}let f=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:h}=await import("os"),y=Be(h(),"vibespot-themes",".references",f);Ae(y);let{fetchTheme:w}=await Promise.resolve().then(()=>(Jn(),fi));await w(u,m,y),r=y}else if(o==="local"){if(!a){p(t,400,{error:"localPath is required for local import"});return}if(!As(a)){p(t,400,{error:`Path not found: ${a}`});return}r=a}else{p(t,400,{error:"source must be 'hubspot' or 'local'"});return}let{extractDesignContext:l}=await Promise.resolve().then(()=>(Cs(),ws)),c=await l(r);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Be(n.themePath,".vibespot");Ae(d),U(Be(d,"styleguide.md"),c),L(),p(t,200,{ok:!0,styleguide:c,source:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}g();et();Se();import{join as Yu}from"path";Zt();function xl(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}p(t,200,{id:n.id,themeName:n.themeName,themePath:n.themePath,messageCount:n.messages.length,moduleCount:n.modules.length,moduleOrder:n.moduleOrder})}function wl(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){let o=me();p(n,200,{modules:o.map(i=>({moduleName:i.moduleName,fieldsJson:i.fieldsJson,moduleHtml:i.moduleHtml,moduleCss:i.moduleCss,moduleJs:i.moduleJs||null})),sharedCss:s.sharedCss,sharedJs:s.sharedJs});return}if(e==="DELETE"){vo(t,n,o=>{o.deleteEntirely?er(o.moduleName):tr(o.moduleName),L(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function Cl(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}R(e,s=>{try{let o=JSON.parse(s);if(o.shared){if(o.shared==="css")n.sharedCss=o.content;else if(o.shared==="js")n.sharedJs=o.content;else{p(t,400,{error:"Invalid shared type"});return}let c=Ce();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),L(),lt(),p(t,200,{ok:!0});return}let{moduleName:i,fileType:a,content:r}=o;if(!i||!a){p(t,400,{error:"moduleName and fileType required"});return}let l=n.modules.find(c=>c.moduleName===i);if(!l){p(t,404,{error:`Module "${i}" not found`});return}switch(a){case"html":l.moduleHtml=r;break;case"css":l.moduleCss=r;break;case"js":l.moduleJs=r||void 0;break;case"fields":try{JSON.parse(r)}catch{p(t,400,{error:"Invalid JSON in fields.json"});return}l.fieldsJson=r;break;default:p(t,400,{error:`Invalid fileType: ${a}`});return}n.updatedAt=Date.now(),L(),lt(),p(t,200,{ok:!0})}catch(o){p(t,400,{error:String(o)})}})}function Al(e,t){vo(e,t,n=>{Array.isArray(n.order)?(Et(n.order),L(),p(t,200,{ok:!0})):p(t,400,{error:"order must be an array"})})}async function kl(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}try{lt();let n=zn(t.themePath),s=hs(`hs cms upload "${t.themePath}" "${t.themeName}"`,"Uploading to HubSpot",{cwd:Yu(t.themePath,".."),timeout:18e4});p(e,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(e,500,{error:String(n)})}}function Il(e,t){R(e,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);nr(s,o,i),L(),p(t,200,{ok:!0})}catch(s){p(t,400,{error:String(s)})}})}function Tl(e,t){R(e,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"url is required"});return}let o=mi(s),i=o.components.map(r=>`- ${r.name}: ${r.description}`).join(`
|
|
1508
1513
|
`),a={sourceDir:o.sourceDir,componentCount:o.components.length,components:o.components.map(r=>({name:r.name,description:r.description})),hasTailwind:o.hasTailwind,cssVarCount:o.cssVarCount,fonts:o.fonts,interactions:o.interactions,conversionPrompt:`Import and convert the React landing page from ${s} to native HubSpot modules.
|
|
1509
1514
|
|
|
1510
1515
|
Source analysis found ${o.components.length} components:
|
|
@@ -1514,11 +1519,11 @@ Design system: ${o.hasTailwind?"Tailwind CSS":"Custom CSS"}, ${o.cssVarCount} CS
|
|
|
1514
1519
|
Fonts: ${o.fonts.length>0?o.fonts.join(", "):"System fonts"}
|
|
1515
1520
|
Interactions: ${o.interactions.join(", ")}
|
|
1516
1521
|
|
|
1517
|
-
Read the React source files from ${o.sourceDir} and convert each component to a HubSpot module. Preserve the design, layout, colors, and content. Generate fields.json so marketers can edit all text, images, colors, and links in the HubSpot page editor.`};p(t,200,a)}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Tl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}if(!_e()){p(t,200,{available:!1,commits:[]});return}let o=new URL(e.url||"/","http://localhost").searchParams.get("templateId"),i=o?Yi(n.themePath,o,50):Ki(n.themePath,50);p(t,200,{available:!0,commits:i,filtered:!!o})}function $l(e,t){N(e,n=>{try{let s=S();if(!s){p(t,404,{error:"No active session"});return}let{hash:o,templateId:i}=JSON.parse(n);if(!o||typeof o!="string"){p(t,400,{error:"Commit hash is required"});return}if(rt("assistant",`Rolled back to version ${o.slice(0,7)}.`),i){let a=s.templates.find(c=>c.id===i);if(!a){p(t,404,{error:"Template not found"});return}let r=a.moduleOrder.map(c=>`modules/${c}.module`);a.templateFile&&r.push(a.templateFile);let l=qi(s.themePath,i,o,r);if(!l.success){p(t,500,{error:l.error||"Rollback failed"});return}fr()}else{let a=zi(s.themePath,o);if(!a.success){p(t,500,{error:a.error||"Rollback failed"});return}pr()}D(),p(t,200,{ok:!0,modules:me().map(a=>a.moduleName)})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}Co();var Pl={".html":"text/html",".css":"text/css",".js":"application/javascript",".json":"application/json",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif",".ico":"image/x-icon",".woff2":"font/woff2"};function Ml(e){let{port:t,uiDir:n}=e,s=Vu((i,a)=>zu(i,a,n)),o=new Yu({server:s});return o.on("connection",i=>Xu(i)),new Promise((i,a)=>{s.on("error",r=>{r.code==="EADDRINUSE"?s.listen(t+1,()=>{i({port:t+1,close:()=>{s.close(),o.close()}})}):a(r)}),s.listen(t,()=>{i({port:t,close:()=>{s.close(),o.close()}})})})}function zu(e,t,n){let s=new URL(e.url||"/",`http://${e.headers.host}`),o=e.method||"GET";if(t.setHeader("X-Content-Type-Options","nosniff"),t.setHeader("X-Frame-Options","DENY"),t.setHeader("X-XSS-Protection","1; mode=block"),t.setHeader("Referrer-Policy","strict-origin-when-cross-origin"),s.pathname.startsWith("/api/")){qu(o,s.pathname,e,t);return}if(s.pathname==="/preview"){let i=ro();t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(i);return}if(s.pathname==="/module-preview"){let i=s.searchParams.get("module")||"",a=ao(i);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){Qu(s.pathname.slice(14),t);return}if(s.pathname==="/docs"){t.writeHead(301,{Location:"/docs/"}),t.end();return}if(s.pathname.startsWith("/docs/")){let i=s.pathname.slice(5)||"/index.html";El(i,tt(n,"docs"),e,t);return}El(s.pathname,n,e,t)}function qu(e,t,n,s){let o=n.headers.origin||"";if(/^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(o)&&s.setHeader("Access-Control-Allow-Origin",o),s.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),s.setHeader("Access-Control-Allow-Headers","Content-Type"),e==="OPTIONS"){s.writeHead(204),s.end();return}switch(t){case"/api/session":vl(e,s);break;case"/api/modules":xl(e,n,s);break;case"/api/modules/reorder":Cl(n,s);break;case"/api/modules/code":wl(n,s);break;case"/api/upload":Al(s);break;case"/api/upload-files":e==="POST"?Lr(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":kl(n,s);break;case"/api/import":Il(n,s);break;case"/api/setup":Ta(s);break;case"/api/setup/create":$a(n,s);break;case"/api/setup/fetch":Ea(n,s);break;case"/api/setup/open":_a(n,s);break;case"/api/setup/resume":Pa(n,s);break;case"/api/setup/apikey":Ma(n,s);break;case"/api/setup/remote-themes":e==="GET"?Oa(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":e==="GET"?ja(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":e==="POST"?Ja(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":e==="POST"?Da(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":e==="POST"?Ha(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":e==="POST"?La(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":e==="POST"?Ga(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":e==="POST"?Ua(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":e==="POST"?Ba(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":e==="POST"?Wa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":e==="POST"?Va(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":e==="POST"?Ka(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":e==="POST"?qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":e==="GET"?Xa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":e==="POST"?Qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":e==="POST"?Ya(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":e==="GET"?p(s,200,{changelog:Ko()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":Za(e,n,s);break;case"/api/themes/switch":e==="POST"?el(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":e==="POST"?tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":e==="POST"?nl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":e==="GET"?Tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":e==="POST"?$l(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":e==="GET"?cl(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":ul(e,n,s);break;case"/api/templates/activate":e==="POST"?ml(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":e==="POST"?pl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":e==="POST"?fl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":e==="GET"?gl(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":yl(e,n,s);break;case"/api/brand-assets/extract":e==="POST"?bl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":e==="POST"?Sl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":e==="GET"?dl(s):p(s,405,{error:"Method not allowed"});break;default:t.startsWith("/api/settings/job/")&&e==="GET"?za(t,s):t.match(/^\/api\/templates\/[^/]+\/add-module$/)&&e==="POST"?hl(t,n,s):p(s,404,{error:"Not found"})}}function Xu(e){e.on("message",async n=>{let s;try{s=JSON.parse(n.toString())}catch{e.send(JSON.stringify({type:"error",message:"Invalid JSON"}));return}switch(s.type){case"chat":{let o=String(s.message||"");if(!o.trim())return;rt("user",o),D();let i=Array.isArray(s.fileIds)?s.fileIds:void 0,a=Ro();a.needsPrompt&&e.send(JSON.stringify({type:"agentic_prompt"}));try{if(a.useAgentic){let l=[],c=[],d=await Oo(o,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...f}=u;e.send(JSON.stringify(f))}else e.send(JSON.stringify(u));if(u.type==="agent_step")l.push({step:u.step,label:u.label});else if(u.type==="agent_decision"){let m=l[l.length-1];m&&(m.decisions||(m.decisions=[]),m.decisions.push(u.decision))}else u.type==="design_system_ready"?Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Et(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(Le({modules:[{moduleName:u.module,fieldsJson:u.moduleFiles.fieldsJson,metaJson:u.moduleFiles.metaJson,moduleHtml:u.moduleFiles.moduleHtml,moduleCss:u.moduleFiles.moduleCss,moduleJs:u.moduleFiles.moduleJs}]}),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)})),c.push({name:u.module,status:"complete"})):u.type==="module_progress"&&u.status==="failed"&&c.push({name:u.module,status:"failed"})},i);No(d,{steps:l,modules:c,stats:d.stats})}else Po(l=>{e.send(JSON.stringify({type:"parse_warning",message:l}))}),await pn(o,l=>{e.send(JSON.stringify({type:"stream",content:l}))},l=>{e.send(JSON.stringify({type:"stream_status",content:l}))},i);let r=S();if(r){lt();let l=Ce(),c=null;if(l){let d=l.moduleOrder.map(u=>`modules/${u}.module`);l.templateFile&&d.push(l.templateFile),l.sharedCss&&d.push(`css/${r.themeName}-theme.css`),l.sharedJs&&d.push(`js/${r.themeName}-animations.js`),c=Vi(r.themePath,l.id,o,d)}else c=Ks(r.themePath,o);c&&e.send(JSON.stringify({type:"version_created",hash:c}))}e.send(JSON.stringify({type:"generation_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:me().map(l=>l.moduleName)}));{let l=S();l&&a.useAgentic&&!l.brandAssets?.styleguide&&!l.brandAssets?.brandvoice&&!l.brandAssets?.themeContext&&e.send(JSON.stringify({type:"suggest_brand_extraction"}))}}catch(r){e.send(JSON.stringify({type:"error",message:r instanceof Error?r.message:String(r)}))}break}case"extract_brand_assets":{let o=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do)),m=await u(d,o.brandAssets?.themeContext,a,r,l),{mkdirSync:f,writeFileSync:h}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let y=tt(o.themePath,".vibespot");yn(y)||f(y,{recursive:!0}),h(tt(y,"theme-context.md"),m),D(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:y}=await Promise.resolve().then(()=>(Cs(),ws)),v=await y(o.themePath);if(v){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=v,o.updatedAt=Date.now();let C=tt(o.themePath,".vibespot");yn(C)||f(C,{recursive:!0}),h(tt(C,"styleguide.md"),v),D(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"styleguide"}))}}catch{}e.send(JSON.stringify({type:"brand_extraction_complete"}))}catch(i){e.send(JSON.stringify({type:"brand_extraction_error",message:i instanceof Error?i.message:String(i)}))}})();break}case"start_upload":{let o=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}try{lt();let i=zn(o.themePath);if(i.length>0&&e.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(_().hubspotUploadMode||"api")==="api"){let l=he();if(!l){e.send(JSON.stringify({type:"upload_failed",output:"No HubSpot account configured. Open Settings \u2192 HubSpot to add one.",errors:[{file:"",message:"No HubSpot account configured",fixable:!1}]}));break}e.send(JSON.stringify({type:"upload_started",jobId:"api-upload"}));let c=await qn(l,o.themePath,o.themeName,{onFileStart:d=>{e.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
|
|
1522
|
+
Read the React source files from ${o.sourceDir} and convert each component to a HubSpot module. Preserve the design, layout, colors, and content. Generate fields.json so marketers can edit all text, images, colors, and links in the HubSpot page editor.`};p(t,200,a)}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function $l(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}if(!_e()){p(t,200,{available:!1,commits:[]});return}let o=new URL(e.url||"/","http://localhost").searchParams.get("templateId"),i=o?zi(n.themePath,o,50):Yi(n.themePath,50);p(t,200,{available:!0,commits:i,filtered:!!o})}function El(e,t){R(e,n=>{try{let s=v();if(!s){p(t,404,{error:"No active session"});return}let{hash:o,templateId:i}=JSON.parse(n);if(!o||typeof o!="string"){p(t,400,{error:"Commit hash is required"});return}if(rt("assistant",`Rolled back to version ${o.slice(0,7)}.`),i){let a=s.templates.find(c=>c.id===i);if(!a){p(t,404,{error:"Template not found"});return}let r=a.moduleOrder.map(c=>`modules/${c}.module`);a.templateFile&&r.push(a.templateFile);let l=Xi(s.themePath,i,o,r);if(!l.success){p(t,500,{error:l.error||"Rollback failed"});return}gr()}else{let a=qi(s.themePath,o);if(!a.success){p(t,500,{error:a.error||"Rollback failed"});return}fr()}L(),p(t,200,{ok:!0,modules:me().map(a=>a.moduleName)})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}Ao();var Ml={".html":"text/html",".css":"text/css",".js":"application/javascript",".json":"application/json",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif",".ico":"image/x-icon",".woff2":"font/woff2"};function Ol(e){let{port:t,uiDir:n}=e,s=zu((i,a)=>Qu(i,a,n)),o=new Xu({server:s});return o.on("connection",i=>em(i)),new Promise((i,a)=>{s.on("error",r=>{r.code==="EADDRINUSE"?s.listen(t+1,()=>{i({port:t+1,close:()=>{s.close(),o.close()}})}):a(r)}),s.listen(t,()=>{i({port:t,close:()=>{s.close(),o.close()}})})})}function Qu(e,t,n){let s=new URL(e.url||"/",`http://${e.headers.host}`),o=e.method||"GET";if(t.setHeader("X-Content-Type-Options","nosniff"),t.setHeader("X-Frame-Options","DENY"),t.setHeader("X-XSS-Protection","1; mode=block"),t.setHeader("Referrer-Policy","strict-origin-when-cross-origin"),s.pathname.startsWith("/api/")){Zu(o,s.pathname,e,t);return}if(s.pathname==="/preview"){let i=ro();t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(i);return}if(s.pathname==="/module-preview"){let i=s.searchParams.get("module")||"",a=ao(i);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){tm(s.pathname.slice(14),t);return}if(s.pathname==="/docs"){t.writeHead(301,{Location:"/docs/"}),t.end();return}if(s.pathname.startsWith("/docs/")){let i=s.pathname.slice(5)||"/index.html";_l(i,tt(n,"docs"),e,t);return}_l(s.pathname,n,e,t)}function Zu(e,t,n,s){let o=n.headers.origin||"";if(/^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(o)&&s.setHeader("Access-Control-Allow-Origin",o),s.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),s.setHeader("Access-Control-Allow-Headers","Content-Type"),e==="OPTIONS"){s.writeHead(204),s.end();return}switch(t){case"/api/session":xl(e,s);break;case"/api/modules":wl(e,n,s);break;case"/api/modules/reorder":Al(n,s);break;case"/api/modules/code":Cl(n,s);break;case"/api/upload":kl(s);break;case"/api/upload-files":e==="POST"?Gr(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":Il(n,s);break;case"/api/import":Tl(n,s);break;case"/api/setup":$a(s);break;case"/api/setup/create":Ea(n,s);break;case"/api/setup/fetch":_a(n,s);break;case"/api/setup/open":Pa(n,s);break;case"/api/setup/resume":Ma(n,s);break;case"/api/setup/apikey":Oa(n,s);break;case"/api/setup/remote-themes":e==="GET"?Na(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":e==="GET"?Ja(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":e==="POST"?Da(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":e==="POST"?Ha(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":e==="POST"?La(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":e==="POST"?Ua(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":e==="POST"?Ga(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":e==="POST"?Ba(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":e==="POST"?Wa(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":e==="POST"?Va(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":e==="POST"?Ka(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":e==="POST"?Ya(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":e==="POST"?Xa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":e==="GET"?Qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":e==="POST"?Za(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":e==="POST"?za(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":e==="GET"?p(s,200,{changelog:Yo()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":el(e,n,s);break;case"/api/themes/switch":e==="POST"?tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":e==="POST"?nl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":e==="POST"?sl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":e==="GET"?$l(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":e==="POST"?El(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":e==="GET"?dl(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":ml(e,n,s);break;case"/api/templates/activate":e==="POST"?pl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":e==="POST"?fl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":e==="POST"?gl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":e==="GET"?hl(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":bl(e,n,s);break;case"/api/brand-assets/extract":e==="POST"?Sl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":e==="POST"?vl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":e==="GET"?ul(s):p(s,405,{error:"Method not allowed"});break;default:t.startsWith("/api/settings/job/")&&e==="GET"?qa(t,s):t.match(/^\/api\/templates\/[^/]+\/add-module$/)&&e==="POST"?yl(t,n,s):p(s,404,{error:"Not found"})}}function em(e){e.on("message",async n=>{let s;try{s=JSON.parse(n.toString())}catch{e.send(JSON.stringify({type:"error",message:"Invalid JSON"}));return}switch(s.type){case"chat":{let o=String(s.message||"");if(!o.trim())return;rt("user",o),L();let i=Array.isArray(s.fileIds)?s.fileIds:void 0,a=jo();a.needsPrompt&&e.send(JSON.stringify({type:"agentic_prompt"}));try{if(a.useAgentic){let l=[],c=[],d=await No(o,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...f}=u;e.send(JSON.stringify(f))}else e.send(JSON.stringify(u));if(u.type==="agent_step")l.push({step:u.step,label:u.label});else if(u.type==="agent_decision"){let m=l[l.length-1];m&&(m.decisions||(m.decisions=[]),m.decisions.push(u.decision))}else u.type==="design_system_ready"?Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Et(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(Le({modules:[{moduleName:u.module,fieldsJson:u.moduleFiles.fieldsJson,metaJson:u.moduleFiles.metaJson,moduleHtml:u.moduleFiles.moduleHtml,moduleCss:u.moduleFiles.moduleCss,moduleJs:u.moduleFiles.moduleJs}]}),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)})),c.push({name:u.module,status:"complete"})):u.type==="module_progress"&&u.status==="failed"&&c.push({name:u.module,status:"failed"})},i);Ro(d,{steps:l,modules:c,stats:d.stats})}else Mo(l=>{e.send(JSON.stringify({type:"parse_warning",message:l}))}),await pn(o,l=>{e.send(JSON.stringify({type:"stream",content:l}))},l=>{e.send(JSON.stringify({type:"stream_status",content:l}))},i);let r=v();if(r){lt();let l=Ce(),c=null;if(l){let d=l.moduleOrder.map(u=>`modules/${u}.module`);l.templateFile&&d.push(l.templateFile),l.sharedCss&&d.push(`css/${r.themeName}-theme.css`),l.sharedJs&&d.push(`js/${r.themeName}-animations.js`),c=Ki(r.themePath,l.id,o,d)}else c=Ks(r.themePath,o);c&&e.send(JSON.stringify({type:"version_created",hash:c}))}e.send(JSON.stringify({type:"generation_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:me().map(l=>l.moduleName)}));{let l=v();l&&a.useAgentic&&!l.brandAssets?.styleguide&&!l.brandAssets?.brandvoice&&!l.brandAssets?.themeContext&&e.send(JSON.stringify({type:"suggest_brand_extraction"}))}}catch(r){e.send(JSON.stringify({type:"error",message:r instanceof Error?r.message:String(r)}))}break}case"extract_brand_assets":{let o=v();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(Lo(),Ho)),m=await u(d,o.brandAssets?.themeContext,a,r,l),{mkdirSync:f,writeFileSync:h}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let y=tt(o.themePath,".vibespot");yn(y)||f(y,{recursive:!0}),h(tt(y,"theme-context.md"),m),L(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:y}=await Promise.resolve().then(()=>(Cs(),ws)),w=await y(o.themePath);if(w){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=w,o.updatedAt=Date.now();let x=tt(o.themePath,".vibespot");yn(x)||f(x,{recursive:!0}),h(tt(x,"styleguide.md"),w),L(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"styleguide"}))}}catch{}e.send(JSON.stringify({type:"brand_extraction_complete"}))}catch(i){e.send(JSON.stringify({type:"brand_extraction_error",message:i instanceof Error?i.message:String(i)}))}})();break}case"start_upload":{let o=v();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}try{lt();let i=zn(o.themePath);if(i.length>0&&e.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(_().hubspotUploadMode||"api")==="api"){let l=he();if(!l){e.send(JSON.stringify({type:"upload_failed",output:"No HubSpot account configured. Open Settings \u2192 HubSpot to add one.",errors:[{file:"",message:"No HubSpot account configured",fixable:!1}]}));break}e.send(JSON.stringify({type:"upload_started",jobId:"api-upload"}));let c=await qn(l,o.themePath,o.themeName,{onFileStart:d=>{e.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
|
|
1518
1523
|
`}))},onFileComplete:d=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2713 ${d}
|
|
1519
1524
|
`}))},onFileError:(d,u)=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2717 ${d}: ${u.message}
|
|
1520
1525
|
`}))},onProgress:(d,u)=>{e.send(JSON.stringify({type:"upload_progress",completed:d,total:u}))}});if(c.success){let d=st();e.send(JSON.stringify({type:"upload_complete",output:`Uploaded ${c.uploaded} files`,portalId:d?.portalId||"",dataCenter:d?.dataCenter||"na1",themeName:o.themeName}))}else{let d=Kn(c.errors);e.send(JSON.stringify({type:"upload_failed",output:c.errors.map(u=>`${u.file}: ${u.message}`).join(`
|
|
1521
|
-
`),errors:d}))}}else{let l=hs(`hs cms upload "${o.themePath}" "${o.themeName}"`,"Uploading to HubSpot",{cwd:tt(o.themePath,".."),timeout:18e4});e.send(JSON.stringify({type:"upload_started",jobId:l}));let c=u=>{e.send(JSON.stringify({type:"upload_output",chunk:u}))};
|
|
1526
|
+
`),errors:d}))}}else{let l=hs(`hs cms upload "${o.themePath}" "${o.themeName}"`,"Uploading to HubSpot",{cwd:tt(o.themePath,".."),timeout:18e4});e.send(JSON.stringify({type:"upload_started",jobId:l}));let c=u=>{e.send(JSON.stringify({type:"upload_output",chunk:u}))};Ca(l,c);let d=setInterval(()=>{let u=gs(l);if(!(!u||u.status==="running"))if(clearInterval(d),Aa(l,c),u.status==="completed"){let m=Fe(),f=m.portalId?Wt(m.portalId):"na1";e.send(JSON.stringify({type:"upload_complete",output:u.output,portalId:m.portalId||"",dataCenter:f,themeName:o.themeName}))}else{let m=Yn(u.output);e.send(JSON.stringify({type:"upload_failed",output:u.output,errors:m,exitCode:u.exitCode}))}},500)}}catch(i){e.send(JSON.stringify({type:"error",message:i instanceof Error?i.message:String(i)}))}break}case"upload_fix_with_ai":{let o=String(s.errorContext||"");if(!o.trim()){e.send(JSON.stringify({type:"error",message:"No error context provided"}));break}let i=`The HubSpot upload ("hs cms upload") failed. Below is the upload log output containing the errors.
|
|
1522
1527
|
|
|
1523
1528
|
IMPORTANT: Be verbose in your response. For each error:
|
|
1524
1529
|
1. State exactly which file has the problem and what the error is
|
|
@@ -1531,9 +1536,9 @@ CRITICAL: After fixing the reported errors, scan ALL other module files in the t
|
|
|
1531
1536
|
After fixing all errors, summarize the changes you made.
|
|
1532
1537
|
|
|
1533
1538
|
Upload log:
|
|
1534
|
-
${o}`;rt("user",i),
|
|
1535
|
-
`));let n=
|
|
1536
|
-
`));try{process.platform==="darwin"?
|
|
1537
|
-
Saving session...`)),
|
|
1538
|
-
`)),a(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(Is.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function
|
|
1539
|
+
${o}`;rt("user",i),L(),e.send(JSON.stringify({type:"upload_fix_started"}));try{await pn(i,r=>{e.send(JSON.stringify({type:"stream",content:r})),e.send(JSON.stringify({type:"upload_fix_stream",content:r}))});let a=v();if(a){lt();let r=Ks(a.themePath,"AI fix: upload errors");r&&e.send(JSON.stringify({type:"version_created",hash:r}))}e.send(JSON.stringify({type:"upload_fix_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:me().map(r=>r.moduleName)}))}catch(a){e.send(JSON.stringify({type:"upload_failed",output:a instanceof Error?a.message:String(a),errors:[{file:"AI fix",message:a instanceof Error?a.message:String(a),fixable:!1}]}))}break}case"ping":e.send(JSON.stringify({type:"pong"}));break;default:e.send(JSON.stringify({type:"error",message:`Unknown type: ${s.type}`}))}});let t=v();if(t){let n=_(),s={"claude-code":"Claude Code","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-cli":"Gemini CLI","gemini-api":"Gemini API","codex-cli":"Codex CLI",api:"Anthropic API"},o=Ce();e.send(JSON.stringify({type:"init",sessionId:t.id,themeName:t.themeName,modules:me().map(i=>i.moduleName),messageCount:t.messages.length,messages:t.messages,gitAvailable:_e(),engine:n.aiEngine?s[n.aiEngine]||n.aiEngine:"",templateId:o?.id||null,pageType:o?.pageType||null,templates:(t.templates||[]).map(i=>({id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}))}))}else e.send(JSON.stringify({type:"needs_setup"}))}function tm(e,t){let n=v();if(!n){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("No session");return}let s=tt(n.themePath,"assets",e);if(!yn(s)){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("Asset not found");return}let o=Pl(s),i=Ml[o]||"application/octet-stream",a=Go(s);t.writeHead(200,{"Content-Type":i,"Cache-Control":"no-cache"}),t.end(a)}function _l(e,t,n,s){let i=tt(t,e==="/"?"/index.html":e);if(!yn(i)){let c=tt(t,"index.html");if(yn(c)){let d=Go(c);s.writeHead(200,{"Content-Type":"text/html","Cache-Control":"no-cache"}),s.end(d)}else s.writeHead(404,{"Content-Type":"text/plain"}),s.end("Not found");return}let a=Pl(i),r=Ml[a]||"application/octet-stream",l=a===".html";try{let c=Go(i),d='"'+qu("md5").update(c).digest("hex").slice(0,16)+'"';if(n.headers["if-none-match"]===d){s.writeHead(304),s.end();return}s.writeHead(200,{"Content-Type":r,"Cache-Control":"no-cache",ETag:d}),s.end(c)}catch{s.writeHead(500,{"Content-Type":"text/plain"}),s.end("Internal Server Error")}}Se();var sm=4200;async function Nl(){let e=Is.hex("#e8613a"),t=Is.dim;console.log(""),console.log(e(" v vibeSpot")),console.log(t(` Starting...
|
|
1540
|
+
`));let n=om();n||(console.error(Is.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await Ol({port:sm,uiDir:n}),i=`http://localhost:${s}`;console.log(e(` v ${i}`)),console.log(t(` Press Ctrl+C to stop
|
|
1541
|
+
`));try{process.platform==="darwin"?Bo("open",[i],{stdio:"ignore"}):process.platform==="win32"?Bo("cmd",["/c","start","",i],{stdio:"ignore"}):Bo("xdg-open",[i],{stdio:"ignore"})}catch{}await new Promise(a=>{process.on("SIGINT",()=>{console.log(t(`
|
|
1542
|
+
Saving session...`)),L(),o(),console.log(t(` Goodbye!
|
|
1543
|
+
`)),a(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(Is.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function om(){let e=[ks(import.meta.dirname,"../../ui"),ks(import.meta.dirname,"../ui"),ks(process.cwd(),"ui")];for(let t of e)if(nm(ks(t,"index.html")))return t;return null}Q();function Rl(){let e=new im;return e.name("vibespot").description("AI-powered HubSpot CMS landing page builder").version(wt()).action(Nl),e.command("wizard").description("Classic CLI wizard \u2014 step-by-step conversion flow").action(Di),e.command("init").description("Check and install required tools").action(Hi),e.command("convert").description("Convert a React project to HubSpot modules").action(Li),e.command("upload").description("Upload theme to HubSpot").action(Ui),e.command("doctor").description("Diagnose environment issues").action(Gi),e}var rm=Rl();rm.parseAsync(process.argv).catch(e=>{console.error(e),process.exit(1)});
|
|
1539
1544
|
//# sourceMappingURL=index.js.map
|