@fugood/bricks-cli 2.24.0-beta.39 → 2.24.0-beta.40
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/lib/465.js +1 -1
- package/lib/612.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
package/lib/465.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const __webpack_esm_id__=465;export const __webpack_esm_ids__=[465];export const __webpack_esm_modules__={16465:(e,i,t)=>{t.d(i,{initProject:()=>w}),t.r(i);var n,r,o=t(99436),l=t(16928),c=t(88568),a=t(29790),s=t(10750),u=t(60637),d=t(74752),p=t(50700),g=t(79896),y=t(35317),m=e=>{try{return(0,y.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},f=(e,i,t)=>new Promise((n,r)=>{var o=[e,...i].join(" "),l=(0,y.spawn)(o,[],{cwd:t,stdio:"pipe",shell:!0}),c=[];l.stderr.on("data",e=>c.push(e)),l.on("close",e=>{if(0===e)n();else{var i=Buffer.concat(c).toString().trim();r(new Error(i||`Command failed with code ${e}`))}}),l.on("error",r)}),h=(n=o(function*(e,i){try{var n=(yield Promise.resolve().then(t.bind(t,79491))).format;return(yield n(i,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,i){return n.apply(this,arguments)}),v=(r=o(function*(e,i,t){var n=t.client,r=t.output;if(!n)throw new Error("client is required");if(!r)throw new Error("output directory is required");var c="application"===e,a=c?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",u=c?n.queries.applicationProject:n.queries.moduleProject,d=(yield n.query(u,{id:i,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini}))[a];if(!d?.files)throw new Error(`${e} project not found`);var p="bricks-
|
|
1
|
+
export const __webpack_esm_id__=465;export const __webpack_esm_ids__=[465];export const __webpack_esm_modules__={16465:(e,i,t)=>{t.d(i,{initProject:()=>w}),t.r(i);var n,r,o=t(99436),l=t(16928),c=t(88568),a=t(29790),s=t(10750),u=t(60637),d=t(74752),p=t(50700),g=t(79896),y=t(35317),m=e=>{try{return(0,y.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},f=(e,i,t)=>new Promise((n,r)=>{var o=[e,...i].join(" "),l=(0,y.spawn)(o,[],{cwd:t,stdio:"pipe",shell:!0}),c=[];l.stderr.on("data",e=>c.push(e)),l.on("close",e=>{if(0===e)n();else{var i=Buffer.concat(c).toString().trim();r(new Error(i||`Command failed with code ${e}`))}}),l.on("error",r)}),h=(n=o(function*(e,i){try{var n=(yield Promise.resolve().then(t.bind(t,79491))).format;return(yield n(i,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,i){return n.apply(this,arguments)}),v=(r=o(function*(e,i,t){var n=t.client,r=t.output;if(!n)throw new Error("client is required");if(!r)throw new Error("output directory is required");var c="application"===e,a=c?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",u=c?n.queries.applicationProject:n.queries.moduleProject,d=(yield n.query(u,{id:i,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini}))[a];if(!d?.files)throw new Error(`${e} project not found`);var p="bricks-ctor",y=d.files.find(e=>"application.json"===e.name);if(y)try{var v=JSON.parse(y.input);p=s(v.name||"bricks-ctor")}catch{}var b=l.resolve(r,p);if(g.existsSync(b))throw new Error(`Directory already exists: ${b}`);g.mkdirSync(b,{recursive:!0});var A,w=yield Promise.all(d.files.map((A=o(function*(e){var i=l.join(b,e.name),t=e.input;return e.formatable&&(t=yield h(t,i)),{...e,filePath:i,content:t}}),function(e){return A.apply(this,arguments)})));w.forEach(e=>{var i=l.dirname(e.filePath);g.existsSync(i)||g.mkdirSync(i,{recursive:!0}),g.writeFileSync(e.filePath,e.content)});var k=m("bun"),_=m("git"),j=!1,S=!1;if(!1!==t.install&&k)try{yield f("bun",["install"],b),j=!0}catch{}if(!1!==t.git&&_)try{yield f("git",["init"],b),yield f("git",["add","."],b),yield f("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],b),S=!0}catch{}return{success:!0,path:b,files:d.files.length,bunInstalled:j,gitInitialized:S}}),function(e,i,t){return r.apply(this,arguments)}),b=()=>{var e=(0,d.getCurrentProfile)(),i=(0,d.getToken)(e);return i||(console.error(c.Ay.red("Not logged in. Use `bricks auth login` first.")),process.exit(1)),(0,p.createClient)((0,d.getBaseUrl)(),i)},A=function(){var e=o(function*(e,i){console.log(c.Ay.bold.cyan(`\nInitialize BRICKS Project: ${i}\n`));var t=yield(0,u.kv)({message:"Select files to include:",choices:[{name:"GitHub Actions workflow (.github/workflows/ci.yml)",value:"githubActions",checked:!1!==e.githubActions},{name:"AGENTS.md",value:"agents",checked:!1!==e.agents},{name:"CLAUDE.md",value:"claude",checked:!1!==e.claude},{name:"GEMINI.md",value:"gemini",checked:!0===e.gemini}]}),n=yield(0,u.kv)({message:"Select post-generation steps:",choices:[{name:"Run bun install",value:"install",checked:!1!==e.install},{name:"Initialize git repository",value:"git",checked:!1!==e.git}]}),r=yield(0,u.hF)({message:"Output directory:",default:e.output||process.cwd()});return{githubActions:t.includes("githubActions"),agents:t.includes("agents"),claude:t.includes("claude"),gemini:t.includes("gemini"),install:n.includes("install"),git:n.includes("git"),output:r}});return function(i,t){return e.apply(this,arguments)}}(),w=function(){var e=o(function*(e,i,t){var n=b(),r=t.json,o=t.yes||r,u="application"===e,d=u?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",p=u?n.queries.applicationProject:n.queries.moduleProject,g=r?null:(0,a.default)(`Fetching ${e} info...`).start(),y="bricks-ctor";try{var m=(yield n.query(p,{id:i,buildApplicationOnly:!0}))[d];if(m?.files){var f=m.files.find(e=>"application.json"===e.name);if(f)try{var h=JSON.parse(f.input);y=s(h.name||"bricks-ctor")}catch{}}g&&g.stop()}catch{g&&g.stop()}var w={...t};if(!o)try{var k=yield A(t,y);w={...t,...k}}catch{console.log(c.Ay.yellow("\nCancelled")),process.exit(0)}g=r?null:(0,a.default)(`Fetching ${e} project...`).start();try{var _=yield v(e,i,{client:n,output:w.output||process.cwd(),install:w.install,git:w.git,githubActions:w.githubActions,agents:w.agents,claude:w.claude,gemini:w.gemini});g&&g.succeed(`Project created: ${c.Ay.green(_.path)} (${_.files} files)`),r?console.log(JSON.stringify(_)):(console.log(""),console.log(c.Ay.bold.green("Project initialized successfully!")),console.log(""),console.log(c.Ay.bold("Next steps:")),console.log(c.Ay.gray(` cd ${l.basename(_.path)}`)),_.bunInstalled||console.log(c.Ay.gray(" bun install")),console.log(c.Ay.gray(" bun preview")),console.log(""),console.log(c.Ay.gray(`For more information, see ${l.basename(_.path)}/README.md`)))}catch(i){r?console.error(JSON.stringify({error:i.message})):g?g.fail(`Failed to initialize ${e} project: ${i.message}`):console.error(c.Ay.red(`Failed to initialize ${e} project: ${i.message}`)),process.exit(1)}});return function(i,t,n){return e.apply(this,arguments)}}()}};
|
package/lib/612.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const __webpack_esm_id__=612;export const __webpack_esm_ids__=[612];export const __webpack_esm_modules__={10750:(e,l,t)=>{var n=t(93640)(function(e,l,t){return e+(t?"-":"")+l.toLowerCase()});e.exports=n},59612:(e,l,t)=>{t.d(l,{App:()=>je,AppDetail:()=>V,AppList:()=>G,CONTROL_ACTIONS:()=>x,DeviceControl:()=>M,DeviceDetail:()=>P,DeviceList:()=>O,DeviceScreenshot:()=>N,DeviceStatus:()=>v,Footer:()=>T,GroupDetail:()=>z,GroupList:()=>$,Header:()=>D,Loading:()=>b,MainMenu:()=>U,MediaBoxDetail:()=>W,MediaBoxList:()=>Y,MediaFileDetail:()=>J,MediaFileList:()=>X,ModuleDetail:()=>H,ModuleList:()=>F,ONLINE_THRESHOLD_MS:()=>h,ProjectInitView:()=>pe,ShortEditEditor:()=>ne,VIEWS:()=>u,runInteractiveMode:()=>De}),t.r(l);var n=t(51649),i=t(8498),o=t(29557),r=t(99436),a=t(68832),s=t(50700),c=t(74752),d=t(47336),u={MAIN:"main",DEVICES:"devices",DEVICE_DETAIL:"device_detail",DEVICE_CONTROL:"device_control",DEVICE_SCREENSHOT:"device_screenshot",APPS:"apps",APP_DETAIL:"app_detail",APP_SHORT_EDIT:"app_short_edit",APP_PROJECT_INIT:"app_project_init",MODULES:"modules",MODULE_DETAIL:"module_detail",MODULE_SHORT_EDIT:"module_short_edit",MODULE_PROJECT_INIT:"module_project_init",GROUPS:"groups",GROUP_DETAIL:"group_detail",MEDIA_BOXES:"media_boxes",MEDIA_BOX_DETAIL:"media_box_detail",MEDIA_FILES:"media_files",MEDIA_FILE_DETAIL:"media_file_detail"},x=[{label:"Refresh Application",value:"refresh"},{label:"Clear Cache",value:"clear-cache"},{label:"Take Screenshot",value:"take-screenshot"},{label:"Open System Menu",value:"system-menu-open"},{label:"Close System Menu",value:"system-menu-close"},{label:"Open Debug Panel",value:"debug-panel-open"},{label:"Close Debug Panel",value:"debug-panel-close"},{label:"Enable Logging",value:"logging-on"},{label:"Disable Logging",value:"logging-off"},{label:"← Back",value:"back"}],h=3e5,g=t(47661);const f=function({type:e="dots"}){const[l,t]=(0,n.useState)(0),o=g[e];return(0,n.useEffect)(()=>{const e=setInterval(()=>{t(e=>e===o.frames.length-1?0:e+1)},o.interval);return()=>{clearInterval(e)}},[o]),n.default.createElement(i.Text,null,o.frames[l])};var m=t(71178),p=(e,l=!0)=>{var t=Math.floor(60),i=(0,n.useState)(t),o=a(i,2),r=o[0],s=o[1],c=(0,n.useState)(null),d=a(c,2),u=d[0],x=d[1],h=(0,n.useRef)(e);(0,n.useEffect)(()=>{h.current=e},[e]);var g=(0,n.useCallback)(()=>{s(t),x(Date.now())},[t]);return(0,n.useEffect)(()=>{if(l){var e=setInterval(()=>{s(e=>e<=1?(h.current?.(),x(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[l,t]),(0,n.useEffect)(()=>{l&&(s(t),x(Date.now()))},[l,t]),{countdown:r,lastRefreshTime:u,resetCountdown:g}},j=({countdown:e,lastRefreshTime:l})=>(0,m.jsx)(i.Box,{children:(0,m.jsxs)(i.Text,{color:"gray",children:["Next refresh in ",(0,m.jsxs)(i.Text,{color:"cyan",children:[e,"s"]}),l&&(0,m.jsxs)(i.Text,{color:"gray",children:[" (last: ",l?new Date(l).toLocaleTimeString():null,")"]})]})}),D=({workspace:e,view:l})=>(0,m.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,m.jsx)(i.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Workspace: "}),(0,m.jsx)(i.Text,{color:"green",children:e?.name||"Not connected"}),(0,m.jsx)(i.Text,{color:"gray",children:" | View: "}),(0,m.jsx)(i.Text,{color:"yellow",children:l})]}),(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)})]}),T=()=>(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)}),(0,m.jsxs)(i.Text,{color:"gray",children:["Press ",(0,m.jsx)(i.Text,{color:"cyan",children:"q"})," to quit, ",(0,m.jsx)(i.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),b=({text:e})=>(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(f,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",e||"Loading..."]})]}),v=({lastAliveTime:e})=>{if(!e)return(0,m.jsx)(i.Text,{color:"gray",children:"○ Unknown"});var l=Date.now()-new Date(e).getTime();if(l<=h)return(0,m.jsx)(i.Text,{color:"green",children:"● Online"});var t=Math.floor(l/6e4);if(t<60)return(0,m.jsxs)(i.Text,{color:"yellow",children:["○ Offline (",t,"m ago)"]});var n=Math.floor(t/60);if(n<24)return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",n,"h ago)"]});var o=Math.floor(n/24);return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",o,"d ago)"]})},_=t(29122);const y={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"█",squareDarkShade:"▓",squareMediumShade:"▒",squareLightShade:"░",squareTop:"▀",squareBottom:"▄",squareLeft:"▌",squareRight:"▐",squareCenter:"■",bullet:"●",dot:"․",ellipsis:"…",pointerSmall:"›",triangleUp:"▲",triangleUpSmall:"▴",triangleDown:"▼",triangleDownSmall:"▾",triangleLeftSmall:"◂",triangleRightSmall:"▸",home:"⌂",heart:"♥",musicNote:"♪",musicNoteBeamed:"♫",arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",arrowLeftRight:"↔",arrowUpDown:"↕",almostEqual:"≈",notEqual:"≠",lessOrEqual:"≤",greaterOrEqual:"≥",identical:"≡",infinity:"∞",subscriptZero:"₀",subscriptOne:"₁",subscriptTwo:"₂",subscriptThree:"₃",subscriptFour:"₄",subscriptFive:"₅",subscriptSix:"₆",subscriptSeven:"₇",subscriptEight:"₈",subscriptNine:"₉",oneHalf:"½",oneThird:"⅓",oneQuarter:"¼",oneFifth:"⅕",oneSixth:"⅙",oneEighth:"⅛",twoThirds:"⅔",twoFifths:"⅖",threeQuarters:"¾",threeFifths:"⅗",threeEighths:"⅜",fourFifths:"⅘",fiveSixths:"⅚",fiveEighths:"⅝",sevenEighths:"⅞",line:"─",lineBold:"━",lineDouble:"═",lineDashed0:"┄",lineDashed1:"┅",lineDashed2:"┈",lineDashed3:"┉",lineDashed4:"╌",lineDashed5:"╍",lineDashed6:"╴",lineDashed7:"╶",lineDashed8:"╸",lineDashed9:"╺",lineDashed10:"╼",lineDashed11:"╾",lineDashed12:"−",lineDashed13:"–",lineDashed14:"‐",lineDashed15:"⁃",lineVertical:"│",lineVerticalBold:"┃",lineVerticalDouble:"║",lineVerticalDashed0:"┆",lineVerticalDashed1:"┇",lineVerticalDashed2:"┊",lineVerticalDashed3:"┋",lineVerticalDashed4:"╎",lineVerticalDashed5:"╏",lineVerticalDashed6:"╵",lineVerticalDashed7:"╷",lineVerticalDashed8:"╹",lineVerticalDashed9:"╻",lineVerticalDashed10:"╽",lineVerticalDashed11:"╿",lineDownLeft:"┐",lineDownLeftArc:"╮",lineDownBoldLeftBold:"┓",lineDownBoldLeft:"┒",lineDownLeftBold:"┑",lineDownDoubleLeftDouble:"╗",lineDownDoubleLeft:"╖",lineDownLeftDouble:"╕",lineDownRight:"┌",lineDownRightArc:"╭",lineDownBoldRightBold:"┏",lineDownBoldRight:"┎",lineDownRightBold:"┍",lineDownDoubleRightDouble:"╔",lineDownDoubleRight:"╓",lineDownRightDouble:"╒",lineUpLeft:"┘",lineUpLeftArc:"╯",lineUpBoldLeftBold:"┛",lineUpBoldLeft:"┚",lineUpLeftBold:"┙",lineUpDoubleLeftDouble:"╝",lineUpDoubleLeft:"╜",lineUpLeftDouble:"╛",lineUpRight:"└",lineUpRightArc:"╰",lineUpBoldRightBold:"┗",lineUpBoldRight:"┖",lineUpRightBold:"┕",lineUpDoubleRightDouble:"╚",lineUpDoubleRight:"╙",lineUpRightDouble:"╘",lineUpDownLeft:"┤",lineUpBoldDownBoldLeftBold:"┫",lineUpBoldDownBoldLeft:"┨",lineUpDownLeftBold:"┥",lineUpBoldDownLeftBold:"┩",lineUpDownBoldLeftBold:"┪",lineUpDownBoldLeft:"┧",lineUpBoldDownLeft:"┦",lineUpDoubleDownDoubleLeftDouble:"╣",lineUpDoubleDownDoubleLeft:"╢",lineUpDownLeftDouble:"╡",lineUpDownRight:"├",lineUpBoldDownBoldRightBold:"┣",lineUpBoldDownBoldRight:"┠",lineUpDownRightBold:"┝",lineUpBoldDownRightBold:"┡",lineUpDownBoldRightBold:"┢",lineUpDownBoldRight:"┟",lineUpBoldDownRight:"┞",lineUpDoubleDownDoubleRightDouble:"╠",lineUpDoubleDownDoubleRight:"╟",lineUpDownRightDouble:"╞",lineDownLeftRight:"┬",lineDownBoldLeftBoldRightBold:"┳",lineDownLeftBoldRightBold:"┯",lineDownBoldLeftRight:"┰",lineDownBoldLeftBoldRight:"┱",lineDownBoldLeftRightBold:"┲",lineDownLeftRightBold:"┮",lineDownLeftBoldRight:"┭",lineDownDoubleLeftDoubleRightDouble:"╦",lineDownDoubleLeftRight:"╥",lineDownLeftDoubleRightDouble:"╤",lineUpLeftRight:"┴",lineUpBoldLeftBoldRightBold:"┻",lineUpLeftBoldRightBold:"┷",lineUpBoldLeftRight:"┸",lineUpBoldLeftBoldRight:"┹",lineUpBoldLeftRightBold:"┺",lineUpLeftRightBold:"┶",lineUpLeftBoldRight:"┵",lineUpDoubleLeftDoubleRightDouble:"╩",lineUpDoubleLeftRight:"╨",lineUpLeftDoubleRightDouble:"╧",lineUpDownLeftRight:"┼",lineUpBoldDownBoldLeftBoldRightBold:"╋",lineUpDownBoldLeftBoldRightBold:"╈",lineUpBoldDownLeftBoldRightBold:"╇",lineUpBoldDownBoldLeftRightBold:"╊",lineUpBoldDownBoldLeftBoldRight:"╉",lineUpBoldDownLeftRight:"╀",lineUpDownBoldLeftRight:"╁",lineUpDownLeftBoldRight:"┽",lineUpDownLeftRightBold:"┾",lineUpBoldDownBoldLeftRight:"╂",lineUpDownLeftBoldRightBold:"┿",lineUpBoldDownLeftBoldRight:"╃",lineUpBoldDownLeftRightBold:"╄",lineUpDownBoldLeftBoldRight:"╅",lineUpDownBoldLeftRightBold:"╆",lineUpDoubleDownDoubleLeftDoubleRightDouble:"╬",lineUpDoubleDownDoubleLeftRight:"╫",lineUpDownLeftDoubleRightDouble:"╪",lineCross:"╳",lineBackslash:"╲",lineSlash:"╱"},B={tick:"✔",info:"ℹ",warning:"⚠",cross:"✘",squareSmall:"◻",squareSmallFilled:"◼",circle:"◯",circleFilled:"◉",circleDotted:"◌",circleDouble:"◎",circleCircle:"ⓞ",circleCross:"ⓧ",circlePipe:"Ⓘ",radioOn:"◉",radioOff:"◯",checkboxOn:"☒",checkboxOff:"☐",checkboxCircleOn:"ⓧ",checkboxCircleOff:"Ⓘ",pointer:"❯",triangleUpOutline:"△",triangleLeft:"◀",triangleRight:"▶",lozenge:"◆",lozengeOutline:"◇",hamburger:"☰",smiley:"㋡",mustache:"෴",star:"★",play:"▶",nodejs:"⬢",oneSeventh:"⅐",oneNinth:"⅑",oneTenth:"⅒"},S={...y,...B},E={...y,tick:"√",info:"i",warning:"‼",cross:"×",squareSmall:"□",squareSmallFilled:"■",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(○)",circleCross:"(×)",circlePipe:"(│)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[×]",checkboxOff:"[ ]",checkboxCircleOn:"(×)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"∆",triangleLeft:"◄",triangleRight:"►",lozenge:"♦",lozengeOutline:"◊",hamburger:"≡",smiley:"☺",mustache:"┌─┐",star:"✶",play:"►",nodejs:"♦",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},w=(0,_.A)(),L=w?S:E;Object.entries(B);const I=function({isSelected:e=!1}){return n.default.createElement(i.Box,{marginRight:1},e?n.default.createElement(i.Text,{color:"blue"},L.pointer):n.default.createElement(i.Text,null," "))};const A=function({isSelected:e=!1,label:l}){return n.createElement(i.Text,{color:e?"blue":void 0},l)};var C=t(57975);function R(e,l){if(!Array.isArray(e))throw new TypeError(`Expected an array, got \`${typeof e}\`.`);if(!Number.isSafeInteger(l))throw new TypeError(`The \`steps\` parameter must be an integer, got ${l}.`);const{length:t}=e;if(0===t)return[...e];const n=(l%t+t)%t;return 0===n?[...e]:[...e.slice(-n),...e.slice(0,-n)]}const k=function({items:e=[],isFocused:l=!0,initialIndex:t=0,indicatorComponent:o=I,itemComponent:r=A,limit:a,onSelect:s,onHighlight:c}){const d="number"==typeof a&&e.length>a,u=d?Math.min(a,e.length):e.length,x=u-1,[h,g]=(0,n.useState)(t>x?x-t:0),[f,m]=(0,n.useState)(t?t>x?x:t:0),p=(0,n.useRef)(e);(0,n.useEffect)(()=>{(0,C.isDeepStrictEqual)(p.current.map(e=>e.value),e.map(e=>e.value))||(g(0),m(0)),p.current=e},[e]),(0,i.useInput)((0,n.useCallback)((l,t)=>{if("k"===l||t.upArrow){const l=(d?u:e.length)-1,t=0===f,n=t?h+1:h,i=t?d?f:l:f-1;g(n),m(i);const o=d?R(e,n).slice(0,u):e;"function"==typeof c&&c(o[i])}if("j"===l||t.downArrow){const l=f===(d?u:e.length)-1,t=l?h-1:h,n=l?d?f:0:f+1;g(t),m(n);const i=d?R(e,t).slice(0,u):e;"function"==typeof c&&c(i[n])}if(/^[1-9]$/.test(l)){const t=Number.parseInt(l,10)-1,n=d?R(e,h).slice(0,u):e;if(t>=0&&t<n.length){const e=n[t];e&&s?.(e)}}if(t.return){const l=d?R(e,h).slice(0,u):e;"function"==typeof s&&s(l[f])}},[d,u,h,f,e,s,c]),{isActive:l});const j=d?R(e,h).slice(0,u):e;return n.default.createElement(i.Box,{flexDirection:"column"},j.map((e,l)=>{const t=l===f;return n.default.createElement(i.Box,{key:e.key??e.value},n.default.createElement(o,{isSelected:t}),n.default.createElement(r,{...e,isSelected:t}))}))};var U=({onSelect:e,mediaEnabled:l})=>{var t=[{label:"Devices",value:u.DEVICES},{label:"Applications",value:u.APPS},{label:"Modules",value:u.MODULES},{label:"Device Groups",value:u.GROUPS},...l?[{label:"Media Flow",value:u.MEDIA_BOXES}]:[],{label:"Exit",value:"exit"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,m.jsx)(k,{items:t,onSelect:e})]})},O=({devices:e,loading:l,onSelect:t,countdown:n,lastRefreshTime:o})=>{if(l)return(0,m.jsx)(b,{text:"Loading devices..."});if(!e?.length)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No devices found"}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]});var r=[...e.map(e=>({label:`${(e=>{if(!e)return"○ Unknown";var l=Date.now()-new Date(e).getTime();if(l<=h)return"● Online";var t=Math.floor(l/6e4);if(t<60)return`○ ${t}m ago`;var n=Math.floor(t/60);return n<24?`○ ${n}h ago`:`○ ${Math.floor(n/24)}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time)} - ${e.name||e.device_name}`,value:e._id,device:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]}),(0,m.jsx)(k,{items:r,onSelect:t})]})},P=({device:e,loading:l,error:t,onSelect:n,mediaEnabled:o,countdown:r,lastRefreshTime:a})=>{if(l)return(0,m.jsx)(b,{text:"Loading device..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...o?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,d=c?.screen,u=c?.update,x=c?.local_sync;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:r,lastRefreshTime:a})]}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Status: "}),(0,m.jsx)(v,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Application"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),d&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screen"}),d.resolution&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Resolution: ",d.resolution.width,"x",d.resolution.height,d.resolution.scale&&` @${d.resolution.scale}x`]}),d.orientation&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Orientation: ",d.orientation]}),d.touch&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Touch:"," ",d.touch.available?`Yes (${d.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),x&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Role: ",x.is_main?"Main":"Peer",x.peer_count>0&&` | Peers: ${x.peer_count}`,x.mean_latency&&` | Latency: ${x.mean_latency}ms`]})]}),u&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Update"}),(0,m.jsxs)(i.Text,{color:u.need_update?"yellow":"gray",children:[" ","Status: ",u.need_update?"⚠ Update available":"✓ Up to date"]}),u.current_version&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Version: ",u.current_version]})]})]}),(0,m.jsx)(k,{items:s,onSelect:n})]})},M=({device:e,onSelect:l,controlling:t,controlResult:n})=>(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&(0,m.jsx)(b,{text:"Sending command..."}),n&&(0,m.jsx)(i.Text,{color:n.success?"green":"red",children:n.message}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:x,onSelect:l})})]}),N=({device:e,screenshot:l,loading:t,error:n,onSelect:r})=>{var a=l?.file?.meta,s=null!=a?.originalWidth&&null!=a?.originalHeight,c=null!=a?.originalFileSize;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&(0,m.jsx)(b,{text:"Loading screenshot..."}),n&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"red",children:String(n)})}),!t&&!n&&l&&(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Box,{height:30,children:(0,m.jsx)(o.default,{src:l.path,width:80,alt:"Device screenshot"})}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:"Screenshot saved to: "}),(0,m.jsx)(i.Text,{color:"cyan",children:String(l.path||"")})]}),s&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",String(a.originalWidth),"x",String(a.originalHeight)]}),c&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(a.originalFileSize)/1024).toFixed(1)," KB"]}),l.file?.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:["Updated: ",new Date(l.file.updatedAt).toLocaleString()]})]})]}),!t&&!n&&!l&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:r})})]})},G=({apps:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading applications..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No applications found"});var n=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,m.jsx)(k,{items:n,onSelect:t})]})},V=({app:e,loading:l,error:t,onSelect:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading application..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Application not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],r=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Devices"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Total: ",r,r>0&&` (${a} online)`]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Features"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"🔒 Locked":"🔓 Unlocked"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:o,onSelect:n})]})},F=({modules:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading modules..."});var n=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No modules found"}),(0,m.jsx)(k,{items:n,onSelect:t})]})},H=({module:e,loading:l,error:t,onSelect:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading module..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Module not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Usage"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Settings"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:o,onSelect:n})]})},$=({groups:e,loading:l,onSelect:t,countdown:n,lastRefreshTime:o})=>{if(l)return(0,m.jsx)(b,{text:"Loading device groups..."});var r=[...(e||[]).map(e=>({label:`📁 ${e.name} (${e.devices?.length||0} devices)`,value:e._id,group:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]}),!e?.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No device groups found"}),(0,m.jsx)(k,{items:r,onSelect:t})]})},q=({loading:e,groupDevices:l})=>e?(0,m.jsx)(b,{text:"Loading devices..."}):l?.length?(0,m.jsxs)(m.Fragment,{children:[l.slice(0,10).map(e=>(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:" "}),(0,m.jsx)(v,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),l.length>10&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",l.length-10," more"]})]}):(0,m.jsx)(i.Text,{color:"gray",children:" No devices in this group"}),z=({group:e,groupDevices:l,loading:t,error:n,onSelect:o,countdown:r,lastRefreshTime:a})=>{if(t&&!e)return(0,m.jsx)(b,{text:"Loading device group..."});if(n)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",n]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:o})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Device group not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:r,lastRefreshTime:a})]}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,m.jsx)(q,{loading:t,groupDevices:l})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})]})},Y=({boxes:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading media boxes..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media boxes found"});var n=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,m.jsx)(k,{items:n,onSelect:t})]})},W=({box:e,loading:l,error:t,onSelect:n})=>{if(l&&!e)return(0,m.jsx)(b,{text:"Loading media box..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Media box not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},X=({files:e,loading:l,onSelect:t,box:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading media files..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media files found"});var o=[...e.map(e=>{return{label:`${l=e.fileType,"Image"===l?"🖼":"Video"===l?"🎞":"Audio"===l?"🎵":"📄"} ${e.name||"Unnamed"}`,value:e.id,file:e};var l}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",n?.name?` - ${n.name}`:""]}),(0,m.jsx)(k,{items:o,onSelect:t})]})},J=({file:e,loading:l,error:t,onSelect:n})=>{if(l&&!e)return(0,m.jsx)(b,{text:"Loading media file..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Media file not found"});var o=e.meta,r=(0,d.Gu)(e),a=(0,d.Gu)(e,{preferThumbnail:!0}),s=Boolean(a&&a!==r);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),null!=o?.originalWidth&&null!=o?.originalHeight&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",o.originalWidth,"x",o.originalHeight]}),null!=o?.originalFileSize&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),r&&(0,m.jsxs)(i.Text,{color:"gray",children:["Original URL: ",r]}),s&&(0,m.jsxs)(i.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},K=t(88568);function Q({value:e,placeholder:l="",focus:t=!0,mask:o,highlightPastedText:r=!1,showCursor:a=!0,onChange:s,onSubmit:c}){const[d,u]=(0,n.useState)({cursorOffset:(e||"").length,cursorWidth:0}),{cursorOffset:x,cursorWidth:h}=d;(0,n.useEffect)(()=>{u(l=>{if(!t||!a)return l;const n=e||"";return l.cursorOffset>n.length-1?{cursorOffset:n.length,cursorWidth:0}:l})},[e,t,a]);const g=r?h:0,f=o?o.repeat(e.length):e;let m=f,p=l?K.Ay.grey(l):void 0;if(a&&t){p=l.length>0?K.Ay.inverse(l[0])+K.Ay.grey(l.slice(1)):K.Ay.inverse(" "),m=f.length>0?"":K.Ay.inverse(" ");let e=0;for(const l of f)m+=e>=x-g&&e<=x?K.Ay.inverse(l):l,e++;f.length>0&&x===f.length&&(m+=K.Ay.inverse(" "))}return(0,i.useInput)((l,t)=>{if(t.upArrow||t.downArrow||t.ctrl&&"c"===l||t.tab||t.shift&&t.tab)return;if(t.return)return void(c&&c(e));let n=x,i=e,o=0;t.leftArrow?a&&n--:t.rightArrow?a&&n++:t.backspace||t.delete?x>0&&(i=e.slice(0,x-1)+e.slice(x,e.length),n--):(i=e.slice(0,x)+l+e.slice(x,e.length),n+=l.length,l.length>1&&(o=l.length)),x<0&&(n=0),x>e.length&&(n=e.length),u({cursorOffset:n,cursorWidth:o}),i!==e&&s(i)},{isActive:t}),n.default.createElement(i.Text,null,l?f.length>0?m:p:m)}const Z=Q;var ee,le=t(35704),te=["B","C","G","D"],ne=({instanceType:e,instance:l,client:t,onDone:o,onCancel:s})=>{var c=(0,i.useApp)().exit,d=(0,n.useState)("select_ref"),u=a(d,2),x=u[0],h=u[1],g=(0,n.useState)(""),f=a(g,2),p=f[0],j=f[1],D=(0,n.useState)("search"),T=a(D,2),v=T[0],_=T[1],y=(0,n.useState)(null),B=a(y,2),S=B[0],E=B[1],w=(0,n.useState)(null),L=a(w,2),I=L[0],A=L[1],C=(0,n.useState)(""),R=a(C,2),U=R[0],O=R[1],P=(0,n.useState)(""),M=a(P,2),N=M[0],G=M[1],V=(0,n.useState)(null),F=a(V,2),H=F[0],$=F[1],q=l?.short_edit?.ref_map||{},z=Object.entries(q).filter(([,e])=>e&&!e.hide),Y=(0,le.V)(q,{keyword:p,types:te}),W=Y.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:l})=>({label:`${l.title||e} (${e})`,value:e,ref:l}))]),X=[...p?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],J=W.length>0?[...W,...X]:X,K=J.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,i.useInput)((e,l)=>{l.tab&&"select_ref"===x?_(e=>"search"===e?"list":"search"):(l.escape&&("select_ref"===x&&s(),"input_path"===x&&h("select_ref"),"input_content"===x&&h("input_path"),"confirm"===x&&h("input_content"),"done"===x&&s()),"q"!==e||("input_path"===x||"input_content"===x)||"select_ref"===x&&"search"===v||c())},{isActive:!0});var Q,ee=e=>{var l=e.trim();if(""===l)return null;try{return JSON.parse(l)}catch{return l}},ne=(Q=r(function*(){if(t&&l?._id&&S){h("submitting"),$(null);try{var n={shortId:S,path:U.trim(),content:ee(N),forwardDataLink:!0};I?.inner_ref?.pid&&(n.innerRefParentShortId=I.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:l._id,list:[n]}):yield t.shortEditModule({id:l._id,list:[n]}),yield o(),h("done")}catch(e){$(e.message),h("confirm")}}}),function(){return Q.apply(this,arguments)});return l?.short_edit?.enabled?0===z.length?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No Short Edit references found."}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,children:"Short Edit References"}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"Search (title or shortId)"}),(0,m.jsx)(Z,{value:p,placeholder:"type to filter, Enter to focus list",onChange:e=>j(e),onSubmit:()=>_("list"),focus:"search"===v}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,m.jsxs)(i.Box,{marginTop:1,children:[0===Y.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No references match your search."}),(0,m.jsx)(k,{items:J,isFocused:"list"===v,initialIndex:K>-1?K:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:l,isHeader:t})=>t?(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(i.Text,{bold:!0,color:"white",children:e})}):(0,m.jsxs)(i.Text,{color:l?"blue":void 0,children:[l?"❯":" "," ",e]}),onSelect:e=>{if("__back__"!==e.value)return"__clear_search__"===e.value?(j(""),void _("search")):void(e.isHeader||(E(e.value),A(e.ref),h("input_path")));s()}})]})]}):"input_path"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(Z,{value:U,placeholder:"path",onChange:e=>{O(e),H&&$(null)},onSubmit:e=>{var l=e.trim();l?(O(l),h("input_content")):$("Path is required")},focus:!0})]}):"input_content"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:U})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(Z,{value:N,placeholder:"content",onChange:e=>{G(e),H&&$(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===x?(0,m.jsx)(b,{text:"Applying short edit..."}):"done"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"green",children:"Short edit applied successfully."}),(0,m.jsx)(k,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),E(null),A(null),O(""),G(""),$(null)):s()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:U})]}),(0,m.jsxs)(i.Text,{children:["Content: ",(0,m.jsx)(i.Text,{color:"cyan",children:N||"<empty>"})]}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(k,{items:[{label:"Apply",value:"apply"},{label:"Edit Path",value:"edit_path"},{label:"Edit Content",value:"edit_content"},{label:"← Back",value:"back"}],onSelect:e=>{"apply"===e.value&&ne(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},ie=t(16928),oe=t(79896),re=t(35317),ae=t(10750),se="options",ce="output_dir",de="confirm",ue="generating",xe="post_install",he="done",ge=e=>{try{return(0,re.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},fe=(e,l,t)=>new Promise((n,i)=>{var o=[e,...l].join(" "),r=(0,re.spawn)(o,[],{cwd:t,stdio:"pipe",shell:!0});r.on("close",e=>{0===e?n():i(new Error(`Command failed with code ${e}`))}),r.on("error",i)}),me=(ee=r(function*(e,l){try{var n=(yield Promise.resolve().then(t.bind(t,79491))).format;return(yield n(l,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,l){return ee.apply(this,arguments)}),pe=({type:e,instance:l,client:t,onDone:o,onCancel:s})=>{var c,d=(0,i.useApp)().exit,u=(0,n.useState)(se),x=a(u,2),h=x[0],g=x[1],p=(0,n.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),j=a(p,2),D=j[0],T=j[1],b=(0,n.useState)(process.cwd()),v=a(b,2),_=v[0],y=v[1],B=(0,n.useState)(""),S=a(B,2),E=S[0],w=S[1],L=(0,n.useState)(null),I=a(L,2),A=I[0],C=I[1],R=(0,n.useState)(null),U=a(R,2),O=U[0],P=U[1],M=ae(l?.name||"bricks-project"),N=ie.resolve(_,M),G=(0,n.useCallback)(e=>{"back"!==e.value?"continue"!==e.value?T(l=>({...l,[e.value]:!l[e.value]})):g(ce):s()},[s]),V=(0,n.useCallback)(()=>{oe.existsSync(N)?C(`Directory already exists: ${N}`):(C(null),g(de))},[N]),F=(0,n.useCallback)((c=r(function*(n){var i;if("back"!==n.value)if("cancel"!==n.value){if("confirm"===n.value){g(ue);try{w("Fetching project from BRICKS...");var o="application"===e,a=o?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",c=o?t.queries.applicationProject:t.queries.moduleProject,d=(yield t.query(c,{id:l._id,buildApplicationOnly:!1,setupGitHubActions:D.setupGitHubActions,setupAgents:D.setupAgents,setupClaudeCode:D.setupClaudeCode,setupGeminiCLI:D.setupGeminiCLI}))[a];if(!d?.files)throw new Error("Failed to fetch project files");w("Creating project directory..."),oe.mkdirSync(N,{recursive:!0}),w(`Writing ${d.files.length} files...`);var u=yield Promise.all(d.files.map((i=r(function*(e){var l=ie.join(N,e.name),t=e.input;return e.formatable&&(t=yield me(t,l)),{...e,filePath:l,content:t}}),function(e){return i.apply(this,arguments)})));u.forEach(e=>{var l=ie.dirname(e.filePath);oe.existsSync(l)||oe.mkdirSync(l,{recursive:!0}),oe.writeFileSync(e.filePath,e.content)}),g(xe);var x={path:N,files:d.files.length,bunInstalled:!1,gitInitialized:!1};if(D.runBunInstall&&ge("bun")){w("Installing dependencies (bun install)...");try{yield fe("bun",["install"],N),x.bunInstalled=!0}catch{}}if(D.initGit&&ge("git")){w("Initializing git repository...");try{yield fe("git",["init"],N),yield fe("git",["add","."],N),yield fe("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],N),x.gitInitialized=!0}catch{}}P(x),g(he)}catch(e){C(e.message),g(se)}}}else s();else g(ce)}),function(e){return c.apply(this,arguments)}),[t,l,e,D,N,s]),H=(0,n.useCallback)(e=>{"exit"===e.value?d():o()},[d,o]);if(h===se){var $=[{label:(D.setupGitHubActions?"[x]":"[ ]")+" GitHub Actions workflow",value:"setupGitHubActions"},{label:(D.setupAgents?"[x]":"[ ]")+" AGENTS.md",value:"setupAgents"},{label:(D.setupClaudeCode?"[x]":"[ ]")+" CLAUDE.md",value:"setupClaudeCode"},{label:(D.setupGeminiCLI?"[x]":"[ ]")+" GEMINI.md",value:"setupGeminiCLI"},{label:(D.runBunInstall?"[x]":"[ ]")+" Run bun install after generation",value:"runBunInstall"},{label:(D.initGit?"[x]":"[ ]")+" Initialize git repository",value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",l?.name||"Untitled"]}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),A&&(0,m.jsxs)(i.Text,{color:"red",marginBottom:1,children:["Error: ",A]}),(0,m.jsx)(k,{items:$,onSelect:G})]})}if(h===ce)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),A&&(0,m.jsx)(i.Text,{color:"red",marginBottom:1,children:A}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{children:"Directory: "}),(0,m.jsx)(Z,{value:_,onChange:y,onSubmit:V})]}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",N]})]});if(h===de){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Name: ",(0,m.jsx)(i.Text,{color:"green",children:l?.name||"Untitled"})]}),(0,m.jsxs)(i.Text,{children:["Type: ",(0,m.jsx)(i.Text,{color:"yellow",children:e})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:N})]}),(0,m.jsx)(i.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GitHub Actions: ",D.setupGitHubActions?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - AGENTS.md: ",D.setupAgents?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - CLAUDE.md: ",D.setupClaudeCode?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GEMINI.md: ",D.setupGeminiCLI?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Run bun install: ",D.runBunInstall?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Initialize git: ",D.initGit?"Yes":"No"]})]}),(0,m.jsx)(k,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:F})]})}if(h===ue||h===xe)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(f,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",E]})]})]});if(h===he&&O){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:O.path})]}),(0,m.jsxs)(i.Text,{children:["Files: ",(0,m.jsx)(i.Text,{color:"green",children:O.files})]}),(0,m.jsxs)(i.Text,{children:["Dependencies:"," ",(0,m.jsx)(i.Text,{color:O.bunInstalled?"green":"yellow",children:O.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,m.jsxs)(i.Text,{children:["Git:"," ",(0,m.jsx)(i.Text,{color:O.gitInitialized?"green":"yellow",children:O.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,m.jsx)(i.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" cd ",M]}),!O.bunInstalled&&(0,m.jsx)(i.Text,{color:"gray",children:" bun install"}),(0,m.jsx)(i.Text,{color:"gray",children:" bun preview"}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["For more information, see ",M,"/README.md"]}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:H})})]})}return null};const je=()=>{var e=(0,i.useApp)().exit,l=(0,n.useState)(u.MAIN),t=a(l,2),o=t[0],x=t[1],h=(0,n.useState)(null),g=a(h,2),f=g[0],j=g[1],v=(0,n.useState)(null),_=a(v,2),y=_[0],B=_[1],S=(0,n.useState)(!0),E=a(S,2),w=E[0],L=E[1],I=(0,n.useState)(null),A=a(I,2),C=A[0],R=A[1],k=(0,n.useState)([]),q=a(k,2),K=q[0],Q=q[1],Z=(0,n.useState)(null),ee=a(Z,2),le=ee[0],te=ee[1],ie=(0,n.useState)([]),oe=a(ie,2),re=oe[0],ae=oe[1],se=(0,n.useState)(null),ce=a(se,2),de=ce[0],ue=ce[1],xe=(0,n.useState)([]),he=a(xe,2),ge=he[0],fe=he[1],me=(0,n.useState)(null),je=a(me,2),De=je[0],Te=je[1],be=(0,n.useState)([]),ve=a(be,2),_e=ve[0],ye=ve[1],Be=(0,n.useState)(null),Se=a(Be,2),Ee=Se[0],we=Se[1],Le=(0,n.useState)([]),Ie=a(Le,2),Ae=Ie[0],Ce=Ie[1],Re=(0,n.useState)(!1),ke=a(Re,2),Ue=ke[0],Oe=ke[1],Pe=(0,n.useState)(null),Me=a(Pe,2),Ne=Me[0],Ge=Me[1],Ve=(0,n.useState)(null),Fe=a(Ve,2),He=Fe[0],$e=Fe[1],qe=(0,n.useState)(null),ze=a(qe,2),Ye=ze[0],We=ze[1],Xe=(0,n.useState)(null),Je=a(Xe,2),Ke=Je[0],Qe=Je[1],Ze=(0,n.useState)([]),el=a(Ze,2),ll=el[0],tl=el[1],nl=(0,n.useState)(null),il=a(nl,2),ol=il[0],rl=il[1],al=(0,n.useState)([]),sl=a(al,2),cl=sl[0],dl=sl[1],ul=(0,n.useState)(null),xl=a(ul,2),hl=xl[0],gl=xl[1],fl=o===u.DEVICES,ml=o===u.DEVICE_DETAIL,pl=o===u.GROUPS,jl=o===u.GROUP_DETAIL;(0,n.useEffect)(()=>{var e=(0,c.getCurrentProfile)(),l=(0,c.getToken)(e);if(!l)return R("Not logged in. Run `bricks auth login` first."),void L(!1);var t=(0,s.createClient)((0,c.getBaseUrl)(),l);j(t),t.workspace().then(e=>{B(e),L(!1)}).catch(e=>{R(e.message),L(!1)})},[]),(0,i.useInput)((l,t)=>{"q"===l&&e(),t.escape&&(o===u.DEVICE_CONTROL?(x(u.DEVICE_DETAIL),Ge(null)):o===u.DEVICE_SCREENSHOT?(x(u.DEVICE_DETAIL),We(null),Qe(null)):o===u.DEVICE_DETAIL?(x(u.DEVICES),te(null)):o===u.APP_DETAIL?(x(u.APPS),ue(null)):o===u.MODULE_DETAIL?(x(u.MODULES),Te(null)):o===u.GROUP_DETAIL?(x(u.GROUPS),we(null),Ce([])):o===u.MEDIA_FILE_DETAIL?(x(u.MEDIA_FILES),gl(null)):o===u.MEDIA_FILES?(x(u.MEDIA_BOX_DETAIL),gl(null)):o===u.MEDIA_BOX_DETAIL?(x(u.MEDIA_BOXES),rl(null),dl([])):(o===u.MEDIA_BOXES||o!==u.MAIN)&&x(u.MAIN))},{isActive:o!==u.APP_SHORT_EDIT&&o!==u.MODULE_SHORT_EDIT&&o!==u.APP_PROJECT_INIT&&o!==u.MODULE_PROJECT_INIT});var Dl,Tl,bl,vl,_l,yl,Bl,Sl,El=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.devices({});Q(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),wl=(0,n.useCallback)((Dl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.device({id:e});te(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Dl.apply(this,arguments)}),[f]),Ll=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.applications({});ae(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Il=(0,n.useCallback)((Tl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.application({id:e});ue(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Tl.apply(this,arguments)}),[f]),Al=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.modules({});fe(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Cl=(0,n.useCallback)((bl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.module({id:e});Te(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return bl.apply(this,arguments)}),[f]),Rl=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.deviceGroups({});ye(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),kl=(0,n.useCallback)((vl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield Promise.all([f.deviceGroup({id:e}),f.devicesByGroup({id:e})]),t=a(l,2),n=t[0],i=t[1];we(n),Ce(i||[])}catch(e){$e(e.message)}L(!1)}}),function(e){return vl.apply(this,arguments)}),[f]),Ul=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.mediaBoxes();tl(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Ol=(0,n.useCallback)((_l=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.mediaBox({id:e});rl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return _l.apply(this,arguments)}),[f]),Pl=(0,n.useCallback)((yl=r(function*(e){if(f){L(!0);try{var l=yield f.mediaFiles({boxId:e});dl(l||[])}catch(e){R(e.message)}L(!1)}}),function(e){return yl.apply(this,arguments)}),[f]),Ml=(0,n.useCallback)((Bl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.mediaFile({id:e});gl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Bl.apply(this,arguments)}),[f]),Nl=(0,n.useCallback)((Sl=r(function*(e){if(f&&le){Oe(!0),Ge(null);try{yield f.controlDevice({id:le._id,type:e}),Ge({success:!0,message:`Command sent: ${e}`})}catch(e){Ge({success:!1,message:e.message})}Oe(!1)}}),function(e){return Sl.apply(this,arguments)}),[f,le]),Gl=(0,n.useCallback)(r(function*(e=!1){if(f&&le&&y){L(!0),Qe(null),We(null);try{e&&(yield f.controlDevice({id:le._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var l=yield(0,d.he)(f,y,le._id,null,{preferThumbnail:!0});l.error?Qe(l.error):We(l)}catch(e){Qe(e.message)}L(!1)}}),[f,le,y]),Vl=p((0,n.useCallback)(()=>{f&&El()},[f,El]),fl),Fl=p((0,n.useCallback)(()=>{f&&le&&wl(le._id)},[f,le,wl]),ml),Hl=p((0,n.useCallback)(()=>{f&&Rl()},[f,Rl]),pl),$l=p((0,n.useCallback)(()=>{f&&Ee&&kl(Ee._id)},[f,Ee,kl]),jl);return w&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),(0,m.jsx)(b,{text:"Connecting to workspace..."})]}):C&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",C]}),(0,m.jsx)(T,{})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),o===u.MAIN&&(0,m.jsx)(U,{onSelect:l=>{"exit"!==l.value?(x(l.value),l.value===u.DEVICES?El():l.value===u.APPS?Ll():l.value===u.MODULES?Al():l.value===u.GROUPS?Rl():l.value===u.MEDIA_BOXES&&Ul()):e()},mediaEnabled:(0,d.wR)(y)}),o===u.DEVICES&&(0,m.jsx)(O,{devices:K,loading:w,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return El(),void Vl.resetCountdown();te(null),L(!0),x(u.DEVICE_DETAIL),wl(e.value)}else x(u.MAIN)},countdown:Vl.countdown,lastRefreshTime:Vl.lastRefreshTime}),o===u.DEVICE_DETAIL&&(0,m.jsx)(P,{device:le,loading:w,error:He,onSelect:e=>"back"===e.value?(x(u.DEVICES),void te(null)):"refresh"===e.value?(wl(le._id),void Fl.resetCountdown()):("control"===e.value&&(x(u.DEVICE_CONTROL),Ge(null)),void("screenshot"===e.value&&(x(u.DEVICE_SCREENSHOT),We(null),Qe(null),Gl(!1)))),mediaEnabled:(0,d.wR)(y),countdown:Fl.countdown,lastRefreshTime:Fl.lastRefreshTime}),o===u.DEVICE_CONTROL&&(0,m.jsx)(M,{device:le,onSelect:e=>{if("back"===e.value)return x(u.DEVICE_DETAIL),void Ge(null);Nl(e.value)},controlling:Ue,controlResult:Ne}),o===u.DEVICE_SCREENSHOT&&(0,m.jsx)(N,{device:le,screenshot:Ye,loading:w,error:Ke,onSelect:e=>{if("back"===e.value)return x(u.DEVICE_DETAIL),We(null),void Qe(null);"refresh"!==e.value?"take"===e.value&&Gl(!0):Gl(!1)}}),o===u.APPS&&(0,m.jsx)(G,{apps:re,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(ue(null),L(!0),x(u.APP_DETAIL),Il(e.value)):Ll():x(u.MAIN)}}),o===u.APP_DETAIL&&(0,m.jsx)(V,{app:de,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.APPS),void ue(null);"refresh"!==e.value?("short_edit"===e.value&&(x(u.APP_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(u.APP_PROJECT_INIT),$e(null))):Il(de._id)}}),o===u.APP_SHORT_EDIT&&(0,m.jsx)(ne,{instanceType:"application",instance:de,client:f,onDone:r(function*(){return Il(de._id)}),onCancel:()=>x(u.APP_DETAIL)}),o===u.APP_PROJECT_INIT&&(0,m.jsx)(pe,{type:"application",instance:de,client:f,onDone:()=>x(u.APP_DETAIL),onCancel:()=>x(u.APP_DETAIL)}),o===u.MODULES&&(0,m.jsx)(F,{modules:ge,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(Te(null),L(!0),x(u.MODULE_DETAIL),Cl(e.value)):Al():x(u.MAIN)}}),o===u.MODULE_DETAIL&&(0,m.jsx)(H,{module:De,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MODULES),void Te(null);"refresh"!==e.value?("short_edit"===e.value&&(x(u.MODULE_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(u.MODULE_PROJECT_INIT),$e(null))):Cl(De._id)}}),o===u.MODULE_SHORT_EDIT&&(0,m.jsx)(ne,{instanceType:"module",instance:De,client:f,onDone:r(function*(){return Cl(De._id)}),onCancel:()=>x(u.MODULE_DETAIL)}),o===u.MODULE_PROJECT_INIT&&(0,m.jsx)(pe,{type:"module",instance:De,client:f,onDone:()=>x(u.MODULE_DETAIL),onCancel:()=>x(u.MODULE_DETAIL)}),o===u.GROUPS&&(0,m.jsx)($,{groups:_e,loading:w,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Rl(),void Hl.resetCountdown();we(null),Ce([]),L(!0),x(u.GROUP_DETAIL),kl(e.value)}else x(u.MAIN)},countdown:Hl.countdown,lastRefreshTime:Hl.lastRefreshTime}),o===u.GROUP_DETAIL&&(0,m.jsx)(z,{group:Ee,groupDevices:Ae,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.GROUPS),we(null),void Ce([]);"refresh"===e.value&&(kl(Ee._id),$l.resetCountdown())},countdown:$l.countdown,lastRefreshTime:$l.lastRefreshTime}),o===u.MEDIA_BOXES&&(0,m.jsx)(Y,{boxes:ll,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(rl(null),dl([]),L(!0),x(u.MEDIA_BOX_DETAIL),Ol(e.value)):Ul():x(u.MAIN)}}),o===u.MEDIA_BOX_DETAIL&&(0,m.jsx)(W,{box:ol,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_BOXES),rl(null),void dl([]);"refresh"!==e.value?"files"===e.value&&(dl([]),gl(null),x(u.MEDIA_FILES),Pl(ol.id)):Ol(ol.id)}}),o===u.MEDIA_FILES&&(0,m.jsx)(X,{files:cl,box:ol,loading:w,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_BOX_DETAIL),void gl(null);"refresh"!==e.value?(gl(null),L(!0),x(u.MEDIA_FILE_DETAIL),Ml(e.value)):Pl(ol.id)}}),o===u.MEDIA_FILE_DETAIL&&(0,m.jsx)(J,{file:hl,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_FILES),void gl(null);"refresh"===e.value&&Ml(hl.id)}}),(0,m.jsx)(T,{})]})};var De=()=>{(0,i.render)((0,m.jsx)(o.TerminalInfoProvider,{children:(0,m.jsx)(je,{})}))}}};
|
|
1
|
+
export const __webpack_esm_id__=612;export const __webpack_esm_ids__=[612];export const __webpack_esm_modules__={10750:(e,l,t)=>{var n=t(93640)(function(e,l,t){return e+(t?"-":"")+l.toLowerCase()});e.exports=n},59612:(e,l,t)=>{t.d(l,{App:()=>je,AppDetail:()=>V,AppList:()=>G,CONTROL_ACTIONS:()=>x,DeviceControl:()=>M,DeviceDetail:()=>P,DeviceList:()=>O,DeviceScreenshot:()=>N,DeviceStatus:()=>v,Footer:()=>T,GroupDetail:()=>z,GroupList:()=>$,Header:()=>D,Loading:()=>b,MainMenu:()=>U,MediaBoxDetail:()=>W,MediaBoxList:()=>Y,MediaFileDetail:()=>J,MediaFileList:()=>X,ModuleDetail:()=>H,ModuleList:()=>F,ONLINE_THRESHOLD_MS:()=>h,ProjectInitView:()=>pe,ShortEditEditor:()=>ne,VIEWS:()=>u,runInteractiveMode:()=>De}),t.r(l);var n=t(51649),i=t(8498),o=t(29557),r=t(99436),a=t(68832),s=t(50700),c=t(74752),d=t(47336),u={MAIN:"main",DEVICES:"devices",DEVICE_DETAIL:"device_detail",DEVICE_CONTROL:"device_control",DEVICE_SCREENSHOT:"device_screenshot",APPS:"apps",APP_DETAIL:"app_detail",APP_SHORT_EDIT:"app_short_edit",APP_PROJECT_INIT:"app_project_init",MODULES:"modules",MODULE_DETAIL:"module_detail",MODULE_SHORT_EDIT:"module_short_edit",MODULE_PROJECT_INIT:"module_project_init",GROUPS:"groups",GROUP_DETAIL:"group_detail",MEDIA_BOXES:"media_boxes",MEDIA_BOX_DETAIL:"media_box_detail",MEDIA_FILES:"media_files",MEDIA_FILE_DETAIL:"media_file_detail"},x=[{label:"Refresh Application",value:"refresh"},{label:"Clear Cache",value:"clear-cache"},{label:"Take Screenshot",value:"take-screenshot"},{label:"Open System Menu",value:"system-menu-open"},{label:"Close System Menu",value:"system-menu-close"},{label:"Open Debug Panel",value:"debug-panel-open"},{label:"Close Debug Panel",value:"debug-panel-close"},{label:"Enable Logging",value:"logging-on"},{label:"Disable Logging",value:"logging-off"},{label:"← Back",value:"back"}],h=3e5,g=t(47661);const f=function({type:e="dots"}){const[l,t]=(0,n.useState)(0),o=g[e];return(0,n.useEffect)(()=>{const e=setInterval(()=>{t(e=>e===o.frames.length-1?0:e+1)},o.interval);return()=>{clearInterval(e)}},[o]),n.default.createElement(i.Text,null,o.frames[l])};var m=t(71178),p=(e,l=!0)=>{var t=Math.floor(60),i=(0,n.useState)(t),o=a(i,2),r=o[0],s=o[1],c=(0,n.useState)(null),d=a(c,2),u=d[0],x=d[1],h=(0,n.useRef)(e);(0,n.useEffect)(()=>{h.current=e},[e]);var g=(0,n.useCallback)(()=>{s(t),x(Date.now())},[t]);return(0,n.useEffect)(()=>{if(l){var e=setInterval(()=>{s(e=>e<=1?(h.current?.(),x(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[l,t]),(0,n.useEffect)(()=>{l&&(s(t),x(Date.now()))},[l,t]),{countdown:r,lastRefreshTime:u,resetCountdown:g}},j=({countdown:e,lastRefreshTime:l})=>(0,m.jsx)(i.Box,{children:(0,m.jsxs)(i.Text,{color:"gray",children:["Next refresh in ",(0,m.jsxs)(i.Text,{color:"cyan",children:[e,"s"]}),l&&(0,m.jsxs)(i.Text,{color:"gray",children:[" (last: ",l?new Date(l).toLocaleTimeString():null,")"]})]})}),D=({workspace:e,view:l})=>(0,m.jsxs)(i.Box,{flexDirection:"column",marginBottom:1,children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,m.jsx)(i.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Workspace: "}),(0,m.jsx)(i.Text,{color:"green",children:e?.name||"Not connected"}),(0,m.jsx)(i.Text,{color:"gray",children:" | View: "}),(0,m.jsx)(i.Text,{color:"yellow",children:l})]}),(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)})]}),T=()=>(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"─".repeat(60)}),(0,m.jsxs)(i.Text,{color:"gray",children:["Press ",(0,m.jsx)(i.Text,{color:"cyan",children:"q"})," to quit, ",(0,m.jsx)(i.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),b=({text:e})=>(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(f,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",e||"Loading..."]})]}),v=({lastAliveTime:e})=>{if(!e)return(0,m.jsx)(i.Text,{color:"gray",children:"○ Unknown"});var l=Date.now()-new Date(e).getTime();if(l<=h)return(0,m.jsx)(i.Text,{color:"green",children:"● Online"});var t=Math.floor(l/6e4);if(t<60)return(0,m.jsxs)(i.Text,{color:"yellow",children:["○ Offline (",t,"m ago)"]});var n=Math.floor(t/60);if(n<24)return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",n,"h ago)"]});var o=Math.floor(n/24);return(0,m.jsxs)(i.Text,{color:"red",children:["○ Offline (",o,"d ago)"]})},_=t(29122);const y={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"█",squareDarkShade:"▓",squareMediumShade:"▒",squareLightShade:"░",squareTop:"▀",squareBottom:"▄",squareLeft:"▌",squareRight:"▐",squareCenter:"■",bullet:"●",dot:"․",ellipsis:"…",pointerSmall:"›",triangleUp:"▲",triangleUpSmall:"▴",triangleDown:"▼",triangleDownSmall:"▾",triangleLeftSmall:"◂",triangleRightSmall:"▸",home:"⌂",heart:"♥",musicNote:"♪",musicNoteBeamed:"♫",arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",arrowLeftRight:"↔",arrowUpDown:"↕",almostEqual:"≈",notEqual:"≠",lessOrEqual:"≤",greaterOrEqual:"≥",identical:"≡",infinity:"∞",subscriptZero:"₀",subscriptOne:"₁",subscriptTwo:"₂",subscriptThree:"₃",subscriptFour:"₄",subscriptFive:"₅",subscriptSix:"₆",subscriptSeven:"₇",subscriptEight:"₈",subscriptNine:"₉",oneHalf:"½",oneThird:"⅓",oneQuarter:"¼",oneFifth:"⅕",oneSixth:"⅙",oneEighth:"⅛",twoThirds:"⅔",twoFifths:"⅖",threeQuarters:"¾",threeFifths:"⅗",threeEighths:"⅜",fourFifths:"⅘",fiveSixths:"⅚",fiveEighths:"⅝",sevenEighths:"⅞",line:"─",lineBold:"━",lineDouble:"═",lineDashed0:"┄",lineDashed1:"┅",lineDashed2:"┈",lineDashed3:"┉",lineDashed4:"╌",lineDashed5:"╍",lineDashed6:"╴",lineDashed7:"╶",lineDashed8:"╸",lineDashed9:"╺",lineDashed10:"╼",lineDashed11:"╾",lineDashed12:"−",lineDashed13:"–",lineDashed14:"‐",lineDashed15:"⁃",lineVertical:"│",lineVerticalBold:"┃",lineVerticalDouble:"║",lineVerticalDashed0:"┆",lineVerticalDashed1:"┇",lineVerticalDashed2:"┊",lineVerticalDashed3:"┋",lineVerticalDashed4:"╎",lineVerticalDashed5:"╏",lineVerticalDashed6:"╵",lineVerticalDashed7:"╷",lineVerticalDashed8:"╹",lineVerticalDashed9:"╻",lineVerticalDashed10:"╽",lineVerticalDashed11:"╿",lineDownLeft:"┐",lineDownLeftArc:"╮",lineDownBoldLeftBold:"┓",lineDownBoldLeft:"┒",lineDownLeftBold:"┑",lineDownDoubleLeftDouble:"╗",lineDownDoubleLeft:"╖",lineDownLeftDouble:"╕",lineDownRight:"┌",lineDownRightArc:"╭",lineDownBoldRightBold:"┏",lineDownBoldRight:"┎",lineDownRightBold:"┍",lineDownDoubleRightDouble:"╔",lineDownDoubleRight:"╓",lineDownRightDouble:"╒",lineUpLeft:"┘",lineUpLeftArc:"╯",lineUpBoldLeftBold:"┛",lineUpBoldLeft:"┚",lineUpLeftBold:"┙",lineUpDoubleLeftDouble:"╝",lineUpDoubleLeft:"╜",lineUpLeftDouble:"╛",lineUpRight:"└",lineUpRightArc:"╰",lineUpBoldRightBold:"┗",lineUpBoldRight:"┖",lineUpRightBold:"┕",lineUpDoubleRightDouble:"╚",lineUpDoubleRight:"╙",lineUpRightDouble:"╘",lineUpDownLeft:"┤",lineUpBoldDownBoldLeftBold:"┫",lineUpBoldDownBoldLeft:"┨",lineUpDownLeftBold:"┥",lineUpBoldDownLeftBold:"┩",lineUpDownBoldLeftBold:"┪",lineUpDownBoldLeft:"┧",lineUpBoldDownLeft:"┦",lineUpDoubleDownDoubleLeftDouble:"╣",lineUpDoubleDownDoubleLeft:"╢",lineUpDownLeftDouble:"╡",lineUpDownRight:"├",lineUpBoldDownBoldRightBold:"┣",lineUpBoldDownBoldRight:"┠",lineUpDownRightBold:"┝",lineUpBoldDownRightBold:"┡",lineUpDownBoldRightBold:"┢",lineUpDownBoldRight:"┟",lineUpBoldDownRight:"┞",lineUpDoubleDownDoubleRightDouble:"╠",lineUpDoubleDownDoubleRight:"╟",lineUpDownRightDouble:"╞",lineDownLeftRight:"┬",lineDownBoldLeftBoldRightBold:"┳",lineDownLeftBoldRightBold:"┯",lineDownBoldLeftRight:"┰",lineDownBoldLeftBoldRight:"┱",lineDownBoldLeftRightBold:"┲",lineDownLeftRightBold:"┮",lineDownLeftBoldRight:"┭",lineDownDoubleLeftDoubleRightDouble:"╦",lineDownDoubleLeftRight:"╥",lineDownLeftDoubleRightDouble:"╤",lineUpLeftRight:"┴",lineUpBoldLeftBoldRightBold:"┻",lineUpLeftBoldRightBold:"┷",lineUpBoldLeftRight:"┸",lineUpBoldLeftBoldRight:"┹",lineUpBoldLeftRightBold:"┺",lineUpLeftRightBold:"┶",lineUpLeftBoldRight:"┵",lineUpDoubleLeftDoubleRightDouble:"╩",lineUpDoubleLeftRight:"╨",lineUpLeftDoubleRightDouble:"╧",lineUpDownLeftRight:"┼",lineUpBoldDownBoldLeftBoldRightBold:"╋",lineUpDownBoldLeftBoldRightBold:"╈",lineUpBoldDownLeftBoldRightBold:"╇",lineUpBoldDownBoldLeftRightBold:"╊",lineUpBoldDownBoldLeftBoldRight:"╉",lineUpBoldDownLeftRight:"╀",lineUpDownBoldLeftRight:"╁",lineUpDownLeftBoldRight:"┽",lineUpDownLeftRightBold:"┾",lineUpBoldDownBoldLeftRight:"╂",lineUpDownLeftBoldRightBold:"┿",lineUpBoldDownLeftBoldRight:"╃",lineUpBoldDownLeftRightBold:"╄",lineUpDownBoldLeftBoldRight:"╅",lineUpDownBoldLeftRightBold:"╆",lineUpDoubleDownDoubleLeftDoubleRightDouble:"╬",lineUpDoubleDownDoubleLeftRight:"╫",lineUpDownLeftDoubleRightDouble:"╪",lineCross:"╳",lineBackslash:"╲",lineSlash:"╱"},B={tick:"✔",info:"ℹ",warning:"⚠",cross:"✘",squareSmall:"◻",squareSmallFilled:"◼",circle:"◯",circleFilled:"◉",circleDotted:"◌",circleDouble:"◎",circleCircle:"ⓞ",circleCross:"ⓧ",circlePipe:"Ⓘ",radioOn:"◉",radioOff:"◯",checkboxOn:"☒",checkboxOff:"☐",checkboxCircleOn:"ⓧ",checkboxCircleOff:"Ⓘ",pointer:"❯",triangleUpOutline:"△",triangleLeft:"◀",triangleRight:"▶",lozenge:"◆",lozengeOutline:"◇",hamburger:"☰",smiley:"㋡",mustache:"෴",star:"★",play:"▶",nodejs:"⬢",oneSeventh:"⅐",oneNinth:"⅑",oneTenth:"⅒"},S={...y,...B},E={...y,tick:"√",info:"i",warning:"‼",cross:"×",squareSmall:"□",squareSmallFilled:"■",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(○)",circleCross:"(×)",circlePipe:"(│)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[×]",checkboxOff:"[ ]",checkboxCircleOn:"(×)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"∆",triangleLeft:"◄",triangleRight:"►",lozenge:"♦",lozengeOutline:"◊",hamburger:"≡",smiley:"☺",mustache:"┌─┐",star:"✶",play:"►",nodejs:"♦",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},w=(0,_.A)(),L=w?S:E;Object.entries(B);const I=function({isSelected:e=!1}){return n.default.createElement(i.Box,{marginRight:1},e?n.default.createElement(i.Text,{color:"blue"},L.pointer):n.default.createElement(i.Text,null," "))};const A=function({isSelected:e=!1,label:l}){return n.createElement(i.Text,{color:e?"blue":void 0},l)};var C=t(57975);function R(e,l){if(!Array.isArray(e))throw new TypeError(`Expected an array, got \`${typeof e}\`.`);if(!Number.isSafeInteger(l))throw new TypeError(`The \`steps\` parameter must be an integer, got ${l}.`);const{length:t}=e;if(0===t)return[...e];const n=(l%t+t)%t;return 0===n?[...e]:[...e.slice(-n),...e.slice(0,-n)]}const k=function({items:e=[],isFocused:l=!0,initialIndex:t=0,indicatorComponent:o=I,itemComponent:r=A,limit:a,onSelect:s,onHighlight:c}){const d="number"==typeof a&&e.length>a,u=d?Math.min(a,e.length):e.length,x=u-1,[h,g]=(0,n.useState)(t>x?x-t:0),[f,m]=(0,n.useState)(t?t>x?x:t:0),p=(0,n.useRef)(e);(0,n.useEffect)(()=>{(0,C.isDeepStrictEqual)(p.current.map(e=>e.value),e.map(e=>e.value))||(g(0),m(0)),p.current=e},[e]),(0,i.useInput)((0,n.useCallback)((l,t)=>{if("k"===l||t.upArrow){const l=(d?u:e.length)-1,t=0===f,n=t?h+1:h,i=t?d?f:l:f-1;g(n),m(i);const o=d?R(e,n).slice(0,u):e;"function"==typeof c&&c(o[i])}if("j"===l||t.downArrow){const l=f===(d?u:e.length)-1,t=l?h-1:h,n=l?d?f:0:f+1;g(t),m(n);const i=d?R(e,t).slice(0,u):e;"function"==typeof c&&c(i[n])}if(/^[1-9]$/.test(l)){const t=Number.parseInt(l,10)-1,n=d?R(e,h).slice(0,u):e;if(t>=0&&t<n.length){const e=n[t];e&&s?.(e)}}if(t.return){const l=d?R(e,h).slice(0,u):e;"function"==typeof s&&s(l[f])}},[d,u,h,f,e,s,c]),{isActive:l});const j=d?R(e,h).slice(0,u):e;return n.default.createElement(i.Box,{flexDirection:"column"},j.map((e,l)=>{const t=l===f;return n.default.createElement(i.Box,{key:e.key??e.value},n.default.createElement(o,{isSelected:t}),n.default.createElement(r,{...e,isSelected:t}))}))};var U=({onSelect:e,mediaEnabled:l})=>{var t=[{label:"Devices",value:u.DEVICES},{label:"Applications",value:u.APPS},{label:"Modules",value:u.MODULES},{label:"Device Groups",value:u.GROUPS},...l?[{label:"Media Flow",value:u.MEDIA_BOXES}]:[],{label:"Exit",value:"exit"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,m.jsx)(k,{items:t,onSelect:e})]})},O=({devices:e,loading:l,onSelect:t,countdown:n,lastRefreshTime:o})=>{if(l)return(0,m.jsx)(b,{text:"Loading devices..."});if(!e?.length)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No devices found"}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]});var r=[...e.map(e=>({label:`${(e=>{if(!e)return"○ Unknown";var l=Date.now()-new Date(e).getTime();if(l<=h)return"● Online";var t=Math.floor(l/6e4);if(t<60)return`○ ${t}m ago`;var n=Math.floor(t/60);return n<24?`○ ${n}h ago`:`○ ${Math.floor(n/24)}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time)} - ${e.name||e.device_name}`,value:e._id,device:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]}),(0,m.jsx)(k,{items:r,onSelect:t})]})},P=({device:e,loading:l,error:t,onSelect:n,mediaEnabled:o,countdown:r,lastRefreshTime:a})=>{if(l)return(0,m.jsx)(b,{text:"Loading device..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...o?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,d=c?.screen,u=c?.update,x=c?.local_sync;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:r,lastRefreshTime:a})]}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:"Status: "}),(0,m.jsx)(v,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Application"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),d&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screen"}),d.resolution&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Resolution: ",d.resolution.width,"x",d.resolution.height,d.resolution.scale&&` @${d.resolution.scale}x`]}),d.orientation&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Orientation: ",d.orientation]}),d.touch&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Touch:"," ",d.touch.available?`Yes (${d.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),x&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Role: ",x.is_main?"Main":"Peer",x.peer_count>0&&` | Peers: ${x.peer_count}`,x.mean_latency&&` | Latency: ${x.mean_latency}ms`]})]}),u&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Update"}),(0,m.jsxs)(i.Text,{color:u.need_update?"yellow":"gray",children:[" ","Status: ",u.need_update?"⚠ Update available":"✓ Up to date"]}),u.current_version&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Version: ",u.current_version]})]})]}),(0,m.jsx)(k,{items:s,onSelect:n})]})},M=({device:e,onSelect:l,controlling:t,controlResult:n})=>(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&(0,m.jsx)(b,{text:"Sending command..."}),n&&(0,m.jsx)(i.Text,{color:n.success?"green":"red",children:n.message}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:x,onSelect:l})})]}),N=({device:e,screenshot:l,loading:t,error:n,onSelect:r})=>{var a=l?.file?.meta,s=null!=a?.originalWidth&&null!=a?.originalHeight,c=null!=a?.originalFileSize;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&(0,m.jsx)(b,{text:"Loading screenshot..."}),n&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"red",children:String(n)})}),!t&&!n&&l&&(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Box,{height:30,children:(0,m.jsx)(o.default,{src:l.path,width:80,alt:"Device screenshot"})}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:"Screenshot saved to: "}),(0,m.jsx)(i.Text,{color:"cyan",children:String(l.path||"")})]}),s&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",String(a.originalWidth),"x",String(a.originalHeight)]}),c&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(a.originalFileSize)/1024).toFixed(1)," KB"]}),l.file?.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:["Updated: ",new Date(l.file.updatedAt).toLocaleString()]})]})]}),!t&&!n&&!l&&(0,m.jsx)(i.Box,{marginY:1,children:(0,m.jsx)(i.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:r})})]})},G=({apps:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading applications..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No applications found"});var n=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,m.jsx)(k,{items:n,onSelect:t})]})},V=({app:e,loading:l,error:t,onSelect:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading application..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Application not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],r=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Devices"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Total: ",r,r>0&&` (${a} online)`]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Features"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,m.jsxs)(i.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"🔒 Locked":"🔓 Unlocked"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:o,onSelect:n})]})},F=({modules:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading modules..."});var n=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No modules found"}),(0,m.jsx)(k,{items:n,onSelect:t})]})},H=({module:e,loading:l,error:t,onSelect:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading module..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Module not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Version"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,m.jsxs)(i.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Usage"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Settings"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:o,onSelect:n})]})},$=({groups:e,loading:l,onSelect:t,countdown:n,lastRefreshTime:o})=>{if(l)return(0,m.jsx)(b,{text:"Loading device groups..."});var r=[...(e||[]).map(e=>({label:`📁 ${e.name} (${e.devices?.length||0} devices)`,value:e._id,group:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{marginBottom:1,children:[(0,m.jsxs)(i.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:n,lastRefreshTime:o})]}),!e?.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No device groups found"}),(0,m.jsx)(k,{items:r,onSelect:t})]})},q=({loading:e,groupDevices:l})=>e?(0,m.jsx)(b,{text:"Loading devices..."}):l?.length?(0,m.jsxs)(m.Fragment,{children:[l.slice(0,10).map(e=>(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{color:"gray",children:" "}),(0,m.jsx)(v,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),l.length>10&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",l.length-10," more"]})]}):(0,m.jsx)(i.Text,{color:"gray",children:" No devices in this group"}),z=({group:e,groupDevices:l,loading:t,error:n,onSelect:o,countdown:r,lastRefreshTime:a})=>{if(t&&!e)return(0,m.jsx)(b,{text:"Loading device group..."});if(n)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",n]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:o})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Device group not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name}),(0,m.jsx)(i.Text,{color:"gray",children:" - "}),(0,m.jsx)(j,{countdown:r,lastRefreshTime:a})]}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,m.jsx)(q,{loading:t,groupDevices:l})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,m.jsxs)(i.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})]})},Y=({boxes:e,loading:l,onSelect:t})=>{if(l)return(0,m.jsx)(b,{text:"Loading media boxes..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media boxes found"});var n=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,m.jsx)(k,{items:n,onSelect:t})]})},W=({box:e,loading:l,error:t,onSelect:n})=>{if(l&&!e)return(0,m.jsx)(b,{text:"Loading media box..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Media box not found"});return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsxs)(i.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,m.jsxs)(i.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&(0,m.jsxs)(i.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},X=({files:e,loading:l,onSelect:t,box:n})=>{if(l)return(0,m.jsx)(b,{text:"Loading media files..."});if(!e?.length)return(0,m.jsx)(i.Text,{color:"yellow",children:"No media files found"});var o=[...e.map(e=>{return{label:`${l=e.fileType,"Image"===l?"🖼":"Video"===l?"🎞":"Audio"===l?"🎵":"📄"} ${e.name||"Unnamed"}`,value:e.id,file:e};var l}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",n?.name?` - ${n.name}`:""]}),(0,m.jsx)(k,{items:o,onSelect:t})]})},J=({file:e,loading:l,error:t,onSelect:n})=>{if(l&&!e)return(0,m.jsx)(b,{text:"Loading media file..."});if(t)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",t]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,m.jsx)(i.Text,{color:"red",children:"Media file not found"});var o=e.meta,r=(0,d.Gu)(e),a=(0,d.Gu)(e,{preferThumbnail:!0}),s=Boolean(a&&a!==r);return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,m.jsx)(i.Text,{color:"gray",children:e.description}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"gray",children:["ID: ",e.id]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,m.jsxs)(i.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,m.jsxs)(i.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),null!=o?.originalWidth&&null!=o?.originalHeight&&(0,m.jsxs)(i.Text,{color:"gray",children:["Size: ",o.originalWidth,"x",o.originalHeight]}),null!=o?.originalFileSize&&(0,m.jsxs)(i.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),r&&(0,m.jsxs)(i.Text,{color:"gray",children:["Original URL: ",r]}),s&&(0,m.jsxs)(i.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,m.jsxs)(i.Box,{flexDirection:"column",marginTop:1,children:[(0,m.jsx)(i.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,m.jsxs)(i.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,m.jsx)(k,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},K=t(88568);function Q({value:e,placeholder:l="",focus:t=!0,mask:o,highlightPastedText:r=!1,showCursor:a=!0,onChange:s,onSubmit:c}){const[d,u]=(0,n.useState)({cursorOffset:(e||"").length,cursorWidth:0}),{cursorOffset:x,cursorWidth:h}=d;(0,n.useEffect)(()=>{u(l=>{if(!t||!a)return l;const n=e||"";return l.cursorOffset>n.length-1?{cursorOffset:n.length,cursorWidth:0}:l})},[e,t,a]);const g=r?h:0,f=o?o.repeat(e.length):e;let m=f,p=l?K.Ay.grey(l):void 0;if(a&&t){p=l.length>0?K.Ay.inverse(l[0])+K.Ay.grey(l.slice(1)):K.Ay.inverse(" "),m=f.length>0?"":K.Ay.inverse(" ");let e=0;for(const l of f)m+=e>=x-g&&e<=x?K.Ay.inverse(l):l,e++;f.length>0&&x===f.length&&(m+=K.Ay.inverse(" "))}return(0,i.useInput)((l,t)=>{if(t.upArrow||t.downArrow||t.ctrl&&"c"===l||t.tab||t.shift&&t.tab)return;if(t.return)return void(c&&c(e));let n=x,i=e,o=0;t.leftArrow?a&&n--:t.rightArrow?a&&n++:t.backspace||t.delete?x>0&&(i=e.slice(0,x-1)+e.slice(x,e.length),n--):(i=e.slice(0,x)+l+e.slice(x,e.length),n+=l.length,l.length>1&&(o=l.length)),x<0&&(n=0),x>e.length&&(n=e.length),u({cursorOffset:n,cursorWidth:o}),i!==e&&s(i)},{isActive:t}),n.default.createElement(i.Text,null,l?f.length>0?m:p:m)}const Z=Q;var ee,le=t(35704),te=["B","C","G","D"],ne=({instanceType:e,instance:l,client:t,onDone:o,onCancel:s})=>{var c=(0,i.useApp)().exit,d=(0,n.useState)("select_ref"),u=a(d,2),x=u[0],h=u[1],g=(0,n.useState)(""),f=a(g,2),p=f[0],j=f[1],D=(0,n.useState)("search"),T=a(D,2),v=T[0],_=T[1],y=(0,n.useState)(null),B=a(y,2),S=B[0],E=B[1],w=(0,n.useState)(null),L=a(w,2),I=L[0],A=L[1],C=(0,n.useState)(""),R=a(C,2),U=R[0],O=R[1],P=(0,n.useState)(""),M=a(P,2),N=M[0],G=M[1],V=(0,n.useState)(null),F=a(V,2),H=F[0],$=F[1],q=l?.short_edit?.ref_map||{},z=Object.entries(q).filter(([,e])=>e&&!e.hide),Y=(0,le.V)(q,{keyword:p,types:te}),W=Y.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:l})=>({label:`${l.title||e} (${e})`,value:e,ref:l}))]),X=[...p?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],J=W.length>0?[...W,...X]:X,K=J.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,i.useInput)((e,l)=>{l.tab&&"select_ref"===x?_(e=>"search"===e?"list":"search"):(l.escape&&("select_ref"===x&&s(),"input_path"===x&&h("select_ref"),"input_content"===x&&h("input_path"),"confirm"===x&&h("input_content"),"done"===x&&s()),"q"!==e||("input_path"===x||"input_content"===x)||"select_ref"===x&&"search"===v||c())},{isActive:!0});var Q,ee=e=>{var l=e.trim();if(""===l)return null;try{return JSON.parse(l)}catch{return l}},ne=(Q=r(function*(){if(t&&l?._id&&S){h("submitting"),$(null);try{var n={shortId:S,path:U.trim(),content:ee(N),forwardDataLink:!0};I?.inner_ref?.pid&&(n.innerRefParentShortId=I.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:l._id,list:[n]}):yield t.shortEditModule({id:l._id,list:[n]}),yield o(),h("done")}catch(e){$(e.message),h("confirm")}}}),function(){return Q.apply(this,arguments)});return l?.short_edit?.enabled?0===z.length?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"yellow",children:"No Short Edit references found."}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,children:"Short Edit References"}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,m.jsxs)(i.Box,{marginTop:1,flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"gray",children:"Search (title or shortId)"}),(0,m.jsx)(Z,{value:p,placeholder:"type to filter, Enter to focus list",onChange:e=>j(e),onSubmit:()=>_("list"),focus:"search"===v}),(0,m.jsx)(i.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,m.jsxs)(i.Box,{marginTop:1,children:[0===Y.length&&(0,m.jsx)(i.Text,{color:"yellow",children:"No references match your search."}),(0,m.jsx)(k,{items:J,isFocused:"list"===v,initialIndex:K>-1?K:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:l,isHeader:t})=>t?(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(i.Text,{bold:!0,color:"white",children:e})}):(0,m.jsxs)(i.Text,{color:l?"blue":void 0,children:[l?"❯":" "," ",e]}),onSelect:e=>{if("__back__"!==e.value)return"__clear_search__"===e.value?(j(""),void _("search")):void(e.isHeader||(E(e.value),A(e.ref),h("input_path")));s()}})]})]}):"input_path"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(Z,{value:U,placeholder:"path",onChange:e=>{O(e),H&&$(null)},onSubmit:e=>{var l=e.trim();l?(O(l),h("input_content")):$("Path is required")},focus:!0})]}):"input_content"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:U})]}),(0,m.jsx)(i.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(Z,{value:N,placeholder:"content",onChange:e=>{G(e),H&&$(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===x?(0,m.jsx)(b,{text:"Applying short edit..."}):"done"===x?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{color:"green",children:"Short edit applied successfully."}),(0,m.jsx)(k,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),E(null),A(null),O(""),G(""),$(null)):s()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,m.jsxs)(i.Text,{children:["Reference:"," ",(0,m.jsxs)(i.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:U})]}),(0,m.jsxs)(i.Text,{children:["Content: ",(0,m.jsx)(i.Text,{color:"cyan",children:N||"<empty>"})]}),H&&(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",H]}),(0,m.jsx)(k,{items:[{label:"Apply",value:"apply"},{label:"Edit Path",value:"edit_path"},{label:"Edit Content",value:"edit_content"},{label:"← Back",value:"back"}],onSelect:e=>{"apply"===e.value&&ne(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,m.jsx)(k,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},ie=t(16928),oe=t(79896),re=t(35317),ae=t(10750),se="options",ce="output_dir",de="confirm",ue="generating",xe="post_install",he="done",ge=e=>{try{return(0,re.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},fe=(e,l,t)=>new Promise((n,i)=>{var o=[e,...l].join(" "),r=(0,re.spawn)(o,[],{cwd:t,stdio:"pipe",shell:!0});r.on("close",e=>{0===e?n():i(new Error(`Command failed with code ${e}`))}),r.on("error",i)}),me=(ee=r(function*(e,l){try{var n=(yield Promise.resolve().then(t.bind(t,79491))).format;return(yield n(l,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,l){return ee.apply(this,arguments)}),pe=({type:e,instance:l,client:t,onDone:o,onCancel:s})=>{var c,d=(0,i.useApp)().exit,u=(0,n.useState)(se),x=a(u,2),h=x[0],g=x[1],p=(0,n.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),j=a(p,2),D=j[0],T=j[1],b=(0,n.useState)(process.cwd()),v=a(b,2),_=v[0],y=v[1],B=(0,n.useState)(""),S=a(B,2),E=S[0],w=S[1],L=(0,n.useState)(null),I=a(L,2),A=I[0],C=I[1],R=(0,n.useState)(null),U=a(R,2),O=U[0],P=U[1],M=ae(l?.name||"bricks-ctor"),N=ie.resolve(_,M),G=(0,n.useCallback)(e=>{"back"!==e.value?"continue"!==e.value?T(l=>({...l,[e.value]:!l[e.value]})):g(ce):s()},[s]),V=(0,n.useCallback)(()=>{oe.existsSync(N)?C(`Directory already exists: ${N}`):(C(null),g(de))},[N]),F=(0,n.useCallback)((c=r(function*(n){var i;if("back"!==n.value)if("cancel"!==n.value){if("confirm"===n.value){g(ue);try{w("Fetching project from BRICKS...");var o="application"===e,a=o?"UNSTABLE_applicationProject":"UNSTABLE_moduleProject",c=o?t.queries.applicationProject:t.queries.moduleProject,d=(yield t.query(c,{id:l._id,buildApplicationOnly:!1,setupGitHubActions:D.setupGitHubActions,setupAgents:D.setupAgents,setupClaudeCode:D.setupClaudeCode,setupGeminiCLI:D.setupGeminiCLI}))[a];if(!d?.files)throw new Error("Failed to fetch project files");w("Creating project directory..."),oe.mkdirSync(N,{recursive:!0}),w(`Writing ${d.files.length} files...`);var u=yield Promise.all(d.files.map((i=r(function*(e){var l=ie.join(N,e.name),t=e.input;return e.formatable&&(t=yield me(t,l)),{...e,filePath:l,content:t}}),function(e){return i.apply(this,arguments)})));u.forEach(e=>{var l=ie.dirname(e.filePath);oe.existsSync(l)||oe.mkdirSync(l,{recursive:!0}),oe.writeFileSync(e.filePath,e.content)}),g(xe);var x={path:N,files:d.files.length,bunInstalled:!1,gitInitialized:!1};if(D.runBunInstall&&ge("bun")){w("Installing dependencies (bun install)...");try{yield fe("bun",["install"],N),x.bunInstalled=!0}catch{}}if(D.initGit&&ge("git")){w("Initializing git repository...");try{yield fe("git",["init"],N),yield fe("git",["add","."],N),yield fe("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],N),x.gitInitialized=!0}catch{}}P(x),g(he)}catch(e){C(e.message),g(se)}}}else s();else g(ce)}),function(e){return c.apply(this,arguments)}),[t,l,e,D,N,s]),H=(0,n.useCallback)(e=>{"exit"===e.value?d():o()},[d,o]);if(h===se){var $=[{label:(D.setupGitHubActions?"[x]":"[ ]")+" GitHub Actions workflow",value:"setupGitHubActions"},{label:(D.setupAgents?"[x]":"[ ]")+" AGENTS.md",value:"setupAgents"},{label:(D.setupClaudeCode?"[x]":"[ ]")+" CLAUDE.md",value:"setupClaudeCode"},{label:(D.setupGeminiCLI?"[x]":"[ ]")+" GEMINI.md",value:"setupGeminiCLI"},{label:(D.runBunInstall?"[x]":"[ ]")+" Run bun install after generation",value:"runBunInstall"},{label:(D.initGit?"[x]":"[ ]")+" Initialize git repository",value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsxs)(i.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",l?.name||"Untitled"]}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),A&&(0,m.jsxs)(i.Text,{color:"red",marginBottom:1,children:["Error: ",A]}),(0,m.jsx)(k,{items:$,onSelect:G})]})}if(h===ce)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,m.jsx)(i.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),A&&(0,m.jsx)(i.Text,{color:"red",marginBottom:1,children:A}),(0,m.jsxs)(i.Box,{children:[(0,m.jsx)(i.Text,{children:"Directory: "}),(0,m.jsx)(Z,{value:_,onChange:y,onSubmit:V})]}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",N]})]});if(h===de){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Name: ",(0,m.jsx)(i.Text,{color:"green",children:l?.name||"Untitled"})]}),(0,m.jsxs)(i.Text,{children:["Type: ",(0,m.jsx)(i.Text,{color:"yellow",children:e})]}),(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:N})]}),(0,m.jsx)(i.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GitHub Actions: ",D.setupGitHubActions?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - AGENTS.md: ",D.setupAgents?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - CLAUDE.md: ",D.setupClaudeCode?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - GEMINI.md: ",D.setupGeminiCLI?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Run bun install: ",D.runBunInstall?"Yes":"No"]}),(0,m.jsxs)(i.Text,{color:"gray",children:[" - Initialize git: ",D.initGit?"Yes":"No"]})]}),(0,m.jsx)(k,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:F})]})}if(h===ue||h===xe)return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,m.jsxs)(i.Box,{marginY:1,children:[(0,m.jsx)(i.Text,{color:"green",children:(0,m.jsx)(f,{type:"dots"})}),(0,m.jsxs)(i.Text,{children:[" ",E]})]})]});if(h===he&&O){return(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(i.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,m.jsxs)(i.Box,{marginY:1,flexDirection:"column",children:[(0,m.jsxs)(i.Text,{children:["Path: ",(0,m.jsx)(i.Text,{color:"cyan",children:O.path})]}),(0,m.jsxs)(i.Text,{children:["Files: ",(0,m.jsx)(i.Text,{color:"green",children:O.files})]}),(0,m.jsxs)(i.Text,{children:["Dependencies:"," ",(0,m.jsx)(i.Text,{color:O.bunInstalled?"green":"yellow",children:O.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,m.jsxs)(i.Text,{children:["Git:"," ",(0,m.jsx)(i.Text,{color:O.gitInitialized?"green":"yellow",children:O.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,m.jsx)(i.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,m.jsxs)(i.Text,{color:"gray",children:[" cd ",M]}),!O.bunInstalled&&(0,m.jsx)(i.Text,{color:"gray",children:" bun install"}),(0,m.jsx)(i.Text,{color:"gray",children:" bun preview"}),(0,m.jsxs)(i.Text,{color:"gray",marginTop:1,children:["For more information, see ",M,"/README.md"]}),(0,m.jsx)(i.Box,{marginTop:1,children:(0,m.jsx)(k,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:H})})]})}return null};const je=()=>{var e=(0,i.useApp)().exit,l=(0,n.useState)(u.MAIN),t=a(l,2),o=t[0],x=t[1],h=(0,n.useState)(null),g=a(h,2),f=g[0],j=g[1],v=(0,n.useState)(null),_=a(v,2),y=_[0],B=_[1],S=(0,n.useState)(!0),E=a(S,2),w=E[0],L=E[1],I=(0,n.useState)(null),A=a(I,2),C=A[0],R=A[1],k=(0,n.useState)([]),q=a(k,2),K=q[0],Q=q[1],Z=(0,n.useState)(null),ee=a(Z,2),le=ee[0],te=ee[1],ie=(0,n.useState)([]),oe=a(ie,2),re=oe[0],ae=oe[1],se=(0,n.useState)(null),ce=a(se,2),de=ce[0],ue=ce[1],xe=(0,n.useState)([]),he=a(xe,2),ge=he[0],fe=he[1],me=(0,n.useState)(null),je=a(me,2),De=je[0],Te=je[1],be=(0,n.useState)([]),ve=a(be,2),_e=ve[0],ye=ve[1],Be=(0,n.useState)(null),Se=a(Be,2),Ee=Se[0],we=Se[1],Le=(0,n.useState)([]),Ie=a(Le,2),Ae=Ie[0],Ce=Ie[1],Re=(0,n.useState)(!1),ke=a(Re,2),Ue=ke[0],Oe=ke[1],Pe=(0,n.useState)(null),Me=a(Pe,2),Ne=Me[0],Ge=Me[1],Ve=(0,n.useState)(null),Fe=a(Ve,2),He=Fe[0],$e=Fe[1],qe=(0,n.useState)(null),ze=a(qe,2),Ye=ze[0],We=ze[1],Xe=(0,n.useState)(null),Je=a(Xe,2),Ke=Je[0],Qe=Je[1],Ze=(0,n.useState)([]),el=a(Ze,2),ll=el[0],tl=el[1],nl=(0,n.useState)(null),il=a(nl,2),ol=il[0],rl=il[1],al=(0,n.useState)([]),sl=a(al,2),cl=sl[0],dl=sl[1],ul=(0,n.useState)(null),xl=a(ul,2),hl=xl[0],gl=xl[1],fl=o===u.DEVICES,ml=o===u.DEVICE_DETAIL,pl=o===u.GROUPS,jl=o===u.GROUP_DETAIL;(0,n.useEffect)(()=>{var e=(0,c.getCurrentProfile)(),l=(0,c.getToken)(e);if(!l)return R("Not logged in. Run `bricks auth login` first."),void L(!1);var t=(0,s.createClient)((0,c.getBaseUrl)(),l);j(t),t.workspace().then(e=>{B(e),L(!1)}).catch(e=>{R(e.message),L(!1)})},[]),(0,i.useInput)((l,t)=>{"q"===l&&e(),t.escape&&(o===u.DEVICE_CONTROL?(x(u.DEVICE_DETAIL),Ge(null)):o===u.DEVICE_SCREENSHOT?(x(u.DEVICE_DETAIL),We(null),Qe(null)):o===u.DEVICE_DETAIL?(x(u.DEVICES),te(null)):o===u.APP_DETAIL?(x(u.APPS),ue(null)):o===u.MODULE_DETAIL?(x(u.MODULES),Te(null)):o===u.GROUP_DETAIL?(x(u.GROUPS),we(null),Ce([])):o===u.MEDIA_FILE_DETAIL?(x(u.MEDIA_FILES),gl(null)):o===u.MEDIA_FILES?(x(u.MEDIA_BOX_DETAIL),gl(null)):o===u.MEDIA_BOX_DETAIL?(x(u.MEDIA_BOXES),rl(null),dl([])):(o===u.MEDIA_BOXES||o!==u.MAIN)&&x(u.MAIN))},{isActive:o!==u.APP_SHORT_EDIT&&o!==u.MODULE_SHORT_EDIT&&o!==u.APP_PROJECT_INIT&&o!==u.MODULE_PROJECT_INIT});var Dl,Tl,bl,vl,_l,yl,Bl,Sl,El=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.devices({});Q(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),wl=(0,n.useCallback)((Dl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.device({id:e});te(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Dl.apply(this,arguments)}),[f]),Ll=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.applications({});ae(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Il=(0,n.useCallback)((Tl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.application({id:e});ue(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Tl.apply(this,arguments)}),[f]),Al=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.modules({});fe(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Cl=(0,n.useCallback)((bl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.module({id:e});Te(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return bl.apply(this,arguments)}),[f]),Rl=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.deviceGroups({});ye(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),kl=(0,n.useCallback)((vl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield Promise.all([f.deviceGroup({id:e}),f.devicesByGroup({id:e})]),t=a(l,2),n=t[0],i=t[1];we(n),Ce(i||[])}catch(e){$e(e.message)}L(!1)}}),function(e){return vl.apply(this,arguments)}),[f]),Ul=(0,n.useCallback)(r(function*(){if(f){L(!0);try{var e=yield f.mediaBoxes();tl(e||[])}catch(e){R(e.message)}L(!1)}}),[f]),Ol=(0,n.useCallback)((_l=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.mediaBox({id:e});rl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return _l.apply(this,arguments)}),[f]),Pl=(0,n.useCallback)((yl=r(function*(e){if(f){L(!0);try{var l=yield f.mediaFiles({boxId:e});dl(l||[])}catch(e){R(e.message)}L(!1)}}),function(e){return yl.apply(this,arguments)}),[f]),Ml=(0,n.useCallback)((Bl=r(function*(e){if(f){L(!0),$e(null);try{var l=yield f.mediaFile({id:e});gl(l)}catch(e){$e(e.message)}L(!1)}}),function(e){return Bl.apply(this,arguments)}),[f]),Nl=(0,n.useCallback)((Sl=r(function*(e){if(f&&le){Oe(!0),Ge(null);try{yield f.controlDevice({id:le._id,type:e}),Ge({success:!0,message:`Command sent: ${e}`})}catch(e){Ge({success:!1,message:e.message})}Oe(!1)}}),function(e){return Sl.apply(this,arguments)}),[f,le]),Gl=(0,n.useCallback)(r(function*(e=!1){if(f&&le&&y){L(!0),Qe(null),We(null);try{e&&(yield f.controlDevice({id:le._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var l=yield(0,d.he)(f,y,le._id,null,{preferThumbnail:!0});l.error?Qe(l.error):We(l)}catch(e){Qe(e.message)}L(!1)}}),[f,le,y]),Vl=p((0,n.useCallback)(()=>{f&&El()},[f,El]),fl),Fl=p((0,n.useCallback)(()=>{f&&le&&wl(le._id)},[f,le,wl]),ml),Hl=p((0,n.useCallback)(()=>{f&&Rl()},[f,Rl]),pl),$l=p((0,n.useCallback)(()=>{f&&Ee&&kl(Ee._id)},[f,Ee,kl]),jl);return w&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),(0,m.jsx)(b,{text:"Connecting to workspace..."})]}):C&&!y?(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),(0,m.jsxs)(i.Text,{color:"red",children:["Error: ",C]}),(0,m.jsx)(T,{})]}):(0,m.jsxs)(i.Box,{flexDirection:"column",children:[(0,m.jsx)(D,{workspace:y,view:o}),o===u.MAIN&&(0,m.jsx)(U,{onSelect:l=>{"exit"!==l.value?(x(l.value),l.value===u.DEVICES?El():l.value===u.APPS?Ll():l.value===u.MODULES?Al():l.value===u.GROUPS?Rl():l.value===u.MEDIA_BOXES&&Ul()):e()},mediaEnabled:(0,d.wR)(y)}),o===u.DEVICES&&(0,m.jsx)(O,{devices:K,loading:w,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return El(),void Vl.resetCountdown();te(null),L(!0),x(u.DEVICE_DETAIL),wl(e.value)}else x(u.MAIN)},countdown:Vl.countdown,lastRefreshTime:Vl.lastRefreshTime}),o===u.DEVICE_DETAIL&&(0,m.jsx)(P,{device:le,loading:w,error:He,onSelect:e=>"back"===e.value?(x(u.DEVICES),void te(null)):"refresh"===e.value?(wl(le._id),void Fl.resetCountdown()):("control"===e.value&&(x(u.DEVICE_CONTROL),Ge(null)),void("screenshot"===e.value&&(x(u.DEVICE_SCREENSHOT),We(null),Qe(null),Gl(!1)))),mediaEnabled:(0,d.wR)(y),countdown:Fl.countdown,lastRefreshTime:Fl.lastRefreshTime}),o===u.DEVICE_CONTROL&&(0,m.jsx)(M,{device:le,onSelect:e=>{if("back"===e.value)return x(u.DEVICE_DETAIL),void Ge(null);Nl(e.value)},controlling:Ue,controlResult:Ne}),o===u.DEVICE_SCREENSHOT&&(0,m.jsx)(N,{device:le,screenshot:Ye,loading:w,error:Ke,onSelect:e=>{if("back"===e.value)return x(u.DEVICE_DETAIL),We(null),void Qe(null);"refresh"!==e.value?"take"===e.value&&Gl(!0):Gl(!1)}}),o===u.APPS&&(0,m.jsx)(G,{apps:re,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(ue(null),L(!0),x(u.APP_DETAIL),Il(e.value)):Ll():x(u.MAIN)}}),o===u.APP_DETAIL&&(0,m.jsx)(V,{app:de,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.APPS),void ue(null);"refresh"!==e.value?("short_edit"===e.value&&(x(u.APP_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(u.APP_PROJECT_INIT),$e(null))):Il(de._id)}}),o===u.APP_SHORT_EDIT&&(0,m.jsx)(ne,{instanceType:"application",instance:de,client:f,onDone:r(function*(){return Il(de._id)}),onCancel:()=>x(u.APP_DETAIL)}),o===u.APP_PROJECT_INIT&&(0,m.jsx)(pe,{type:"application",instance:de,client:f,onDone:()=>x(u.APP_DETAIL),onCancel:()=>x(u.APP_DETAIL)}),o===u.MODULES&&(0,m.jsx)(F,{modules:ge,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(Te(null),L(!0),x(u.MODULE_DETAIL),Cl(e.value)):Al():x(u.MAIN)}}),o===u.MODULE_DETAIL&&(0,m.jsx)(H,{module:De,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MODULES),void Te(null);"refresh"!==e.value?("short_edit"===e.value&&(x(u.MODULE_SHORT_EDIT),$e(null)),"project_init"===e.value&&(x(u.MODULE_PROJECT_INIT),$e(null))):Cl(De._id)}}),o===u.MODULE_SHORT_EDIT&&(0,m.jsx)(ne,{instanceType:"module",instance:De,client:f,onDone:r(function*(){return Cl(De._id)}),onCancel:()=>x(u.MODULE_DETAIL)}),o===u.MODULE_PROJECT_INIT&&(0,m.jsx)(pe,{type:"module",instance:De,client:f,onDone:()=>x(u.MODULE_DETAIL),onCancel:()=>x(u.MODULE_DETAIL)}),o===u.GROUPS&&(0,m.jsx)($,{groups:_e,loading:w,onSelect:e=>{if("back"!==e.value){if("refresh"===e.value)return Rl(),void Hl.resetCountdown();we(null),Ce([]),L(!0),x(u.GROUP_DETAIL),kl(e.value)}else x(u.MAIN)},countdown:Hl.countdown,lastRefreshTime:Hl.lastRefreshTime}),o===u.GROUP_DETAIL&&(0,m.jsx)(z,{group:Ee,groupDevices:Ae,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.GROUPS),we(null),void Ce([]);"refresh"===e.value&&(kl(Ee._id),$l.resetCountdown())},countdown:$l.countdown,lastRefreshTime:$l.lastRefreshTime}),o===u.MEDIA_BOXES&&(0,m.jsx)(Y,{boxes:ll,loading:w,onSelect:e=>{"back"!==e.value?"refresh"!==e.value?(rl(null),dl([]),L(!0),x(u.MEDIA_BOX_DETAIL),Ol(e.value)):Ul():x(u.MAIN)}}),o===u.MEDIA_BOX_DETAIL&&(0,m.jsx)(W,{box:ol,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_BOXES),rl(null),void dl([]);"refresh"!==e.value?"files"===e.value&&(dl([]),gl(null),x(u.MEDIA_FILES),Pl(ol.id)):Ol(ol.id)}}),o===u.MEDIA_FILES&&(0,m.jsx)(X,{files:cl,box:ol,loading:w,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_BOX_DETAIL),void gl(null);"refresh"!==e.value?(gl(null),L(!0),x(u.MEDIA_FILE_DETAIL),Ml(e.value)):Pl(ol.id)}}),o===u.MEDIA_FILE_DETAIL&&(0,m.jsx)(J,{file:hl,loading:w,error:He,onSelect:e=>{if("back"===e.value)return x(u.MEDIA_FILES),void gl(null);"refresh"===e.value&&Ml(hl.id)}}),(0,m.jsx)(T,{})]})};var De=()=>{(0,i.render)((0,m.jsx)(o.TerminalInfoProvider,{children:(0,m.jsx)(je,{})}))}}};
|
package/lib/index.js
CHANGED
|
@@ -3141,4 +3141,4 @@ import{createRequire as e}from"node:module";const t=e(import.meta.url);import*as
|
|
|
3141
3141
|
}
|
|
3142
3142
|
}
|
|
3143
3143
|
${Xh}
|
|
3144
|
-
`,Sy={query:"query",mutation:"mutate"},wy=(e,t,a)=>([n,r])=>{if(e[n])throw new Error(`Overwriting client.${n}`);e[n]=async(i,o={})=>{let s,p;const l={[t]:r,variables:i,...o};if(a&&(l.variables={...a,...l.variables}),o.readQuery)s=e.readQuery(l);else if(o.writeQuery)e.writeQuery({...l,data:o.writeQuery});else{const a=await e[Sy[t]](l);({data:s,errors:p}=a||{})}if(p)throw new Error(p.map(e=>e.message).join("\n"));return s?s[n]:null}},Iy=e=>({data:t,errors:a})=>{const n=((e,t)=>e?.length?new Error(e.map(e=>e.message).join("\n")):t?new Error(t):null)(a,!t?.mediaBoxChanged&&"Missing mediaBoxChanged payload");return n?e(n):e(null,t.mediaBoxChanged)},Cy=(e={})=>{const t=(({endpoint:e="http://localhost:3002",accessToken:t,boxId:a,passcode:n,enableSubscription:r=!0,enableRetry:i=!0,subscriptionOnConnectionOrError:o,onNetworkError:s}={})=>{const p=a&&n;let l=`${e}/api/graphql`;return p&&(l=`${e}/api/graphql_with_passcode`),Zh({endpointURL:l,subscriptionEndpointURL:l.replace("http:","ws:"),accessToken:t,enableSubscription:!p&&r,enableRetry:i,subscriptionOnConnectionOrError:o,onNetworkError:s})})(e);if(e.boxId&&e.passcode){t.type="passcode",t.queries=S,t.mutations=w;const a={boxId:e.boxId,passcode:e.passcode};Object.entries(S).forEach(wy(t,"query",a)),Object.entries(w).forEach(wy(t,"mutation",a)),t.listenBoxChanged=(e,n)=>t.subscribe({query:Ay,variables:{...a,...e}}).subscribe({next:Iy(n),error(e){n(e)}})}else t.accessToken=e.accessToken,t.type="token",t.queries=N,t.mutations=A,Object.entries(N).forEach(wy(t,"query")),Object.entries(A).forEach(wy(t,"mutation")),t.listenBoxChanged=(e,a)=>t.subscribe({query:Ey,variables:e}).subscribe({next:Iy(a),error(e){a(e)}});return t};function Dy(e,t,a){switch(a){case"user":return new Rf(e,t);case"workspace":return new sh(e,t);default:throw new Error(`Invalid token type: ${a}.`)}}process.env.STAGE,process.env.URL_BASE;var Py="bricks-mcp",jy={bricks:process.env.BRICKS_API_SERVER||"https://display-beta.bricks.tools",media:process.env.MEDIA_API_SERVER||"https://media-beta.bricks.tools"},ky=(process.env.AUTH0_DOMAIN,process.env.CACHE_URL,E(1639));const Ly=({type:e,title:t,template_key:a})=>{var n,r,i=(0,ky.makeId)(e);switch(e){case"subspace":n={title:t,layout:{width:"number",height:"number"},root_canvas_id:"CANVAS_<UUID>",canvas_map:{},brick_map:{},animation_map:{},generator_map:{},property_bank_map:{},property_bank_calc_map:{}},r={"canvas_map.CANVAS_<UUID>.item_list":[{type:"subspace",subspace_id:"SUBSPACE_<UUID>",$note:"If not a root subspace, it can be linked to canvas in other subspace"}]};break;case"canvas":var o=cd(ud.canvas);n={title:t,item_list:[],property:{$definitions:Object.fromEntries(Object.entries(o.propTypes).map(([e,t])=>[e,{...t,description:o.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(o.eventTypes).map(([e])=>[e,{description:o.brickEventDescriptions[e]}]))}},r={property_bank_map:{[(0,ky.makeId)("property_bank")]:{title:`Canvas ID: ${t}`,type:"string",value:i,routing:"read-only",kind:"auto-generated-item-id",idType:"canvas"}}};break;case"brick":var s=cd(ud.components.Basic),p=cd(ud.brickMapping[a]);if(!p)throw new Error(`Brick ${a} not found`);var l={...p,propTypes:{...s.propTypes,...p.propTypes},brickPropDescriptions:{...s.brickPropDescriptions,...p.brickPropDescriptions},eventTypes:{...s.eventTypes,...p.eventTypes},brickEventDescriptions:{...s.brickEventDescriptions,...p.brickEventDescriptions}};n={title:t,template_key:a,property:{$definitions:Object.fromEntries(Object.entries(l.propTypes).map(([e,t])=>[e,{...t,description:l.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(l.eventTypes).map(([e])=>[e,{description:l.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(l.outletTypes).map(([e])=>[e,{description:l.brickOutletDescriptions[e]}]))},state_group:{"BRICK_STATE_GROUP_<UUID>":{}}},r={canvas_map:{"CANVAS_<UUID WHICH NEED DISPLAY THIS BRICK>":{item_list:[{type:"brick",brick_id:i,frame:{x:"number",y:"number",width:"number",height:"number",standby_mode:"custom|top|left|right|bottom",standby_delay:"number",standby_easing:{default:{method:"ease",duration:"number"}}}}]}}};break;case"state_group":n={title:t,description:"State Group Description",conds:[{type:"property_bank|inner_state",key:"PROPERTY_BANK#<Data Node ID>|[current_canvas|BRICK_<OUTLET NAME>]|",method:"==|!=|>|>=|<|<=",value:"value_to_compare"}],override:{property:!1,event:!1,outlet:!1},commented:!1,break:!1,property:{},outlet:{},animation:{}};case"generator":var u=cd(ud.generatorMapping[a]);if(!u)throw new Error(`Generator ${a} not found`);n={title:t,template_key:a,property:{$definitions:Object.fromEntries(Object.entries(u.propTypes).map(([e,t])=>[e,{...t,description:u.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(u.eventTypes).map(([e])=>[e,{description:u.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(u.outletTypes).map(([e])=>[e,{description:u.brickOutletDescriptions[e]}]))}};break;case"animation":n={title:t,type:"timing|decay|spring",property:"opacity|transform.translateX|transform.scale|etc",config:{$note:"Config for the animation"},compose_type:"parallel|sequence",item_list:[{animation_id:"ANIMATION_<SUB ANIMATION UUID>"}]};break;case"property_bank":n={title:t,description:"Property Bank Description",linkedFrom:"SUBSPACE_<UUID WHICH IS CROSS SUBSPACE>",type:"string|number|bool|object|array|any",kind:"color|datetime|id|media-resource-*|lottie-file-uri",unit:"grid|px|ms",routing:"read-only|default",value:"fit-to-type",event_map:{$note:`Available events: ${Object.keys(ud.propertyBank.eventTypes).join(", ")}`},local_sync:{update_mode:"all|main-only|minor-only|dont-sync"},$remote_update_additional:{$note:"Configure remote update behavior",enable_remote_update:!0,bank_type:"create|create-device-specific"}};break;case"property_bank_command":break;case"property_bank_calc":var c=(0,ky.makeId)("property_bank_command"),d=(0,ky.makeId)("property_bank_command"),m=(0,ky.makeId)("property_bank_command"),f="const { arg_name } = inputs;\n\nreturn { arg_name };";n={title:t,map:{$note:"Required, actual implementation","PROPERTY_BANK_DATA_NODE_<UUID>":{type:"data-node",properties:{},in:{change:null},out:{value:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID>",port:"value"}]},$note:"Use this to input data to the sandbox"},"PROPERTY_BANK_COMMAND_NODE_<UUID FIRST>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:null,path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${c}`,port:"obj | inputs"}]}},"PROPERTY_BANK_COMMAND_NODE_<UUID SECOND>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PREVIOUS>",port:"result"}],path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID SECOND>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${c}`,port:"obj | inputs"}]}},[c]:{type:"command-node-sandbox",title:"Command: SANDBOX_RUN_JAVASCRIPT",properties:{command:"SANDBOX_RUN_JAVASCRIPT",args:{code:f,enable_async:!1}},in:{code:null,inputs:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID FINAL>",port:"result"}]},out:{result:[{id:m,port:"result"},{id:d,port:"result"}]}},[m]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_ERROR",properties:{command:"SANDBOX_GET_ERROR"},in:{result:[{id:c,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR>",port:"change"}],$note:"Set `result` as null if there is no error"}},[d]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_RETURN_VALUE",properties:{command:"SANDBOX_GET_RETURN_VALUE"},in:{result:[{id:c,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT> | null",port:"change"}]}},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT>":{type:"data-node",properties:{},in:{change:[{id:d,port:"result"}]},out:{value:null},$note:"Put full result into data node"},"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>":{type:"command-node-object",title:"Command: OBJECT_GET",properties:{command:"OBJECT_GET",args:{path:"obj_key"}},in:{obj:[{id:d,port:"obj"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>",port:"change"}]},$note:"Parse result object into data node"},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>":{type:"data-node",properties:{},in:{change:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>",port:"result"}]},out:{value:null},$note:"Put partial result into data node"}},editor_info:{},type:"script",script_config:{title:t,enable_async:!1,inputs:{"PROPERTY_BANK_DATA_NODE_<UUID>":"arg_name"},disabled_triggers:{},error:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR> | null",output:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | null",outputs:{obj_key:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>"},code:f,$note:"Required, info for GUI editor"}}}return sc({id:i,example:n,extraInfo:r})};function xy(e,t){var a,n,r,i,o,s,p,l,u,c,d,m,f,h="user"===t.tokenType,y=((e,t=null)=>({name:a,description:n,inputSchema:r,permission:i},o)=>{_d(t,i)&&e.tool(a,n,r,o)})(e,t),_=e=>({...e,...h?{workspace_id:da().describe("Workspace ID")}:{}}),E=t.client,T=h?function(e){var t=e.endpoint,a=e.accessToken;if(!t)throw new Error("Media API endpoint is required");if(!a)throw new Error("Access token is required");return Cy({endpoint:t,accessToken:a,enableSubscription:!1,enableRetry:!0})}({endpoint:jy.media,accessToken:t.token}):E;h&&e.tool("list_workspaces","List all workspaces",{},I(function*(){return sc(yield E.workspaces())})),y({name:"get_workspace_overview",description:"Get comprehensive overview of the BRICKS workspace including stats and summary",inputSchema:_({}),permission:"info"},function(){var e=I(function*({workspace_id:e}){var t=yield Promise.all([E.workspace({id:e}),E.applications({workspaceId:e,paginate:{limit:50,offset:0}}),E.modules({workspaceId:e,paginate:{limit:50,offset:0}}),E.devices({workspaceId:e,paginate:{limit:50,offset:0}}),h?T.mediaWorkspace({workspaceId:e}).catch(()=>null):T.mediaWorkspace().catch(()=>null),h?T.mediaBoxes({workspaceId:e}).catch(()=>[]):T.mediaBoxes().catch(()=>[])]),a=ye(t,6),n=a[0],r=a[1],i=a[2],o=a[3],s=a[4],p=a[5];if(!n)throw new Error("Authentication failed, please check your token");return sc({workspace:n,stats:{applications:r?.length??"No permission",modules:i?.length??"No permission",devices:o?.length??"No permission",running_apps:r?.filter(e=>e.status?.running).length??"No permission",media_boxes:p?.length??"No permission",media_enabled:!!s,notes:"Note: The stats are based on the first 50 applications, modules, and devices in the workspace."},recent_activity:{latest_apps:r?.slice(0,5).map(e=>({id:e._id,name:e.name,status:e.status?.running?"running":"stopped",last_update:e.last_modify_datetime}))||[]},media_info:s?{workspace_id:s.id,name:s.name,size_used:s.size,size_limit:s.sizeLimit,boxes:p?.slice(0,5).map(e=>({id:e.id,name:e.name,size:e.size,description:e.description}))||[]}:{enabled:!1,note:"Media workspace is not enabled for this workspace"}})});return function(t){return e.apply(this,arguments)}}()),y({name:"get_applications",description:"List all applications in the workspace",inputSchema:_({limit:ma().describe("Maximum number of applications to return").optional().default(50),offset:ma().describe("Number of applications to skip").optional().default(0)}),permission:"query_application"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.applications({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_application",description:"Get detailed info and config of a specific application",inputSchema:_({id:da().describe("Application ID")}),permission:"query_application"},function(){var e=I(function*({workspace_id:e,id:t}){return sc(yield E.application({workspaceId:e,id:t}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_modules",description:"List all modules in the workspace",inputSchema:_({limit:ma().describe("Maximum number of modules to return").optional().default(50),offset:ma().describe("Number of modules to skip").optional().default(0)}),permission:"query_module"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.modules({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_module",description:"Get detailed info and config of a specific module",inputSchema:_({id:da().describe("Module ID")}),permission:"query_module"},function(){var e=I(function*({workspace_id:e,id:t}){return sc(yield E.module({workspaceId:e,id:t}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_module_info",description:"Update a specific module info",inputSchema:_({id:da().describe("Module ID"),name:da().describe("Module name"),description:da().describe("Module description")}),permission:"update_module"},function(){var e=I(function*({workspace_id:e,id:t,name:a,description:n}){return sc(yield E.updateModule({workspaceId:e,id:t,name:a,description:n}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_module_config",description:"Update a specific module configuration",inputSchema:_({id:da().describe("Module ID"),config:ha({}).passthrough().describe("New configuration object, see file://docs/config-schema.md for schema reference")}),permission:"update_module"},function(){var e=I(function*({workspace_id:e,id:t,config:a}){var n=yield pd(a);if(!n.valid)throw new Error(`Config validation failed: ${n.errors.join(", ")}`);return sc(yield E.updateModule({workspaceId:e,id:t,config:JSON.stringify(a),validateConfig:!0}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_devices",description:"List all devices in the workspace",inputSchema:_({limit:ma().describe("Maximum number of devices to return").optional().default(50),offset:ma().describe("Number of devices to skip").optional().default(0)}),permission:"query_device"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.devices({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"create_application",description:"Create a new BRICKS application with default grid layout",inputSchema:_({name:da().describe("Application name"),description:da().describe("Application description").optional(),grid_width:ma().describe("Grid width in units").optional().default(96),grid_height:ma().describe("Grid height in units").optional().default(54)}),permission:"create_application"},function(){var e=I(function*({workspace_id:e,name:t,description:a,grid_width:n,grid_height:r}){return sc(yield E.createApplication({workspaceId:e,name:t,description:a,gridWidth:n,gridHeight:r}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_application_info",description:"Update application info",inputSchema:{id:da().describe("Application ID"),name:da().describe("Application name"),description:da().describe("Application description")},permission:"update_application"},function(){var e=I(function*({id:e,name:t,description:a}){return sc(yield E.updateApplication({id:e,name:t,description:a}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_application_config",description:"Update application configuration with validation",inputSchema:{id:da().describe("Application ID"),config:ha({}).passthrough().describe("New application configuration. Please read `getting-started` for BRICKS concepts before changing")},permission:"update_application"},function(){var e=I(function*({id:e,config:t}){var a=yield pd(t);if(!a.valid)throw new Error(`Config validation failed: ${a.errors.join(", ")}`);return sc(yield E.updateApplication({id:e,config:JSON.stringify(t)}))});return function(t){return e.apply(this,arguments)}}()),y({name:"bind_application",description:"Bind application to device with viewport configuration",inputSchema:{app_id:da().describe("Application ID"),viewports:fa(ha({device_id:da().describe("Device ID"),x:ma().describe("X coordinate"),y:ma().describe("Y coordinate"),width:ma().describe("Width"),height:ma().describe("Height"),rotate:ma().describe("Rotation"),rotateType:da().describe("Rotation type")})).describe("Viewport configuration")},permission:"bind_application"},(a=I(function*({app_id:e,viewports:t}){return sc(yield E.bindApplication({id:e,bind_devices:t.map(e=>e.device_id),device_frames:t.reduce((e,t)=>({...e,[t.device_id]:{x:t.x,y:t.y,width:t.width,height:t.height,rotate:t.rotate,rotateType:t.rotateType}}),{})}))}),function(e){return a.apply(this,arguments)})),y({name:"unbind_application",description:"Unbind application from device",inputSchema:{app_id:da().describe("Application ID"),device_id:da().describe("Device ID")},permission:"bind_application"},(n=I(function*({app_id:e,device_id:t}){return sc(yield E.bindApplication({id:e,unbindDevices:[t]}))}),function(e){return n.apply(this,arguments)})),h&&y({name:"list_media_workspaces",description:"List all media workspaces",inputSchema:{},permission:"query_media_flow"},I(function*(){return sc(yield T.mediaWorkspaces())})),y({name:"get_media_workspace",description:"Get media workspace information and status",inputSchema:_({}),permission:"query_media_flow"},(r=I(function*({workspace_id:e}){return sc(yield T.mediaWorkspace({workspaceId:e}))}),function(e){return r.apply(this,arguments)})),y({name:"list_media_boxes",description:"List all media boxes in the workspace",inputSchema:_({}),permission:"query_media_flow"},(i=I(function*({workspace_id:e}){return sc(yield T.mediaBoxes({workspaceId:e}))}),function(e){return i.apply(this,arguments)})),y({name:"get_media_box",description:"Get detailed information about a specific media box",inputSchema:{box_id:da().describe("Media box ID")},permission:"query_media_flow"},(o=I(function*({box_id:e}){return sc(yield T.mediaBox({boxId:e}))}),function(e){return o.apply(this,arguments)})),y({name:"list_media_files",description:"List media files in a specific box with filtering options",inputSchema:{box_id:da().describe("Media box ID"),include_types:fa(da()).optional().describe('Filter by file types (e.g., ["image", "video", "audio"])'),user_tags:fa(da()).optional().describe("Filter by user tags"),limit:ma().optional().default(50).describe("Maximum number of files to return"),offset:ma().optional().default(0).describe("Number of files to skip")},permission:"query_media_flow"},(s=I(function*({box_id:e,include_types:t,user_tags:a,limit:n,offset:r}){return sc(yield T.mediaFiles({boxId:e,includeTypes:t,userTags:a,limit:n,offset:r}))}),function(e){return s.apply(this,arguments)})),y({name:"get_media_file_meta",description:"Get detailed information about a specific media file",inputSchema:{file_id:da().describe("Media file ID")},permission:"query_media_flow"},(p=I(function*({file_id:e}){return sc(yield T.mediaFile({fileId:e}))}),function(e){return p.apply(this,arguments)})),y({name:"media_box_upload",description:"Upload a file to a media box from URL or base64 data",inputSchema:{box_id:da().describe("Target media box ID"),name:da().describe("File name"),description:da().optional().default("").describe("File description"),file_type:ya(["image","video","audio","file"]).describe("File type"),source_url:da().optional().describe("URL to download the file from"),base64_data:da().optional().describe("Base64 encoded file data"),user_tags:fa(da()).optional().default([]).describe("User-defined tags for the file")},permission:"write_media_flow"},(l=I(function*({box_id:e,name:t,description:a,source_url:n,base64_data:r,file_type:i,user_tags:o}){if(!n&&!r)throw new Error("Either source_url or base64_data must be provided");if(n&&r)throw new Error("Provide either source_url OR base64_data, not both");var s=n?null:"application/octet-stream",p=n?yield(0,pc.Ay)(n,{agent:Rc(n)}).then(e=>(s=e.headers.get("content-type"),e.blob())):new Blob([oc.Buffer.from(r,"base64")],{type:s}),l=yield T.requestFileUpload({name:t,description:a,boxId:e,fileType:h?i.toUpperCase():i,contentType:s,userTags:o,meta:{}}),u=JSON.parse(l?.meta.uploadInfo),c=new FormData;c.append("file",p),c.append("Content-Type",s),c.append("AWSAccessKeyId",u.AWSAccessKeyId),c.append("Signature",u.Signature),c.append("Policy",u.Policy),c.append("acl",u.acl),c.append("key",u.key);var d=yield(0,pc.Ay)(u.url,{method:"POST",body:c}).then(e=>e.ok).catch(()=>!1);return sc({file_id:l.id,upload_success:d,upload_info:{content_type:s,file_type:i,source_type:n?"url":"base64",processing_note:"File will be processed automatically. Use get_media_file to check processing status."}})}),function(e){return l.apply(this,arguments)})),y({name:"update_media_file_meta",description:"Update media file information",inputSchema:{file_id:da().describe("Media file ID"),name:da().optional().describe("New file name"),description:da().optional().describe("New file description"),user_tags:fa(da()).optional().describe("New user tags")},permission:"write_media_flow"},(u=I(function*({file_id:e,name:t,description:a,user_tags:n}){return sc(yield T.updateMediaFile({fileId:e,name:t,description:a,userTags:n,requestUploadAgain:!1}))}),function(e){return u.apply(this,arguments)})),y({name:"copy_media_files",description:"Copy media files from one box to another",inputSchema:{from_box_id:da().describe("Source media box ID"),to_box_id:da().describe("Target media box ID"),file_ids:fa(da()).describe("Array of media file IDs to copy")},permission:"write_media_flow"},(c=I(function*({from_box_id:e,to_box_id:t,file_ids:a}){return sc(yield T.copyMediaFiles({fromBoxId:e,toBoxId:t,list:a}))}),function(e){return c.apply(this,arguments)})),y({name:"delete_media_files",description:"Delete specific media files from a box",inputSchema:{box_id:da().describe("Media box ID"),file_ids:fa(da()).describe("Array of media file IDs to delete")},permission:"write_media_flow"},(d=I(function*({box_id:e,file_ids:t}){return sc(yield T.deleteMediaFiles({boxId:e,list:t}))}),function(e){return d.apply(this,arguments)})),y({name:"cleanup_media_box",description:"Delete all files in a media box, optionally filtered by type",inputSchema:{box_id:da().describe("Media box ID"),include_types:fa(da()).optional().describe('Only delete files of these types (e.g., ["image", "video"])')},permission:"write_media_flow"},(m=I(function*({box_id:e,include_types:t}){if("deleteMediaBoxFiles"in T)return sc(yield T.deleteMediaBoxFiles({boxId:e,includeTypes:t}));var a=yield T.mediaFiles({boxId:e,includeTypes:t});return sc(yield T.deleteMediaFiles({boxId:e,list:a.map(e=>e.id)}))}),function(e){return m.apply(this,arguments)})),e.tool("calculate_grid_layout","Calculate grid layout and pixel conversions for different device resolutions",{device_width:ma().describe("Device width in pixels"),device_height:ma().describe("Device height in pixels"),app_grid_width:ma().describe("Application grid width").optional().default(96),app_grid_height:ma().describe("Application grid height").optional().default(54)},(f=I(function*({device_width:e,device_height:t,app_grid_width:a,app_grid_height:n}){var r,i,o={deviceBrickWidth:(r=e)/(i=r/a),deviceBrickHeight:t/i,deviceBrickUnit:i},s=function(e,t,a=96){var n=e/a;return t>e&&(n=t/a),{deviceBrickWidth:Math.round(e/n),deviceBrickHeight:Math.round(t/n),deviceBrickUnit:n}}(e,t,a);return sc({device_resolution:{width:e,height:t,aspect_ratio:(e/t).toFixed(2)},current_grid:{width:a,height:n,unit_size_px:o.deviceBrickUnit.toFixed(2),total_pixels:{width:o.deviceBrickWidth.toFixed(2),height:o.deviceBrickHeight.toFixed(2)}},recommended_grid:{width:s.deviceBrickWidth,height:s.deviceBrickHeight,unit_size_px:s.deviceBrickUnit.toFixed(2),note:"Optimized for device aspect ratio"}})}),function(e){return f.apply(this,arguments)})),e.tool("create_item","Use this tool to create new item that you can put in application configuration",{type:ya(["subspace","canvas","brick","generator","property_bank","property_bank_calc","property_bank_command","animation","state_group","automation_map"]).describe("Item type"),title:da().describe("Item title"),template_key:da().optional().describe("Template key for brick or generator")},Ly),e.tool("getting_started","Get documentation content for getting started",{},I(function*(){return sc(yd)}))}var My="2.24.0-beta.39";function Gy(){return Gy=I(function*(e={}){var t=e.token||process.env.BRICKS_API_TOKEN;if(!t)throw console.error("Error: API token is required"),console.error("Please provide a token via options or set BRICKS_API_TOKEN environment variable"),new Error("API token is required");var a=rc({queryStringParameters:{token:t}});if(!a.success)throw console.error("Error: Invalid BRICKS_API_TOKEN"),console.error(a.message),new Error("Invalid BRICKS_API_TOKEN");var n,r=new Vu({name:Py,version:My}),i={...a,client:Dy(jy.bricks,a.token,a.tokenType)};(n=r).prompt("getting-started","Getting started with BRICKS",{},I(function*(){return{messages:[{role:"user",content:{type:"text",text:'Welcome to BRICKS — start here.\n\nBefore doing any complex work (application design, deployments, etc.),\nalways consult the official docs rather than guessing.\n\nIMPORTANT: BRICKS users interact through a GUI editor, not raw config files.\nNever show users JSON config details, schema fields, or technical implementation.\nFocus on user-friendly descriptions of what the app will do and how it will look.\n\nGolden rules for working with BRICKS:\n1) Read before you act\n - Open these resources first, then proceed:\n - `getting-started` — overview & architecture\n - `config-schema` — canonical schema for apps, subspaces, bricks, generators, etc.\n - `components-index` — available bricks/generators\n2) Source of truth\n - Rely on the docs above; do not invent fields not present in the schema\n3) No guessing\n - If names, constraints, or device details are missing, ask to fetch them first\n4) Plan then execute\n - Propose a clear step-by-step plan and wait for approval before writing or mutating data\n5) User-friendly communication\n - Describe features in terms of what users see and do, not technical config\n - Use visual/functional language: "text display", "button", "screen transition"\n - Avoid exposing JSON, IDs, or schema details to end users\n\nBRICKS essentials:\n- Applications: interactive digital signage experiences\n- Devices: deployment targets (screens/players)\n- Modules: Reusable module across applications\n- Grid system: default 96×54; 1 unit = device_width/96 (e.g., 20px at 1920×1080)\n- Key primitives: Subspaces, Canvas, Bricks, Generators, Property Banks (Data)\n\nQuick actions:\n- "Create a new application" → use the `create-application` prompt\n- "Deploy an application to a device" → use the `deploy-to-device` prompt\n\nTry asking:\n- "Draft a plan to create an app with a text display and deploy it; ask any missing questions first"'}}]}})),n.prompt("create-application","Create a new BRICKS application with guided setup",{app_name:da().describe("Name for the new application"),description:da().describe("Short description for the new application").optional()},function(){var e=I(function*(e){var t=e?.app_name||"New Application",a=e?.description||"";return{messages:[{role:"user",content:{type:"text",text:`Help me create a new BRICKS application called "${t}".\n\n${a?`Goal: ${a}`:""}\n\nIMPORTANT: Users see a visual GUI editor, not raw config. Describe features in user-friendly terms:\n- "text display" not "BRICK_TEXT"\n- "image" not "BRICK_IMAGE"\n- "canvas name" not "CANVAS_xxx"\n- "data storage" not "PROPERTY_BANK"\n- Focus on what users see and do, not technical implementation\n\nHow we'll proceed (no guessing, schema-first):\n1) Confirm intent\n - Restate objectives and success criteria in 1–3 bullets\n2) Consult docs (as needed)\n - getting-started, config-schema, components-index\n - Ensure proposed fields exist in the schema\n3) Ask missing questions before changes\n - Target device(s) and resolution(s)\n - Layout needs (pages/screens), content types, data sources\n - Localization, scheduling, or interaction needs\n4) Propose a minimal viable design (After confirming intent)\n - App structure: screens → visual elements\n - Initial component selection with rationale\n - Grid usage: default 96×54 (≈20px at 1920×1080)\n5) Produce a schema-valid skeleton (no side effects yet)\n - Include only fields defined by config-schema\n - Use clear placeholders for text/assets/URLs/ids\n\nWhat I'll produce first:\n- Short recap of requirements\n- Clarifying questions (only what's necessary)\n- High-level architecture plan\n- Minimal config skeleton that validates against the schema`}}]}});return function(t){return e.apply(this,arguments)}}()),function(e){e.resource("getting-started-docs","file://docs/getting-started.md",{mimeType:"text/markdown",title:"Getting Started with BRICKS",description:"Comprehensive guide to BRICKS architecture, concepts, and development workflow"},I(function*(){return sc(ic,{uri:"file://docs/getting-started.md",mimeType:"text/markdown"})}))}(r),xy(r,i);var o=new Zu;try{yield r.connect(o),console.error("BRICKS MCP Server running on STDIO"),console.error(`Server: ${Py} v${My}`),console.error(`Token Type: ${a.tokenType}`),console.error(`Permissions: ${a.tokenInfo.permissions.join(", ")}`),console.error("Ready to accept requests...")}catch(e){throw console.error("Failed to start MCP server:",e),e}}),Gy.apply(this,arguments)}var Fy=new G("mcp").description("MCP server management");Fy.command("start").description("Start the BRICKS MCP server in STDIO mode").option("-t, --token <token>","API token (overrides saved token)").action(function(){var e=I(function*(e){var t=(0,$.getCurrentProfile)(),a=e.token||(0,$.getToken)(t);a||(console.error(V.Ay.red("Error: No API token found.")),console.error(V.Ay.gray("Please login first with: bricks auth login <passcode>")),console.error(V.Ay.gray("Or provide a token with: bricks mcp start --token <token>")),process.exit(1));try{yield function(){return Gy.apply(this,arguments)}({token:a})}catch(e){console.error(V.Ay.red(`Failed to start MCP server: ${e.message}`)),process.exit(1)}});return function(t){return e.apply(this,arguments)}}());var By="2.24",zy=e=>{if(!e)return!1;for(var t=e.replace(/^v/,"").split(".").map(Number),a=By.split(".").map(Number),n=0;n<a.length;n++){if((t[n]||0)>a[n])return!0;if((t[n]||0)<a[n])return!1}return!0},Vy=function(){var e=I(function*(e,t,a=3e3){try{var n=new AbortController,r=setTimeout(()=>n.abort(),a),i=yield fetch(`http://${e}:${t}/json/list`,{signal:n.signal});return clearTimeout(r),i.ok?yield i.json():null}catch{return null}});return function(t,a){return e.apply(this,arguments)}}(),$y=e=>{if(!e)return null;var t=e.match(/\/ws\/(.+)$/);return t?decodeURIComponent(t[1]):null},Uy=e=>e.requiredOption("-a, --address <address>","DevTools server address").option("-p, --port <port>","Server port","19851").option("--passcode <passcode>","Device passcode").option("-j, --json","Output as JSON"),Hy=function(){var e=I(function*(e,t){var a,n=(yield Promise.resolve().then(E.bind(E,29790))).default,r=(yield E.e(44).then(E.bind(E,12044))).verifyDevToolsServer,i=(yield E.e(999).then(E.bind(E,12999))).createCdpClient,o=parseInt(e.port,10),s=n("Connecting to DevTools...").start();try{var p=yield r(e.address,o);p||(s.fail(`Cannot reach DevTools server at ${e.address}:${o}`),process.exit(1)),p.version&&!zy(p.version)&&(s.fail(`CDP requires app version >= ${By} (device: ${p.version})`),process.exit(1)),a=i(e.address,o,e.passcode),yield a.connect(),s.stop(),yield t(a)}catch(e){s.isSpinning&&s.stop(),console.error(V.Ay.red(e.message)),process.exit(1)}finally{a?.close()}});return function(t,a){return e.apply(this,arguments)}}(),qy=e=>{if(!e)return{};for(var t={},a=0;a<e.length;a+=2)t[e[a]]=e[a+1];return t},Ky=(e,t="",a=!0,n=!0)=>{var r=[],i=n?"":a?"└─ ":"├─ ",o=n?"":a?" ":"│ ",s=e.nodeName||"#unknown";if(9===e.nodeType)s="#document";else if(3===e.nodeType){var p=e.nodeValue||"";s=V.Ay.gray(`"${p}"`)}else if(1===e.nodeType){var l=qy(e.attributes),u=l.id||l["short-id"];u&&(s+=V.Ay.gray(`#${u}`)),l.title&&(s+=` ${V.Ay.green(`"${l.title}"`)}`),void 0!==l.w&&void 0!==l.h&&(s+=V.Ay.blue(` ${l.w}×${l.h}`),void 0!==l.x&&void 0!==l.y&&(s+=V.Ay.blue(` @${l.x},${l.y}`)));var c=[];void 0!==l.hide&&c.push(V.Ay.red("hidden")),void 0!==l.pressable&&c.push(V.Ay.yellow("pressable")),void 0!==l.editable&&c.push(V.Ay.yellow("editable")),c.length>0&&(s+=` [${c.join(", ")}]`)}r.push(`${t}${i}${s}`);var d=e.children||[];return d.forEach((e,a)=>{r.push(...Ky(e,t+o,a===d.length-1,!1))}),r},Wy=new G("devtools").description("DevTools server discovery, inspection, and CDP commands"),Qy=function(){var e=I(function*(e){for(var t=yield Promise.resolve().then(E.t.bind(E,51455,19)),a=yield Promise.resolve().then(E.t.bind(E,76760,19)),n=[],r=process.cwd(),i=0;i<10;i++){var o=a.join(r,".bricks","devtools.json");try{var s=yield t.readFile(o,"utf8"),p=JSON.parse(s),l=yield e(p.address||"localhost",p.port,1e3);l&&n.push({name:p.name||"BRICKS Preview",address:p.address||"localhost",port:p.port,protocols:["cdp"],hasPasscode:!1,source:"project",projectPath:r,...l})}catch{}var u=a.dirname(r);if(u===r)break;r=u}return n});return function(t){return e.apply(this,arguments)}}();Wy.command("scan").description("Scan LAN for DevTools servers via UDP + HTTP").option("-t, --timeout <ms>","Scan timeout in milliseconds","3000").option("-j, --json","Output as JSON").option("--verify","Verify each discovered server via HTTP").option("--udp-only","Skip HTTP subnet probe (UDP only)").option("--project","Include local BRICKS project preview servers").option("-p, --port <port>","Port for HTTP probe","19851").action(function(){var e=I(function*(e){var t=(yield Promise.resolve().then(E.bind(E,29790))).default,a=yield E.e(44).then(E.bind(E,12044)),n=a.discoverDevToolsServers,r=a.verifyDevToolsServer,i=a.httpProbeSubnet,o=yield Promise.resolve().then(E.bind(E,74752)),s=o.getCurrentProfile,p=o.getTokenInfo,l=parseInt(e.timeout,10),u=t(`Scanning for DevTools servers (${l}ms)...`).start();try{var c=n({timeout:l,idleTimeout:800}),d=e.udpOnly?Promise.resolve([]):(u.text="Scanning via UDP + HTTP probe...",i({port:parseInt(e.port,10),timeout:l})),m=e.project?Qy(r):Promise.resolve([]),f=yield Promise.all([c,d,m]),h=ye(f,3),y=h[0],_=h[1],T=h[2],g=[...y,..._,...T],R=new Map;for(var v of g){var b=v.deviceId||`${v.address}:${v.port}`,O=R.get(b);if(O)for(var N of(O.addresses.includes(v.address)||O.addresses.push(v.address),"127.0.0.1"===O.address&&"127.0.0.1"!==v.address&&(O.address=v.address),v.protocols||[]))O.protocols?.includes(N)||O.protocols?.push(N);else R.set(b,{...v,addresses:[v.address]})}var A=[...R.values()];if(0===A.length)return void(e.json?(u.stop(),console.log(JSON.stringify([],null,2))):u.info("No DevTools servers found on the network."));if(e.verify){u.text=`Verifying ${A.length} server(s)...`;var S=yield Promise.all(A.map(function(){var e=I(function*(e){var t=yield r(e.address,e.port);return{...e,verified:!!t,version:t?.version||e.version}});return function(t){return e.apply(this,arguments)}}()));A.splice(0,A.length,...S)}u.text="Checking chrome://inspect support...",yield Promise.all(A.map(function(){var e=I(function*(e){var t=yield Vy(e.address,e.port);if(t){e.chromeInspect=!0;var a=$y(t?.[0]?.webSocketDebuggerUrl);a&&(e.passcode=a)}});return function(t){return e.apply(this,arguments)}}())),u.stop(),e.json&&(console.log(JSON.stringify(A,null,2)),process.exit(0));var w=p(s()),C=w?.workspaceId||null;console.log(V.Ay.bold(`\nFound ${A.length} DevTools server(s)`)),console.log("─".repeat(80));var D=function*(e){var t=!1===e.verified?V.Ay.red("unverified"):V.Ay.green("online"),a=e.hasPasscode?V.Ay.yellow("passcode"):V.Ay.gray("open"),n=(e.protocols||[]).map(e=>V.Ay.cyan(e)).join(", "),r=e.workspaceId&&C&&e.workspaceId===C,i=e.addresses||[e.address],o=i.filter(t=>t!==e.address),s=o.length>0?`${e.address}:${e.port} +${o.length} more`:`${e.address}:${e.port}`;if(console.log(` ${V.Ay.bold(e.name||"Unknown")} ${V.Ay.gray(`(${s})`)} [${t}]`),o.length>0&&console.log(` Addresses: ${i.map(e=>V.Ay.gray(e)).join(", ")}`),e.version&&console.log(` Version: ${V.Ay.green(e.version)}`),e.chromeInspect){var p=e.passcode?V.Ay.cyan(e.passcode):V.Ay.gray("no passcode");console.log(` Chrome Inspect: ${V.Ay.green("supported")} (passcode: ${p})`)}var l=` Protocols: ${n||V.Ay.gray("none")} Auth: ${a}`;if(e.deviceId&&(l+=` Device: ${V.Ay.gray(e.deviceId)}`),console.log(l),e.workspaceId){var u=r?V.Ay.green(`${e.workspaceId} (current profile)`):V.Ay.gray(e.workspaceId);console.log(` Workspace: ${u}`)}};for(var P of A)yield*D(P);console.log("─".repeat(80));var j=A[0],k=`${j.address}:${j.port||19851}`,L=j.passcode?`/ws/${encodeURIComponent(j.passcode)}`:"/ws/<passcode>";console.log(V.Ay.gray(`\nConnect via: devtools://devtools/bundled/inspector.html?ws=${k}${L}`)),process.exit(0)}catch(e){u.fail(`Scan failed: ${e.message}`),process.exit(1)}});return function(t){return e.apply(this,arguments)}}()),Wy.command("open <address>").description("Show DevTools server information").option("-p, --port <port>","Server port","19851").option("--info","Show connection URLs").action(function(){var e=I(function*(e,t){var a=(yield Promise.resolve().then(E.bind(E,29790))).default,n=(yield E.e(44).then(E.bind(E,12044))).verifyDevToolsServer,r=parseInt(t.port,10),i=`${e}:${r}`,o=a(`Fetching server info from ${i}...`).start(),s=yield n(e,r);s||(o.fail(`Could not reach DevTools server at ${i}`),process.exit(1)),o.stop();var p=yield Vy(e,r),l=p?$y(p?.[0]?.webSocketDebuggerUrl):null,u=l?`/ws/${encodeURIComponent(l)}`:"/ws/<passcode>";if(t.info)return console.log(V.Ay.bold("Connection URLs")),console.log("─".repeat(60)),console.log(` Web UI: ${V.Ay.cyan(`http://${i}`)}`),console.log(` CDP: ${V.Ay.cyan(`devtools://devtools/bundled/inspector.html?ws=${i}${u}`)}`),console.log(` MCP: ${V.Ay.cyan(`http://${i}/mcp`)}`),console.log(` MCP SSE: ${V.Ay.cyan(`http://${i}/sse`)}`),console.log(` Info: ${V.Ay.cyan(`http://${i}/devtools/info`)}`),console.log("─".repeat(60)),console.log(),console.log(V.Ay.bold("Authorization")),l&&console.log(` Passcode: ${V.Ay.cyan(l)}`),console.log(" MCP and MCP SSE require a Bearer token header with the device passcode:"),void console.log(` ${V.Ay.gray(`Authorization: Bearer ${l||"<passcode>"}`)}`);if(console.log(V.Ay.bold("DevTools Server")),console.log("─".repeat(60)),console.log(` Name: ${V.Ay.cyan(s.name||"Unknown")}`),console.log(` Version: ${s.version?V.Ay.green(s.version):V.Ay.gray("N/A")}`),console.log(` Device ID: ${V.Ay.gray(s.deviceId||"N/A")}`),console.log(` Workspace: ${V.Ay.gray(s.workspaceId||"N/A")}`),console.log(` Protocols: ${(s.protocols||[]).map(e=>V.Ay.cyan(e)).join(", ")||V.Ay.gray("none")}`),console.log(` Auth: ${s.hasPasscode?V.Ay.yellow("passcode required"):V.Ay.gray("open")}`),console.log(` Port: ${s.port}`),p){var c=l?V.Ay.cyan(l):V.Ay.gray("no passcode");console.log(` Inspect: ${V.Ay.green("chrome://inspect supported")} (passcode: ${c})`)}else console.log(` Inspect: ${V.Ay.gray("chrome://inspect not available")}`);console.log("─".repeat(60)),s.version&&!zy(s.version)&&console.log(V.Ay.yellow(`\n CDP commands require version >= ${By}`)),console.log(V.Ay.gray("\n Use --info to see connection URLs"))});return function(t,a){return e.apply(this,arguments)}}()),Uy(Wy.command("screenshot").description("Capture device screenshot").option("-o, --output <path>","Output file path")).action(function(){var e=I(function*(e){yield Hy(e,function(){var t=I(function*(t){var a=yield t.send("Page.captureScreenshot",{format:"png"});a.data||(console.error(V.Ay.red("No screenshot data received")),process.exit(1));var n=yield Promise.resolve().then(E.t.bind(E,73024,19)),r=yield Promise.resolve().then(E.t.bind(E,76760,19)),i=e.output||`screenshot-${Date.now()}.png`,o=r.resolve(i);n.writeFileSync(o,Buffer.from(a.data,"base64")),console.log(V.Ay.green(`Screenshot saved to ${o}`))});return function(e){return t.apply(this,arguments)}}())});return function(t){return e.apply(this,arguments)}}());var Yy,Xy,Jy,Zy,e_,t_=Wy.command("brick").description("Brick component inspection");Uy(t_.command("tree").description("Print brick component tree").option("-d, --depth <depth>","Max depth (-1 for full)","3")).action(function(){var e=I(function*(e){yield Hy(e,function(){var t=I(function*(t){yield t.send("DOM.enable");var a=parseInt(e.depth,10),n=(yield t.send("DOM.getDocument",{depth:a})).root;e.json?console.log(JSON.stringify(n,null,2)):console.log(Ky(n).join("\n"))});return function(e){return t.apply(this,arguments)}}())});return function(t){return e.apply(this,arguments)}}()),Uy(t_.command("query <selector>").description("Find brick by CSS selector")).action(function(){var e=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=(yield a.send("DOM.getDocument",{depth:0})).root,r=(yield a.send("DOM.querySelector",{nodeId:n.nodeId,selector:e})).nodeId;if(0!==r){var i=yield a.send("DOM.describeNode",{nodeId:r}),o=(yield a.send("DOM.getAttributes",{nodeId:r})).attributes,s=qy(o);if(t.json)console.log(JSON.stringify({nodeId:r,...i.node,attributes:s},null,2));else if(console.log(V.Ay.bold(`Node ${r}: ${i.node?.nodeName||"unknown"}`)),Object.keys(s).length>0)for(var p of(console.log(V.Ay.bold("Attributes:")),Object.entries(s))){var l=ye(p,2),u=l[0],c=l[1];console.log(` ${V.Ay.cyan(u)}: ${c}`)}}else console.log(V.Ay.yellow("No element found"))}),function(e){return a.apply(this,arguments)}))});return function(t,a){return e.apply(this,arguments)}}()),Uy(t_.command("query-all <selector>").description("Find all bricks matching CSS selector")).action((Yy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=(yield a.send("DOM.getDocument",{depth:0})).root,r=(yield a.send("DOM.querySelectorAll",{nodeId:n.nodeId,selector:e})).nodeIds;if(t.json)console.log(JSON.stringify({nodeIds:r,count:r.length},null,2));else for(var i of(console.log(V.Ay.bold(`Found ${r.length} element(s)`)),r)){var o=yield a.send("DOM.describeNode",{nodeId:i}),s=(yield a.send("DOM.getAttributes",{nodeId:i})).attributes,p=qy(s),l=p.id||p["short-id"]||"";console.log(` ${i}: ${o.node?.nodeName}${l?V.Ay.gray(`#${l}`):""}`)}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Yy.apply(this,arguments)})),Uy(t_.command("attributes <nodeId>").description("Get brick attributes")).action((Xy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.getAttributes",{nodeId:n})).attributes,i=qy(r);if(t.json)console.log(JSON.stringify(i,null,2));else if(0!==Object.keys(i).length)for(var o of Object.entries(i)){var s=ye(o,2),p=s[0],l=s[1];console.log(` ${V.Ay.cyan(p)}: ${l}`)}else console.log(V.Ay.gray("No attributes"))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Xy.apply(this,arguments)})),Uy(t_.command("box-model <nodeId>").description("Get brick dimensions and position")).action((Jy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.getBoxModel",{nodeId:n})).model;t.json?console.log(JSON.stringify(r,null,2)):(console.log(V.Ay.bold(`Box Model for node ${n}`)),console.log(` Width: ${r.width}`),console.log(` Height: ${r.height}`),r.content&&console.log(` Content: [${r.content.join(", ")}]`),r.padding&&console.log(` Padding: [${r.padding.join(", ")}]`),r.border&&console.log(` Border: [${r.border.join(", ")}]`),r.margin&&console.log(` Margin: [${r.margin.join(", ")}]`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Jy.apply(this,arguments)})),Uy(t_.command("resolve <nodeId>").description("Resolve brick to JavaScript object with properties")).action((Zy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.resolveNode",{nodeId:n})).object;if(t.json)console.log(JSON.stringify(r,null,2));else if(console.log(V.Ay.bold(`Resolved node ${n}`)),console.log(` Type: ${r.type}`),r.className&&console.log(` Class: ${r.className}`),r.description&&console.log(` Description: ${r.description}`),r.objectId&&console.log(` Object ID: ${V.Ay.gray(r.objectId)}`),r.preview?.properties)for(var i of(console.log(V.Ay.bold(" Properties:")),r.preview.properties))console.log(` ${V.Ay.cyan(i.name)}: ${i.value}`)}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Zy.apply(this,arguments)})),Uy(t_.command("focus <nodeId>").description("Focus a brick element")).action((e_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("DOM.enable");var a=parseInt(e,10);yield t.send("DOM.focus",{nodeId:a}),console.log(V.Ay.green(`Focused node ${a}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return e_.apply(this,arguments)}));var a_,n_,r_,i_=Wy.command("input").description("Input emulation");Uy(i_.command("tap <x> <y>").description("Tap/click at coordinates")).action((a_=I(function*(e,t,a){var n;yield Hy(a,(n=I(function*(a){var n=parseFloat(e),r=parseFloat(t);yield a.send("Input.dispatchMouseEvent",{type:"mousePressed",x:n,y:r,button:"left",clickCount:1}),yield a.send("Input.dispatchMouseEvent",{type:"mouseReleased",x:n,y:r,button:"left",clickCount:1}),console.log(V.Ay.green(`Tapped at (${n}, ${r})`))}),function(e){return n.apply(this,arguments)}))}),function(e,t,a){return a_.apply(this,arguments)})),Uy(i_.command("type <text>").description("Insert text into focused element")).action((n_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("Input.insertText",{text:e}),console.log(V.Ay.green(`Typed: ${e}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return n_.apply(this,arguments)})),Uy(i_.command("key <key>").description("Dispatch key event (e.g., Enter, Escape, Tab)")).action((r_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("Input.dispatchKeyEvent",{type:"keyDown",key:e}),yield t.send("Input.dispatchKeyEvent",{type:"keyUp",key:e}),console.log(V.Ay.green(`Key: ${e}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return r_.apply(this,arguments)}));var o_,s_,p_=Wy.command("network").description("Network inspection");Uy(p_.command("list").description("Capture snapshot of network activity").option("--duration <ms>","Capture duration in milliseconds","2000")).action((o_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){var a=new Map,n=parseInt(e.duration,10);t.on("Network.requestWillBeSent",e=>{a.set(e.requestId,{method:e.request.method,url:e.request.url,requestId:e.requestId,timestamp:e.timestamp})}),t.on("Network.responseReceived",e=>{var t=a.get(e.requestId);t&&(t.status=e.response.status,t.mimeType=e.response.mimeType)}),t.on("Network.loadingFailed",e=>{var t=a.get(e.requestId);t&&(t.error=e.errorText)}),yield t.send("Network.enable"),yield new Promise(e=>setTimeout(e,n)),yield t.send("Network.disable");var r=[...a.values()];if(e.json)console.log(JSON.stringify(r,null,2));else if(console.log(V.Ay.bold(`Network Activity (captured ${(n/1e3).toFixed(1)}s, ${r.length} requests)`)),0!==r.length)for(var i of r){var o=i.error?V.Ay.red("ERR"):i.status?i.status<300?V.Ay.green(i.status):i.status<400?V.Ay.yellow(i.status):V.Ay.red(i.status):V.Ay.gray("..."),s=i.url.length>60?i.url.substring(0,57)+"...":i.url;console.log(` ${o} ${V.Ay.bold(i.method.padEnd(6))} ${s} ${V.Ay.gray(`(${i.requestId})`)}`)}else console.log(V.Ay.gray(" No network activity captured"))}),function(e){return t.apply(this,arguments)}))}),function(e){return o_.apply(this,arguments)})),Uy(p_.command("get <requestId>").description("Get response body for a network request")).action((s_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("Network.enable");var n=yield a.send("Network.getResponseBody",{requestId:e}),r=n.body,i=n.base64Encoded;t.json?console.log(JSON.stringify({body:r,base64Encoded:i},null,2)):i?console.log(V.Ay.gray(`[base64 encoded, ${r.length} chars]`)):console.log(r)}),function(e){return a.apply(this,arguments)}))}),function(e,t){return s_.apply(this,arguments)}));var l_,u_,c_=Wy.command("storage").description("Storage inspection"),d_=c_.command("system").description("System key-value storage");Uy(d_.command("persist").description("Show persistent system storage entries")).action((l_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("DOMStorage.enable");var a=(yield t.send("DOMStorage.getDOMStorageItems",{storageId:{securityOrigin:"bricks://app",isLocalStorage:!0}})).entries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Persistent Storage (${a.length} items)`)),console.log("─".repeat(60)),a)){var r=ye(n,2),i=r[0],o=r[1],s=o.length>80?o.substring(0,80)+"...":o;console.log(` ${V.Ay.cyan(i)}: ${s}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return l_.apply(this,arguments)})),Uy(d_.command("memory").description("Show in-memory system storage entries")).action((u_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("DOMStorage.enable");var a=(yield t.send("DOMStorage.getDOMStorageItems",{storageId:{securityOrigin:"bricks://app",isLocalStorage:!1}})).entries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Memory Storage (${a.length} items)`)),console.log("─".repeat(60)),a)){var r=ye(n,2),i=r[0],o=r[1],s=o.length>80?o.substring(0,80)+"...":o;console.log(` ${V.Ay.cyan(i)}: ${s}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return u_.apply(this,arguments)}));var m_,f_,h_,y_=c_.command("data-bank").description("Property Bank data stores");Uy(y_.command("list").description("List Property Banks")).action((m_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("IndexedDB.enable");var a=(yield t.send("IndexedDB.requestDatabaseNames",{securityOrigin:"bricks://app"})).databaseNames.filter(e=>e.startsWith("DATA-"));if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Property Banks (${a.length})`)),a))console.log(` ${V.Ay.cyan(n)}`)}),function(e){return t.apply(this,arguments)}))}),function(e){return m_.apply(this,arguments)})),Uy(y_.command("get <name> <store>").description("Query Property Bank data").option("-l, --limit <count>","Max items to fetch","25").option("-s, --skip <count>","Items to skip","0")).action((f_=I(function*(e,t,a){var n;yield Hy(a,(n=I(function*(n){yield n.send("IndexedDB.enable");var r=(yield n.send("IndexedDB.requestData",{securityOrigin:"bricks://app",databaseName:e,objectStoreName:t,indexName:"",skipCount:parseInt(a.skip,10),pageSize:parseInt(a.limit,10)})).objectStoreDataEntries;if(a.json)console.log(JSON.stringify(r,null,2));else for(var i of(console.log(V.Ay.bold(`${e} / ${t} (${r.length} entries)`)),console.log("─".repeat(60)),r)){var o=JSON.stringify(i.key?.value??i.key),s=JSON.stringify(i.value?.value??i.value),p=s.length>100?s.substring(0,100)+"...":s;console.log(` ${V.Ay.cyan(o)}: ${p}`)}}),function(e){return n.apply(this,arguments)}))}),function(e,t,a){return f_.apply(this,arguments)})),Uy(c_.command("generator-cache").description("Show generator cache entries")).action((h_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("IndexedDB.enable");var a=(yield t.send("IndexedDB.requestData",{securityOrigin:"bricks://app",databaseName:"GENERATOR_CACHE",objectStoreName:"entries",indexName:"",skipCount:0,pageSize:100})).objectStoreDataEntries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Generator Cache (${a.length} entries)`)),console.log("─".repeat(60)),a)){var r=JSON.stringify(n.key?.value??n.key),i=JSON.stringify(n.value?.value??n.value),o=i.length>100?i.substring(0,100)+"...":i;console.log(` ${V.Ay.cyan(r)}: ${o}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return h_.apply(this,arguments)}));var __,E_,T_=Wy.command("runtime").description("Runtime and evaluation");Uy(T_.command("eval <expression>").description("Evaluate JavaScript expression").option("--await","Await promise result")).action((__=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("Runtime.enable");var n=yield a.send("Runtime.evaluate",{expression:e,objectGroup:"console",returnByValue:!0,awaitPromise:!!t.await,generatePreview:!0});if(t.json)console.log(JSON.stringify(n,null,2));else{n.exceptionDetails&&(console.error(V.Ay.red(`Error: ${n.exceptionDetails.text}`)),n.exceptionDetails.exception?.description&&console.error(V.Ay.red(n.exceptionDetails.exception.description)),process.exit(1));var r=n.result;if("undefined"===r.type)console.log(V.Ay.gray("undefined"));else if(void 0!==r.value){var i="object"==typeof r.value?JSON.stringify(r.value,null,2):String(r.value);console.log(i)}else r.description?console.log(r.description):console.log(V.Ay.gray(`[${r.type}${r.subtype?`:${r.subtype}`:""}]`))}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return __.apply(this,arguments)})),Uy(T_.command("properties <objectId>").description("Get properties of a remote object")).action((E_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){var n=(yield a.send("Runtime.getProperties",{objectId:e,ownProperties:!0})).result;if(t.json)console.log(JSON.stringify(n,null,2));else for(var r of(console.log(V.Ay.bold(`Properties of ${e}`)),n))if(r.enumerable){var i=r.value,o=i?.description||i?.value?.toString()||V.Ay.gray(`[${i?.type}]`);console.log(` ${V.Ay.cyan(r.name)}: ${o}`)}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return E_.apply(this,arguments)}));var g_=E(69278),R_=E(70857),v_=process.env.BRICKS_PROJECT_DESKTOP_DATA_DIR||ve.join(R_.homedir(),".bricks-project-desktop"),b_=ve.join(v_,"acp.sock"),O_=new G("desktop-acp-bridge").description("ACP bridge — connects acpx to the running BRICKS Project Desktop app").action(()=>{var e=g_.connect(b_);e.on("connect",()=>{process.stdin.pipe(e),e.pipe(process.stdout)}),e.on("error",e=>{"ENOENT"===e.code||"ECONNREFUSED"===e.code?process.stderr.write(`[acp] Cannot connect to BRICKS Project Desktop.\n Make sure the desktop app is running and ACP is enabled in Settings.\n Socket: ${b_}\n`):process.stderr.write(`[acp] Connection error: ${e.message}\n`),process.exit(1)}),e.on("close",()=>{process.exit(0)})}),N_=function(){var e=I(function*(){var e=process.argv.findIndex(e=>"--auth-profile"===e||"-ap"===e);if(-1!==e&&process.argv[e+1]&&((0,$.setProfileOverride)(process.argv[e+1]),process.argv.splice(e,2)),D.name("bricks").description("BRICKS CLI - Command-line interface for BRICKS Workspace API").version("2.24.0-beta.39").enablePositionalOptions(),D.addCommand(Y),D.addCommand(ie),D.addCommand(me),D.addCommand(he),D.addCommand(ge),D.addCommand(we),D.addCommand(xe),D.addCommand(Fy),D.addCommand(Wy),D.addCommand(O_),D.command("interactive").alias("i").description("Start interactive mode with Ink UI").action(I(function*(){try{(0,(yield E.e(612).then(E.bind(E,59612))).runInteractiveMode)()}catch(e){console.error(V.Ay.red(`Failed to start interactive mode: ${e.message}`)),process.exit(1)}})),D.command("workspace").alias("ws").description("Show current workspace information").option("-j, --json","Output as JSON").action(function(){var e=I(function*(e){var t=yield Promise.resolve().then(E.bind(E,74752)),a=t.getToken,n=t.getBaseUrl,r=t.getCurrentProfile,i=(yield Promise.resolve().then(E.bind(E,50700))).createClient,o=(yield Promise.resolve().then(E.bind(E,29790))).default,s=a(r());s||(console.error(V.Ay.red("Not logged in. Use `bricks auth login` first.")),process.exit(1));var p=o("Fetching workspace info...").start();try{var l=i(n(),s),u=yield l.workspace();if(p.stop(),e.json)return void console.log(JSON.stringify(u,null,2));console.log(V.Ay.bold("\nWorkspace Information")),console.log("─".repeat(60)),console.log(`Name: ${V.Ay.green(u.name)}`),console.log(`ID: ${V.Ay.gray(u._id)}`),console.log(`Description: ${u.description||V.Ay.gray("N/A")}`),console.log(`\n${V.Ay.bold("Data")}`),console.log(`Remote Update: ${u.bank?.enable_remote_update?V.Ay.green("Enabled"):V.Ay.gray("Disabled")}`),console.log(`Spacename: ${u.bank?.spacename||V.Ay.gray("N/A")}`),console.log("─".repeat(60))}catch(e){p.fail(`Failed to get workspace: ${e.message}`),process.exit(1)}});return function(t){return e.apply(this,arguments)}}()),D.on("--help",()=>{console.log(""),console.log(V.Ay.bold("Examples:")),console.log(""),console.log(V.Ay.gray(" # Login with a one-time passcode (recommended)")),console.log(" $ bricks auth login <passcode>"),console.log(""),console.log(V.Ay.gray(" # List all devices")),console.log(" $ bricks device list"),console.log(""),console.log(V.Ay.gray(" # Monitor devices in real-time")),console.log(" $ bricks device monitor"),console.log(""),console.log(V.Ay.gray(" # Control a device")),console.log(" $ bricks device refresh <device-id>"),console.log(" $ bricks device control <device-id> clear-cache"),console.log(""),console.log(V.Ay.gray(" # Bind a new device")),console.log(' $ bricks device bind <passcode> -n "My Device"'),console.log(""),console.log(V.Ay.gray(" # List applications")),console.log(" $ bricks app list"),console.log(""),console.log(V.Ay.gray(" # Start interactive mode")),console.log(" $ bricks interactive"),console.log(""),console.log(V.Ay.gray(" # Change API endpoint")),console.log(" $ bricks config endpoint beta"),console.log(""),console.log(V.Ay.gray("Get workspace token from BRICKS Controller:")),console.log(V.Ay.cyan(" https://control.bricks.tools")),console.log(V.Ay.gray(" Go to Workspace Settings > API Token"))}),0===process.argv.slice(2).length)try{return void(0,(yield E.e(612).then(E.bind(E,59612))).runInteractiveMode)()}catch(e){console.error(V.Ay.red(`Failed to start interactive mode: ${e.message}`)),process.exit(1)}yield D.parseAsync(process.argv)});return function(){return e.apply(this,arguments)}}();const A_=N_;export{A_ as default,N_ as run};
|
|
3144
|
+
`,Sy={query:"query",mutation:"mutate"},wy=(e,t,a)=>([n,r])=>{if(e[n])throw new Error(`Overwriting client.${n}`);e[n]=async(i,o={})=>{let s,p;const l={[t]:r,variables:i,...o};if(a&&(l.variables={...a,...l.variables}),o.readQuery)s=e.readQuery(l);else if(o.writeQuery)e.writeQuery({...l,data:o.writeQuery});else{const a=await e[Sy[t]](l);({data:s,errors:p}=a||{})}if(p)throw new Error(p.map(e=>e.message).join("\n"));return s?s[n]:null}},Iy=e=>({data:t,errors:a})=>{const n=((e,t)=>e?.length?new Error(e.map(e=>e.message).join("\n")):t?new Error(t):null)(a,!t?.mediaBoxChanged&&"Missing mediaBoxChanged payload");return n?e(n):e(null,t.mediaBoxChanged)},Cy=(e={})=>{const t=(({endpoint:e="http://localhost:3002",accessToken:t,boxId:a,passcode:n,enableSubscription:r=!0,enableRetry:i=!0,subscriptionOnConnectionOrError:o,onNetworkError:s}={})=>{const p=a&&n;let l=`${e}/api/graphql`;return p&&(l=`${e}/api/graphql_with_passcode`),Zh({endpointURL:l,subscriptionEndpointURL:l.replace("http:","ws:"),accessToken:t,enableSubscription:!p&&r,enableRetry:i,subscriptionOnConnectionOrError:o,onNetworkError:s})})(e);if(e.boxId&&e.passcode){t.type="passcode",t.queries=S,t.mutations=w;const a={boxId:e.boxId,passcode:e.passcode};Object.entries(S).forEach(wy(t,"query",a)),Object.entries(w).forEach(wy(t,"mutation",a)),t.listenBoxChanged=(e,n)=>t.subscribe({query:Ay,variables:{...a,...e}}).subscribe({next:Iy(n),error(e){n(e)}})}else t.accessToken=e.accessToken,t.type="token",t.queries=N,t.mutations=A,Object.entries(N).forEach(wy(t,"query")),Object.entries(A).forEach(wy(t,"mutation")),t.listenBoxChanged=(e,a)=>t.subscribe({query:Ey,variables:e}).subscribe({next:Iy(a),error(e){a(e)}});return t};function Dy(e,t,a){switch(a){case"user":return new Rf(e,t);case"workspace":return new sh(e,t);default:throw new Error(`Invalid token type: ${a}.`)}}process.env.STAGE,process.env.URL_BASE;var Py="bricks-mcp",jy={bricks:process.env.BRICKS_API_SERVER||"https://display-beta.bricks.tools",media:process.env.MEDIA_API_SERVER||"https://media-beta.bricks.tools"},ky=(process.env.AUTH0_DOMAIN,process.env.CACHE_URL,E(1639));const Ly=({type:e,title:t,template_key:a})=>{var n,r,i=(0,ky.makeId)(e);switch(e){case"subspace":n={title:t,layout:{width:"number",height:"number"},root_canvas_id:"CANVAS_<UUID>",canvas_map:{},brick_map:{},animation_map:{},generator_map:{},property_bank_map:{},property_bank_calc_map:{}},r={"canvas_map.CANVAS_<UUID>.item_list":[{type:"subspace",subspace_id:"SUBSPACE_<UUID>",$note:"If not a root subspace, it can be linked to canvas in other subspace"}]};break;case"canvas":var o=cd(ud.canvas);n={title:t,item_list:[],property:{$definitions:Object.fromEntries(Object.entries(o.propTypes).map(([e,t])=>[e,{...t,description:o.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(o.eventTypes).map(([e])=>[e,{description:o.brickEventDescriptions[e]}]))}},r={property_bank_map:{[(0,ky.makeId)("property_bank")]:{title:`Canvas ID: ${t}`,type:"string",value:i,routing:"read-only",kind:"auto-generated-item-id",idType:"canvas"}}};break;case"brick":var s=cd(ud.components.Basic),p=cd(ud.brickMapping[a]);if(!p)throw new Error(`Brick ${a} not found`);var l={...p,propTypes:{...s.propTypes,...p.propTypes},brickPropDescriptions:{...s.brickPropDescriptions,...p.brickPropDescriptions},eventTypes:{...s.eventTypes,...p.eventTypes},brickEventDescriptions:{...s.brickEventDescriptions,...p.brickEventDescriptions}};n={title:t,template_key:a,property:{$definitions:Object.fromEntries(Object.entries(l.propTypes).map(([e,t])=>[e,{...t,description:l.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(l.eventTypes).map(([e])=>[e,{description:l.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(l.outletTypes).map(([e])=>[e,{description:l.brickOutletDescriptions[e]}]))},state_group:{"BRICK_STATE_GROUP_<UUID>":{}}},r={canvas_map:{"CANVAS_<UUID WHICH NEED DISPLAY THIS BRICK>":{item_list:[{type:"brick",brick_id:i,frame:{x:"number",y:"number",width:"number",height:"number",standby_mode:"custom|top|left|right|bottom",standby_delay:"number",standby_easing:{default:{method:"ease",duration:"number"}}}}]}}};break;case"state_group":n={title:t,description:"State Group Description",conds:[{type:"property_bank|inner_state",key:"PROPERTY_BANK#<Data Node ID>|[current_canvas|BRICK_<OUTLET NAME>]|",method:"==|!=|>|>=|<|<=",value:"value_to_compare"}],override:{property:!1,event:!1,outlet:!1},commented:!1,break:!1,property:{},outlet:{},animation:{}};case"generator":var u=cd(ud.generatorMapping[a]);if(!u)throw new Error(`Generator ${a} not found`);n={title:t,template_key:a,property:{$definitions:Object.fromEntries(Object.entries(u.propTypes).map(([e,t])=>[e,{...t,description:u.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(u.eventTypes).map(([e])=>[e,{description:u.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(u.outletTypes).map(([e])=>[e,{description:u.brickOutletDescriptions[e]}]))}};break;case"animation":n={title:t,type:"timing|decay|spring",property:"opacity|transform.translateX|transform.scale|etc",config:{$note:"Config for the animation"},compose_type:"parallel|sequence",item_list:[{animation_id:"ANIMATION_<SUB ANIMATION UUID>"}]};break;case"property_bank":n={title:t,description:"Property Bank Description",linkedFrom:"SUBSPACE_<UUID WHICH IS CROSS SUBSPACE>",type:"string|number|bool|object|array|any",kind:"color|datetime|id|media-resource-*|lottie-file-uri",unit:"grid|px|ms",routing:"read-only|default",value:"fit-to-type",event_map:{$note:`Available events: ${Object.keys(ud.propertyBank.eventTypes).join(", ")}`},local_sync:{update_mode:"all|main-only|minor-only|dont-sync"},$remote_update_additional:{$note:"Configure remote update behavior",enable_remote_update:!0,bank_type:"create|create-device-specific"}};break;case"property_bank_command":break;case"property_bank_calc":var c=(0,ky.makeId)("property_bank_command"),d=(0,ky.makeId)("property_bank_command"),m=(0,ky.makeId)("property_bank_command"),f="const { arg_name } = inputs;\n\nreturn { arg_name };";n={title:t,map:{$note:"Required, actual implementation","PROPERTY_BANK_DATA_NODE_<UUID>":{type:"data-node",properties:{},in:{change:null},out:{value:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID>",port:"value"}]},$note:"Use this to input data to the sandbox"},"PROPERTY_BANK_COMMAND_NODE_<UUID FIRST>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:null,path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${c}`,port:"obj | inputs"}]}},"PROPERTY_BANK_COMMAND_NODE_<UUID SECOND>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PREVIOUS>",port:"result"}],path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID SECOND>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${c}`,port:"obj | inputs"}]}},[c]:{type:"command-node-sandbox",title:"Command: SANDBOX_RUN_JAVASCRIPT",properties:{command:"SANDBOX_RUN_JAVASCRIPT",args:{code:f,enable_async:!1}},in:{code:null,inputs:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID FINAL>",port:"result"}]},out:{result:[{id:m,port:"result"},{id:d,port:"result"}]}},[m]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_ERROR",properties:{command:"SANDBOX_GET_ERROR"},in:{result:[{id:c,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR>",port:"change"}],$note:"Set `result` as null if there is no error"}},[d]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_RETURN_VALUE",properties:{command:"SANDBOX_GET_RETURN_VALUE"},in:{result:[{id:c,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT> | null",port:"change"}]}},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT>":{type:"data-node",properties:{},in:{change:[{id:d,port:"result"}]},out:{value:null},$note:"Put full result into data node"},"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>":{type:"command-node-object",title:"Command: OBJECT_GET",properties:{command:"OBJECT_GET",args:{path:"obj_key"}},in:{obj:[{id:d,port:"obj"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>",port:"change"}]},$note:"Parse result object into data node"},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>":{type:"data-node",properties:{},in:{change:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>",port:"result"}]},out:{value:null},$note:"Put partial result into data node"}},editor_info:{},type:"script",script_config:{title:t,enable_async:!1,inputs:{"PROPERTY_BANK_DATA_NODE_<UUID>":"arg_name"},disabled_triggers:{},error:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR> | null",output:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | null",outputs:{obj_key:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>"},code:f,$note:"Required, info for GUI editor"}}}return sc({id:i,example:n,extraInfo:r})};function xy(e,t){var a,n,r,i,o,s,p,l,u,c,d,m,f,h="user"===t.tokenType,y=((e,t=null)=>({name:a,description:n,inputSchema:r,permission:i},o)=>{_d(t,i)&&e.tool(a,n,r,o)})(e,t),_=e=>({...e,...h?{workspace_id:da().describe("Workspace ID")}:{}}),E=t.client,T=h?function(e){var t=e.endpoint,a=e.accessToken;if(!t)throw new Error("Media API endpoint is required");if(!a)throw new Error("Access token is required");return Cy({endpoint:t,accessToken:a,enableSubscription:!1,enableRetry:!0})}({endpoint:jy.media,accessToken:t.token}):E;h&&e.tool("list_workspaces","List all workspaces",{},I(function*(){return sc(yield E.workspaces())})),y({name:"get_workspace_overview",description:"Get comprehensive overview of the BRICKS workspace including stats and summary",inputSchema:_({}),permission:"info"},function(){var e=I(function*({workspace_id:e}){var t=yield Promise.all([E.workspace({id:e}),E.applications({workspaceId:e,paginate:{limit:50,offset:0}}),E.modules({workspaceId:e,paginate:{limit:50,offset:0}}),E.devices({workspaceId:e,paginate:{limit:50,offset:0}}),h?T.mediaWorkspace({workspaceId:e}).catch(()=>null):T.mediaWorkspace().catch(()=>null),h?T.mediaBoxes({workspaceId:e}).catch(()=>[]):T.mediaBoxes().catch(()=>[])]),a=ye(t,6),n=a[0],r=a[1],i=a[2],o=a[3],s=a[4],p=a[5];if(!n)throw new Error("Authentication failed, please check your token");return sc({workspace:n,stats:{applications:r?.length??"No permission",modules:i?.length??"No permission",devices:o?.length??"No permission",running_apps:r?.filter(e=>e.status?.running).length??"No permission",media_boxes:p?.length??"No permission",media_enabled:!!s,notes:"Note: The stats are based on the first 50 applications, modules, and devices in the workspace."},recent_activity:{latest_apps:r?.slice(0,5).map(e=>({id:e._id,name:e.name,status:e.status?.running?"running":"stopped",last_update:e.last_modify_datetime}))||[]},media_info:s?{workspace_id:s.id,name:s.name,size_used:s.size,size_limit:s.sizeLimit,boxes:p?.slice(0,5).map(e=>({id:e.id,name:e.name,size:e.size,description:e.description}))||[]}:{enabled:!1,note:"Media workspace is not enabled for this workspace"}})});return function(t){return e.apply(this,arguments)}}()),y({name:"get_applications",description:"List all applications in the workspace",inputSchema:_({limit:ma().describe("Maximum number of applications to return").optional().default(50),offset:ma().describe("Number of applications to skip").optional().default(0)}),permission:"query_application"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.applications({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_application",description:"Get detailed info and config of a specific application",inputSchema:_({id:da().describe("Application ID")}),permission:"query_application"},function(){var e=I(function*({workspace_id:e,id:t}){return sc(yield E.application({workspaceId:e,id:t}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_modules",description:"List all modules in the workspace",inputSchema:_({limit:ma().describe("Maximum number of modules to return").optional().default(50),offset:ma().describe("Number of modules to skip").optional().default(0)}),permission:"query_module"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.modules({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_module",description:"Get detailed info and config of a specific module",inputSchema:_({id:da().describe("Module ID")}),permission:"query_module"},function(){var e=I(function*({workspace_id:e,id:t}){return sc(yield E.module({workspaceId:e,id:t}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_module_info",description:"Update a specific module info",inputSchema:_({id:da().describe("Module ID"),name:da().describe("Module name"),description:da().describe("Module description")}),permission:"update_module"},function(){var e=I(function*({workspace_id:e,id:t,name:a,description:n}){return sc(yield E.updateModule({workspaceId:e,id:t,name:a,description:n}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_module_config",description:"Update a specific module configuration",inputSchema:_({id:da().describe("Module ID"),config:ha({}).passthrough().describe("New configuration object, see file://docs/config-schema.md for schema reference")}),permission:"update_module"},function(){var e=I(function*({workspace_id:e,id:t,config:a}){var n=yield pd(a);if(!n.valid)throw new Error(`Config validation failed: ${n.errors.join(", ")}`);return sc(yield E.updateModule({workspaceId:e,id:t,config:JSON.stringify(a),validateConfig:!0}))});return function(t){return e.apply(this,arguments)}}()),y({name:"get_devices",description:"List all devices in the workspace",inputSchema:_({limit:ma().describe("Maximum number of devices to return").optional().default(50),offset:ma().describe("Number of devices to skip").optional().default(0)}),permission:"query_device"},function(){var e=I(function*({workspace_id:e,limit:t=50,offset:a=0}){return sc(yield E.devices({workspaceId:e,paginate:{limit:t,offset:a}}))});return function(t){return e.apply(this,arguments)}}()),y({name:"create_application",description:"Create a new BRICKS application with default grid layout",inputSchema:_({name:da().describe("Application name"),description:da().describe("Application description").optional(),grid_width:ma().describe("Grid width in units").optional().default(96),grid_height:ma().describe("Grid height in units").optional().default(54)}),permission:"create_application"},function(){var e=I(function*({workspace_id:e,name:t,description:a,grid_width:n,grid_height:r}){return sc(yield E.createApplication({workspaceId:e,name:t,description:a,gridWidth:n,gridHeight:r}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_application_info",description:"Update application info",inputSchema:{id:da().describe("Application ID"),name:da().describe("Application name"),description:da().describe("Application description")},permission:"update_application"},function(){var e=I(function*({id:e,name:t,description:a}){return sc(yield E.updateApplication({id:e,name:t,description:a}))});return function(t){return e.apply(this,arguments)}}()),y({name:"update_application_config",description:"Update application configuration with validation",inputSchema:{id:da().describe("Application ID"),config:ha({}).passthrough().describe("New application configuration. Please read `getting-started` for BRICKS concepts before changing")},permission:"update_application"},function(){var e=I(function*({id:e,config:t}){var a=yield pd(t);if(!a.valid)throw new Error(`Config validation failed: ${a.errors.join(", ")}`);return sc(yield E.updateApplication({id:e,config:JSON.stringify(t)}))});return function(t){return e.apply(this,arguments)}}()),y({name:"bind_application",description:"Bind application to device with viewport configuration",inputSchema:{app_id:da().describe("Application ID"),viewports:fa(ha({device_id:da().describe("Device ID"),x:ma().describe("X coordinate"),y:ma().describe("Y coordinate"),width:ma().describe("Width"),height:ma().describe("Height"),rotate:ma().describe("Rotation"),rotateType:da().describe("Rotation type")})).describe("Viewport configuration")},permission:"bind_application"},(a=I(function*({app_id:e,viewports:t}){return sc(yield E.bindApplication({id:e,bind_devices:t.map(e=>e.device_id),device_frames:t.reduce((e,t)=>({...e,[t.device_id]:{x:t.x,y:t.y,width:t.width,height:t.height,rotate:t.rotate,rotateType:t.rotateType}}),{})}))}),function(e){return a.apply(this,arguments)})),y({name:"unbind_application",description:"Unbind application from device",inputSchema:{app_id:da().describe("Application ID"),device_id:da().describe("Device ID")},permission:"bind_application"},(n=I(function*({app_id:e,device_id:t}){return sc(yield E.bindApplication({id:e,unbindDevices:[t]}))}),function(e){return n.apply(this,arguments)})),h&&y({name:"list_media_workspaces",description:"List all media workspaces",inputSchema:{},permission:"query_media_flow"},I(function*(){return sc(yield T.mediaWorkspaces())})),y({name:"get_media_workspace",description:"Get media workspace information and status",inputSchema:_({}),permission:"query_media_flow"},(r=I(function*({workspace_id:e}){return sc(yield T.mediaWorkspace({workspaceId:e}))}),function(e){return r.apply(this,arguments)})),y({name:"list_media_boxes",description:"List all media boxes in the workspace",inputSchema:_({}),permission:"query_media_flow"},(i=I(function*({workspace_id:e}){return sc(yield T.mediaBoxes({workspaceId:e}))}),function(e){return i.apply(this,arguments)})),y({name:"get_media_box",description:"Get detailed information about a specific media box",inputSchema:{box_id:da().describe("Media box ID")},permission:"query_media_flow"},(o=I(function*({box_id:e}){return sc(yield T.mediaBox({boxId:e}))}),function(e){return o.apply(this,arguments)})),y({name:"list_media_files",description:"List media files in a specific box with filtering options",inputSchema:{box_id:da().describe("Media box ID"),include_types:fa(da()).optional().describe('Filter by file types (e.g., ["image", "video", "audio"])'),user_tags:fa(da()).optional().describe("Filter by user tags"),limit:ma().optional().default(50).describe("Maximum number of files to return"),offset:ma().optional().default(0).describe("Number of files to skip")},permission:"query_media_flow"},(s=I(function*({box_id:e,include_types:t,user_tags:a,limit:n,offset:r}){return sc(yield T.mediaFiles({boxId:e,includeTypes:t,userTags:a,limit:n,offset:r}))}),function(e){return s.apply(this,arguments)})),y({name:"get_media_file_meta",description:"Get detailed information about a specific media file",inputSchema:{file_id:da().describe("Media file ID")},permission:"query_media_flow"},(p=I(function*({file_id:e}){return sc(yield T.mediaFile({fileId:e}))}),function(e){return p.apply(this,arguments)})),y({name:"media_box_upload",description:"Upload a file to a media box from URL or base64 data",inputSchema:{box_id:da().describe("Target media box ID"),name:da().describe("File name"),description:da().optional().default("").describe("File description"),file_type:ya(["image","video","audio","file"]).describe("File type"),source_url:da().optional().describe("URL to download the file from"),base64_data:da().optional().describe("Base64 encoded file data"),user_tags:fa(da()).optional().default([]).describe("User-defined tags for the file")},permission:"write_media_flow"},(l=I(function*({box_id:e,name:t,description:a,source_url:n,base64_data:r,file_type:i,user_tags:o}){if(!n&&!r)throw new Error("Either source_url or base64_data must be provided");if(n&&r)throw new Error("Provide either source_url OR base64_data, not both");var s=n?null:"application/octet-stream",p=n?yield(0,pc.Ay)(n,{agent:Rc(n)}).then(e=>(s=e.headers.get("content-type"),e.blob())):new Blob([oc.Buffer.from(r,"base64")],{type:s}),l=yield T.requestFileUpload({name:t,description:a,boxId:e,fileType:h?i.toUpperCase():i,contentType:s,userTags:o,meta:{}}),u=JSON.parse(l?.meta.uploadInfo),c=new FormData;c.append("file",p),c.append("Content-Type",s),c.append("AWSAccessKeyId",u.AWSAccessKeyId),c.append("Signature",u.Signature),c.append("Policy",u.Policy),c.append("acl",u.acl),c.append("key",u.key);var d=yield(0,pc.Ay)(u.url,{method:"POST",body:c}).then(e=>e.ok).catch(()=>!1);return sc({file_id:l.id,upload_success:d,upload_info:{content_type:s,file_type:i,source_type:n?"url":"base64",processing_note:"File will be processed automatically. Use get_media_file to check processing status."}})}),function(e){return l.apply(this,arguments)})),y({name:"update_media_file_meta",description:"Update media file information",inputSchema:{file_id:da().describe("Media file ID"),name:da().optional().describe("New file name"),description:da().optional().describe("New file description"),user_tags:fa(da()).optional().describe("New user tags")},permission:"write_media_flow"},(u=I(function*({file_id:e,name:t,description:a,user_tags:n}){return sc(yield T.updateMediaFile({fileId:e,name:t,description:a,userTags:n,requestUploadAgain:!1}))}),function(e){return u.apply(this,arguments)})),y({name:"copy_media_files",description:"Copy media files from one box to another",inputSchema:{from_box_id:da().describe("Source media box ID"),to_box_id:da().describe("Target media box ID"),file_ids:fa(da()).describe("Array of media file IDs to copy")},permission:"write_media_flow"},(c=I(function*({from_box_id:e,to_box_id:t,file_ids:a}){return sc(yield T.copyMediaFiles({fromBoxId:e,toBoxId:t,list:a}))}),function(e){return c.apply(this,arguments)})),y({name:"delete_media_files",description:"Delete specific media files from a box",inputSchema:{box_id:da().describe("Media box ID"),file_ids:fa(da()).describe("Array of media file IDs to delete")},permission:"write_media_flow"},(d=I(function*({box_id:e,file_ids:t}){return sc(yield T.deleteMediaFiles({boxId:e,list:t}))}),function(e){return d.apply(this,arguments)})),y({name:"cleanup_media_box",description:"Delete all files in a media box, optionally filtered by type",inputSchema:{box_id:da().describe("Media box ID"),include_types:fa(da()).optional().describe('Only delete files of these types (e.g., ["image", "video"])')},permission:"write_media_flow"},(m=I(function*({box_id:e,include_types:t}){if("deleteMediaBoxFiles"in T)return sc(yield T.deleteMediaBoxFiles({boxId:e,includeTypes:t}));var a=yield T.mediaFiles({boxId:e,includeTypes:t});return sc(yield T.deleteMediaFiles({boxId:e,list:a.map(e=>e.id)}))}),function(e){return m.apply(this,arguments)})),e.tool("calculate_grid_layout","Calculate grid layout and pixel conversions for different device resolutions",{device_width:ma().describe("Device width in pixels"),device_height:ma().describe("Device height in pixels"),app_grid_width:ma().describe("Application grid width").optional().default(96),app_grid_height:ma().describe("Application grid height").optional().default(54)},(f=I(function*({device_width:e,device_height:t,app_grid_width:a,app_grid_height:n}){var r,i,o={deviceBrickWidth:(r=e)/(i=r/a),deviceBrickHeight:t/i,deviceBrickUnit:i},s=function(e,t,a=96){var n=e/a;return t>e&&(n=t/a),{deviceBrickWidth:Math.round(e/n),deviceBrickHeight:Math.round(t/n),deviceBrickUnit:n}}(e,t,a);return sc({device_resolution:{width:e,height:t,aspect_ratio:(e/t).toFixed(2)},current_grid:{width:a,height:n,unit_size_px:o.deviceBrickUnit.toFixed(2),total_pixels:{width:o.deviceBrickWidth.toFixed(2),height:o.deviceBrickHeight.toFixed(2)}},recommended_grid:{width:s.deviceBrickWidth,height:s.deviceBrickHeight,unit_size_px:s.deviceBrickUnit.toFixed(2),note:"Optimized for device aspect ratio"}})}),function(e){return f.apply(this,arguments)})),e.tool("create_item","Use this tool to create new item that you can put in application configuration",{type:ya(["subspace","canvas","brick","generator","property_bank","property_bank_calc","property_bank_command","animation","state_group","automation_map"]).describe("Item type"),title:da().describe("Item title"),template_key:da().optional().describe("Template key for brick or generator")},Ly),e.tool("getting_started","Get documentation content for getting started",{},I(function*(){return sc(yd)}))}var My="2.24.0-beta.40";function Gy(){return Gy=I(function*(e={}){var t=e.token||process.env.BRICKS_API_TOKEN;if(!t)throw console.error("Error: API token is required"),console.error("Please provide a token via options or set BRICKS_API_TOKEN environment variable"),new Error("API token is required");var a=rc({queryStringParameters:{token:t}});if(!a.success)throw console.error("Error: Invalid BRICKS_API_TOKEN"),console.error(a.message),new Error("Invalid BRICKS_API_TOKEN");var n,r=new Vu({name:Py,version:My}),i={...a,client:Dy(jy.bricks,a.token,a.tokenType)};(n=r).prompt("getting-started","Getting started with BRICKS",{},I(function*(){return{messages:[{role:"user",content:{type:"text",text:'Welcome to BRICKS — start here.\n\nBefore doing any complex work (application design, deployments, etc.),\nalways consult the official docs rather than guessing.\n\nIMPORTANT: BRICKS users interact through a GUI editor, not raw config files.\nNever show users JSON config details, schema fields, or technical implementation.\nFocus on user-friendly descriptions of what the app will do and how it will look.\n\nGolden rules for working with BRICKS:\n1) Read before you act\n - Open these resources first, then proceed:\n - `getting-started` — overview & architecture\n - `config-schema` — canonical schema for apps, subspaces, bricks, generators, etc.\n - `components-index` — available bricks/generators\n2) Source of truth\n - Rely on the docs above; do not invent fields not present in the schema\n3) No guessing\n - If names, constraints, or device details are missing, ask to fetch them first\n4) Plan then execute\n - Propose a clear step-by-step plan and wait for approval before writing or mutating data\n5) User-friendly communication\n - Describe features in terms of what users see and do, not technical config\n - Use visual/functional language: "text display", "button", "screen transition"\n - Avoid exposing JSON, IDs, or schema details to end users\n\nBRICKS essentials:\n- Applications: interactive digital signage experiences\n- Devices: deployment targets (screens/players)\n- Modules: Reusable module across applications\n- Grid system: default 96×54; 1 unit = device_width/96 (e.g., 20px at 1920×1080)\n- Key primitives: Subspaces, Canvas, Bricks, Generators, Property Banks (Data)\n\nQuick actions:\n- "Create a new application" → use the `create-application` prompt\n- "Deploy an application to a device" → use the `deploy-to-device` prompt\n\nTry asking:\n- "Draft a plan to create an app with a text display and deploy it; ask any missing questions first"'}}]}})),n.prompt("create-application","Create a new BRICKS application with guided setup",{app_name:da().describe("Name for the new application"),description:da().describe("Short description for the new application").optional()},function(){var e=I(function*(e){var t=e?.app_name||"New Application",a=e?.description||"";return{messages:[{role:"user",content:{type:"text",text:`Help me create a new BRICKS application called "${t}".\n\n${a?`Goal: ${a}`:""}\n\nIMPORTANT: Users see a visual GUI editor, not raw config. Describe features in user-friendly terms:\n- "text display" not "BRICK_TEXT"\n- "image" not "BRICK_IMAGE"\n- "canvas name" not "CANVAS_xxx"\n- "data storage" not "PROPERTY_BANK"\n- Focus on what users see and do, not technical implementation\n\nHow we'll proceed (no guessing, schema-first):\n1) Confirm intent\n - Restate objectives and success criteria in 1–3 bullets\n2) Consult docs (as needed)\n - getting-started, config-schema, components-index\n - Ensure proposed fields exist in the schema\n3) Ask missing questions before changes\n - Target device(s) and resolution(s)\n - Layout needs (pages/screens), content types, data sources\n - Localization, scheduling, or interaction needs\n4) Propose a minimal viable design (After confirming intent)\n - App structure: screens → visual elements\n - Initial component selection with rationale\n - Grid usage: default 96×54 (≈20px at 1920×1080)\n5) Produce a schema-valid skeleton (no side effects yet)\n - Include only fields defined by config-schema\n - Use clear placeholders for text/assets/URLs/ids\n\nWhat I'll produce first:\n- Short recap of requirements\n- Clarifying questions (only what's necessary)\n- High-level architecture plan\n- Minimal config skeleton that validates against the schema`}}]}});return function(t){return e.apply(this,arguments)}}()),function(e){e.resource("getting-started-docs","file://docs/getting-started.md",{mimeType:"text/markdown",title:"Getting Started with BRICKS",description:"Comprehensive guide to BRICKS architecture, concepts, and development workflow"},I(function*(){return sc(ic,{uri:"file://docs/getting-started.md",mimeType:"text/markdown"})}))}(r),xy(r,i);var o=new Zu;try{yield r.connect(o),console.error("BRICKS MCP Server running on STDIO"),console.error(`Server: ${Py} v${My}`),console.error(`Token Type: ${a.tokenType}`),console.error(`Permissions: ${a.tokenInfo.permissions.join(", ")}`),console.error("Ready to accept requests...")}catch(e){throw console.error("Failed to start MCP server:",e),e}}),Gy.apply(this,arguments)}var Fy=new G("mcp").description("MCP server management");Fy.command("start").description("Start the BRICKS MCP server in STDIO mode").option("-t, --token <token>","API token (overrides saved token)").action(function(){var e=I(function*(e){var t=(0,$.getCurrentProfile)(),a=e.token||(0,$.getToken)(t);a||(console.error(V.Ay.red("Error: No API token found.")),console.error(V.Ay.gray("Please login first with: bricks auth login <passcode>")),console.error(V.Ay.gray("Or provide a token with: bricks mcp start --token <token>")),process.exit(1));try{yield function(){return Gy.apply(this,arguments)}({token:a})}catch(e){console.error(V.Ay.red(`Failed to start MCP server: ${e.message}`)),process.exit(1)}});return function(t){return e.apply(this,arguments)}}());var By="2.24",zy=e=>{if(!e)return!1;for(var t=e.replace(/^v/,"").split(".").map(Number),a=By.split(".").map(Number),n=0;n<a.length;n++){if((t[n]||0)>a[n])return!0;if((t[n]||0)<a[n])return!1}return!0},Vy=function(){var e=I(function*(e,t,a=3e3){try{var n=new AbortController,r=setTimeout(()=>n.abort(),a),i=yield fetch(`http://${e}:${t}/json/list`,{signal:n.signal});return clearTimeout(r),i.ok?yield i.json():null}catch{return null}});return function(t,a){return e.apply(this,arguments)}}(),$y=e=>{if(!e)return null;var t=e.match(/\/ws\/(.+)$/);return t?decodeURIComponent(t[1]):null},Uy=e=>e.requiredOption("-a, --address <address>","DevTools server address").option("-p, --port <port>","Server port","19851").option("--passcode <passcode>","Device passcode").option("-j, --json","Output as JSON"),Hy=function(){var e=I(function*(e,t){var a,n=(yield Promise.resolve().then(E.bind(E,29790))).default,r=(yield E.e(44).then(E.bind(E,12044))).verifyDevToolsServer,i=(yield E.e(999).then(E.bind(E,12999))).createCdpClient,o=parseInt(e.port,10),s=n("Connecting to DevTools...").start();try{var p=yield r(e.address,o);p||(s.fail(`Cannot reach DevTools server at ${e.address}:${o}`),process.exit(1)),p.version&&!zy(p.version)&&(s.fail(`CDP requires app version >= ${By} (device: ${p.version})`),process.exit(1)),a=i(e.address,o,e.passcode),yield a.connect(),s.stop(),yield t(a)}catch(e){s.isSpinning&&s.stop(),console.error(V.Ay.red(e.message)),process.exit(1)}finally{a?.close()}});return function(t,a){return e.apply(this,arguments)}}(),qy=e=>{if(!e)return{};for(var t={},a=0;a<e.length;a+=2)t[e[a]]=e[a+1];return t},Ky=(e,t="",a=!0,n=!0)=>{var r=[],i=n?"":a?"└─ ":"├─ ",o=n?"":a?" ":"│ ",s=e.nodeName||"#unknown";if(9===e.nodeType)s="#document";else if(3===e.nodeType){var p=e.nodeValue||"";s=V.Ay.gray(`"${p}"`)}else if(1===e.nodeType){var l=qy(e.attributes),u=l.id||l["short-id"];u&&(s+=V.Ay.gray(`#${u}`)),l.title&&(s+=` ${V.Ay.green(`"${l.title}"`)}`),void 0!==l.w&&void 0!==l.h&&(s+=V.Ay.blue(` ${l.w}×${l.h}`),void 0!==l.x&&void 0!==l.y&&(s+=V.Ay.blue(` @${l.x},${l.y}`)));var c=[];void 0!==l.hide&&c.push(V.Ay.red("hidden")),void 0!==l.pressable&&c.push(V.Ay.yellow("pressable")),void 0!==l.editable&&c.push(V.Ay.yellow("editable")),c.length>0&&(s+=` [${c.join(", ")}]`)}r.push(`${t}${i}${s}`);var d=e.children||[];return d.forEach((e,a)=>{r.push(...Ky(e,t+o,a===d.length-1,!1))}),r},Wy=new G("devtools").description("DevTools server discovery, inspection, and CDP commands"),Qy=function(){var e=I(function*(e){for(var t=yield Promise.resolve().then(E.t.bind(E,51455,19)),a=yield Promise.resolve().then(E.t.bind(E,76760,19)),n=[],r=process.cwd(),i=0;i<10;i++){var o=a.join(r,".bricks","devtools.json");try{var s=yield t.readFile(o,"utf8"),p=JSON.parse(s),l=yield e(p.address||"localhost",p.port,1e3);l&&n.push({name:p.name||"BRICKS Preview",address:p.address||"localhost",port:p.port,protocols:["cdp"],hasPasscode:!1,source:"project",projectPath:r,...l})}catch{}var u=a.dirname(r);if(u===r)break;r=u}return n});return function(t){return e.apply(this,arguments)}}();Wy.command("scan").description("Scan LAN for DevTools servers via UDP + HTTP").option("-t, --timeout <ms>","Scan timeout in milliseconds","3000").option("-j, --json","Output as JSON").option("--verify","Verify each discovered server via HTTP").option("--udp-only","Skip HTTP subnet probe (UDP only)").option("--project","Include local BRICKS project preview servers").option("-p, --port <port>","Port for HTTP probe","19851").action(function(){var e=I(function*(e){var t=(yield Promise.resolve().then(E.bind(E,29790))).default,a=yield E.e(44).then(E.bind(E,12044)),n=a.discoverDevToolsServers,r=a.verifyDevToolsServer,i=a.httpProbeSubnet,o=yield Promise.resolve().then(E.bind(E,74752)),s=o.getCurrentProfile,p=o.getTokenInfo,l=parseInt(e.timeout,10),u=t(`Scanning for DevTools servers (${l}ms)...`).start();try{var c=n({timeout:l,idleTimeout:800}),d=e.udpOnly?Promise.resolve([]):(u.text="Scanning via UDP + HTTP probe...",i({port:parseInt(e.port,10),timeout:l})),m=e.project?Qy(r):Promise.resolve([]),f=yield Promise.all([c,d,m]),h=ye(f,3),y=h[0],_=h[1],T=h[2],g=[...y,..._,...T],R=new Map;for(var v of g){var b=v.deviceId||`${v.address}:${v.port}`,O=R.get(b);if(O)for(var N of(O.addresses.includes(v.address)||O.addresses.push(v.address),"127.0.0.1"===O.address&&"127.0.0.1"!==v.address&&(O.address=v.address),v.protocols||[]))O.protocols?.includes(N)||O.protocols?.push(N);else R.set(b,{...v,addresses:[v.address]})}var A=[...R.values()];if(0===A.length)return void(e.json?(u.stop(),console.log(JSON.stringify([],null,2))):u.info("No DevTools servers found on the network."));if(e.verify){u.text=`Verifying ${A.length} server(s)...`;var S=yield Promise.all(A.map(function(){var e=I(function*(e){var t=yield r(e.address,e.port);return{...e,verified:!!t,version:t?.version||e.version}});return function(t){return e.apply(this,arguments)}}()));A.splice(0,A.length,...S)}u.text="Checking chrome://inspect support...",yield Promise.all(A.map(function(){var e=I(function*(e){var t=yield Vy(e.address,e.port);if(t){e.chromeInspect=!0;var a=$y(t?.[0]?.webSocketDebuggerUrl);a&&(e.passcode=a)}});return function(t){return e.apply(this,arguments)}}())),u.stop(),e.json&&(console.log(JSON.stringify(A,null,2)),process.exit(0));var w=p(s()),C=w?.workspaceId||null;console.log(V.Ay.bold(`\nFound ${A.length} DevTools server(s)`)),console.log("─".repeat(80));var D=function*(e){var t=!1===e.verified?V.Ay.red("unverified"):V.Ay.green("online"),a=e.hasPasscode?V.Ay.yellow("passcode"):V.Ay.gray("open"),n=(e.protocols||[]).map(e=>V.Ay.cyan(e)).join(", "),r=e.workspaceId&&C&&e.workspaceId===C,i=e.addresses||[e.address],o=i.filter(t=>t!==e.address),s=o.length>0?`${e.address}:${e.port} +${o.length} more`:`${e.address}:${e.port}`;if(console.log(` ${V.Ay.bold(e.name||"Unknown")} ${V.Ay.gray(`(${s})`)} [${t}]`),o.length>0&&console.log(` Addresses: ${i.map(e=>V.Ay.gray(e)).join(", ")}`),e.version&&console.log(` Version: ${V.Ay.green(e.version)}`),e.chromeInspect){var p=e.passcode?V.Ay.cyan(e.passcode):V.Ay.gray("no passcode");console.log(` Chrome Inspect: ${V.Ay.green("supported")} (passcode: ${p})`)}var l=` Protocols: ${n||V.Ay.gray("none")} Auth: ${a}`;if(e.deviceId&&(l+=` Device: ${V.Ay.gray(e.deviceId)}`),console.log(l),e.workspaceId){var u=r?V.Ay.green(`${e.workspaceId} (current profile)`):V.Ay.gray(e.workspaceId);console.log(` Workspace: ${u}`)}};for(var P of A)yield*D(P);console.log("─".repeat(80));var j=A[0],k=`${j.address}:${j.port||19851}`,L=j.passcode?`/ws/${encodeURIComponent(j.passcode)}`:"/ws/<passcode>";console.log(V.Ay.gray(`\nConnect via: devtools://devtools/bundled/inspector.html?ws=${k}${L}`)),process.exit(0)}catch(e){u.fail(`Scan failed: ${e.message}`),process.exit(1)}});return function(t){return e.apply(this,arguments)}}()),Wy.command("open <address>").description("Show DevTools server information").option("-p, --port <port>","Server port","19851").option("--info","Show connection URLs").action(function(){var e=I(function*(e,t){var a=(yield Promise.resolve().then(E.bind(E,29790))).default,n=(yield E.e(44).then(E.bind(E,12044))).verifyDevToolsServer,r=parseInt(t.port,10),i=`${e}:${r}`,o=a(`Fetching server info from ${i}...`).start(),s=yield n(e,r);s||(o.fail(`Could not reach DevTools server at ${i}`),process.exit(1)),o.stop();var p=yield Vy(e,r),l=p?$y(p?.[0]?.webSocketDebuggerUrl):null,u=l?`/ws/${encodeURIComponent(l)}`:"/ws/<passcode>";if(t.info)return console.log(V.Ay.bold("Connection URLs")),console.log("─".repeat(60)),console.log(` Web UI: ${V.Ay.cyan(`http://${i}`)}`),console.log(` CDP: ${V.Ay.cyan(`devtools://devtools/bundled/inspector.html?ws=${i}${u}`)}`),console.log(` MCP: ${V.Ay.cyan(`http://${i}/mcp`)}`),console.log(` MCP SSE: ${V.Ay.cyan(`http://${i}/sse`)}`),console.log(` Info: ${V.Ay.cyan(`http://${i}/devtools/info`)}`),console.log("─".repeat(60)),console.log(),console.log(V.Ay.bold("Authorization")),l&&console.log(` Passcode: ${V.Ay.cyan(l)}`),console.log(" MCP and MCP SSE require a Bearer token header with the device passcode:"),void console.log(` ${V.Ay.gray(`Authorization: Bearer ${l||"<passcode>"}`)}`);if(console.log(V.Ay.bold("DevTools Server")),console.log("─".repeat(60)),console.log(` Name: ${V.Ay.cyan(s.name||"Unknown")}`),console.log(` Version: ${s.version?V.Ay.green(s.version):V.Ay.gray("N/A")}`),console.log(` Device ID: ${V.Ay.gray(s.deviceId||"N/A")}`),console.log(` Workspace: ${V.Ay.gray(s.workspaceId||"N/A")}`),console.log(` Protocols: ${(s.protocols||[]).map(e=>V.Ay.cyan(e)).join(", ")||V.Ay.gray("none")}`),console.log(` Auth: ${s.hasPasscode?V.Ay.yellow("passcode required"):V.Ay.gray("open")}`),console.log(` Port: ${s.port}`),p){var c=l?V.Ay.cyan(l):V.Ay.gray("no passcode");console.log(` Inspect: ${V.Ay.green("chrome://inspect supported")} (passcode: ${c})`)}else console.log(` Inspect: ${V.Ay.gray("chrome://inspect not available")}`);console.log("─".repeat(60)),s.version&&!zy(s.version)&&console.log(V.Ay.yellow(`\n CDP commands require version >= ${By}`)),console.log(V.Ay.gray("\n Use --info to see connection URLs"))});return function(t,a){return e.apply(this,arguments)}}()),Uy(Wy.command("screenshot").description("Capture device screenshot").option("-o, --output <path>","Output file path")).action(function(){var e=I(function*(e){yield Hy(e,function(){var t=I(function*(t){var a=yield t.send("Page.captureScreenshot",{format:"png"});a.data||(console.error(V.Ay.red("No screenshot data received")),process.exit(1));var n=yield Promise.resolve().then(E.t.bind(E,73024,19)),r=yield Promise.resolve().then(E.t.bind(E,76760,19)),i=e.output||`screenshot-${Date.now()}.png`,o=r.resolve(i);n.writeFileSync(o,Buffer.from(a.data,"base64")),console.log(V.Ay.green(`Screenshot saved to ${o}`))});return function(e){return t.apply(this,arguments)}}())});return function(t){return e.apply(this,arguments)}}());var Yy,Xy,Jy,Zy,e_,t_=Wy.command("brick").description("Brick component inspection");Uy(t_.command("tree").description("Print brick component tree").option("-d, --depth <depth>","Max depth (-1 for full)","3")).action(function(){var e=I(function*(e){yield Hy(e,function(){var t=I(function*(t){yield t.send("DOM.enable");var a=parseInt(e.depth,10),n=(yield t.send("DOM.getDocument",{depth:a})).root;e.json?console.log(JSON.stringify(n,null,2)):console.log(Ky(n).join("\n"))});return function(e){return t.apply(this,arguments)}}())});return function(t){return e.apply(this,arguments)}}()),Uy(t_.command("query <selector>").description("Find brick by CSS selector")).action(function(){var e=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=(yield a.send("DOM.getDocument",{depth:0})).root,r=(yield a.send("DOM.querySelector",{nodeId:n.nodeId,selector:e})).nodeId;if(0!==r){var i=yield a.send("DOM.describeNode",{nodeId:r}),o=(yield a.send("DOM.getAttributes",{nodeId:r})).attributes,s=qy(o);if(t.json)console.log(JSON.stringify({nodeId:r,...i.node,attributes:s},null,2));else if(console.log(V.Ay.bold(`Node ${r}: ${i.node?.nodeName||"unknown"}`)),Object.keys(s).length>0)for(var p of(console.log(V.Ay.bold("Attributes:")),Object.entries(s))){var l=ye(p,2),u=l[0],c=l[1];console.log(` ${V.Ay.cyan(u)}: ${c}`)}}else console.log(V.Ay.yellow("No element found"))}),function(e){return a.apply(this,arguments)}))});return function(t,a){return e.apply(this,arguments)}}()),Uy(t_.command("query-all <selector>").description("Find all bricks matching CSS selector")).action((Yy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=(yield a.send("DOM.getDocument",{depth:0})).root,r=(yield a.send("DOM.querySelectorAll",{nodeId:n.nodeId,selector:e})).nodeIds;if(t.json)console.log(JSON.stringify({nodeIds:r,count:r.length},null,2));else for(var i of(console.log(V.Ay.bold(`Found ${r.length} element(s)`)),r)){var o=yield a.send("DOM.describeNode",{nodeId:i}),s=(yield a.send("DOM.getAttributes",{nodeId:i})).attributes,p=qy(s),l=p.id||p["short-id"]||"";console.log(` ${i}: ${o.node?.nodeName}${l?V.Ay.gray(`#${l}`):""}`)}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Yy.apply(this,arguments)})),Uy(t_.command("attributes <nodeId>").description("Get brick attributes")).action((Xy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.getAttributes",{nodeId:n})).attributes,i=qy(r);if(t.json)console.log(JSON.stringify(i,null,2));else if(0!==Object.keys(i).length)for(var o of Object.entries(i)){var s=ye(o,2),p=s[0],l=s[1];console.log(` ${V.Ay.cyan(p)}: ${l}`)}else console.log(V.Ay.gray("No attributes"))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Xy.apply(this,arguments)})),Uy(t_.command("box-model <nodeId>").description("Get brick dimensions and position")).action((Jy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.getBoxModel",{nodeId:n})).model;t.json?console.log(JSON.stringify(r,null,2)):(console.log(V.Ay.bold(`Box Model for node ${n}`)),console.log(` Width: ${r.width}`),console.log(` Height: ${r.height}`),r.content&&console.log(` Content: [${r.content.join(", ")}]`),r.padding&&console.log(` Padding: [${r.padding.join(", ")}]`),r.border&&console.log(` Border: [${r.border.join(", ")}]`),r.margin&&console.log(` Margin: [${r.margin.join(", ")}]`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Jy.apply(this,arguments)})),Uy(t_.command("resolve <nodeId>").description("Resolve brick to JavaScript object with properties")).action((Zy=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("DOM.enable");var n=parseInt(e,10),r=(yield a.send("DOM.resolveNode",{nodeId:n})).object;if(t.json)console.log(JSON.stringify(r,null,2));else if(console.log(V.Ay.bold(`Resolved node ${n}`)),console.log(` Type: ${r.type}`),r.className&&console.log(` Class: ${r.className}`),r.description&&console.log(` Description: ${r.description}`),r.objectId&&console.log(` Object ID: ${V.Ay.gray(r.objectId)}`),r.preview?.properties)for(var i of(console.log(V.Ay.bold(" Properties:")),r.preview.properties))console.log(` ${V.Ay.cyan(i.name)}: ${i.value}`)}),function(e){return a.apply(this,arguments)}))}),function(e,t){return Zy.apply(this,arguments)})),Uy(t_.command("focus <nodeId>").description("Focus a brick element")).action((e_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("DOM.enable");var a=parseInt(e,10);yield t.send("DOM.focus",{nodeId:a}),console.log(V.Ay.green(`Focused node ${a}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return e_.apply(this,arguments)}));var a_,n_,r_,i_=Wy.command("input").description("Input emulation");Uy(i_.command("tap <x> <y>").description("Tap/click at coordinates")).action((a_=I(function*(e,t,a){var n;yield Hy(a,(n=I(function*(a){var n=parseFloat(e),r=parseFloat(t);yield a.send("Input.dispatchMouseEvent",{type:"mousePressed",x:n,y:r,button:"left",clickCount:1}),yield a.send("Input.dispatchMouseEvent",{type:"mouseReleased",x:n,y:r,button:"left",clickCount:1}),console.log(V.Ay.green(`Tapped at (${n}, ${r})`))}),function(e){return n.apply(this,arguments)}))}),function(e,t,a){return a_.apply(this,arguments)})),Uy(i_.command("type <text>").description("Insert text into focused element")).action((n_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("Input.insertText",{text:e}),console.log(V.Ay.green(`Typed: ${e}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return n_.apply(this,arguments)})),Uy(i_.command("key <key>").description("Dispatch key event (e.g., Enter, Escape, Tab)")).action((r_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(t){yield t.send("Input.dispatchKeyEvent",{type:"keyDown",key:e}),yield t.send("Input.dispatchKeyEvent",{type:"keyUp",key:e}),console.log(V.Ay.green(`Key: ${e}`))}),function(e){return a.apply(this,arguments)}))}),function(e,t){return r_.apply(this,arguments)}));var o_,s_,p_=Wy.command("network").description("Network inspection");Uy(p_.command("list").description("Capture snapshot of network activity").option("--duration <ms>","Capture duration in milliseconds","2000")).action((o_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){var a=new Map,n=parseInt(e.duration,10);t.on("Network.requestWillBeSent",e=>{a.set(e.requestId,{method:e.request.method,url:e.request.url,requestId:e.requestId,timestamp:e.timestamp})}),t.on("Network.responseReceived",e=>{var t=a.get(e.requestId);t&&(t.status=e.response.status,t.mimeType=e.response.mimeType)}),t.on("Network.loadingFailed",e=>{var t=a.get(e.requestId);t&&(t.error=e.errorText)}),yield t.send("Network.enable"),yield new Promise(e=>setTimeout(e,n)),yield t.send("Network.disable");var r=[...a.values()];if(e.json)console.log(JSON.stringify(r,null,2));else if(console.log(V.Ay.bold(`Network Activity (captured ${(n/1e3).toFixed(1)}s, ${r.length} requests)`)),0!==r.length)for(var i of r){var o=i.error?V.Ay.red("ERR"):i.status?i.status<300?V.Ay.green(i.status):i.status<400?V.Ay.yellow(i.status):V.Ay.red(i.status):V.Ay.gray("..."),s=i.url.length>60?i.url.substring(0,57)+"...":i.url;console.log(` ${o} ${V.Ay.bold(i.method.padEnd(6))} ${s} ${V.Ay.gray(`(${i.requestId})`)}`)}else console.log(V.Ay.gray(" No network activity captured"))}),function(e){return t.apply(this,arguments)}))}),function(e){return o_.apply(this,arguments)})),Uy(p_.command("get <requestId>").description("Get response body for a network request")).action((s_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("Network.enable");var n=yield a.send("Network.getResponseBody",{requestId:e}),r=n.body,i=n.base64Encoded;t.json?console.log(JSON.stringify({body:r,base64Encoded:i},null,2)):i?console.log(V.Ay.gray(`[base64 encoded, ${r.length} chars]`)):console.log(r)}),function(e){return a.apply(this,arguments)}))}),function(e,t){return s_.apply(this,arguments)}));var l_,u_,c_=Wy.command("storage").description("Storage inspection"),d_=c_.command("system").description("System key-value storage");Uy(d_.command("persist").description("Show persistent system storage entries")).action((l_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("DOMStorage.enable");var a=(yield t.send("DOMStorage.getDOMStorageItems",{storageId:{securityOrigin:"bricks://app",isLocalStorage:!0}})).entries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Persistent Storage (${a.length} items)`)),console.log("─".repeat(60)),a)){var r=ye(n,2),i=r[0],o=r[1],s=o.length>80?o.substring(0,80)+"...":o;console.log(` ${V.Ay.cyan(i)}: ${s}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return l_.apply(this,arguments)})),Uy(d_.command("memory").description("Show in-memory system storage entries")).action((u_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("DOMStorage.enable");var a=(yield t.send("DOMStorage.getDOMStorageItems",{storageId:{securityOrigin:"bricks://app",isLocalStorage:!1}})).entries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Memory Storage (${a.length} items)`)),console.log("─".repeat(60)),a)){var r=ye(n,2),i=r[0],o=r[1],s=o.length>80?o.substring(0,80)+"...":o;console.log(` ${V.Ay.cyan(i)}: ${s}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return u_.apply(this,arguments)}));var m_,f_,h_,y_=c_.command("data-bank").description("Property Bank data stores");Uy(y_.command("list").description("List Property Banks")).action((m_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("IndexedDB.enable");var a=(yield t.send("IndexedDB.requestDatabaseNames",{securityOrigin:"bricks://app"})).databaseNames.filter(e=>e.startsWith("DATA-"));if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Property Banks (${a.length})`)),a))console.log(` ${V.Ay.cyan(n)}`)}),function(e){return t.apply(this,arguments)}))}),function(e){return m_.apply(this,arguments)})),Uy(y_.command("get <name> <store>").description("Query Property Bank data").option("-l, --limit <count>","Max items to fetch","25").option("-s, --skip <count>","Items to skip","0")).action((f_=I(function*(e,t,a){var n;yield Hy(a,(n=I(function*(n){yield n.send("IndexedDB.enable");var r=(yield n.send("IndexedDB.requestData",{securityOrigin:"bricks://app",databaseName:e,objectStoreName:t,indexName:"",skipCount:parseInt(a.skip,10),pageSize:parseInt(a.limit,10)})).objectStoreDataEntries;if(a.json)console.log(JSON.stringify(r,null,2));else for(var i of(console.log(V.Ay.bold(`${e} / ${t} (${r.length} entries)`)),console.log("─".repeat(60)),r)){var o=JSON.stringify(i.key?.value??i.key),s=JSON.stringify(i.value?.value??i.value),p=s.length>100?s.substring(0,100)+"...":s;console.log(` ${V.Ay.cyan(o)}: ${p}`)}}),function(e){return n.apply(this,arguments)}))}),function(e,t,a){return f_.apply(this,arguments)})),Uy(c_.command("generator-cache").description("Show generator cache entries")).action((h_=I(function*(e){var t;yield Hy(e,(t=I(function*(t){yield t.send("IndexedDB.enable");var a=(yield t.send("IndexedDB.requestData",{securityOrigin:"bricks://app",databaseName:"GENERATOR_CACHE",objectStoreName:"entries",indexName:"",skipCount:0,pageSize:100})).objectStoreDataEntries;if(e.json)console.log(JSON.stringify(a,null,2));else for(var n of(console.log(V.Ay.bold(`Generator Cache (${a.length} entries)`)),console.log("─".repeat(60)),a)){var r=JSON.stringify(n.key?.value??n.key),i=JSON.stringify(n.value?.value??n.value),o=i.length>100?i.substring(0,100)+"...":i;console.log(` ${V.Ay.cyan(r)}: ${o}`)}}),function(e){return t.apply(this,arguments)}))}),function(e){return h_.apply(this,arguments)}));var __,E_,T_=Wy.command("runtime").description("Runtime and evaluation");Uy(T_.command("eval <expression>").description("Evaluate JavaScript expression").option("--await","Await promise result")).action((__=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){yield a.send("Runtime.enable");var n=yield a.send("Runtime.evaluate",{expression:e,objectGroup:"console",returnByValue:!0,awaitPromise:!!t.await,generatePreview:!0});if(t.json)console.log(JSON.stringify(n,null,2));else{n.exceptionDetails&&(console.error(V.Ay.red(`Error: ${n.exceptionDetails.text}`)),n.exceptionDetails.exception?.description&&console.error(V.Ay.red(n.exceptionDetails.exception.description)),process.exit(1));var r=n.result;if("undefined"===r.type)console.log(V.Ay.gray("undefined"));else if(void 0!==r.value){var i="object"==typeof r.value?JSON.stringify(r.value,null,2):String(r.value);console.log(i)}else r.description?console.log(r.description):console.log(V.Ay.gray(`[${r.type}${r.subtype?`:${r.subtype}`:""}]`))}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return __.apply(this,arguments)})),Uy(T_.command("properties <objectId>").description("Get properties of a remote object")).action((E_=I(function*(e,t){var a;yield Hy(t,(a=I(function*(a){var n=(yield a.send("Runtime.getProperties",{objectId:e,ownProperties:!0})).result;if(t.json)console.log(JSON.stringify(n,null,2));else for(var r of(console.log(V.Ay.bold(`Properties of ${e}`)),n))if(r.enumerable){var i=r.value,o=i?.description||i?.value?.toString()||V.Ay.gray(`[${i?.type}]`);console.log(` ${V.Ay.cyan(r.name)}: ${o}`)}}),function(e){return a.apply(this,arguments)}))}),function(e,t){return E_.apply(this,arguments)}));var g_=E(69278),R_=E(70857),v_=process.env.BRICKS_PROJECT_DESKTOP_DATA_DIR||ve.join(R_.homedir(),".bricks-project-desktop"),b_=ve.join(v_,"acp.sock"),O_=new G("desktop-acp-bridge").description("ACP bridge — connects acpx to the running CTOR desktop app").action(()=>{var e=g_.connect(b_);e.on("connect",()=>{process.stdin.pipe(e),e.pipe(process.stdout)}),e.on("error",e=>{"ENOENT"===e.code||"ECONNREFUSED"===e.code?process.stderr.write(`[acp] Cannot connect to CTOR.\n Make sure the desktop app is running and ACP is enabled in Settings.\n Socket: ${b_}\n`):process.stderr.write(`[acp] Connection error: ${e.message}\n`),process.exit(1)}),e.on("close",()=>{process.exit(0)})}),N_=function(){var e=I(function*(){var e=process.argv.findIndex(e=>"--auth-profile"===e||"-ap"===e);if(-1!==e&&process.argv[e+1]&&((0,$.setProfileOverride)(process.argv[e+1]),process.argv.splice(e,2)),D.name("bricks").description("BRICKS CLI - Command-line interface for BRICKS Workspace API").version("2.24.0-beta.40").enablePositionalOptions(),D.addCommand(Y),D.addCommand(ie),D.addCommand(me),D.addCommand(he),D.addCommand(ge),D.addCommand(we),D.addCommand(xe),D.addCommand(Fy),D.addCommand(Wy),D.addCommand(O_),D.command("interactive").alias("i").description("Start interactive mode with Ink UI").action(I(function*(){try{(0,(yield E.e(612).then(E.bind(E,59612))).runInteractiveMode)()}catch(e){console.error(V.Ay.red(`Failed to start interactive mode: ${e.message}`)),process.exit(1)}})),D.command("workspace").alias("ws").description("Show current workspace information").option("-j, --json","Output as JSON").action(function(){var e=I(function*(e){var t=yield Promise.resolve().then(E.bind(E,74752)),a=t.getToken,n=t.getBaseUrl,r=t.getCurrentProfile,i=(yield Promise.resolve().then(E.bind(E,50700))).createClient,o=(yield Promise.resolve().then(E.bind(E,29790))).default,s=a(r());s||(console.error(V.Ay.red("Not logged in. Use `bricks auth login` first.")),process.exit(1));var p=o("Fetching workspace info...").start();try{var l=i(n(),s),u=yield l.workspace();if(p.stop(),e.json)return void console.log(JSON.stringify(u,null,2));console.log(V.Ay.bold("\nWorkspace Information")),console.log("─".repeat(60)),console.log(`Name: ${V.Ay.green(u.name)}`),console.log(`ID: ${V.Ay.gray(u._id)}`),console.log(`Description: ${u.description||V.Ay.gray("N/A")}`),console.log(`\n${V.Ay.bold("Data")}`),console.log(`Remote Update: ${u.bank?.enable_remote_update?V.Ay.green("Enabled"):V.Ay.gray("Disabled")}`),console.log(`Spacename: ${u.bank?.spacename||V.Ay.gray("N/A")}`),console.log("─".repeat(60))}catch(e){p.fail(`Failed to get workspace: ${e.message}`),process.exit(1)}});return function(t){return e.apply(this,arguments)}}()),D.on("--help",()=>{console.log(""),console.log(V.Ay.bold("Examples:")),console.log(""),console.log(V.Ay.gray(" # Login with a one-time passcode (recommended)")),console.log(" $ bricks auth login <passcode>"),console.log(""),console.log(V.Ay.gray(" # List all devices")),console.log(" $ bricks device list"),console.log(""),console.log(V.Ay.gray(" # Monitor devices in real-time")),console.log(" $ bricks device monitor"),console.log(""),console.log(V.Ay.gray(" # Control a device")),console.log(" $ bricks device refresh <device-id>"),console.log(" $ bricks device control <device-id> clear-cache"),console.log(""),console.log(V.Ay.gray(" # Bind a new device")),console.log(' $ bricks device bind <passcode> -n "My Device"'),console.log(""),console.log(V.Ay.gray(" # List applications")),console.log(" $ bricks app list"),console.log(""),console.log(V.Ay.gray(" # Start interactive mode")),console.log(" $ bricks interactive"),console.log(""),console.log(V.Ay.gray(" # Change API endpoint")),console.log(" $ bricks config endpoint beta"),console.log(""),console.log(V.Ay.gray("Get workspace token from BRICKS Controller:")),console.log(V.Ay.cyan(" https://control.bricks.tools")),console.log(V.Ay.gray(" Go to Workspace Settings > API Token"))}),0===process.argv.slice(2).length)try{return void(0,(yield E.e(612).then(E.bind(E,59612))).runInteractiveMode)()}catch(e){console.error(V.Ay.red(`Failed to start interactive mode: ${e.message}`)),process.exit(1)}yield D.parseAsync(process.argv)});return function(){return e.apply(this,arguments)}}();const A_=N_;export{A_ as default,N_ as run};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-cli",
|
|
3
|
-
"version": "2.24.0-beta.
|
|
3
|
+
"version": "2.24.0-beta.40",
|
|
4
4
|
"description": "BRICKS CLI - Command-line interface for BRICKS Workspace API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bricks",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=18.0.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c07ad6f9f378a3040385f99bdf0033c834c7d96c"
|
|
63
63
|
}
|