@heygaia/cli 0.1.9 → 0.1.10
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 +23 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as ao}from"commander";import{render as Ur}from"ink";import Xr from"react";import{Box as ye,Text as te}from"ink";import Er from"react";import{ProgressBar as ut,Select as Oe,Spinner as Me}from"@inkjs/ui";import{Box as p,Text as s,useInput as ee}from"ink";import me from"ink-text-input";import{useEffect as Se,useState as M}from"react";import{Box as de,Text as ct}from"ink";var h="#00bbff";import{Box as rr,Text as Be}from"ink";import{jsx as it,jsxs as at}from"react/jsx-runtime";var st=({status:e,step:t})=>t.toLowerCase()==="welcome"?null:at(rr,{width:"100%",borderStyle:"single",borderColor:"gray",paddingX:1,justifyContent:"space-between",children:[at(Be,{color:h,children:[it(Be,{bold:!0,children:"Status:"})," ",t]}),it(Be,{color:"white",dimColor:!0,children:e})]});import{Box as or}from"ink";import nr from"ink-big-text";import ir from"ink-gradient";import{jsx as Ae}from"react/jsx-runtime";var ne=()=>Ae(or,{flexDirection:"column",marginTop:1,marginBottom:1,children:Ae(ir,{colors:[h,"#b0eaff",h],children:Ae(nr,{text:"GAIA",font:"3d"})})});import{jsx as ie,jsxs as xe}from"react/jsx-runtime";var ar=["Welcome","Prerequisites","Repository Setup","Install Tools","Environment Setup","Project Setup","Finished"],lt=["Detect Repo","Prerequisites","Environment Setup","Project Setup","Finished"],sr=({currentStep:e,steps:t})=>{let o=t.indexOf(e);return ie(de,{marginBottom:1,children:t.map((r,n)=>{let a=r===e,c=o>n;return xe(de,{marginRight:2,children:[xe(ct,{color:a?h:c?"green":"gray",children:[c?"\u2713 ":a?"\u25CF ":"\u25CB ",r]}),n<t.length-1&&ie(ct,{color:"gray",children:" \u203A "})]},r)})})},he=({children:e,status:t,step:o,steps:r=ar})=>xe(de,{flexDirection:"column",height:"100%",width:"100%",children:[xe(de,{flexGrow:1,flexDirection:"column",children:[ie(ne,{}),ie(sr,{currentStep:o,steps:r}),ie(de,{flexDirection:"column",flexGrow:1,children:e})]}),ie(st,{status:t,step:o})]});import{Fragment as Ao,jsx as i,jsxs as u}from"react/jsx-runtime";var _e=({label:e,status:t})=>u(p,{children:[i(p,{marginRight:1,children:t==="pending"?i(Me,{type:"dots"}):t==="success"?i(s,{color:h,children:"\u2714"}):t==="error"?i(s,{color:"red",children:"\u2716"}):i(s,{color:"yellow",children:"\u26A0"})}),i(s,{children:e})]}),cr=({onConfirm:e})=>(ee((t,o)=>{o.return&&e()}),u(p,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[i(s,{bold:!0,children:"Welcome to the Interactive GAIA Setup"}),u(p,{flexDirection:"column",marginTop:1,marginBottom:1,children:[i(s,{children:"This wizard will guide you through the setup process:"}),i(s,{children:" 1. Check Prerequisites (Git, Docker, Mise)"}),i(s,{children:" 2. Clone Repository (from GitHub)"}),i(s,{children:" 3. Install Tools (node, python, uv via mise)"}),i(s,{children:" 4. Configure Env Vars (databases, API keys, etc.)"}),i(s,{children:" 5. Setup Project (install all dependencies)"})]}),i(s,{color:h,children:"Press Enter to start..."})]})),lr=({portResults:e,onAccept:t,onAbort:o})=>{ee((n,a)=>{a.return?t():a.escape&&o()});let r=e.filter(n=>!n.available);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[i(p,{marginBottom:1,children:i(s,{bold:!0,color:"yellow",children:"Port Conflicts Detected"})}),e.map(n=>u(p,{children:[u(s,{color:n.available?"green":n.alternative?"yellow":"red",children:[n.available?"\u2714":n.alternative?"\u26A0":"\u2716"," "]}),u(s,{children:[n.service," (:",n.port,")"]}),!n.available&&u(s,{color:n.alternative?"gray":"red",children:[" ","- in use",n.usedBy?` by ${n.usedBy}`:"",n.alternative?` \u2192 will use :${n.alternative}`:" \u2014 NO ALTERNATIVE FOUND"]})]},n.port)),u(p,{marginTop:1,flexDirection:"column",children:[r.some(n=>!n.alternative)&&i(p,{borderStyle:"single",borderColor:"red",paddingX:1,marginBottom:1,children:i(s,{color:"red",children:"Some ports have no available alternative. Free them and retry."})}),!r.some(n=>!n.alternative)&&r.some(n=>n.alternative)&&i(s,{color:"gray",children:"Alternative ports will be used for conflicting services."}),i(p,{marginTop:1,children:u(s,{children:[i(s,{color:"green",bold:!0,children:"Enter"})," to continue with alternatives ",i(s,{color:"yellow",bold:!0,children:"Escape"})," to abort"]})})]})]})},ur=({defaultValue:e,onSubmit:t})=>{let[o,r]=M(e);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(s,{children:"Where should we clone the repository?"}),u(p,{children:[i(s,{color:h,children:"\u279C "}),i(me,{value:o,onChange:r,onSubmit:t})]}),u(s,{color:"gray",children:["(Press Enter for default: ",e,")"]})]})},pr=({repoPath:e,onAction:t})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[i(p,{marginBottom:1,children:i(s,{bold:!0,color:"yellow",children:"Existing Installation Found"})}),u(s,{children:["Found a GAIA installation at"," ",i(s,{color:"cyan",bold:!0,children:e})]}),i(p,{marginTop:1,children:i(s,{color:"gray",children:"What would you like to do?"})}),i(p,{marginTop:1,children:i(Oe,{options:[{label:"Use existing installation",value:"use_existing"},{label:"Delete and re-clone",value:"delete_reclone"},{label:"Choose a different path",value:"different_path"},{label:"Exit setup",value:"exit"}],onChange:r=>t(r)})})]}),dr=({setupMode:e,portOverrides:t,onConfirm:o})=>{ee((c,d)=>{d.return&&o()});let r=e||"developer",n=t?.[3e3]??3e3,a=t?.[8e3]??8e3;return u(p,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[i(s,{color:h,bold:!0,children:"You are all set!"}),u(p,{marginTop:1,flexDirection:"column",children:[i(s,{bold:!0,children:"To start GAIA, run:"}),i(p,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:i(s,{color:"cyan",children:"$ gaia start"})}),i(p,{marginTop:1,children:i(s,{color:"gray",dimColor:!0,children:r==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),u(p,{marginTop:1,flexDirection:"column",children:[i(s,{bold:!0,children:"Access GAIA at:"}),u(p,{marginLeft:2,flexDirection:"column",children:[u(s,{children:["Web:"," ",u(s,{color:"cyan",bold:!0,children:["http://localhost:",n]})]}),u(s,{children:["API:"," ",u(s,{color:"cyan",bold:!0,children:["http://localhost:",a]})]})]})]}),i(Fe,{}),i(p,{marginTop:1,children:i(s,{dimColor:!0,children:"Press Enter to exit"})})]})},Fe=()=>u(p,{marginTop:1,flexDirection:"column",children:[i(s,{bold:!0,children:"Available commands:"}),u(p,{marginLeft:2,flexDirection:"column",children:[u(s,{children:[u(s,{color:h,bold:!0,children:["gaia start"," "]}),i(s,{color:"gray",children:" Start all services"})]}),u(s,{children:[u(s,{color:h,bold:!0,children:["gaia stop"," "]}),i(s,{color:"gray",children:" Stop all services"})]}),u(s,{children:[i(s,{color:h,bold:!0,children:"gaia status"}),i(s,{color:"gray",children:" Check service health"})]}),u(s,{children:[u(s,{color:h,bold:!0,children:["gaia setup"," "]}),i(s,{color:"gray",children:" Reconfigure environment"})]})]})]}),mr=({phase:e,progress:t,isComplete:o,logs:r,title:n})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(p,{marginBottom:1,children:i(s,{bold:!0,color:h,children:n||"Installing Dependencies"})}),u(p,{flexDirection:"column",gap:1,children:[i(p,{children:o?u(s,{color:"green",children:["\u2713 ",e]}):i(Me,{label:e||"Preparing..."})}),!o&&t>0&&i(p,{width:50,children:i(ut,{value:t})}),!o&&r&&r.length>0&&i(p,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,paddingY:0,minHeight:6,children:r.map((a,c)=>i(s,{color:"gray",wrap:"truncate",children:a},c))})]})]});var Le=({onSelect:e})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(s,{bold:!0,children:"Setup Mode"}),i(p,{marginTop:1,children:i(s,{color:"gray",children:"How do you want to run GAIA?"})}),i(p,{marginTop:1,children:i(Oe,{options:[{label:"Self-Host (Docker)",value:"selfhost"},{label:"Developer Mode (Local)",value:"developer"}],onChange:o=>e(o)})}),u(p,{marginTop:1,flexDirection:"column",children:[i(s,{color:"gray",dimColor:!0,children:"Self-Host: Run everything in Docker containers (recommended for deployment)"}),i(s,{color:"gray",dimColor:!0,children:"Developer: Run backend locally with Docker services (recommended for contributing)"})]})]}),Ne=({onSelect:e})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(s,{bold:!0,children:"Environment Variables Setup"}),i(p,{marginTop:1,children:i(s,{color:"gray",children:"Choose how you want to configure environment variables:"})}),i(p,{marginTop:1,children:i(Oe,{options:[{label:"Manual Setup (Recommended)",value:"manual"},{label:"Infisical (Advanced)",value:"infisical"}],onChange:o=>e(o)})}),u(p,{marginTop:1,flexDirection:"column",children:[i(s,{color:"gray",dimColor:!0,children:"Manual Setup: Configure variables interactively (recommended for most users)"}),i(s,{color:"gray",dimColor:!0,children:"Infisical: All secrets managed in Infisical dashboard (requires pre-configuration)"})]})]}),Ge=({onSubmit:e})=>{let[t,o]=M({INFISICAL_TOKEN:"",INFISICAL_PROJECT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET:""}),[r,n]=M(0),[a,c]=M(null),d=[{key:"INFISICAL_TOKEN",description:"Service token from project settings (st.xxx...)"},{key:"INFISICAL_PROJECT_ID",description:"Found in your Infisical project settings"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_ID",description:"From Access Control \u2192 Machine Identities"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET",description:"Generated when creating the machine identity"}];ee((f,y)=>{if(y.tab||y.downArrow)n(g=>g<d.length-1?g+1:g);else if(y.upArrow)n(g=>g>0?g-1:g);else if(y.return){if(r<d.length-1){n(v=>v+1);return}let g=d.filter(v=>!t[v.key].trim());if(g.length>0){c(`Required: ${g.map(b=>b.key).join(", ")}`);let v=d.findIndex(b=>!t[b.key].trim());v>=0&&n(v);return}e(t)}});let m=d[r];return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(p,{marginBottom:1,children:i(s,{bold:!0,color:h,children:"Infisical Configuration"})}),i(p,{marginBottom:1,borderStyle:"single",borderColor:"cyan",paddingX:1,children:i(s,{color:"cyan",children:"All environment variables (API keys, auth secrets, etc.) must be configured in your Infisical project. Only Infisical credentials will be stored locally."})}),u(p,{marginBottom:1,flexDirection:"column",children:[i(s,{color:"gray",children:"Configure your Infisical credentials."}),u(s,{color:"gray",dimColor:!0,children:["Visit"," ",i(s,{color:"cyan",underline:!0,children:"app.infisical.com"})," ","to get these values."]})]}),d.map((f,y)=>{let g=f.key.includes("SECRET")||f.key.includes("TOKEN");return u(p,{flexDirection:"column",marginBottom:1,children:[i(p,{children:u(s,{color:y===r?h:"white",children:[y===r?"\u25B8 ":" ",f.key,":"]})}),i(p,{marginLeft:2,children:i(s,{color:"gray",dimColor:!0,children:f.description})}),y===r?i(p,{marginLeft:2,children:i(me,{value:t[f.key],onChange:v=>{o(b=>({...b,[f.key]:v})),c(null)},placeholder:"Enter value...",mask:g?"*":void 0})}):i(p,{marginLeft:2,children:i(s,{color:t[f.key]?"green":"gray",children:t[f.key]?g?`\u2713 ${"*".repeat(8)}`:`\u2713 ${t[f.key]}`:"(not set)"})})]},f.key)}),a&&i(p,{marginTop:1,children:i(s,{color:"red",children:a})}),i(p,{marginTop:1,children:i(s,{color:"gray",dimColor:!0,children:"\u2191\u2193/Tab to navigate \u2022 Enter to confirm"})})]})},qe=({category:e,currentIndex:t,totalGroups:o,onSubmit:r})=>{let[n,a]=M(()=>{let v={};for(let b of e.variables)v[b.name]=b.defaultValue||"";return v}),[c,d]=M(0),[m,f]=M(null);Se(()=>{let v={};for(let b of e.variables)v[b.name]=b.defaultValue||"";a(v),d(0),f(null)},[e.name]),ee((v,b)=>{if(b.tab||b.downArrow)d(l=>l<e.variables.length-1?l+1:l);else if(b.upArrow)d(l=>l>0?l-1:l);else if(b.escape){let l=e.variables.filter(S=>S.required&&!n[S.name]?.trim());if(l.length>0){f(`Required fields cannot be skipped: ${l.map(S=>S.name).join(", ")}`);return}r(n)}});let y=()=>{if(c<e.variables.length-1)d(c+1);else{let v=e.variables.filter(b=>b.required&&!n[b.name]?.trim());if(v.length>0){f(`Required fields are missing: ${v.map(b=>b.name).join(", ")}`);return}f(null),r(n)}},g=e.variables.some(v=>v.required);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":h,children:[u(p,{justifyContent:"space-between",children:[u(s,{bold:!0,children:["Configure ",e.name]}),u(s,{color:"gray",children:["Group ",t+1," / ",o]})]}),u(p,{marginTop:1,flexDirection:"column",children:[u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),i(s,{color:"white",children:e.description})]}),e.affectedFeatures&&u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),i(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&u(p,{marginTop:1,children:[i(s,{color:"green",children:"\u{1F4D6} Docs: "}),i(s,{color:"blue",underline:!0,children:e.docsUrl})]})]}),i(p,{marginTop:1,flexDirection:"column",children:e.variables.map((v,b)=>{let l=b===c,S=!!v.defaultValue;return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[u(s,{color:l?h:"gray",bold:l,children:[l?"\u279C ":" ",v.name]}),v.required&&u(s,{color:"red",bold:!0,children:[" ","*"]}),S&&!l&&u(s,{color:"gray",dimColor:!0,children:[" ","(default: ",v.defaultValue,")"]})]}),l&&i(p,{marginLeft:2,children:i(me,{value:n[v.name]||"",onChange:x=>{a(C=>({...C,[v.name]:x})),m&&f(null)},onSubmit:y,placeholder:S?`Default: ${v.defaultValue}`:v.required?"Enter a value (required)":"Press Enter to skip"})})]},v.name)})}),m&&i(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),i(p,{marginTop:1,flexDirection:"column",children:u(s,{color:"gray",dimColor:!0,children:["\u21B5 Enter to next field \u2022 Tab/\u2193 move down \u2022 \u2191 move up",!g&&" \u2022 ESC skip group"]})})]})},$e=({alternatives:e,onSubmit:t})=>{let[o,r]=M(new Set),[n,a]=M({}),[c,d]=M(0),[m,f]=M(null);Se(()=>{let x={};for(let C of e)for(let I of C.variables)x[I.name]=I.defaultValue||"";a(x)},[e]);let y=[];for(let x=0;x<e.length;x++)if(y.push({type:"provider",categoryIndex:x}),o.has(x)){let C=e[x];if(C)for(let I=0;I<C.variables.length;I++)y.push({type:"field",categoryIndex:x,fieldIndex:I})}y.push({type:"submit"});let g=y[c],v=g?.type==="field",b=g?.type==="submit";ee((x,C)=>{let I=Math.min(c,y.length-1);if(I!==c){d(I);return}if(v)C.upArrow?d(w=>Math.max(0,w-1)):(C.downArrow||C.tab)&&d(w=>Math.min(y.length-1,w+1));else if(b)C.upArrow?d(w=>Math.max(0,w-1)):(C.return||x===" ")&&S();else if(C.upArrow)d(w=>Math.max(0,w-1));else if(C.downArrow||C.tab)d(w=>Math.min(y.length-1,w+1));else if((C.return||x===" ")&&g?.type==="provider"){let w=g.categoryIndex;r(Y=>{let k=new Set(Y);return k.has(w)?k.delete(w):k.add(w),k}),m&&f(null)}});let l=()=>{m&&f(null),d(x=>Math.min(y.length-1,x+1))},S=()=>{let x=[],C={};for(let I of o){let w=e[I];if(!w)continue;if(w.variables.some(k=>n[k.name]?.trim())){x.push(w.name);for(let k of w.variables){let ge=n[k.name];ge&&(C[k.name]=ge)}}}if(x.length===0){o.size===0?f("Enable at least one provider (press Space or Enter)"):f("Enter a value for at least one field");return}t(x,C)};return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":h,children:[u(p,{justifyContent:"space-between",children:[i(s,{bold:!0,children:"Configure AI Provider"}),i(s,{color:"yellow",children:"* At least one required"})]}),i(p,{marginTop:1,children:i(s,{color:"gray",children:"Enable and configure at least one AI provider below:"})}),i(p,{marginTop:1,flexDirection:"column",children:e.map((x,C)=>{let I=o.has(C),w=y.findIndex(k=>k.type==="provider"&&k.categoryIndex===C),Y=c===w;return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[i(s,{color:Y?h:void 0,bold:Y,children:Y?"\u279C ":" "}),i(s,{color:I?"green":"gray",children:I?"[\u2714]":"[ ]"}),u(s,{color:I?h:"gray",bold:I,children:[" ",x.name]}),x.description&&u(s,{color:"gray",dimColor:!0,children:[" ","- ",x.description]})]}),Y&&x.docsUrl&&u(p,{marginLeft:6,children:[i(s,{color:"yellow",children:"\u{1F4D6} "}),i(s,{color:"blue",underline:!0,children:x.docsUrl})]}),I&&i(p,{marginLeft:4,flexDirection:"column",marginTop:1,children:x.variables.map((k,ge)=>{let er=y.findIndex(pe=>pe.type==="field"&&pe.categoryIndex===C&&pe.fieldIndex===ge),oe=c===er,nt=!!k.defaultValue,ke=n[k.name]||"";return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[u(s,{color:oe?h:"gray",bold:oe,children:[oe?" \u279C ":" ",k.name]}),!oe&&ke&&i(s,{color:"green",children:" \u2713"}),!oe&&!ke&&nt&&u(s,{color:"gray",dimColor:!0,children:[" ","(default: ",k.defaultValue,")"]})]}),oe&&i(p,{marginLeft:4,children:i(me,{value:ke,onChange:pe=>{a(tr=>({...tr,[k.name]:pe})),m&&f(null)},onSubmit:l,placeholder:nt?`Default: ${k.defaultValue}`:"Enter value..."})})]},k.name)})})]},x.name)})}),m&&i(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),u(p,{marginTop:1,children:[i(s,{color:b?h:void 0,bold:b,children:b?"\u279C ":" "}),i(p,{borderStyle:"round",borderColor:b?h:"gray",paddingX:2,children:i(s,{color:b?h:"gray",bold:b,children:"Continue \u2192"})})]}),i(p,{marginTop:1,children:i(s,{color:"gray",dimColor:!0,children:"\u2191/\u2193 navigate \u2022 Space/Enter toggle/select \u2022 Tab skip field"})})]})},je=({currentVar:e,currentIndex:t,totalCount:o,onSubmit:r,onSkip:n})=>{let[a,c]=M(e.defaultValue||""),[d,m]=M(null);Se(()=>{c(e.defaultValue||""),m(null)},[e.name]),ee((g,v)=>{if(v.escape){if(e.required&&!a.trim()){m("This field is required and cannot be skipped");return}n()}});let f=g=>{if(e.required&&!g.trim()){m("This field is required");return}m(null),r(g)},y=!!e.defaultValue;return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:d?"red":h,children:[u(p,{justifyContent:"space-between",children:[i(s,{bold:!0,children:"Configure Environment Variables"}),u(s,{color:"gray",children:[t+1," / ",o]})]}),u(p,{marginTop:1,flexDirection:"column",children:[u(p,{children:[i(s,{color:h,bold:!0,children:e.name}),e.required?u(s,{color:"red",bold:!0,children:[" ","* required"]}):u(s,{color:"gray",dimColor:!0,children:[" ","(optional)"]})]}),u(p,{marginTop:1,children:[u(s,{color:"cyan",bold:!0,children:["Category:"," "]}),i(s,{color:"white",children:e.category})]}),u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),i(s,{color:"white",children:e.description})]}),e.affectedFeatures&&u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),i(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&u(p,{marginTop:1,children:[i(s,{color:"green",children:"\u{1F4D6} Docs: "}),i(s,{color:"blue",underline:!0,children:e.docsUrl})]}),y&&u(p,{marginTop:1,children:[u(s,{color:"green",bold:!0,children:["Default:"," "]}),i(s,{color:"white",children:e.defaultValue})]})]}),u(p,{marginTop:1,children:[i(s,{color:h,children:"\u279C "}),i(me,{value:a,onChange:g=>{c(g),d&&m(null)},onSubmit:f,placeholder:y?"Press Enter to use default":e.required?"Enter a value (required)":"Press Enter to skip"})]}),d&&i(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",d]})}),i(p,{marginTop:1,flexDirection:"column",children:e.required?i(s,{color:"yellow",dimColor:!0,children:"\u21B5 Enter to confirm (required field)"}):y?i(s,{color:"green",dimColor:!0,children:"\u21B5 Enter to use default \u2022 ESC to skip"}):i(s,{color:"gray",dimColor:!0,children:"\u21B5 Enter to confirm \u2022 ESC to skip"})})]})},pt=({store:e})=>{let[t,o]=M(e.currentState);return Se(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),u(he,{status:t.status,step:t.step,children:[t.step==="Welcome"&&t.inputRequest?.id==="welcome"&&i(cr,{onConfirm:()=>e.submitInput(!0)}),t.step==="Prerequisites"&&t.data.checks&&u(p,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[i(s,{bold:!0,children:"System Checks"}),u(p,{flexDirection:"column",marginTop:1,children:[i(_e,{label:"Git",status:t.data.checks.git}),i(_e,{label:"Docker",status:t.data.checks.docker}),i(_e,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&i(lr,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="repo_path"&&i(ur,{defaultValue:t.inputRequest.meta.default,onSubmit:r=>e.submitInput(r)}),t.inputRequest?.id==="existing_repo"&&t.data.existingRepoPath&&i(pr,{repoPath:t.data.existingRepoPath,onAction:r=>e.submitInput(r)}),t.step==="Repository Setup"&&!t.inputRequest&&u(p,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:h,children:[i(s,{bold:!0,children:"Cloning Repository"}),u(p,{marginTop:1,flexDirection:"column",children:[i(ut,{value:t.data.repoProgress||0}),t.data.repoPhase&&i(p,{marginTop:1,children:i(s,{color:"gray",children:t.data.repoPhase})})]})]}),t.inputRequest?.id==="setup_mode"&&i(Le,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&i(Ne,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&i(Ge,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&i(je,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&i(qe,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&i($e,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Environment Setup"&&!t.inputRequest&&u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[i(s,{bold:!0,children:"Environment Setup"}),i(p,{marginTop:1,children:i(Me,{label:t.status||"Configuring environment..."})})]}),t.step==="Finished"&&i(dr,{setupMode:t.data.setupMode,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput("exit")}),(t.step==="Install Tools"||t.step==="Project Setup")&&i(mr,{title:t.step==="Install Tools"?"Installing Tools":"Project Setup",phase:t.data.dependencyPhase||"",progress:t.data.dependencyProgress||0,isComplete:t.step==="Install Tools"?t.data.toolComplete||!1:t.data.dependencyComplete||!1,logs:t.data.dependencyLogs||[]}),t.error&&i(p,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:u(s,{color:"red",children:["Error: ",t.error.message]})})]})};import{Spinner as fr}from"@inkjs/ui";import{Box as q,Text as O,useInput as gr}from"ink";import{useEffect as xr,useState as hr}from"react";import{jsx as G,jsxs as B}from"react/jsx-runtime";var dt=({store:e,command:t})=>{let[o,r]=hr(e.currentState);xr(()=>{let a=()=>r({...e.currentState});return e.on("change",a),()=>{e.off("change",a)}},[e]),gr((a,c)=>{(c.return||c.escape)&&(o.data.started||o.data.stopped||o.error)&&e.submitInput("exit")});let n=t==="start";return B(q,{flexDirection:"column",width:"100%",children:[G(ne,{}),(o.step==="Starting"||o.step==="Stopping")&&B(q,{flexDirection:"column",marginTop:1,paddingX:2,borderStyle:"round",borderColor:h,children:[G(fr,{label:o.status||"Working..."}),o.data.repoPath&&G(q,{marginTop:1,children:B(O,{color:"gray",children:["Repository: ",o.data.repoPath]})}),o.data.setupMode&&G(q,{children:B(O,{color:"gray",children:["Mode: ",o.data.setupMode]})})]}),o.step==="Running"&&o.data.started&&B(q,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:"green",children:[B(O,{color:"green",bold:!0,children:["\u2713"," GAIA is running!"]}),o.data.setupMode!=="developer"&&B(q,{marginTop:1,flexDirection:"column",children:[B(O,{children:["Web:"," ",B(O,{color:"cyan",bold:!0,children:["http://localhost:",o.data.webPort||3e3]})]}),B(O,{children:["API:"," ",B(O,{color:"cyan",bold:!0,children:["http://localhost:",o.data.apiPort||8e3]})]})]}),o.data.setupMode==="developer"&&B(q,{marginTop:1,flexDirection:"column",children:[G(O,{color:"gray",children:"Dev servers started in background."}),B(O,{color:"gray",children:["Logs: ",G(O,{color:h,children:"dev-start.log"})," in your repo root."]}),B(O,{color:"gray",children:["Run ",G(O,{color:h,children:"gaia stop"})," to shut down."]})]}),G(q,{marginTop:1,children:G(O,{dimColor:!0,children:"Press Enter to exit"})})]}),o.step==="Stopped"&&o.data.stopped&&B(q,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:h,children:[B(O,{color:h,bold:!0,children:["\u2713"," All GAIA services stopped."]}),G(q,{marginTop:1,children:G(O,{dimColor:!0,children:"Press Enter to exit"})})]}),o.error&&B(q,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:[B(O,{color:"red",children:["Error: ",o.error.message]}),G(q,{marginTop:1,children:G(O,{dimColor:!0,children:"Press Enter to exit"})})]})]})};import{ProgressBar as Sr,Spinner as ve}from"@inkjs/ui";import{Box as P,Text as E,useInput as mt}from"ink";import{useEffect as vr,useState as yr}from"react";import{jsx as T,jsxs as R}from"react/jsx-runtime";var ft=({store:e})=>{let[t,o]=yr(e.currentState);return vr(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),R(he,{status:t.status,step:t.step,steps:lt,children:[t.step==="Detect Repo"&&R(P,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[T(E,{bold:!0,children:"Detecting GAIA Repository"}),T(P,{marginTop:1,children:T(ve,{label:"Searching for repository..."})}),t.data.repoPath&&T(P,{marginTop:1,children:R(E,{color:"green",children:["Found: ",t.data.repoPath]})})]}),t.step==="Prerequisites"&&t.data.checks&&R(P,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[T(E,{bold:!0,children:"System Checks"}),R(P,{flexDirection:"column",marginTop:1,children:[T(He,{label:"Git",status:t.data.checks.git}),T(He,{label:"Docker",status:t.data.checks.docker}),T(He,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&T(Tr,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="setup_mode"&&T(Le,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&T(Ne,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&T(Ge,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&T(je,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&T(qe,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&T($e,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Environment Setup"&&!t.inputRequest&&R(P,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[T(E,{bold:!0,children:"Environment Setup"}),T(P,{marginTop:1,children:T(ve,{label:t.status||"Configuring environment..."})})]}),t.step==="Project Setup"&&R(P,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[T(P,{marginBottom:1,children:T(E,{bold:!0,color:h,children:"Project Setup"})}),R(P,{flexDirection:"column",gap:1,children:[T(P,{children:t.data.dependencyComplete?R(E,{color:"green",children:["\u2713"," ",t.data.dependencyPhase]}):T(ve,{label:t.data.dependencyPhase||"Preparing..."})}),!t.data.dependencyComplete&&t.data.dependencyProgress>0&&T(P,{width:50,children:T(Sr,{value:t.data.dependencyProgress})}),!t.data.dependencyComplete&&t.data.dependencyLogs?.length>0&&T(P,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,minHeight:6,children:t.data.dependencyLogs.map((r,n)=>T(E,{color:"gray",wrap:"truncate",children:r},n))})]})]}),t.step==="Finished"&&T(br,{setupMode:t.data.setupMode,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput("exit")}),t.error&&T(P,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:R(E,{color:"red",children:["Error: ",t.error.message]})})]})},He=({label:e,status:t})=>R(P,{children:[T(P,{marginRight:1,children:t==="pending"?T(ve,{type:"dots"}):t==="success"?T(E,{color:h,children:"\u2714"}):t==="error"?T(E,{color:"red",children:"\u2716"}):T(E,{color:"yellow",children:"\u26A0"})}),T(E,{children:e})]}),Tr=({portResults:e,onAccept:t,onAbort:o})=>(mt((r,n)=>{n.return?t():n.escape&&o()}),R(P,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[T(E,{bold:!0,color:"yellow",children:"Port Conflicts Detected"}),e.map(r=>R(P,{children:[R(E,{color:r.available?"green":"red",children:[r.available?"\u2714":"\u2716"," "]}),R(E,{children:[r.service," (:",r.port,")"]}),!r.available&&R(E,{color:"gray",children:[" ","- in use",r.usedBy?` by ${r.usedBy}`:"",r.alternative?` (alt: :${r.alternative})`:""]})]},r.port)),T(P,{marginTop:1,children:R(E,{children:[T(E,{color:"green",bold:!0,children:"Enter"})," continue ",T(E,{color:"yellow",bold:!0,children:"Escape"})," abort"]})})]})),br=({setupMode:e,portOverrides:t,onConfirm:o})=>{mt((c,d)=>{d.return&&o()});let r=e||"developer",n=t?.[3e3]??3e3,a=t?.[8e3]??8e3;return R(P,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[T(E,{color:h,bold:!0,children:"Setup Complete!"}),R(P,{marginTop:1,flexDirection:"column",children:[T(E,{bold:!0,children:"To start GAIA, run:"}),T(P,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:T(E,{color:"cyan",children:"$ gaia start"})}),T(P,{marginTop:1,children:T(E,{color:"gray",dimColor:!0,children:r==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),R(P,{marginTop:1,flexDirection:"column",children:[T(E,{bold:!0,children:"Access GAIA at:"}),R(P,{marginLeft:2,flexDirection:"column",children:[R(E,{children:["Web:"," ",R(E,{color:"cyan",bold:!0,children:["http://localhost:",n]})]}),R(E,{children:["API:"," ",R(E,{color:"cyan",bold:!0,children:["http://localhost:",a]})]})]})]}),T(Fe,{}),T(P,{marginTop:1,children:T(E,{dimColor:!0,children:"Press Enter to exit"})})]})};import{Spinner as Cr}from"@inkjs/ui";import{Box as A,Text as _,useInput as Ir}from"ink";import{useEffect as gt,useState as xt}from"react";import{jsx as D,jsxs as F}from"react/jsx-runtime";var ht=({store:e})=>{let[t,o]=xt(e.currentState),[r,n]=xt(!1);return gt(()=>{let a=()=>o({...e.currentState});return e.on("change",a),()=>{e.off("change",a)}},[e]),gt(()=>{t.step==="Results"&&n(!1)},[t.step]),Ir((a,c)=>{(c.return||c.escape)&&t.step==="Results"&&e.submitInput("exit"),a==="r"&&t.step==="Results"&&t.data.refreshable&&!r&&(n(!0),e.submitInput("refresh"))}),F(A,{flexDirection:"column",width:"100%",children:[D(ne,{}),t.step==="Checking"&&D(A,{marginTop:1,children:D(Cr,{label:t.data.services?"Refreshing service health...":"Checking service health..."})}),t.step==="Results"&&t.data.services&&F(A,{flexDirection:"column",children:[F(A,{flexDirection:"column",borderStyle:"round",borderColor:h,paddingX:2,paddingY:1,children:[D(_,{bold:!0,color:h,children:"GAIA Service Status"}),F(A,{marginTop:1,flexDirection:"column",children:[F(A,{children:[D(A,{width:22,children:D(_,{bold:!0,children:"Service"})}),D(A,{width:10,children:D(_,{bold:!0,children:"Status"})}),D(A,{width:10,children:D(_,{bold:!0,children:"Latency"})})]}),D(_,{color:"gray",children:"\u2500".repeat(42)}),t.data.services.map(a=>F(A,{children:[D(A,{width:22,children:F(_,{children:[a.name," (:",a.port,")"]})}),D(A,{width:10,children:D(_,{color:a.status==="up"?"green":"red",bold:!0,children:a.status==="up"?"\u2713 UP":"\u2717 DOWN"})}),D(A,{width:10,children:D(_,{color:"gray",children:a.latency?`${a.latency}ms`:"--"})})]},a.name))]})]}),t.data.docker&&F(A,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,marginTop:1,children:[D(_,{bold:!0,children:"Docker Containers"}),F(_,{color:"gray",children:["Docker:"," ",t.data.docker.running?D(_,{color:"green",children:"Running"}):D(_,{color:"red",children:"Not running"})]}),t.data.docker.containers?.length>0&&D(A,{marginTop:1,flexDirection:"column",children:t.data.docker.containers.map(a=>F(A,{children:[F(_,{color:a.status==="running"?"green":"red",children:[a.status==="running"?"\u2713":"\u2717"," "]}),D(_,{children:a.name}),a.health&&F(_,{color:"gray",children:[" (",a.health,")"]})]},a.name))})]}),D(A,{marginTop:1,children:F(_,{dimColor:!0,children:["Press Enter or Escape to exit \xB7 Press"," ",D(_,{color:h,children:"r"})," to refresh"]})})]}),t.error&&D(A,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:F(_,{color:"red",children:["Error: ",t.error.message]})})]})};import{jsx as $,jsxs as fe}from"react/jsx-runtime";var wr=["init","setup","status","start","stop"],We=class extends Er.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?fe(ye,{flexDirection:"column",padding:1,children:[$(te,{color:"red",bold:!0,children:"An unexpected error occurred:"}),$(te,{color:"red",children:this.state.error.message}),this.state.error.stack&&$(ye,{marginTop:1,children:$(te,{color:"gray",dimColor:!0,children:this.state.error.stack})})]}):this.props.children}},Pr=({store:e,command:t})=>{switch(t){case"init":return $(pt,{store:e});case"setup":return $(ft,{store:e});case"status":return $(ht,{store:e});case"start":case"stop":return $(dt,{store:e,command:t});default:return fe(ye,{flexDirection:"column",padding:1,children:[fe(te,{color:"red",children:["Unknown command: ",t]}),fe(ye,{marginTop:1,flexDirection:"column",children:[$(te,{bold:!0,children:"Available commands:"}),wr.map(o=>fe(te,{children:[" ",$(te,{color:"cyan",children:o})]},o))]})]})}},W=({store:e,command:t})=>$(We,{children:$(Pr,{store:e,command:t})});import{EventEmitter as Rr}from"events";var Dr=150,Ve=class extends Rr{state={step:"init",status:"",error:null,data:{},inputRequest:null};inputResolver=null;emitTimer=null;emitPending=!1;get currentState(){return this.state}scheduleEmit(){this.emitPending=!0,this.emitTimer||(this.emitTimer=setTimeout(()=>{this.emitTimer=null,this.emitPending&&(this.emitPending=!1,this.emit("change",this.state))},Dr))}emitNow(){this.emitTimer&&(clearTimeout(this.emitTimer),this.emitTimer=null),this.emitPending=!1,this.emit("change",this.state)}setStep(t){this.state.step=t,this.emitNow()}setStatus(t){this.state.status=t,this.scheduleEmit()}setError(t){this.state.error=t,t!==null&&this.inputResolver&&(this.inputResolver(null),this.inputResolver=null,this.state.inputRequest=null),this.emitNow()}updateData(t,o){this.state.data={...this.state.data,[t]:o},this.scheduleEmit()}waitForInput(t,o){return this.state.inputRequest={id:t,meta:o},this.emitNow(),new Promise(r=>{this.inputResolver=r})}submitInput(t){this.inputResolver&&(this.inputResolver(t),this.inputResolver=null,this.state.inputRequest=null,this.emitNow())}},V=()=>new Ve;import*as z from"fs";import*as Gt from"os";import*as re from"path";import*as K from"fs";import*as St from"os";import*as Qe from"path";var Ue=Qe.join(St.homedir(),".gaia"),Xe=Qe.join(Ue,"config.json");function kr(){K.existsSync(Ue)||K.mkdirSync(Ue,{recursive:!0})}function Ye(){try{if(!K.existsSync(Xe))return null;let e=K.readFileSync(Xe,"utf-8");return JSON.parse(e)}catch{return null}}function Te(e){kr(),K.writeFileSync(Xe,`${JSON.stringify(e,null,2)}
|
|
3
|
-
`)}function
|
|
4
|
-
`)){let
|
|
5
|
-
`),"utf-8")}function
|
|
6
|
-
`),"utf-8")}var
|
|
7
|
-
`),"utf-8")}function
|
|
8
|
-
`)){let
|
|
2
|
+
import{Command as vo}from"commander";import{render as no}from"ink";import ao from"react";import{Box as Re,Text as ce}from"ink";import Br from"react";import{ProgressBar as ht,Select as je,Spinner as qe}from"@inkjs/ui";import{Box as m,Text as u,useInput as de}from"ink";import ye from"ink-text-input";import{useEffect as we,useState as F}from"react";import{Box as Ce,Text as Ie}from"ink";var v="#00bbff";import{Box as cr,Text as lr}from"ink";import{jsx as mt}from"react/jsx-runtime";var ft=({status:e,step:t})=>t.toLowerCase()==="welcome"?null:mt(cr,{width:"100%",paddingX:1,marginTop:1,children:mt(lr,{color:"gray",dimColor:!0,children:e})});import{Box as ur}from"ink";import pr from"ink-big-text";import dr from"ink-gradient";import{jsx as $e}from"react/jsx-runtime";var ue=()=>$e(ur,{flexDirection:"column",marginTop:1,marginBottom:1,children:$e(dr,{colors:[v,"#b0eaff",v],children:$e(pr,{text:"GAIA",font:"3d"})})});import{jsx as pe,jsxs as ve}from"react/jsx-runtime";var mr=["Welcome","Prerequisites","Setup Mode","Repository Setup","Environment Setup","Install Tools","Project Setup","Installing CLI","Finished"],gt=["Detect Repo","Prerequisites","Environment Setup","Project Setup","Finished"],fr=({currentStep:e,steps:t})=>{let r=t.indexOf(e),o=t.length,n=r+1;return ve(Ce,{marginBottom:1,gap:1,children:[r>0&&ve(Ie,{color:"green",children:["\u2713 ",r]}),ve(Ie,{color:"gray",children:[n,"/",o]}),pe(Ie,{color:"gray",children:"\xB7"}),pe(Ie,{color:v,bold:!0,children:e})]})},Ee=({children:e,status:t,step:r,steps:o=mr})=>ve(Ce,{flexDirection:"column",height:"100%",width:"100%",children:[ve(Ce,{flexGrow:1,flexDirection:"column",children:[pe(ue,{}),pe(fr,{currentStep:r,steps:o}),pe(Ce,{flexDirection:"column",flexGrow:1,children:e})]}),pe(ft,{status:t,step:r})]});import{Spinner as gr}from"@inkjs/ui";import{Box as re,Text as q,useInput as hr}from"ink";import{jsx as L,jsxs as se}from"react/jsx-runtime";var oe=({label:e,status:t})=>se(re,{children:[L(re,{marginRight:1,children:t==="pending"?L(gr,{type:"dots"}):t==="success"?L(q,{color:"green",children:"\u2714"}):t==="error"?L(q,{color:"red",children:"\u2716"}):L(q,{color:"yellow",children:"\u26A0"})}),L(q,{children:e})]}),Pe=({portResults:e,onAccept:t,onAbort:r})=>{hr((n,i)=>{i.return?t():i.escape&&r()});let o=e.filter(n=>!n.available);return se(re,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[L(re,{marginBottom:1,children:L(q,{bold:!0,color:"yellow",children:"Port Conflicts Detected"})}),e.map(n=>se(re,{children:[se(q,{color:n.available?"green":n.alternative?"yellow":"red",children:[n.available?"\u2714":n.alternative?"\u26A0":"\u2716"," "]}),se(q,{children:[n.service," (:",n.port,")"]}),!n.available&&se(q,{color:n.alternative?"gray":"red",children:[" ","- in use",n.usedBy?` by ${n.usedBy}`:"",n.alternative?` \u2192 will use :${n.alternative}`:" \u2014 NO ALTERNATIVE FOUND"]})]},n.port)),o.some(n=>!n.alternative)&&L(re,{marginTop:1,children:L(q,{color:"red",children:"Some ports have no available alternative. Free them and retry."})}),!o.some(n=>!n.alternative)&&o.some(n=>n.alternative)&&L(re,{marginTop:1,children:L(q,{color:"gray",children:"Alternative ports will be used for conflicting services."})}),L(re,{marginTop:1,children:se(q,{dimColor:!0,children:[L(q,{bold:!0,children:"Enter"})," continue \xB7 ",L(q,{bold:!0,children:"ESC"})," abort"]})})]})};import{Fragment as Qo,jsx as a,jsxs as S}from"react/jsx-runtime";var Sr=({onConfirm:e})=>(de((t,r)=>{r.return&&e()}),S(m,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:v,children:[a(u,{bold:!0,children:"Welcome to GAIA Setup"}),S(m,{flexDirection:"column",marginTop:1,marginBottom:1,children:[a(u,{children:"This wizard will guide you through the setup process:"}),a(u,{children:" 1. Check prerequisites and choose setup mode"}),a(u,{children:" 2. Clone repository"}),a(u,{children:" 3. Configure environment variables"}),a(u,{children:" 4. Install tools and dependencies"})]}),a(u,{dimColor:!0,children:"~5-15 min depending on network speed"}),a(m,{marginTop:1,children:S(u,{color:v,children:[a(u,{bold:!0,children:"Enter"})," to start"]})})]})),xr=({defaultValue:e,onSubmit:t})=>{let[r,o]=F(e);return S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(u,{children:"Clone repository to:"}),a(u,{color:"gray",dimColor:!0,children:"Press Enter for default, or type a custom path"}),S(m,{marginTop:1,children:[a(u,{color:v,children:"\u2192 "}),a(ye,{value:r,onChange:o,onSubmit:t})]})]})},vr=({repoPath:e,onAction:t})=>S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[a(m,{marginBottom:1,children:a(u,{bold:!0,color:"yellow",children:"Existing Installation Found"})}),S(u,{children:["Found a GAIA installation at"," ",a(u,{color:"cyan",bold:!0,children:e})]}),a(m,{marginTop:1,children:a(u,{color:"gray",children:"What would you like to do?"})}),a(m,{marginTop:1,children:a(je,{options:[{label:"Use existing installation",value:"use_existing"},{label:"Delete and re-clone",value:"delete_reclone"},{label:"Choose a different path",value:"different_path"},{label:"Exit setup",value:"exit"}],onChange:o=>t(o)})})]}),yr=({portOverrides:e,onConfirm:t})=>{de((n,i)=>{i.return&&t()});let r=e?.[3e3]??3e3,o=e?.[8e3]??8e3;return S(m,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:v,padding:1,children:[a(u,{color:v,bold:!0,children:"You're all set!"}),S(m,{marginTop:1,children:[a(u,{bold:!0,children:"Run: "}),a(u,{color:"cyan",children:"$ gaia start"})]}),S(m,{marginTop:1,flexDirection:"column",children:[S(u,{children:["Web:"," ",S(u,{color:"cyan",bold:!0,children:["http://localhost:",r]})]}),S(u,{children:["API:"," ",S(u,{color:"cyan",bold:!0,children:["http://localhost:",o]})]})]}),a(m,{marginTop:1,children:a(u,{color:"gray",children:"gaia stop \xB7 gaia status \xB7 gaia setup"})}),a(m,{marginTop:1,children:S(u,{dimColor:!0,children:[a(u,{bold:!0,children:"Enter"})," to exit"]})})]})},Tr=({phase:e,progress:t,isComplete:r,logs:o,title:n})=>S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(m,{marginBottom:1,children:a(u,{bold:!0,color:v,children:n||"Installing Dependencies"})}),S(m,{flexDirection:"column",gap:1,children:[a(m,{children:r?S(u,{color:"green",children:["\u2713 ",e]}):a(qe,{label:e||"Preparing..."})}),!r&&t>0&&a(m,{width:50,children:a(ht,{value:t})}),!r&&o&&o.length>0&&a(m,{flexDirection:"column",marginTop:1,marginLeft:1,children:o.map((i,c)=>a(u,{color:"gray",wrap:"truncate",children:i},c))})]})]});var He=({onSelect:e})=>S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(u,{bold:!0,children:"Setup Mode"}),a(m,{marginTop:1,children:a(u,{color:"gray",children:"How do you want to run GAIA?"})}),a(m,{marginTop:1,children:a(je,{options:[{label:"Self-Host \u2014 run everything in Docker",value:"selfhost"},{label:"Developer \u2014 local dev with hot reload",value:"developer"}],onChange:r=>e(r)})})]}),Ve=({onSelect:e})=>S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(u,{bold:!0,children:"Environment Variables Setup"}),a(m,{marginTop:1,children:a(u,{color:"gray",children:"Choose how you want to configure environment variables:"})}),a(m,{marginTop:1,children:a(je,{options:[{label:"Manual Setup (Recommended)",value:"manual"},{label:"Infisical (Advanced)",value:"infisical"}],onChange:r=>e(r)})}),S(m,{marginTop:1,flexDirection:"column",children:[a(u,{color:"gray",dimColor:!0,children:"Manual Setup: Configure variables interactively (recommended for most users)"}),a(u,{color:"gray",dimColor:!0,children:"Infisical: All secrets managed in Infisical dashboard (requires pre-configuration)"})]})]}),We=({onSubmit:e})=>{let[t,r]=F({INFISICAL_TOKEN:"",INFISICAL_PROJECT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET:""}),[o,n]=F(0),[i,c]=F(null),s=[{key:"INFISICAL_TOKEN",description:"Service token from project settings (st.xxx...)"},{key:"INFISICAL_PROJECT_ID",description:"Found in your Infisical project settings"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_ID",description:"From Access Control \u2192 Machine Identities"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET",description:"Generated when creating the machine identity"}];de((f,b)=>{if(b.tab||b.downArrow)n(y=>y<s.length-1?y+1:y);else if(b.upArrow)n(y=>y>0?y-1:y);else if(b.return){if(o<s.length-1){n(x=>x+1);return}let y=s.filter(x=>!t[x.key].trim());if(y.length>0){c(`Required: ${y.map(g=>g.key).join(", ")}`);let x=s.findIndex(g=>!t[g.key].trim());x>=0&&n(x);return}e(t)}});let l=s[o];return S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(m,{marginBottom:1,children:a(u,{bold:!0,color:v,children:"Infisical Configuration"})}),a(m,{marginBottom:1,children:a(u,{color:"gray",children:"All secrets managed in your Infisical project. Only credentials stored locally."})}),S(m,{marginBottom:1,flexDirection:"column",children:[a(u,{color:"gray",children:"Configure your Infisical credentials."}),S(u,{color:"gray",dimColor:!0,children:["Visit"," ",a(u,{color:"cyan",underline:!0,children:"app.infisical.com"})," ","to get these values."]})]}),s.map((f,b)=>{let y=f.key.includes("SECRET")||f.key.includes("TOKEN");return S(m,{flexDirection:"column",marginBottom:1,children:[a(m,{children:S(u,{color:b===o?v:"white",children:[b===o?"\u25B8 ":" ",f.key,":"]})}),a(m,{marginLeft:2,children:a(u,{color:"gray",dimColor:!0,children:f.description})}),b===o?a(m,{marginLeft:2,children:a(ye,{value:t[f.key],onChange:x=>{r(g=>({...g,[f.key]:x})),c(null)},placeholder:"Enter value...",mask:y?"*":void 0})}):a(m,{marginLeft:2,children:a(u,{color:t[f.key]?"green":"gray",children:t[f.key]?y?`\u2713 ${"*".repeat(8)}`:`\u2713 ${t[f.key]}`:"(not set)"})})]},f.key)}),i&&a(m,{marginTop:1,children:a(u,{color:"red",children:i})}),a(m,{marginTop:1,children:S(u,{dimColor:!0,children:[a(u,{bold:!0,children:"Enter"})," confirm \xB7 ",a(u,{bold:!0,children:"\u2191\u2193"})," navigate"]})})]})},Ue=({category:e,currentIndex:t,totalGroups:r,onSubmit:o})=>{let[n,i]=F(()=>{let x={};for(let g of e.variables)x[g.name]=g.defaultValue||"";return x}),[c,s]=F(0),[l,f]=F(null);we(()=>{let x={};for(let g of e.variables)x[g.name]=g.defaultValue||"";i(x),s(0),f(null)},[e.name]),de((x,g)=>{if(g.tab||g.downArrow)s(d=>d<e.variables.length-1?d+1:d);else if(g.upArrow)s(d=>d>0?d-1:d);else if(g.escape){let d=e.variables.filter(p=>p.required&&!n[p.name]?.trim());if(d.length>0){f(`Required fields cannot be skipped: ${d.map(p=>p.name).join(", ")}`);return}o(n)}});let b=()=>{if(c<e.variables.length-1)s(c+1);else{let x=e.variables.filter(g=>g.required&&!n[g.name]?.trim());if(x.length>0){f(`Required fields are missing: ${x.map(g=>g.name).join(", ")}`);return}f(null),o(n)}},y=e.variables.some(x=>x.required);return S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:l?"red":v,children:[S(m,{justifyContent:"space-between",children:[S(u,{bold:!0,children:["Configure ",e.name]}),S(u,{color:"gray",children:["Group ",t+1," / ",r]})]}),a(m,{marginTop:1,children:a(u,{color:"gray",children:e.description})}),a(m,{marginTop:1,flexDirection:"column",children:e.variables.map((x,g)=>{let d=g===c,p=!!x.defaultValue;return S(m,{flexDirection:"column",marginBottom:1,children:[S(m,{children:[S(u,{color:d?v:"gray",bold:d,children:[d?"\u279C ":" ",x.name]}),x.required&&S(u,{color:"red",bold:!0,children:[" ","*"]}),p&&!d&&S(u,{color:"gray",dimColor:!0,children:[" ","(default: ",x.defaultValue,")"]})]}),d&&a(m,{marginLeft:2,children:a(ye,{value:n[x.name]||"",onChange:h=>{i(T=>({...T,[x.name]:h})),l&&f(null)},onSubmit:b,placeholder:p?`Default: ${x.defaultValue}`:x.required?"Enter a value (required)":"Press Enter to skip"})})]},x.name)})}),l&&a(m,{marginTop:1,children:S(u,{color:"red",bold:!0,children:["\u26A0 ",l]})}),a(m,{marginTop:1,children:S(u,{dimColor:!0,children:[a(u,{bold:!0,children:"Enter"})," next \xB7 ",a(u,{bold:!0,children:"\u2191\u2193"})," navigate",!y&&S(u,{children:[" ","\xB7 ",a(u,{bold:!0,children:"ESC"})," skip"]})]})})]})},Xe=({alternatives:e,onSubmit:t})=>{let[r,o]=F(new Set),[n,i]=F({}),[c,s]=F(0),[l,f]=F(null);we(()=>{let h={};for(let T of e)for(let C of T.variables)h[C.name]=C.defaultValue||"";i(h)},[e]);let b=[];for(let h=0;h<e.length;h++)if(b.push({type:"provider",categoryIndex:h}),r.has(h)){let T=e[h];if(T)for(let C=0;C<T.variables.length;C++)b.push({type:"field",categoryIndex:h,fieldIndex:C})}b.push({type:"submit"});let y=b[c],x=y?.type==="field",g=y?.type==="submit";de((h,T)=>{let C=Math.min(c,b.length-1);if(C!==c){s(C);return}if(x)T.upArrow?s(E=>Math.max(0,E-1)):(T.downArrow||T.tab)&&s(E=>Math.min(b.length-1,E+1));else if(g)T.upArrow?s(E=>Math.max(0,E-1)):(T.return||h===" ")&&p();else if(T.upArrow)s(E=>Math.max(0,E-1));else if(T.downArrow||T.tab)s(E=>Math.min(b.length-1,E+1));else if((T.return||h===" ")&&y?.type==="provider"){let E=y.categoryIndex;o($=>{let D=new Set($);return D.has(E)?D.delete(E):D.add(E),D}),l&&f(null)}});let d=()=>{l&&f(null),s(h=>Math.min(b.length-1,h+1))},p=()=>{let h=[],T={};for(let C of r){let E=e[C];if(!E)continue;if(E.variables.some(D=>n[D.name]?.trim())){h.push(E.name);for(let D of E.variables){let be=n[D.name];be&&(T[D.name]=be)}}}if(h.length===0){r.size===0?f("Enable at least one provider (press Space or Enter)"):f("Enter a value for at least one field");return}t(h,T)};return S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:l?"red":v,children:[S(m,{justifyContent:"space-between",children:[a(u,{bold:!0,children:"Configure AI Provider"}),a(u,{color:"yellow",children:"* At least one required"})]}),a(m,{marginTop:1,children:a(u,{color:"gray",children:"Enable and configure at least one AI provider below:"})}),a(m,{marginTop:1,flexDirection:"column",children:e.map((h,T)=>{let C=r.has(T),E=b.findIndex(D=>D.type==="provider"&&D.categoryIndex===T),$=c===E;return S(m,{flexDirection:"column",marginBottom:1,children:[S(m,{children:[a(u,{color:$?v:void 0,bold:$,children:$?"\u279C ":" "}),a(u,{color:C?"green":"gray",children:C?"[\u2714]":"[ ]"}),S(u,{color:C?v:"gray",bold:C,children:[" ",h.name]}),h.description&&S(u,{color:"gray",dimColor:!0,children:[" ","- ",h.description]})]}),$&&h.docsUrl&&S(m,{marginLeft:6,children:[a(u,{color:"yellow",children:"\u{1F4D6} "}),a(u,{color:"blue",underline:!0,children:h.docsUrl})]}),C&&a(m,{marginLeft:4,flexDirection:"column",marginTop:1,children:h.variables.map((D,be)=>{let ir=b.findIndex(xe=>xe.type==="field"&&xe.categoryIndex===T&&xe.fieldIndex===be),le=c===ir,dt=!!D.defaultValue,Ge=n[D.name]||"";return S(m,{flexDirection:"column",marginBottom:1,children:[S(m,{children:[S(u,{color:le?v:"gray",bold:le,children:[le?" \u279C ":" ",D.name]}),!le&&Ge&&a(u,{color:"green",children:" \u2713"}),!le&&!Ge&&dt&&S(u,{color:"gray",dimColor:!0,children:[" ","(default: ",D.defaultValue,")"]})]}),le&&a(m,{marginLeft:4,children:a(ye,{value:Ge,onChange:xe=>{i(sr=>({...sr,[D.name]:xe})),l&&f(null)},onSubmit:d,placeholder:dt?`Default: ${D.defaultValue}`:"Enter value..."})})]},D.name)})})]},h.name)})}),l&&a(m,{marginTop:1,children:S(u,{color:"red",bold:!0,children:["\u26A0 ",l]})}),S(m,{marginTop:1,children:[a(u,{color:g?v:void 0,bold:g,children:g?"\u279C ":" "}),a(m,{borderStyle:"round",borderColor:g?v:"gray",paddingX:2,children:a(u,{color:g?v:"gray",bold:g,children:"Continue \u2192"})})]}),a(m,{marginTop:1,children:a(u,{color:"gray",dimColor:!0,children:"\u2191/\u2193 navigate \u2022 Space/Enter toggle/select \u2022 Tab skip field"})})]})},Qe=({currentVar:e,currentIndex:t,totalCount:r,onSubmit:o,onSkip:n})=>{let[i,c]=F(e.defaultValue||""),[s,l]=F(null);we(()=>{c(e.defaultValue||""),l(null)},[e.name]),de((y,x)=>{if(x.escape){if(e.required&&!i.trim()){l("This field is required and cannot be skipped");return}n()}});let f=y=>{if(e.required&&!y.trim()){l("This field is required");return}l(null),o(y)},b=!!e.defaultValue;return S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:s?"red":v,children:[S(m,{justifyContent:"space-between",children:[S(m,{children:[a(u,{color:v,bold:!0,children:e.name}),e.required?a(u,{color:"red",children:" *"}):S(u,{color:"gray",dimColor:!0,children:[" ","optional"]})]}),S(u,{color:"gray",children:[t+1,"/",r]})]}),a(m,{marginLeft:1,children:a(u,{color:"gray",children:e.description})}),S(m,{marginTop:1,children:[a(u,{color:v,children:"\u2192 "}),a(ye,{value:i,onChange:y=>{c(y),s&&l(null)},onSubmit:f,placeholder:b?`Default: ${e.defaultValue}`:e.required?"required":"skip with Enter"})]}),s&&a(m,{marginTop:1,children:a(u,{color:"red",children:s})}),a(m,{marginTop:1,children:S(u,{dimColor:!0,children:[a(u,{bold:!0,children:"Enter"})," confirm",!e.required&&S(u,{children:[" ","\xB7 ",a(u,{bold:!0,children:"ESC"})," skip"]})]})})]})},St=({store:e})=>{let[t,r]=F(e.currentState);return we(()=>{let o=()=>r({...e.currentState});return e.on("change",o),()=>{e.off("change",o)}},[e]),S(Ee,{status:t.status,step:t.step,children:[t.step==="Welcome"&&t.inputRequest?.id==="welcome"&&a(Sr,{onConfirm:()=>e.submitInput(!0)}),t.step==="Prerequisites"&&t.data.checks&&S(m,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:v,children:[a(u,{bold:!0,children:"System Checks"}),S(m,{flexDirection:"column",marginTop:1,children:[a(oe,{label:"Git",status:t.data.checks.git}),a(oe,{label:"Docker",status:t.data.checks.docker}),a(oe,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&a(Pe,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="repo_path"&&a(xr,{defaultValue:t.inputRequest.meta.default,onSubmit:o=>e.submitInput(o)}),t.inputRequest?.id==="existing_repo"&&t.data.existingRepoPath&&a(vr,{repoPath:t.data.existingRepoPath,onAction:o=>e.submitInput(o)}),t.step==="Repository Setup"&&!t.inputRequest&&S(m,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:v,children:[a(u,{bold:!0,children:"Cloning Repository"}),S(m,{marginTop:1,flexDirection:"column",children:[a(ht,{value:t.data.repoProgress||0}),t.data.repoPhase&&a(m,{marginTop:1,children:a(u,{color:"gray",children:t.data.repoPhase})})]})]}),t.inputRequest?.id==="setup_mode"&&a(He,{onSelect:o=>e.submitInput(o)}),t.inputRequest?.id==="env_method"&&a(Ve,{onSelect:o=>e.submitInput(o)}),t.inputRequest?.id==="env_infisical"&&a(We,{onSubmit:o=>e.submitInput(o)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&a(Qe,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:o=>e.submitInput(o),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&a(Ue,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:o=>e.submitInput(o)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&a(Xe,{alternatives:t.data.alternativeGroups,onSubmit:(o,n)=>e.submitInput({selectedGroups:o,values:n})}),t.step==="Environment Setup"&&!t.inputRequest&&S(m,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[a(u,{bold:!0,children:"Environment Setup"}),a(m,{marginTop:1,children:a(qe,{label:t.status||"Configuring environment..."})})]}),t.step==="Finished"&&a(yr,{setupMode:t.data.setupMode,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput("exit")}),(t.step==="Install Tools"||t.step==="Project Setup")&&a(Tr,{title:t.step==="Install Tools"?"Installing Tools":"Project Setup",phase:t.data.dependencyPhase||"",progress:t.data.dependencyProgress||0,isComplete:t.step==="Install Tools"?t.data.toolComplete||!1:t.data.dependencyComplete||!1,logs:t.data.dependencyLogs||[]}),t.step==="Installing CLI"&&S(m,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:v,children:[a(u,{bold:!0,color:v,children:"Installing CLI"}),a(m,{marginTop:1,children:a(qe,{label:t.status||"Installing gaia CLI globally..."})})]}),t.error&&a(m,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:S(u,{color:"red",children:["Error: ",t.error.message]})})]})};import{Spinner as br}from"@inkjs/ui";import{Box as H,Text as k,useInput as Ir}from"ink";import{useEffect as Cr,useState as Er}from"react";import{jsx as j,jsxs as w}from"react/jsx-runtime";var xt=({store:e})=>{let[t,r]=Er(e.currentState);return Cr(()=>{let o=()=>r({...e.currentState});return e.on("change",o),()=>{e.off("change",o)}},[e]),Ir((o,n)=>{(n.return||n.escape)&&(t.data.started||t.data.stopped||t.error)&&e.submitInput("exit")}),w(H,{flexDirection:"column",width:"100%",children:[j(ue,{}),(t.step==="Starting"||t.step==="Stopping")&&w(H,{flexDirection:"column",marginTop:1,paddingX:2,borderStyle:"round",borderColor:v,children:[j(br,{label:t.status||"Working..."}),t.data.repoPath&&j(H,{marginTop:1,children:w(k,{color:"gray",children:["Repository: ",t.data.repoPath]})}),t.data.setupMode&&j(H,{children:w(k,{color:"gray",children:["Mode: ",t.data.setupMode]})})]}),t.step==="Running"&&t.data.started&&w(H,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:"green",children:[w(k,{color:"green",bold:!0,children:["\u2713"," GAIA is running!"]}),t.data.setupMode!=="developer"&&w(H,{marginTop:1,flexDirection:"column",children:[w(k,{children:["Web:"," ",w(k,{color:"cyan",bold:!0,children:["http://localhost:",t.data.webPort||3e3]})]}),w(k,{children:["API:"," ",w(k,{color:"cyan",bold:!0,children:["http://localhost:",t.data.apiPort||8e3]})]})]}),t.data.setupMode==="developer"&&w(H,{marginTop:1,flexDirection:"column",children:[j(k,{color:"gray",children:"Dev servers started in background."}),w(k,{color:"gray",children:["Logs: ",j(k,{color:v,children:"dev-start.log"})," in your repo root."]}),w(k,{color:"gray",children:["Run ",j(k,{color:v,children:"gaia stop"})," to shut down."]})]}),j(H,{marginTop:1,children:w(k,{dimColor:!0,children:[j(k,{bold:!0,children:"Enter"})," to exit"]})})]}),t.step==="Stopped"&&t.data.stopped&&w(H,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:v,children:[w(k,{color:v,bold:!0,children:["\u2713"," All GAIA services stopped."]}),j(H,{marginTop:1,children:w(k,{dimColor:!0,children:[j(k,{bold:!0,children:"Enter"})," to exit"]})})]}),t.error&&w(H,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:[w(k,{color:"red",children:["Error: ",t.error.message]}),j(H,{marginTop:1,children:w(k,{dimColor:!0,children:[j(k,{bold:!0,children:"Enter"})," to exit"]})})]})]})};import{ProgressBar as Pr,Spinner as Ye}from"@inkjs/ui";import{Box as A,Text as B,useInput as wr}from"ink";import{useEffect as Rr,useState as Dr}from"react";import{jsx as I,jsxs as O}from"react/jsx-runtime";var vt=({store:e})=>{let[t,r]=Dr(e.currentState);return Rr(()=>{let o=()=>r({...e.currentState});return e.on("change",o),()=>{e.off("change",o)}},[e]),O(Ee,{status:t.status,step:t.step,steps:gt,children:[t.step==="Detect Repo"&&O(A,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:v,children:[I(B,{bold:!0,children:"Detecting GAIA Repository"}),I(A,{marginTop:1,children:I(Ye,{label:"Searching for repository..."})}),t.data.repoPath&&I(A,{marginTop:1,children:O(B,{color:"green",children:["Found: ",t.data.repoPath]})})]}),t.step==="Prerequisites"&&t.data.checks&&O(A,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:v,children:[I(B,{bold:!0,children:"System Checks"}),O(A,{flexDirection:"column",marginTop:1,children:[I(oe,{label:"Git",status:t.data.checks.git}),I(oe,{label:"Docker",status:t.data.checks.docker}),I(oe,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&I(Pe,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="setup_mode"&&I(He,{onSelect:o=>e.submitInput(o)}),t.inputRequest?.id==="env_method"&&I(Ve,{onSelect:o=>e.submitInput(o)}),t.inputRequest?.id==="env_infisical"&&I(We,{onSubmit:o=>e.submitInput(o)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&I(Qe,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:o=>e.submitInput(o),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&I(Ue,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:o=>e.submitInput(o)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&I(Xe,{alternatives:t.data.alternativeGroups,onSubmit:(o,n)=>e.submitInput({selectedGroups:o,values:n})}),t.step==="Environment Setup"&&!t.inputRequest&&O(A,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[I(B,{bold:!0,children:"Environment Setup"}),I(A,{marginTop:1,children:I(Ye,{label:t.status||"Configuring environment..."})})]}),t.step==="Project Setup"&&O(A,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:v,children:[I(A,{marginBottom:1,children:I(B,{bold:!0,color:v,children:"Project Setup"})}),O(A,{flexDirection:"column",gap:1,children:[I(A,{children:t.data.dependencyComplete?O(B,{color:"green",children:["\u2713"," ",t.data.dependencyPhase]}):I(Ye,{label:t.data.dependencyPhase||"Preparing..."})}),!t.data.dependencyComplete&&t.data.dependencyProgress>0&&I(A,{width:50,children:I(Pr,{value:t.data.dependencyProgress})}),!t.data.dependencyComplete&&t.data.dependencyLogs?.length>0&&I(A,{flexDirection:"column",marginTop:1,marginLeft:1,children:t.data.dependencyLogs.map((o,n)=>I(B,{color:"gray",wrap:"truncate",children:o},n))})]})]}),t.step==="Finished"&&I(kr,{setupMode:t.data.setupMode,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput("exit")}),t.error&&I(A,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:O(B,{color:"red",children:["Error: ",t.error.message]})})]})},kr=({portOverrides:e,onConfirm:t})=>{wr((n,i)=>{i.return&&t()});let r=e?.[3e3]??3e3,o=e?.[8e3]??8e3;return O(A,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:v,padding:1,children:[I(B,{color:v,bold:!0,children:"Setup Complete!"}),O(A,{marginTop:1,children:[I(B,{bold:!0,children:"Run: "}),I(B,{color:"cyan",children:"$ gaia start"})]}),O(A,{marginTop:1,flexDirection:"column",children:[O(B,{children:["Web:"," ",O(B,{color:"cyan",bold:!0,children:["http://localhost:",r]})]}),O(B,{children:["API:"," ",O(B,{color:"cyan",bold:!0,children:["http://localhost:",o]})]})]}),I(A,{marginTop:1,children:I(B,{color:"gray",children:"gaia stop \xB7 gaia status \xB7 gaia setup"})}),I(A,{marginTop:1,children:O(B,{dimColor:!0,children:[I(B,{bold:!0,children:"Enter"})," to exit"]})})]})};import{Spinner as Ar}from"@inkjs/ui";import{Box as _,Text as R,useInput as _r}from"ink";import{useEffect as yt,useState as Ke}from"react";import{jsx as P,jsxs as M}from"react/jsx-runtime";var Tt=({store:e})=>{let[t,r]=Ke(e.currentState),[o,n]=Ke(!1),[i,c]=Ke(null);return yt(()=>{let s=()=>r({...e.currentState});return e.on("change",s),()=>{e.off("change",s)}},[e]),yt(()=>{t.step==="Results"&&(n(!1),c(new Date().toLocaleTimeString()))},[t.step]),_r((s,l)=>{(l.return||l.escape)&&t.step==="Results"&&e.submitInput("exit"),s==="r"&&t.step==="Results"&&t.data.refreshable&&!o&&(n(!0),e.submitInput("refresh"))}),M(_,{flexDirection:"column",width:"100%",children:[P(ue,{}),t.step==="Checking"&&P(_,{marginTop:1,children:P(Ar,{label:t.data.services?"Refreshing service health...":"Checking service health..."})}),t.step==="Results"&&t.data.services&&M(_,{flexDirection:"column",children:[M(_,{flexDirection:"column",borderStyle:"round",borderColor:v,paddingX:2,paddingY:1,children:[M(_,{justifyContent:"space-between",children:[P(R,{bold:!0,color:v,children:"GAIA Service Status"}),i&&M(R,{color:"gray",dimColor:!0,children:["checked ",i," \xB7 ",P(R,{bold:!0,children:"r"})," refresh"]})]}),M(_,{marginTop:1,flexDirection:"column",children:[M(_,{children:[P(_,{width:22,children:P(R,{bold:!0,children:"Service"})}),P(_,{width:10,children:P(R,{bold:!0,children:"Status"})}),P(_,{width:10,children:P(R,{bold:!0,children:"Latency"})})]}),P(R,{color:"gray",children:"\u2500".repeat(42)}),[...t.data.services].sort((s,l)=>s.status==="down"&&l.status!=="down"?-1:s.status!=="down"&&l.status==="down"?1:s.name.localeCompare(l.name)).map(s=>M(_,{children:[P(_,{width:22,children:M(R,{children:[s.name," (:",s.port,")"]})}),P(_,{width:10,children:P(R,{color:s.status==="up"?"green":"red",bold:!0,children:s.status==="up"?"\u2713 UP":"\u2717 DOWN"})}),P(_,{width:10,children:P(R,{color:"gray",children:s.latency?`${s.latency}ms`:"--"})})]},s.name))]})]}),t.data.docker&&M(_,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,marginTop:1,children:[P(R,{bold:!0,children:"Docker Containers"}),M(R,{color:"gray",children:["Docker:"," ",t.data.docker.running?P(R,{color:"green",children:"Running"}):P(R,{color:"red",children:"Not running"})]}),t.data.docker.containers?.length>0&&P(_,{marginTop:1,flexDirection:"column",children:t.data.docker.containers.map(s=>M(_,{children:[M(R,{color:s.status==="running"?"green":"red",children:[s.status==="running"?"\u2713":"\u2717"," "]}),P(R,{children:s.name}),s.health&&M(R,{color:"gray",children:[" (",s.health,")"]})]},s.name))})]}),P(_,{marginTop:1,children:M(R,{dimColor:!0,children:[P(R,{bold:!0,children:"Enter"})," exit \xB7 ",P(R,{bold:!0,children:"r"})," refresh"]})})]}),t.error&&P(_,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:M(R,{color:"red",children:["Error: ",t.error.message]})})]})};import{jsx as V,jsxs as Te}from"react/jsx-runtime";var Or=["init","setup","status","start","stop"],Je=class extends Br.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?Te(Re,{flexDirection:"column",padding:1,children:[V(ce,{color:"red",bold:!0,children:"An unexpected error occurred:"}),V(ce,{color:"red",children:this.state.error.message}),this.state.error.stack&&V(Re,{marginTop:1,children:V(ce,{color:"gray",dimColor:!0,children:this.state.error.stack})})]}):this.props.children}},Mr=({store:e,command:t})=>{switch(t){case"init":return V(St,{store:e});case"setup":return V(vt,{store:e});case"status":return V(Tt,{store:e});case"start":case"stop":return V(xt,{store:e,command:t});default:return Te(Re,{flexDirection:"column",padding:1,children:[Te(ce,{color:"red",children:["Unknown command: ",t]}),Te(Re,{marginTop:1,flexDirection:"column",children:[V(ce,{bold:!0,children:"Available commands:"}),Or.map(r=>Te(ce,{children:[" ",V(ce,{color:"cyan",children:r})]},r))]})]})}},X=({store:e,command:t})=>V(Je,{children:V(Mr,{store:e,command:t})});import{EventEmitter as Lr}from"events";var Fr=150,ze=class extends Lr{state={step:"init",status:"",error:null,data:{},inputRequest:null};inputResolver=null;emitTimer=null;emitPending=!1;get currentState(){return this.state}scheduleEmit(){this.emitPending=!0,this.emitTimer||(this.emitTimer=setTimeout(()=>{this.emitTimer=null,this.emitPending&&(this.emitPending=!1,this.emit("change",this.state))},Fr))}emitNow(){this.emitTimer&&(clearTimeout(this.emitTimer),this.emitTimer=null),this.emitPending=!1,this.emit("change",this.state)}setStep(t){this.state.step=t,this.emitNow()}setStatus(t){this.state.status=t,this.scheduleEmit()}setError(t){this.state.error=t,t!==null&&this.inputResolver&&(this.inputResolver(null),this.inputResolver=null,this.state.inputRequest=null),this.emitNow()}updateData(t,r){this.state.data={...this.state.data,[t]:r},this.scheduleEmit()}waitForInput(t,r){return this.state.inputRequest={id:t,meta:r},this.emitNow(),new Promise(o=>{this.inputResolver=o})}submitInput(t){this.inputResolver&&(this.inputResolver(t),this.inputResolver=null,this.state.inputRequest=null,this.emitNow())}},Q=()=>new ze;import*as te from"fs";import*as Wt from"os";import*as ae from"path";import*as z from"fs";import*as bt from"os";import*as tt from"path";var Ze=tt.join(bt.homedir(),".gaia"),et=tt.join(Ze,"config.json");function Nr(){z.existsSync(Ze)||z.mkdirSync(Ze,{recursive:!0})}function rt(){try{if(!z.existsSync(et))return null;let e=z.readFileSync(et,"utf-8");return JSON.parse(e)}catch{return null}}function De(e){Nr(),z.writeFileSync(et,`${JSON.stringify(e,null,2)}
|
|
3
|
+
`)}function ot(e){let r={...rt()??{version:"0.1.8",setupComplete:!1,setupMethod:"manual",repoPath:"",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},...e,updatedAt:new Date().toISOString()};De(r)}import*as Ft from"path";import*as fe from"node:fs";import*as me from"node:path";import{execa as It}from"execa";var nt={selfhost:{MONGO_DB:"mongodb://mongo:27017/gaia",REDIS_URL:"redis://redis:6379",POSTGRES_URL:"postgresql://postgres:postgres@postgres:5432/langgraph",CHROMADB_HOST:"chromadb",CHROMADB_PORT:"8000",RABBITMQ_URL:"amqp://guest:guest@rabbitmq:5672/"},developer:{MONGO_DB:"mongodb://localhost:27017/gaia",REDIS_URL:"redis://localhost:6379",POSTGRES_URL:"postgresql://postgres:postgres@localhost:5432/postgres",CHROMADB_HOST:"localhost",CHROMADB_PORT:"8080",RABBITMQ_URL:"amqp://guest:guest@localhost:5672/"}},Ct={selfhost:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://gaia-backend:80",SETUP_MODE:"selfhost"},developer:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://host.docker.internal:8000",SETUP_MODE:"developer"}};function at(e,t){return nt[t][e]??Ct[t][e]}async function Et(e){let t=me.join(e,"apps/api/scripts/dump_config_schema.py"),r=me.join(e,"apps/api/app/config/settings_validator.py"),o=me.join(e,"apps/api/app/config/settings.py");if(!fe.existsSync(t))throw new Error("dump_config_schema.py not found in apps/api/scripts");try{try{let{stdout:n}=await It("python3",[t,r,o],{cwd:e});return JSON.parse(n)}catch{let{stdout:n}=await It("python",[t,r,o],{cwd:e});return JSON.parse(n)}}catch(n){throw new Error(`Failed to parse settings schema: ${n.message}. Ensure python is installed.`)}}function Pt(e){let t=me.join(e,"apps","web",".env.local"),r=fe.existsSync(t)?t:me.join(e,"apps","web",".env");if(!fe.existsSync(r))return[];let o=fe.readFileSync(r,"utf-8"),n=[],i="General";for(let c of o.split(`
|
|
4
|
+
`)){let s=c.trim();if(s.startsWith("#")&&!s.startsWith("#=")){let y=s.replace(/^#+\s*/,"").trim();y&&!y.startsWith("These are")&&(i=y);continue}if(!s||s.startsWith("#"))continue;let l=s.indexOf("=");if(l===-1)continue;let f=s.substring(0,l).trim(),b=s.substring(l+1).trim();n.push({name:f,value:b,category:i})}return n}function wt(e,t){return{NEXT_PUBLIC_API_BASE_URL:`http://localhost:${t?.[8e3]??8e3}/api/v1/`}}function Rt(e,t,r){let o=r==="selfhost"?new Set(Object.keys(nt.selfhost)):new Set;for(let[n,i]of Object.entries(t)){let c=Number(n),s=Number(i);for(let[l,f]of Object.entries(e)){if(o.has(l))continue;if(f===String(c)){e[l]=String(s);continue}let b=new RegExp(`:${c}(?=[/\\s]|$)`,"g");e[l]=f.replaceAll(b,`:${s}`)}}}function Dt(e,t){return e.map(r=>({...r,variables:r.variables.map(o=>{let n=at(o.name,t);return{...o,defaultValue:n||o.defaultValue}})}))}function it(){return Object.keys(nt.selfhost)}function kt(e){return{...Ct[e]}}import*as N from"fs";import*as ge from"path";function st(e){N.existsSync(e)&&N.copyFileSync(e,`${e}.bak`)}function _t(e,t){let r=ge.join(e,".env");st(r);let o=["# GAIA Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],n=["MONGO","REDIS","POSTGRES","CHROMADB","RABBITMQ","WORKOS","GOOGLE","OPENAI","INFISICAL","LANGSMITH","DISCORD","SLACK","TELEGRAM","CLOUDINARY","COMPOSIO","FIRECRAWL","LIVEKIT","DEEPGRAM","ELEVENLABS","RESEND","SENTRY","POSTHOG","MEM0","E2B","DODO","NEXT_PUBLIC","GAIA"];function i(s){for(let f of n)if(s===f||s.startsWith(`${f}_`))return f;let l=s.split("_");return l.length===1?"Core":l[0]||"Core"}let c=new Map;for(let[s,l]of Object.entries(t)){let f=i(s);c.has(f)||c.set(f,[]);let y=/[\s#"'\\]/.test(l)||l===""?`"${l.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:l;c.get(f).push(`${s}=${y}`)}for(let[s,l]of c.entries())o.push(`# ${s} Configuration`),o.push(...l),o.push("");N.writeFileSync(r,o.join(`
|
|
5
|
+
`),"utf-8")}function Bt(e,t,r){let o=ge.join(e,"apps","web",".env.local");st(o);let n=Pt(e),i=wt(t,r),c=["# GAIA Web App Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],s=new Map;for(let l of n){s.has(l.category)||s.set(l.category,[]);let f=i[l.name]??l.value;s.get(l.category).push({name:l.name,value:f})}if(n.length===0){c.push("# Core URLs");for(let[l,f]of Object.entries(i))c.push(`${l}=${f}`);c.push("")}else for(let[l,f]of s.entries()){c.push(`# ${l}`);for(let{name:b,value:y}of f)c.push(`${b}=${y}`);c.push("")}N.writeFileSync(o,c.join(`
|
|
6
|
+
`),"utf-8")}var Ot={8e3:"API_HOST_PORT",5432:"POSTGRES_HOST_PORT",6379:"REDIS_HOST_PORT",27017:"MONGO_HOST_PORT",5672:"RABBITMQ_HOST_PORT",8080:"CHROMADB_HOST_PORT",8083:"MONGO_EXPRESS_HOST_PORT",3e3:"WEB_HOST_PORT"};function Mt(e,t,r){let o=ge.join(e,"infra","docker",".env");st(o);let n=["# Docker Compose environment overrides","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""];for(let[i,c]of Object.entries(t)){let s=Number(i),l=Ot[s];l&&n.push(`${l}=${c}`)}if(r==="selfhost"){let i=t[8e3]??8e3;n.push(""),n.push("# Web build args"),n.push(`NEXT_PUBLIC_API_BASE_URL=http://localhost:${i}/api/v1/`)}n.push(""),N.writeFileSync(o,n.join(`
|
|
7
|
+
`),"utf-8")}function he(e){let t={};for(let[r,o]of Object.entries(e)){let n=Number(r),i=Ot[n];i&&(t[i]=String(o))}return t}function Lt(e){let t=ge.join(e,"infra","docker","docker-compose.yml");if(!N.existsSync(t))return;let r=N.readFileSync(t,"utf-8"),o=[{varName:"API_HOST_PORT",hostPort:8e3,containerPort:80},{varName:"CHROMADB_HOST_PORT",hostPort:8080,containerPort:8e3},{varName:"POSTGRES_HOST_PORT",hostPort:5432,containerPort:5432},{varName:"REDIS_HOST_PORT",hostPort:6379,containerPort:6379},{varName:"MONGO_HOST_PORT",hostPort:27017,containerPort:27017},{varName:"RABBITMQ_HOST_PORT",hostPort:5672,containerPort:5672},{varName:"MONGO_EXPRESS_HOST_PORT",hostPort:8083,containerPort:8081},{varName:"WEB_HOST_PORT",hostPort:3e3,containerPort:3e3}],n=!1;for(let{varName:i,hostPort:c,containerPort:s}of o){let l=`"${c}:${s}"`,f=`"\${${i}:-${c}}:${s}"`;r.includes(l)&&(r=r.replace(l,f),n=!0)}n&&N.writeFileSync(t,r,"utf-8")}var At={API_HOST_PORT:8e3,POSTGRES_HOST_PORT:5432,REDIS_HOST_PORT:6379,MONGO_HOST_PORT:27017,RABBITMQ_HOST_PORT:5672,CHROMADB_HOST_PORT:8080,MONGO_EXPRESS_HOST_PORT:8083,WEB_HOST_PORT:3e3};function Se(e){let t=ge.join(e,"infra","docker",".env"),r={};if(!N.existsSync(t))return r;let o=N.readFileSync(t,"utf-8");for(let n of o.split(`
|
|
8
|
+
`)){let i=n.trim();if(i&&!i.startsWith("#")){let[c,...s]=i.split("=");if(c&&At[c]){let l=Number(s.join("=").trim());!Number.isNaN(l)&&l>0&&(r[At[c]]=l)}}}return r}var qr=e=>new Promise(t=>setTimeout(t,e));async function ke(e){e.setStep("Setup Mode"),e.setStatus("Choose how to run GAIA...");let t=await e.waitForInput("setup_mode");return e.updateData("setupMode",t),t}async function Ae(e,t,r,o){e.setStep("Environment Setup"),e.setStatus("Configuring environment..."),e.updateData("setupMode",r),e.setStatus("Configuring environment variables...");let n=await e.waitForInput("env_method");e.updateData("envMethod",n);let i={};i.ENV="development";let c=it();for(let l of c){let f=at(l,r);f&&(i[l]=f)}let s=kt(r);for(let[l,f]of Object.entries(s))i[l]=f;if(n==="infisical")await jr(e,i),e.setStatus("Infisical credentials saved. Ensure your Infisical project contains all required variables.");else try{await Hr(e,t,i,r)}catch(l){e.setError(l);return}o&&Rt(i,o,r);try{await Vr(e,t,i,r,o)}catch(l){e.setError(l);return}await qr(1e3)}async function jr(e,t){e.setStatus("Configuring Infisical...");let r=await e.waitForInput("env_infisical");t.INFISICAL_PROJECT_ID=r.INFISICAL_PROJECT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_ID=r.INFISICAL_MACHINE_IDENTITY_CLIENT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET=r.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET}async function Hr(e,t,r,o){e.setStatus("Parsing environment variables...");let n;try{n=await Et(t),n=Dt(n,o)}catch(d){throw o==="selfhost"?new Error(`Manual environment setup requires Python to parse config schema.
|
|
9
9
|
For self-host mode, we recommend using Infisical for secret management.
|
|
10
10
|
Alternatively, install Python 3.11+ and try again.
|
|
11
11
|
|
|
12
|
-
Original error: ${
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`).
|
|
23
|
-
|
|
12
|
+
Original error: ${d.message}`):new Error(`Failed to parse settings: ${d.message}`)}let i=new Set,c=[],s=new Set;for(let d of n)if(d.alternativeGroup&&!s.has(d.name)){let p=n.find(h=>h.name===d.alternativeGroup);p&&(c.push([d,p]),i.add(d.name),i.add(p.name),s.add(d.name),s.add(p.name))}let l=n.filter(d=>d.variables.length===1&&!i.has(d.name)),f=n.filter(d=>d.variables.length>1&&!i.has(d.name));for(let d of c){e.updateData("alternativeGroups",d),e.setStatus("Choose an AI provider...");let p=await e.waitForInput("env_alternatives");for(let[h,T]of Object.entries(p.values))T&&(r[h]=T)}let b=it(),x=[...l.flatMap(d=>d.variables).filter(d=>!b.includes(d.name))].sort((d,p)=>d.required&&!p.required?-1:!d.required&&p.required?1:0);e.updateData("envVarTotal",x.length);for(let d=0;d<x.length;d++){let p=x[d];if(!p)continue;e.updateData("currentEnvVar",p),e.updateData("envVarIndex",d),e.setStatus(`Configuring ${p.name}...`);let h=await e.waitForInput("env_var",{varName:p.name});(h||p.required||p.defaultValue)&&(r[p.name]=h||p.defaultValue||"")}let g=[...f].filter(d=>!d.variables.every(p=>b.includes(p.name))).sort((d,p)=>{let h=d.variables.some(C=>C.required),T=p.variables.some(C=>C.required);return h&&!T?-1:!h&&T?1:0});e.updateData("envGroupTotal",g.length);for(let d=0;d<g.length;d++){let p=g[d];if(!p)continue;e.updateData("currentEnvGroup",p),e.updateData("envGroupIndex",d),e.setStatus(`Configuring ${p.name}...`);let h=await e.waitForInput("env_group",{groupName:p.name});for(let[T,C]of Object.entries(h)){let E=p.variables.find($=>$.name===T);(C||E?.required||E?.defaultValue)&&(r[T]=C||E?.defaultValue||"")}}}async function Vr(e,t,r,o,n){e.setStatus("Writing API environment file...");try{let c=Ft.join(t,"apps","api");_t(c,r),e.setStatus("API environment variables configured!")}catch(c){throw new Error(`Failed to write API .env file: ${c.message}`)}e.setStatus("Writing web environment file...");try{Bt(t,o,n),e.setStatus("Web environment variables configured!")}catch(c){throw new Error(`Failed to write web .env file: ${c.message}`)}let i=n&&Object.keys(n).length>0;if(i||o==="selfhost"){e.setStatus("Writing Docker Compose environment...");try{i&&Lt(t),Mt(t,n??{},o),e.setStatus("Docker Compose environment configured!")}catch(c){throw new Error(`Failed to write Docker Compose .env: ${c.message}`)}}}import{execa as Wr}from"execa";import _e from"fs";import Ur from"simple-git";async function Nt(e,t,r,o){if(_e.existsSync(e)){let n=`${e}/.git`;if(!_e.existsSync(n))throw new Error(`Directory ${e} exists but is not a git repository`);await Ur().cwd(e).pull(),r(100,"Already exists, pulled latest")}else try{let n=["clone","--progress"];o&&n.push("--branch",o),n.push(t,e);let i=Wr("git",n);i.stderr?.on("data",c=>{let s=c.toString();s.includes("Counting objects")?r(5,"Counting objects"):s.includes("Compressing objects")&&r(10,"Compressing objects");let l=s.match(/Receiving objects:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(l?.[1]){let b=Math.min(100,parseInt(l[1],10)),y=l[2],x=l[3];r(10+Math.floor(b*.5),`Receiving objects: ${y}/${x}`)}let f=s.match(/Resolving deltas:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(f?.[1]){let b=Math.min(100,parseInt(f[1],10)),y=f[2],x=f[3];r(60+Math.floor(b*.4),`Resolving deltas: ${y}/${x}`)}}),await i,r(100,"Clone complete")}catch(n){throw _e.existsSync(e)&&_e.rmSync(e,{recursive:!0,force:!0}),n}}import{execSync as Gt}from"child_process";import*as ne from"fs";import*as $t from"os";import*as Z from"path";function Qr(){try{let e=Gt("npm config get prefix",{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim();return Z.join(e,"bin")}catch{return null}}function Yr(){try{let e=process.platform==="win32"?"where gaia":"command -v gaia";return Gt(e,{stdio:["pipe","pipe","pipe"]}),!0}catch{return!1}}function Kr(){let e=process.env.SHELL||"",t=$t.homedir();if(e.includes("zsh"))return Z.join(t,".zshrc");if(e.includes("bash")){let r=Z.join(t,".bashrc"),o=Z.join(t,".bash_profile");return ne.existsSync(r)?r:o}return e.includes("fish")?Z.join(t,".config","fish","config.fish"):null}function Jr(e,t){try{if((ne.existsSync(t)?ne.readFileSync(t,"utf-8"):"").includes(e))return!0;let n=t.includes("fish")?`
|
|
13
|
+
set -gx PATH "${e}" $PATH # Added by GAIA CLI
|
|
14
|
+
`:`
|
|
15
|
+
export PATH="${e}:$PATH" # Added by GAIA CLI
|
|
16
|
+
`;return ne.appendFileSync(t,n),!0}catch{return!1}}async function ct(){if(Yr())return{success:!0,message:"gaia command is ready.",inPath:!0,pathAdded:!1};let e=Qr();if(!e)return{success:!1,message:"Could not detect npm bin directory. Run manually: npm install -g @heygaia/cli",inPath:!1,pathAdded:!1};let t=Z.join(e,"gaia");if(!ne.existsSync(t))return{success:!1,message:`gaia binary not found at ${t}. Install may have failed.`,inPath:!1,pathAdded:!1};let r=Kr();if(!r)return{success:!1,message:`Add to your PATH: export PATH="${e}:$PATH"`,inPath:!1,pathAdded:!1};if(Jr(e,r)){let n=Z.basename(r);return{success:!0,message:`Added to PATH via ~/${n}. Restart terminal or run: source ~/${n}`,inPath:!1,pathAdded:!0}}return{success:!1,message:`Could not write to ${r}. Add manually: export PATH="${e}:$PATH"`,inPath:!1,pathAdded:!1}}import{execa as ee}from"execa";var Y={git:"https://git-scm.com/downloads",docker:"https://docs.docker.com/get-docker/",mise:"https://mise.jdx.dev/getting-started.html"},zr={8e3:"API Server",5432:"PostgreSQL",6379:"Redis",27017:"MongoDB",5672:"RabbitMQ",3e3:"Web Frontend",8080:"ChromaDB",8083:"Mongo Express"};async function Be(){try{return await ee("git",["--version"]),"success"}catch{return"error"}}async function Oe(){let e=!1,t=!1,r;try{await ee("docker",["--version"]),e=!0}catch{return{name:"Docker",installUrl:Y.docker,installed:!1,working:!1,errorMessage:"Docker is not installed"}}try{await ee("docker",["info"],{timeout:5e3}),t=!0}catch{r="Docker is installed but the daemon is not running. Please start Docker Desktop or the Docker daemon."}return{name:"Docker",installUrl:Y.docker,installed:e,working:t,errorMessage:r}}async function Me(){try{return await ee("mise",["--version"]),"success"}catch{return"missing"}}async function Le(){if((await import("node:os")).platform()==="win32")try{return await ee("powershell",["-Command","irm https://mise.jdx.dev/install.ps1 | iex"]),!0}catch{return!1}try{return await ee("sh",["-c","curl https://mise.jdx.dev/install.sh | sh"]),!0}catch{return!1}}async function Fe(e){let t=await import("node:net"),r=[],o=n=>new Promise(i=>{let c=t.createServer();c.once("error",()=>i(!1)),c.once("listening",()=>{c.close(()=>i(!0))}),c.listen(n)});for(let n of e){let i=zr[n]||`Port ${n}`;if(await o(n))r.push({port:n,service:i,available:!0});else{let s=await Zr(n),l=await eo(n+1,n+100,o);r.push({port:n,service:i,available:!1,usedBy:s,alternative:l||void 0})}}return r}async function Zr(e){if((await import("node:os")).platform()==="win32"){try{let{stdout:o}=await ee("netstat",["-ano","-p","TCP"]),n=o.trim().split(`
|
|
17
|
+
`);for(let i of n)if(i.includes(`:${e}`)&&i.includes("LISTENING")){let c=i.trim().split(/\s+/),s=c[c.length-1];if(s)try{let{stdout:l}=await ee("tasklist",["/FI",`PID eq ${s}`,"/FO","CSV","/NH"]);return l.trim().split(",")[0]?.replace(/"/g,"")||`PID ${s}`}catch{return`PID ${s}`}}}catch{}return}try{let{stdout:o}=await ee("lsof",["-i",`:${e}`,"-sTCP:LISTEN","-P","-n"]),n=o.trim().split(`
|
|
18
|
+
`);if(n.length>1)return n[1]?.split(/\s+/)?.[0]||void 0}catch{}}async function eo(e,t,r){for(let o=e;o<=t;o++)if(await r(o))return o;return null}import*as W from"fs";import*as U from"path";var to=e=>new Promise(t=>setTimeout(t,e)),ro="dev-start.log";function jt(e){let t=U.join(e,".env");return W.existsSync(t)?["--env-file",".env"]:[]}async function Ht(e,t,r,o){if(t==="selfhost"){r?.("Starting all services in Docker (selfhost mode)...");let n=U.join(e,"infra/docker"),i=jt(n),c=o&&Object.keys(o).length>0?he(o):void 0;await G("docker",["compose","-f","docker-compose.selfhost.yml",...i,"up","-d","--build","--remove-orphans"],n,void 0,void 0,c),r?.("All services started in Docker!")}else{r?.("Starting development servers...");let{spawn:n}=await import("child_process"),i=U.join(e,ro),c=W.openSync(i,"a"),s;try{s=n("mise",["dev"],{cwd:e,stdio:["ignore",c,c],detached:!0,shell:!0}),s.unref()}finally{W.closeSync(c)}if(await to(1500),s.pid!=null)try{process.kill(s.pid,0)}catch{throw new Error(`Development servers crashed on startup. Check logs at: ${i}`)}r?.(`Development servers started! Logs: ${i}`)}}async function Vt(e,t,r){let o=U.join(e,"infra/docker"),n=await lt(e);t?.("Stopping Docker services...");try{let i=jt(o),c=n==="selfhost"?["compose","-f","docker-compose.selfhost.yml",...i,"down"]:["compose",...i,"down"];await G("docker",c,o)}catch{}if(n!=="selfhost"){t?.("Stopping local processes...");try{let i=r?.[8e3]??8e3,c=r?.[3e3]??3e3;if(process.platform==="win32")for(let s of[i,c])try{await G("powershell",["-Command",`Get-NetTCPConnection -LocalPort ${s} -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }`],e)}catch{}else for(let s of[i,c])try{await G("sh",["-c",`lsof -ti :${s} -sTCP:LISTEN | xargs kill 2>/dev/null || true`],e)}catch{}}catch{}}t?.("All services stopped.")}async function lt(e){let t=U.join(e,"apps","api",".env");if(!W.existsSync(t))return null;let r=W.readFileSync(t,"utf-8"),o=r.match(/^SETUP_MODE=(.+)$/m);if(o?.[1]){let n=o[1].trim().replace(/^["']|["']$/g,"");if(n==="selfhost"||n==="developer")return n}return r.includes("mongodb://mongo:")?"selfhost":(r.includes("mongodb://localhost:"),"developer")}async function G(e,t,r,o,n,i){let{spawn:c}=await import("child_process");return new Promise((s,l)=>{let f=c(e,t,{cwd:r,stdio:["ignore","pipe","pipe"],shell:!0,env:i?{...process.env,...i}:void 0}),b="",y=0;f.stdout?.on("data",x=>{let g=x.toString();b+=g,n?.(g),y=Math.min(y+5,95),o?.(y)}),f.stderr?.on("data",x=>{let g=x.toString();b+=g,n?.(g),y=Math.min(y+5,95),o?.(y)}),f.on("close",x=>{x===0?(o?.(100),s()):l(new Error(`Command failed with code ${x}: ${b.slice(-500)}`))}),f.on("error",x=>{l(x)})})}function K(e){let t=e||process.cwd();for(;t!==U.dirname(t);){if(W.existsSync(U.join(t,"apps/api/app/config/settings_validator.py")))return t;t=U.dirname(t)}let r=rt();return r?.repoPath&&W.existsSync(U.join(r.repoPath,"apps/api/app/config/settings_validator.py"))?r.repoPath:null}var oo=process.env.GAIA_CLI_DEV==="true",J=e=>new Promise(t=>setTimeout(t,e));async function Ut(e,t){e.setStep("Welcome"),e.setStatus("Waiting for user input..."),await e.waitForInput("welcome");let r=p=>{let h=e.currentState.data.dependencyLogs||[],T=p.split(`
|
|
19
|
+
`).filter(E=>E.trim()!==""),C=[...h,...T].slice(-20);e.updateData("dependencyLogs",C)};e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await J(800),e.setStatus("Checking Git...");let o=await Be();e.updateData("checks",{...e.currentState.data.checks,git:o}),e.setStatus("Checking Docker...");let n=await Oe(),i=n.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:i}),n.working||e.updateData("dockerError",n.errorMessage),e.setStatus("Checking Mise...");let c=await Me();e.updateData("checks",{...e.currentState.data.checks,mise:c}),c==="missing"&&(e.setStatus("Installing Mise..."),c=await Le()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:c}));let s=[];if(o==="error"&&s.push({name:"Git"}),i==="error"&&s.push({name:"Docker",message:n.errorMessage}),s.length>0){let p=[];p.push("Prerequisites failed:");for(let h of s)p.push(` \u2022 ${h.name}: ${h.message||"Not installed or not working"}`);p.push(`
|
|
20
|
+
Installation guides:`),o==="error"&&p.push(` \u2022 Git: ${Y.git}`),i==="error"&&(n.installed?p.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):p.push(` \u2022 Docker: ${Y.docker}`)),e.setError(new Error(p.join(`
|
|
21
|
+
`)));return}e.setStatus("Checking Ports...");let f=await Fe([8e3,5432,6379,27017,5672,3e3,8080,8083]),b={},y=f.filter(p=>!p.available);if(y.length>0){let p=y.filter(T=>!T.alternative);if(p.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${p.map(T=>`${T.port} (${T.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",f),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let T of f)!T.available&&T.alternative&&(b[T.port]=T.alternative)}e.updateData("portOverrides",b),e.setStatus("Prerequisites check complete!"),await J(1e3);let x=await ke(e),g="";if(oo){if(g=K()||"",!g){e.setError(new Error("DEV_MODE: Could not find workspace root. Run from within the gaia repo."));return}e.setStep("Repository Setup"),e.setStatus("[DEV MODE] Using current workspace..."),await J(500),e.setStatus("Repository ready!")}else{e.setStep("Repository Setup");let p=x==="selfhost"?ae.join(Wt.homedir(),"gaia"):ae.resolve("gaia"),h=!0;for(g=p;;){if(g=await e.waitForInput("repo_path",{default:p}),ae.isAbsolute(g)||(g=ae.resolve(g)),te.existsSync(g)){if(!te.statSync(g).isDirectory()){e.setError(new Error(`Path ${g} exists and is not a directory.`)),await J(2e3),e.setError(null);continue}if(te.existsSync(ae.join(g,"apps/api/app/config/settings_validator.py"))){e.updateData("existingRepoPath",g);let $=await e.waitForInput("existing_repo");if($==="use_existing"){h=!1;break}else if($==="delete_reclone"){e.setStatus("Removing existing installation..."),te.rmSync(g,{recursive:!0,force:!0});break}else{if($==="different_path")continue;e.setError(new Error("Setup cancelled by user."));return}}if(te.readdirSync(g).length>0){e.setError(new Error(`Directory ${g} is not empty and is not a GAIA installation. Please choose another path.`)),await J(2e3),e.setError(null);continue}}break}if(h){e.setStep("Repository Setup"),e.setStatus("Preparing repository..."),e.updateData("repoProgress",0),e.updateData("repoPhase","");try{await Nt(g,"https://github.com/theexperiencecompany/gaia.git",(T,C)=>{e.updateData("repoProgress",T),C?(e.updateData("repoPhase",C),e.setStatus(`${C}...`)):e.setStatus(`Cloning repository to ${g}... ${T}%`)},t),e.setStatus("Repository ready!")}catch(T){e.setError(T);return}}else e.setStatus("Using existing repository!")}if(await J(1e3),await Ae(e,g,x,b),e.currentState.error)return;if(x==="selfhost"){let p=e.currentState.data.envMethod||"manual";De({version:"0.1.8",setupComplete:!0,setupMethod:p,repoPath:g,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}),e.setStep("Installing CLI"),e.setStatus("Installing gaia CLI globally...");try{await G("npm",["install","-g","@heygaia/cli"],g),e.setStatus("Verifying PATH...");let h=await ct();h.inPath?e.setStatus("CLI installed! gaia command is ready."):(h.pathAdded,e.setStatus(h.message))}catch{e.setStatus("CLI install failed. Install manually: npm install -g @heygaia/cli")}await J(500),e.setStep("Finished"),e.setStatus("Setup complete! Run 'gaia start' to build and start all services in Docker."),await e.waitForInput("exit");return}if(c==="error"){e.setError(new Error(`Developer mode requires Mise but it failed to install.
|
|
22
|
+
\u2022 Mise: ${Y.mise}`));return}e.setStep("Install Tools"),e.setStatus("Installing toolchain..."),e.updateData("dependencyPhase","Initializing mise..."),e.updateData("dependencyProgress",0),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyPhase","Trusting mise configuration..."),await G("mise",["trust"],g,void 0,r),e.updateData("dependencyProgress",50),e.updateData("dependencyPhase","Installing tools (node, python, uv, nx)..."),await G("mise",["install"],g,p=>{e.updateData("dependencyProgress",50+p*.5)},r),e.updateData("dependencyProgress",100),e.updateData("toolComplete",!0)}catch(p){e.setError(new Error(`Failed to install tools: ${p.message}`));return}await J(1e3),e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("repoPath",g),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyProgress",0),e.updateData("dependencyPhase","Running mise setup (all dependencies)...");let p=Object.keys(b).length>0?he(b):void 0;await G("mise",["setup"],g,h=>{e.updateData("dependencyProgress",h)},r,p),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(p){e.setError(new Error(`Failed to setup project: ${p.message}`));return}await J(1e3);let d=e.currentState.data.envMethod||"manual";De({version:"0.1.8",setupComplete:!0,setupMethod:d,repoPath:g,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}),e.setStep("Installing CLI"),e.setStatus("Installing gaia CLI globally...");try{await G("npm",["install","-g","@heygaia/cli"],g),e.setStatus("Verifying PATH...");let p=await ct();p.inPath?e.setStatus("CLI installed! gaia command is ready."):(p.pathAdded,e.setStatus(p.message))}catch{e.setStatus("CLI install failed. Install manually: npm install -g @heygaia/cli")}await J(500),e.setStep("Finished"),e.setStatus("Setup complete!"),await e.waitForInput("exit")}async function Xt(e={}){let t=Q(),{unmount:r}=no(ao.createElement(X,{store:t,command:"init"}));try{await Ut(t,e.branch)}catch(o){t.setError(o)}t.currentState.error&&await t.waitForInput("exit"),r(),process.exit(t.currentState.error?1:0)}import{render as io}from"ink";import so from"react";var Ne=e=>new Promise(t=>setTimeout(t,e));async function Qt(e){e.setStep("Detect Repo"),e.setStatus("Looking for GAIA repository...");let t=K();if(!t){e.setError(new Error("Could not find GAIA repository. Run this command from within a cloned gaia repo, or use 'gaia init' to set up from scratch."));return}e.updateData("repoPath",t),e.setStatus(`Found repository at ${t}`),await Ne(1e3),e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await Ne(500);let r=await Be();e.updateData("checks",{...e.currentState.data.checks,git:r});let o=await Oe(),n=o.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:n}),o.working||e.updateData("dockerError",o.errorMessage);let i=await Me();e.updateData("checks",{...e.currentState.data.checks,mise:i}),i==="missing"&&(e.setStatus("Installing Mise..."),i=await Le()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:i}));let c=[];if(r==="error"&&c.push({name:"Git"}),n==="error"&&c.push({name:"Docker",message:o.errorMessage}),c.length>0){let d=[];d.push("Prerequisites failed:");for(let p of c)d.push(` \u2022 ${p.name}: ${p.message||"Not installed or not working"}`);d.push(`
|
|
23
|
+
Installation guides:`),r==="error"&&d.push(` \u2022 Git: ${Y.git}`),n==="error"&&(o.installed?d.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):d.push(` \u2022 Docker: ${Y.docker}`)),e.setError(new Error(d.join(`
|
|
24
|
+
`)));return}e.setStatus("Checking Ports...");let l=await Fe([8e3,5432,6379,27017,5672,3e3,8080,8083]),f={},b=l.filter(d=>!d.available);if(b.length>0){let d=b.filter(h=>!h.alternative);if(d.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${d.map(h=>`${h.port} (${h.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",l),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let h of l)!h.available&&h.alternative&&(f[h.port]=h.alternative)}e.updateData("portOverrides",f),e.setStatus("Prerequisites check complete!"),await Ne(1e3);let y=await ke(e);if(await Ae(e,t,y,f),e.currentState.error)return;if(y==="selfhost"){let d=e.currentState.data.envMethod||"manual";ot({setupComplete:!0,setupMethod:d,repoPath:t}),e.setStep("Finished"),e.setStatus("Setup complete! Run 'gaia start' to build and start all services in Docker."),await e.waitForInput("exit");return}if(i==="error"){e.setError(new Error(`Developer mode requires Mise but it failed to install.
|
|
25
|
+
\u2022 Mise: ${Y.mise}`));return}e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("dependencyLogs",[]);let x=d=>{let p=e.currentState.data.dependencyLogs||[],h=d.split(`
|
|
26
|
+
`).filter(C=>C.trim()!==""),T=[...p,...h].slice(-20);e.updateData("dependencyLogs",T)};try{e.updateData("dependencyPhase","Trusting mise configuration..."),await G("mise",["trust"],t,void 0,x),e.updateData("dependencyProgress",20),e.updateData("dependencyPhase","Installing tools..."),await G("mise",["install"],t,p=>{e.updateData("dependencyProgress",20+p*.3)},x),e.updateData("dependencyPhase","Running mise setup...");let d=Object.keys(f).length>0?he(f):void 0;await G("mise",["setup"],t,p=>{e.updateData("dependencyProgress",50+p*.5)},x,d),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(d){e.setError(new Error(`Failed to setup project: ${d.message}`));return}await Ne(1e3);let g=e.currentState.data.envMethod||"manual";ot({setupComplete:!0,setupMethod:g,repoPath:t}),e.setStep("Finished"),e.setStatus("Setup complete!"),await e.waitForInput("exit")}async function Yt(){let e=Q(),{unmount:t}=io(so.createElement(X,{store:e,command:"setup"}));try{await Qt(e)}catch(r){e.setError(r)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as co}from"ink";import lo from"react";async function Kt(e){e.setStep("Starting"),e.setStatus("Locating GAIA repository...");let t=K();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);let r=await lt(t);if(!r){e.setError(new Error("No .env file found. Run 'gaia setup' first to configure the environment."));return}let o=Se(t),n=o[3e3]??3e3,i=o[8e3]??8e3;e.updateData("setupMode",r),e.updateData("webPort",n),e.updateData("apiPort",i),e.setStatus(`Starting GAIA in ${r} mode...`);try{await Ht(t,r,c=>{e.setStatus(c)},o),e.setStep("Running"),e.setStatus("GAIA is running!"),e.updateData("started",!0)}catch(c){e.setError(new Error(`Failed to start services: ${c.message}`));return}await e.waitForInput("exit")}async function Jt(){let e=Q(),{unmount:t}=co(lo.createElement(X,{store:e,command:"start"}));await new Promise(r=>setTimeout(r,50));try{await Kt(e)}catch(r){e.setError(r)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as go}from"ink";import ho from"react";import{execa as pt}from"execa";var ut=["gaia-backend","gaia-web","chromadb","postgres","redis","mongo","rabbitmq","arq_worker"];async function zt(){try{let{stdout:e}=await pt("docker",["inspect","--format","{{.Name}}|{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",...ut]),t=new Map;for(let r of e.trim().split(`
|
|
27
|
+
`)){if(!r)continue;let[o,n,i]=r.split("|"),c=o?.replace(/^\//,"")??"";t.set(c,{name:c,status:n==="running"?"running":"stopped",health:i!=="none"?i:void 0})}return ut.map(r=>t.get(r)??{name:r,status:"not_found"})}catch{let e=ut.map(async t=>{try{let{stdout:r}=await pt("docker",["inspect","--format","{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",t]),[o,n]=r.trim().split("|");return{name:t,status:o==="running"?"running":"stopped",health:n!=="none"?n:void 0}}catch{return{name:t,status:"not_found"}}});return Promise.all(e)}}async function Zt(){try{return await pt("docker",["info"]),!0}catch{return!1}}var uo=[{name:"API",port:8e3,type:"http",path:"/health"},{name:"Web",port:3e3,type:"http",path:"/"},{name:"PostgreSQL",port:5432,type:"tcp"},{name:"Redis",port:6379,type:"tcp"},{name:"MongoDB",port:27017,type:"tcp"},{name:"RabbitMQ",port:5672,type:"tcp"},{name:"ChromaDB",port:8080,type:"tcp"}];async function er(e){let r=uo.map(o=>({...o,port:e?.[o.port]??o.port})).map(o=>o.type==="http"?po(o.name,o.port,o.path):mo(o.name,o.port));return Promise.all(r)}async function po(e,t,r){let o=Date.now();try{let n=await fetch(`http://localhost:${t}${r}`,{signal:AbortSignal.timeout(5e3)}),i=Date.now()-o;return{name:e,port:t,status:"up",latency:i,details:n.ok?`HTTP ${n.status}`:`HTTP ${n.status} (error)`}}catch{return{name:e,port:t,status:"down",details:"Connection failed"}}}async function mo(e,t){let r=await import("node:net"),o=Date.now();return new Promise(n=>{let i=new r.Socket;i.setTimeout(3e3),i.on("connect",()=>{let c=Date.now()-o;i.destroy(),n({name:e,port:t,status:"up",latency:c})}),i.on("timeout",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.on("error",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.connect(t,"localhost")})}async function tr(){return await Zt()?{running:!0,containers:await zt()}:{running:!1,containers:[]}}async function fo(e){e.setStep("Checking"),e.setStatus("Checking service health..."),e.updateData("refreshable",!1);let t=K(),r=t?Se(t):void 0,[o,n]=await Promise.all([er(r),tr()]);e.updateData("services",o),e.updateData("docker",n);let i=o.filter(s=>s.status==="up").length,c=o.length;e.setStep("Results"),e.setStatus(`${i}/${c} services running`),e.updateData("refreshable",!0)}async function rr(e){for(;await fo(e),await e.waitForInput("exit_or_refresh")==="refresh";);}async function or(){let e=Q(),{unmount:t}=go(ho.createElement(X,{store:e,command:"status"}));await new Promise(r=>setTimeout(r,50));try{await rr(e)}catch(r){e.setError(r)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as So}from"ink";import xo from"react";async function nr(e){e.setStep("Stopping"),e.setStatus("Locating GAIA repository...");let t=K();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);let r=Se(t);try{await Vt(t,o=>{e.setStatus(o)},r),e.setStep("Stopped"),e.setStatus("All services stopped."),e.updateData("stopped",!0)}catch(o){e.setError(new Error(`Failed to stop services: ${o.message}`));return}await e.waitForInput("exit")}async function ar(){let e=Q(),{unmount:t}=So(xo.createElement(X,{store:e,command:"stop"}));await new Promise(r=>setTimeout(r,50));try{await nr(e)}catch(r){e.setError(r)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}var ie=new vo;ie.name("gaia").description("CLI tool for setting up and managing GAIA").version("0.1.0");ie.command("init").description("Full setup from scratch (clone, configure, start)").option("--branch <branch>","Git branch to clone").action(async e=>{await Xt({branch:e.branch})});ie.command("setup").description("Configure an existing GAIA repository").action(async()=>{await Yt()});ie.command("status").description("Check health of all GAIA services").action(async()=>{await or()});ie.command("start").description("Start GAIA services").action(async()=>{await Jt()});ie.command("stop").description("Stop all GAIA services").action(async()=>{await ar()});process.argv.slice(2).length||(ie.outputHelp(),process.exit(0));ie.parse();
|