magicpath-ai 2.3.0 → 2.3.1
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/cli.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -145,5 +145,5 @@ Tailwind v4:
|
|
|
145
145
|
Do not use @tailwind base/components/utilities; and do not replace the
|
|
146
146
|
template @theme inline, :root, or .dark token blocks. Append custom CSS below
|
|
147
147
|
the existing setup.
|
|
148
|
-
`);n.command("start").description("Start a pending create or edit session before writing code").option("--project <projectId>","Target MagicPath project ID for create").option("--component <componentId>","Existing MagicPath component ID for edit").option("--revision <revisionId>","Start editing this revision. Defaults to the component's currently selected revision.").option("--dir <dir>","Working directory to initialize",".").option("--name <name>","Component name").option("--width <px>","Canvas component width for create").option("--height <px>","Canvas component height for create").action(async t=>{try{let o=M.resolve(t.dir),r=ut(t);if(!!t.project==!!t.component)throw new p("Run code start with exactly one of --project for create or --component for edit.");if(t.component){if(r)throw new p("Use --width and --height with code submit when resizing an existing component.");let d=await Bo(),I=(await V.post(Pt(t.component),{...t.revision?{revisionId:t.revision}:{},...d.length>0?{selectedImages:d}:{}},{headers:E()})).data.data;O.ensureDirSync(o);for(let h of I.editableFiles)gt(o,h);let $=await Ko(o,I.selectedImages),w={mode:"edit",componentId:I.component.id,projectId:I.component.projectId,selectedRevisionId:I.component.selectedRevisionId,baseRevisionId:I.component.baseRevisionId,jobId:I.jobId,generatedName:I.component.generatedName,name:I.component.name,selectedImages:$,editableFiles:I.editableFiles.map(h=>({path:h.path,sha256:pe(h.content)}))};Ie(o,w);let u={dir:o,manifestPath:He(o),...w,status:"pending",scaffoldedPaths:I.editableFiles.map(h=>h.path),selectedImages:$};x()&&v(u),console.log(`Started pending edit ${w.selectedRevisionId} for component ${w.componentId} in ${o}`);return}let s=t.project;if(!s)throw new p("Create sessions require --project.");let i=await Bo(s),a=(await V.post(Be(),{projectId:s,...t.name?{name:t.name}:{},...r?{dimensions:r}:{},...i.length>0?{selectedImages:i}:{}},{headers:E()})).data.data,l=a.editableFiles??[];O.ensureDirSync(o);for(let d of l)gt(o,d);let g=await Ko(o,a.selectedImages),m={mode:"create",componentId:a.componentId,projectId:s,selectedRevisionId:a.revisionId,jobId:a.jobId,generatedName:a.generatedName,name:t.name,dimensions:r,selectedImages:g,editableFiles:l.map(d=>({path:d.path,sha256:pe(d.content)}))};Ie(o,m);let f={dir:o,manifestPath:He(o),...m,status:"pending",scaffoldedPaths:l.map(d=>d.path),selectedImages:g};x()&&v(f),console.log(`Started pending component ${m.componentId} in ${o}`+(l.length>0?` (scaffolded ${l.length} file${l.length===1?"":"s"})`:""))}catch(o){be(o)}}),n.command("context").description("Fetch editable files for an existing MagicPath component").argument("<componentId>","MagicPath component ID").option("--dir <dir>","Working directory to write",".").option("--revision <revisionId>","Pull this revision of the component. Defaults to the component's currently selected revision.").action(async(t,o)=>{try{let r=M.resolve(o.dir);O.ensureDirSync(r);let s=o.revision?`${Ke(t)}?revisionId=${encodeURIComponent(o.revision)}`:Ke(t),c=(await V.get(s,{headers:E()})).data.data;for(let l of c.editableFiles)gt(r,l);let a={dir:r,readOnly:!0,component:c.component,editableFiles:c.editableFiles.map(l=>({path:l.path,sha256:pe(l.content)}))};x()&&v(a),console.log(`Fetched ${c.editableFiles.length} read-only editable file(s) into ${r}. Run \`magicpath-ai code start --component ${t} --dir ${r}\` before submitting edits.`)}catch(r){be(r)}}),n.command("submit").description("Submit changed editable files for the component in this working directory").option("--dir <dir>","Working directory containing magicpath-code.json",".").option("--wait","Wait for the build job to finish",!1).option("--interval <ms>","Polling interval when --wait is set","2000").option("--width <px>","Updated canvas component width").option("--height <px>","Updated canvas component height").action(async t=>{try{let o=M.resolve(t.dir),r=sr(o),s=ut(t);Vo(o);let i=ir(o,r),c=ar(o,r);if(r.mode==="create"&&!i.some(m=>m.path==="src/App.tsx"))throw new p("Create submit requires src/App.tsx in the working directory.");if(i.length===0&&c.length===0&&!s){let m={status:"unchanged",componentId:r.componentId,revisionId:r.selectedRevisionId};x()&&v(m),console.log("No editable file changes to submit.");return}let l=r.mode==="create"||!!r.baseRevisionId&&r.selectedRevisionId!==r.baseRevisionId?await V.post(Xe(r.componentId,r.selectedRevisionId),{files:i.map(m=>({path:m.path,content:m.content,encoding:m.encoding,mimeType:m.mimeType})),contextJobId:r.jobId,...s?{dimensions:s}:{},...r.mode==="edit"?{deletedPaths:c}:{}},{headers:E()}):await V.post(Tt(r.componentId),{baseRevisionId:r.baseRevisionId??r.selectedRevisionId,files:i.map(m=>({path:m.path,content:m.content,encoding:m.encoding,mimeType:m.mimeType,baseSha256:m.baseSha256})),deletedPaths:c,...s?{dimensions:s}:{}},{headers:E()}),g=l.data.data;if(t.wait&&(g=await zo(l.data.data.jobId,Number(t.interval))),g.status==="completed"){let m=ve(o),f={...r,mode:"edit",jobId:l.data.data.jobId,selectedRevisionId:g.revisionId,baseRevisionId:g.revisionId,...s?{dimensions:s}:{},editableFiles:m.map(d=>({path:d.path,sha256:d.sha256??pe(d.content)}))};Ie(o,f)}x()&&v({...g,jobId:l.data.data.jobId,deletedPaths:c,...s?{dimensions:s}:{}}),console.log(`Submitted ${i.length} file(s)`+(c.length>0?` and ${c.length} deletion(s)`:"")+`. Job ${l.data.data.jobId}: ${g.status}`)}catch(o){be(o)}}),n.command("create").description("Create a new MagicPath component from local editable files").requiredOption("--project <projectId>","Target MagicPath project ID").option("--dir <dir>","Working directory containing src/App.tsx",".").option("--name <name>","Component name").option("--wait","Wait for the build job to finish",!1).option("--width <px>","Canvas component width").option("--height <px>","Canvas component height").action(async t=>{try{let o=M.resolve(t.dir),r=ut(t);Vo(o);let s=ve(o);if(!s.some(g=>g.path==="src/App.tsx"))throw new p("Create requires src/App.tsx in the working directory.");let i=await V.post(Be(),{projectId:t.project,...t.name?{name:t.name}:{},...r?{dimensions:r}:{}},{headers:E()}),c={mode:"create",componentId:i.data.data.componentId,projectId:t.project,selectedRevisionId:i.data.data.revisionId,jobId:i.data.data.jobId,generatedName:i.data.data.generatedName,name:t.name,dimensions:r,editableFiles:[]};Ie(o,c);let a=await V.post(Xe(c.componentId,c.selectedRevisionId),{files:s.map(g=>({path:g.path,content:g.content,encoding:g.encoding,mimeType:g.mimeType})),contextJobId:c.jobId,...r?{dimensions:r}:{}},{headers:E()}),l=a.data.data;t.wait&&(l=await zo(a.data.data.jobId,2e3)),l.status==="completed"&&Ie(o,{...c,mode:"edit",jobId:a.data.data.jobId,selectedRevisionId:l.revisionId,...r?{dimensions:r}:{},editableFiles:s.map(g=>({path:g.path,sha256:g.sha256??pe(g.content)}))}),x()&&v({...l,jobId:a.data.data.jobId,...r?{dimensions:r}:{}}),console.log(`Created component ${a.data.data.componentId}. Job ${a.data.data.jobId}: ${l.status}`)}catch(o){be(o)}}),n.command("status").description("Fetch external-agent build job status").argument("<jobId>","External agent job ID").action(async t=>{try{let o=await V.get(qe(t),{headers:E()});x()&&v(o.data.data),console.log(`${t}: ${o.data.data.status}`)}catch(o){be(o)}})}import xe from"axios";import Yo from"fs";import yt from"path";import{imageSize as lr}from"image-size";var Qo=512;async function mr(e){if(/^https?:\/\//i.test(e)){let t=await xe.get(e,{responseType:"arraybuffer"}),o=yt.basename(new URL(e).pathname)||"image";return{buffer:Buffer.from(t.data),fileName:o}}let n=yt.resolve(e);if(!Yo.existsSync(n))throw new Error(`Image file not found: ${n}`);return{buffer:Yo.readFileSync(n),fileName:yt.basename(n)}}function Ge(e){if(e===void 0)return;let n=Number(e);if(!Number.isFinite(n))throw new Error(`Invalid number: ${e}`);return n}function en(e){let n=e.command("image").description("Add and list images on a project canvas");n.command("add").description("Add an image to a project canvas from a local file path or a URL").argument("<projectId>","The id of the project to add the image to").argument("<pathOrUrl>","A local image file path or an http(s) URL").option("--name <name>","Display name for the image (defaults to the file name)").option("--x <x>","Canvas x position (default 0)").option("--y <y>","Canvas y position (default 0)").option("--width <width>","Width in canvas units (defaults to the intrinsic width)").option("--height <height>","Height in canvas units (defaults to the intrinsic height)").action(async(t,o,r)=>{var c,a;let s=x(),i=s?null:T("Adding image to project...").start();try{let l=E(),{buffer:g,fileName:m}=await mr(o),f=Ge(r.width),d=Ge(r.height);if(f===void 0||d===void 0)try{let P=lr(g);f=f??P.width,d=d??P.height}catch{}f=f??Qo,d=d??Qo;let b={x:Ge(r.x)??0,y:Ge(r.y)??0,z:0,width:f,height:d},I=r.name??m,$=await xe.get(St(),{headers:l,params:{filename:m,content_type:"image/*",make_public:"true"}}),{upload_url:w,upload_token:u}=$.data;await xe.put(w,g,{headers:{"Content-Type":"image/*","x-goog-acl":"public-read"}});let y=(a=(c=(await xe.post(Ye(t),{name:I,position:b,upload_token:u},{headers:l})).data)==null?void 0:c.data)==null?void 0:a.image;i==null||i.succeed("Image added to project"),s&&v({image:y}),console.log(`Added "${(y==null?void 0:y.name)??I}" (${(y==null?void 0:y.id)??"unknown id"})`),y!=null&&y.url&&console.log(y.url)}catch(l){i==null||i.fail("Failed to add image"),s&&A(l),console.error(l instanceof Error?l.message:String(l)),process.exit(1)}}),n.command("list").description("List the images on a project canvas").argument("<projectId>","The id of the project").action(async t=>{var s,i;let o=x(),r=o?null:T("Fetching images...").start();try{let c=E(),l=((i=(s=(await xe.get(Ye(t),{headers:c})).data)==null?void 0:s.data)==null?void 0:i.images)??[];if(r==null||r.succeed(`Found ${l.length} image(s)`),o&&v({images:l}),l.length===0){console.log("No images in this project.");return}for(let g of l)console.log(`- ${g.name} (${g.id})${g.url?` \u2014 ${g.url}`:""}`)}catch(c){r==null||r.fail("Failed to list images"),o&&A(c),console.error(c instanceof Error?c.message:String(c)),process.exit(1)}})}import It from"axios";function tn(e){var n;return((n=e==null?void 0:e.data)==null?void 0:n.project)??(e==null?void 0:e.project)??e}function on(e){e.command("create-project").description("Create a new project (personal or in a team)").option("--name <name>","Project name (defaults to an auto-generated name)").option("--team <nameOrId>","Create the project in this team").action(async n=>{var o,r,s,i;let t=x();try{let c;try{c=E()}catch{throw new p("Not authenticated. Set MAGICPATH_TOKEN or run `magicpath-ai login`.",{code:"NOT_AUTHENTICATED",suggestion:"Run `magicpath-ai login` or set the MAGICPATH_TOKEN environment variable."})}let a=t?null:T("Creating project...").start();try{let l={...c},g=null;n.team&&(g=await G(n.team,c),l["X-Organization-ID"]=g.id);let m=await It.post(Nt(),{},{headers:l}),f=tn(m.data);if(n.name){let b=await It.patch(Rt(String(f.id)),{data:{name:n.name}},{headers:l});f=tn(b.data)}let d=g?{...f,ownerType:"team",ownerName:g.name}:{...f,ownerType:"personal",ownerName:((o=f.owner)==null?void 0:o.email)??""};a==null||a.succeed(`Created project "${d.name}"${g?` in ${g.name}`:""}`),t&&v({project:d}),console.log(""),console.log(` ID: ${d.id}`),console.log(` Name: ${d.name}`),console.log(` Workspace: ${g?g.name+" (team)":"personal"}`)}catch(l){throw a==null||a.fail("Failed to create project"),l instanceof p?l:It.isAxiosError(l)?((r=l.response)==null?void 0:r.status)===401?new p("Token is invalid or expired. Run `magicpath-ai login`.",{code:"TOKEN_EXPIRED",suggestion:"Run `magicpath-ai login` to re-authenticate."}):((s=l.response)==null?void 0:s.status)===403?new p("Not allowed to create a project in this workspace.",{code:"FORBIDDEN",suggestion:"Verify you are a member of the team and have permission to create projects."}):new p(`API error: ${(i=l.response)==null?void 0:i.status}`):l}}catch(c){throw t&&A(c),c instanceof p&&(console.error(`
|
|
148
|
+
`);n.command("start").description("Start a pending create or edit session before writing code").option("--project <projectId>","Target MagicPath project ID for create").option("--component <componentId>","Existing MagicPath component ID for edit").option("--revision <revisionId>","Start editing this revision. Defaults to the component's currently selected revision.").option("--dir <dir>","Working directory to initialize",".").option("--name <name>","Component name").option("--width <px>","Canvas component width for create").option("--height <px>","Canvas component height for create").action(async t=>{try{let o=M.resolve(t.dir),r=ut(t);if(!!t.project==!!t.component)throw new p("Run code start with exactly one of --project for create or --component for edit.");if(t.component){if(r)throw new p("Use --width and --height with code submit when resizing an existing component.");let d=await Bo(),I=(await V.post(Pt(t.component),{...t.revision?{revisionId:t.revision}:{},...d.length>0?{selectedImages:d}:{}},{headers:E()})).data.data;O.ensureDirSync(o);for(let h of I.editableFiles)gt(o,h);let $=await Ko(o,I.selectedImages),w={mode:"edit",componentId:I.component.id,projectId:I.component.projectId,selectedRevisionId:I.component.selectedRevisionId,baseRevisionId:I.component.baseRevisionId,jobId:I.jobId,generatedName:I.component.generatedName,name:I.component.name,selectedImages:$,editableFiles:I.editableFiles.map(h=>({path:h.path,sha256:pe(h.content)}))};Ie(o,w);let u={dir:o,manifestPath:He(o),...w,status:"pending",scaffoldedPaths:I.editableFiles.map(h=>h.path),selectedImages:$};x()&&v(u),console.log(`Started pending edit ${w.selectedRevisionId} for component ${w.componentId} in ${o}`);return}let s=t.project;if(!s)throw new p("Create sessions require --project.");let i=await Bo(s),a=(await V.post(Be(),{projectId:s,...t.name?{name:t.name}:{},...r?{dimensions:r}:{},...i.length>0?{selectedImages:i}:{}},{headers:E()})).data.data,l=a.editableFiles??[];O.ensureDirSync(o);for(let d of l)gt(o,d);let g=await Ko(o,a.selectedImages),m={mode:"create",componentId:a.componentId,projectId:s,selectedRevisionId:a.revisionId,jobId:a.jobId,generatedName:a.generatedName,name:t.name,dimensions:r,selectedImages:g,editableFiles:l.map(d=>({path:d.path,sha256:pe(d.content)}))};Ie(o,m);let f={dir:o,manifestPath:He(o),...m,status:"pending",scaffoldedPaths:l.map(d=>d.path),selectedImages:g};x()&&v(f),console.log(`Started pending component ${m.componentId} in ${o}`+(l.length>0?` (scaffolded ${l.length} file${l.length===1?"":"s"})`:""))}catch(o){be(o)}}),n.command("context").description("Fetch editable files for an existing MagicPath component").argument("<componentId>","MagicPath component ID").option("--dir <dir>","Working directory to write",".").option("--revision <revisionId>","Pull this revision of the component. Defaults to the component's currently selected revision.").action(async(t,o)=>{try{let r=M.resolve(o.dir);O.ensureDirSync(r);let s=o.revision?`${Ke(t)}?revisionId=${encodeURIComponent(o.revision)}`:Ke(t),c=(await V.get(s,{headers:E()})).data.data;for(let l of c.editableFiles)gt(r,l);let a={dir:r,readOnly:!0,component:c.component,editableFiles:c.editableFiles.map(l=>({path:l.path,sha256:pe(l.content)}))};x()&&v(a),console.log(`Fetched ${c.editableFiles.length} read-only editable file(s) into ${r}. Run \`magicpath-ai code start --component ${t} --dir ${r}\` before submitting edits.`)}catch(r){be(r)}}),n.command("submit").description("Submit changed editable files for the component in this working directory").option("--dir <dir>","Working directory containing magicpath-code.json",".").option("--wait","Wait for the build job to finish",!1).option("--interval <ms>","Polling interval when --wait is set","2000").option("--width <px>","Updated canvas component width").option("--height <px>","Updated canvas component height").action(async t=>{try{let o=M.resolve(t.dir),r=sr(o),s=ut(t);Vo(o);let i=ir(o,r),c=ar(o,r);if(r.mode==="create"&&!i.some(m=>m.path==="src/App.tsx"))throw new p("Create submit requires src/App.tsx in the working directory.");if(i.length===0&&c.length===0&&!s){let m={status:"unchanged",componentId:r.componentId,revisionId:r.selectedRevisionId};x()&&v(m),console.log("No editable file changes to submit.");return}let l=r.mode==="create"||!!r.baseRevisionId&&r.selectedRevisionId!==r.baseRevisionId?await V.post(Xe(r.componentId,r.selectedRevisionId),{files:i.map(m=>({path:m.path,content:m.content,encoding:m.encoding,mimeType:m.mimeType})),contextJobId:r.jobId,...s?{dimensions:s}:{},...r.mode==="edit"?{deletedPaths:c}:{}},{headers:E()}):await V.post(Tt(r.componentId),{baseRevisionId:r.baseRevisionId??r.selectedRevisionId,files:i.map(m=>({path:m.path,content:m.content,encoding:m.encoding,mimeType:m.mimeType,baseSha256:m.baseSha256})),deletedPaths:c,...s?{dimensions:s}:{}},{headers:E()}),g=l.data.data;if(t.wait&&(g=await zo(l.data.data.jobId,Number(t.interval))),g.status==="completed"){let m=ve(o),f={...r,mode:"edit",jobId:l.data.data.jobId,selectedRevisionId:g.revisionId,baseRevisionId:g.revisionId,...s?{dimensions:s}:{},editableFiles:m.map(d=>({path:d.path,sha256:d.sha256??pe(d.content)}))};Ie(o,f)}x()&&v({...g,jobId:l.data.data.jobId,deletedPaths:c,...s?{dimensions:s}:{}}),console.log(`Submitted ${i.length} file(s)`+(c.length>0?` and ${c.length} deletion(s)`:"")+`. Job ${l.data.data.jobId}: ${g.status}`)}catch(o){be(o)}}),n.command("create").description("Create a new MagicPath component from local editable files").requiredOption("--project <projectId>","Target MagicPath project ID").option("--dir <dir>","Working directory containing src/App.tsx",".").option("--name <name>","Component name").option("--wait","Wait for the build job to finish",!1).option("--width <px>","Canvas component width").option("--height <px>","Canvas component height").action(async t=>{try{let o=M.resolve(t.dir),r=ut(t);Vo(o);let s=ve(o);if(!s.some(g=>g.path==="src/App.tsx"))throw new p("Create requires src/App.tsx in the working directory.");let i=await V.post(Be(),{projectId:t.project,...t.name?{name:t.name}:{},...r?{dimensions:r}:{}},{headers:E()}),c={mode:"create",componentId:i.data.data.componentId,projectId:t.project,selectedRevisionId:i.data.data.revisionId,jobId:i.data.data.jobId,generatedName:i.data.data.generatedName,name:t.name,dimensions:r,editableFiles:[]};Ie(o,c);let a=await V.post(Xe(c.componentId,c.selectedRevisionId),{files:s.map(g=>({path:g.path,content:g.content,encoding:g.encoding,mimeType:g.mimeType})),contextJobId:c.jobId,...r?{dimensions:r}:{}},{headers:E()}),l=a.data.data;t.wait&&(l=await zo(a.data.data.jobId,2e3)),l.status==="completed"&&Ie(o,{...c,mode:"edit",jobId:a.data.data.jobId,selectedRevisionId:l.revisionId,...r?{dimensions:r}:{},editableFiles:s.map(g=>({path:g.path,sha256:g.sha256??pe(g.content)}))}),x()&&v({...l,jobId:a.data.data.jobId,...r?{dimensions:r}:{}}),console.log(`Created component ${a.data.data.componentId}. Job ${a.data.data.jobId}: ${l.status}`)}catch(o){be(o)}}),n.command("status").description("Fetch external-agent build job status").argument("<jobId>","External agent job ID").action(async t=>{try{let o=await V.get(qe(t),{headers:E()});x()&&v(o.data.data),console.log(`${t}: ${o.data.data.status}`)}catch(o){be(o)}})}import xe from"axios";import Yo from"fs";import yt from"path";import{imageSize as lr}from"image-size";var Qo=512;async function mr(e){if(/^https?:\/\//i.test(e)){let t=await xe.get(e,{responseType:"arraybuffer"}),o=yt.basename(new URL(e).pathname)||"image";return{buffer:Buffer.from(t.data),fileName:o}}let n=yt.resolve(e);if(!Yo.existsSync(n))throw new Error(`Image file not found: ${n}`);return{buffer:Yo.readFileSync(n),fileName:yt.basename(n)}}function Ge(e){if(e===void 0)return;let n=Number(e);if(!Number.isFinite(n))throw new Error(`Invalid number: ${e}`);return n}function en(e){let n=e.command("image").description("Add and list images on a project canvas");n.command("add").description("Add an image to a project canvas from a local file path or a URL").argument("<projectId>","The id of the project to add the image to").argument("<pathOrUrl>","A local image file path or an http(s) URL").option("--name <name>","Display name for the image (defaults to the file name)").option("--x <x>","Canvas x position (default 0)").option("--y <y>","Canvas y position (default 0)").option("--width <width>","Width in canvas units (defaults to the intrinsic width)").option("--height <height>","Height in canvas units (defaults to the intrinsic height)").action(async(t,o,r)=>{var c,a;let s=x(),i=s?null:T("Adding image to project...").start();try{let l=E(),{buffer:g,fileName:m}=await mr(o),f=Ge(r.width),d=Ge(r.height);if(f===void 0||d===void 0)try{let P=lr(g);f=f??P.width,d=d??P.height}catch{}f=f??Qo,d=d??Qo;let b={x:Ge(r.x)??0,y:Ge(r.y)??0,z:0,width:f,height:d},I=r.name??(m.replace(/\.[^/.]+$/,"")||m),$=await xe.get(St(),{headers:l,params:{filename:m,content_type:"image/*",make_public:"true"}}),{upload_url:w,upload_token:u}=$.data;await xe.put(w,g,{headers:{"Content-Type":"image/*","x-goog-acl":"public-read"}});let y=(a=(c=(await xe.post(Ye(t),{name:I,position:b,upload_token:u},{headers:l})).data)==null?void 0:c.data)==null?void 0:a.image;i==null||i.succeed("Image added to project"),s&&v({image:y}),console.log(`Added "${(y==null?void 0:y.name)??I}" (${(y==null?void 0:y.id)??"unknown id"})`),y!=null&&y.url&&console.log(y.url)}catch(l){i==null||i.fail("Failed to add image"),s&&A(l),console.error(l instanceof Error?l.message:String(l)),process.exit(1)}}),n.command("list").description("List the images on a project canvas").argument("<projectId>","The id of the project").action(async t=>{var s,i;let o=x(),r=o?null:T("Fetching images...").start();try{let c=E(),l=((i=(s=(await xe.get(Ye(t),{headers:c})).data)==null?void 0:s.data)==null?void 0:i.images)??[];if(r==null||r.succeed(`Found ${l.length} image(s)`),o&&v({images:l}),l.length===0){console.log("No images in this project.");return}for(let g of l)console.log(`- ${g.name} (${g.id})${g.url?` \u2014 ${g.url}`:""}`)}catch(c){r==null||r.fail("Failed to list images"),o&&A(c),console.error(c instanceof Error?c.message:String(c)),process.exit(1)}})}import It from"axios";function tn(e){var n;return((n=e==null?void 0:e.data)==null?void 0:n.project)??(e==null?void 0:e.project)??e}function on(e){e.command("create-project").description("Create a new project (personal or in a team)").option("--name <name>","Project name (defaults to an auto-generated name)").option("--team <nameOrId>","Create the project in this team").action(async n=>{var o,r,s,i;let t=x();try{let c;try{c=E()}catch{throw new p("Not authenticated. Set MAGICPATH_TOKEN or run `magicpath-ai login`.",{code:"NOT_AUTHENTICATED",suggestion:"Run `magicpath-ai login` or set the MAGICPATH_TOKEN environment variable."})}let a=t?null:T("Creating project...").start();try{let l={...c},g=null;n.team&&(g=await G(n.team,c),l["X-Organization-ID"]=g.id);let m=await It.post(Nt(),{},{headers:l}),f=tn(m.data);if(n.name){let b=await It.patch(Rt(String(f.id)),{data:{name:n.name}},{headers:l});f=tn(b.data)}let d=g?{...f,ownerType:"team",ownerName:g.name}:{...f,ownerType:"personal",ownerName:((o=f.owner)==null?void 0:o.email)??""};a==null||a.succeed(`Created project "${d.name}"${g?` in ${g.name}`:""}`),t&&v({project:d}),console.log(""),console.log(` ID: ${d.id}`),console.log(` Name: ${d.name}`),console.log(` Workspace: ${g?g.name+" (team)":"personal"}`)}catch(l){throw a==null||a.fail("Failed to create project"),l instanceof p?l:It.isAxiosError(l)?((r=l.response)==null?void 0:r.status)===401?new p("Token is invalid or expired. Run `magicpath-ai login`.",{code:"TOKEN_EXPIRED",suggestion:"Run `magicpath-ai login` to re-authenticate."}):((s=l.response)==null?void 0:s.status)===403?new p("Not allowed to create a project in this workspace.",{code:"FORBIDDEN",suggestion:"Verify you are a member of the team and have permission to create projects."}):new p(`API error: ${(i=l.response)==null?void 0:i.status}`):l}}catch(c){throw t&&A(c),c instanceof p&&(console.error(`
|
|
149
149
|
${c.message}`),process.exit(1)),c}})}var fr=pr(ur(import.meta.url)),hr=JSON.parse(dr(gr(fr,"..","package.json"),"utf8"));jt(hr.version);xt();process.argv.length<=2&&(Kt(B),process.exit(0));N.name("magicpath").description("").version(B).option("-o, --output <format>","Output format: json").hook("preAction",e=>{e.optsWithGlobals().output==="json"&&Ct(!0)});lo(N);vo(N);bo(N);$o(N);Co(N);jo(N);Eo(N);Ao(N);Po(N);So(N);Ro(N);No(N);Oo(N);Mo(N);Uo(N);_o(N);Lo(N);Ho(N);Zo(N);en(N);on(N);N.parse();
|