@fugood/bricks-cli 2.26.0-beta.39 → 2.26.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/7294.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as e from"ink";import*as r from"react";import*as t from"react/jsx-runtime";export const __rspack_esm_id=7294;export const __rspack_esm_ids=[7294];export const __webpack_modules__={8498(r){r.exports=e},51649(e){e.exports=r},71178(e){e.exports=t},94685(e,r,t){t.r(r),t.d(r,{AppList:()=>C,CONTROL_ACTIONS:()=>h,MainMenu:()=>S,Header:()=>v,ModuleDetail:()=>O,ONLINE_THRESHOLD_MS:()=>m.RZ,ShortEditEditor:()=>W,MediaFileList:()=>$,App:()=>eo,DeviceDetail:()=>A,VIEWS:()=>x,runInteractiveMode:()=>es,DeviceList:()=>I,MediaBoxList:()=>N,Loading:()=>T,DeviceControl:()=>B,ProjectInitView:()=>el,GroupDetail:()=>R,ModuleList:()=>L,MediaBoxDetail:()=>U,GroupList:()=>P,Footer:()=>j,DeviceStatus:()=>b,AppDetail:()=>k,DeviceScreenshot:()=>w,MediaFileDetail:()=>G});var n,i=t(99436),l=t(51649),o=t(8498),a=t(68832),s=t(85382),c=t(47988),u=t(31802),d=t(60450),x={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",ACTIVITY_LOG:"activity_log"},h=[{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"}],f=t(47882),m=t(9683),p=t(71178),y=(e,r=!0)=>{var t=Math.floor(60),n=a((0,l.useState)(t),2),i=n[0],o=n[1],s=a((0,l.useState)(null),2),c=s[0],u=s[1],d=(0,l.useRef)(e);(0,l.useEffect)(()=>{d.current=e},[e]);var x=(0,l.useCallback)(()=>{o(t),u(Date.now())},[t]);return(0,l.useEffect)(()=>{if(r){var e=setInterval(()=>{o(e=>e<=1?(d.current?.(),u(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[r,t]),(0,l.useEffect)(()=>{r&&(o(t),u(Date.now()))},[r,t]),{countdown:i,lastRefreshTime:c,resetCountdown:x}},g=({countdown:e,lastRefreshTime:r})=>(0,p.jsx)(o.Box,{children:(0,p.jsxs)(o.Text,{color:"gray",children:["Next refresh in ",(0,p.jsxs)(o.Text,{color:"cyan",children:[e,"s"]}),r&&(0,p.jsxs)(o.Text,{color:"gray",children:[" (last: ",r?new Date(r).toLocaleTimeString():null,")"]})]})}),v=({workspace:e,view:r})=>(0,p.jsxs)(o.Box,{flexDirection:"column",marginBottom:1,children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,p.jsx)(o.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:"Workspace: "}),(0,p.jsx)(o.Text,{color:"green",children:e?.name||"Not connected"}),(0,p.jsx)(o.Text,{color:"gray",children:" | View: "}),(0,p.jsx)(o.Text,{color:"yellow",children:r})]}),(0,p.jsx)(o.Text,{color:"gray",children:"─".repeat(60)})]}),j=()=>(0,p.jsxs)(o.Box,{marginTop:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"gray",children:"─".repeat(60)}),(0,p.jsxs)(o.Text,{color:"gray",children:["Press ",(0,p.jsx)(o.Text,{color:"cyan",children:"q"})," to quit, ",(0,p.jsx)(o.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),T=({text:e})=>(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"green",children:(0,p.jsx)(f.A,{type:"dots"})}),(0,p.jsxs)(o.Text,{children:[" ",e||"Loading..."]})]}),b=({lastAliveTime:e})=>{var r=(0,m.Ed)(e);return(0,p.jsx)(o.Text,{color:r.tone,children:(0,m.mz)(r)})},_=t(48724),S=({onSelect:e,mediaEnabled:r,activityLogEnabled:t})=>{var n=[{label:"Devices",value:x.DEVICES},{label:"Applications",value:x.APPS},{label:"Modules",value:x.MODULES},{label:"Device Groups",value:x.GROUPS},...r?[{label:"Media Flow",value:x.MEDIA_BOXES}]:[],...t?[{label:"Activity Log",value:x.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,p.jsx)(_.Ay,{items:n,onSelect:e})]})},E="1"===process.env.BRICKS_CLI_DISTRIBUTION,D=e=>{var r=a((0,l.useState)(null),2),n=r[0],i=r[1];return((0,l.useEffect)(()=>{if(!E){var e=!0;return t.e(8166).then(t.bind(t,29557)).then(r=>{e&&i(()=>r.default)}).catch(()=>{e&&i(!1)}),()=>{e=!1}}},[]),E||!1===n)?(0,p.jsx)(o.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):n?(0,p.jsx)(n,{...e}):(0,p.jsx)(T,{text:"Preparing image preview..."})},I=({devices:e,loading:r,onSelect:t,countdown:n,lastRefreshTime:i})=>{if(r)return(0,p.jsx)(T,{text:"Loading devices..."});if(!e?.length)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"yellow",children:"No devices found"}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]});var l=[...e.map(e=>{var r,t,n,i,l=(r=e.entry_detail?.watch_dog_timer?.last_alive_time,n=(t=(0,m.Ed)(r)).glyph,i=t.label,`${n} ${i}`);return{label:`${l} - ${e.name||e.device_name}`,value:e._id,device:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{marginBottom:1,children:[(0,p.jsxs)(o.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]}),(0,p.jsx)(_.Ay,{items:l,onSelect:t})]})},A=({device:e,loading:r,error:t,onSelect:n,mediaEnabled:i,countdown:l,lastRefreshTime:a})=>{if(r)return(0,p.jsx)(T,{text:"Loading device..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...i?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,u=c?.screen,d=c?.update,x=c?.local_sync;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:l,lastRefreshTime:a})]}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:"Status: "}),(0,p.jsx)(b,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Application"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),u&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Screen"}),u.resolution&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Resolution: ",u.resolution.width,"x",u.resolution.height,u.resolution.scale&&` @${u.resolution.scale}x`]}),u.orientation&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Orientation: ",u.orientation]}),u.touch&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Touch:"," ",u.touch.available?`Yes (${u.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),x&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,p.jsxs)(o.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`]})]}),d&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Update"}),(0,p.jsxs)(o.Text,{color:d.need_update?"yellow":"gray",children:[" ","Status: ",d.need_update?"⚠ Update available":"✓ Up to date"]}),d.current_version&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Version: ",d.current_version]})]})]}),(0,p.jsx)(_.Ay,{items:s,onSelect:n})]})},B=({device:e,onSelect:r,controlling:t,controlResult:n})=>(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&(0,p.jsx)(T,{text:"Sending command..."}),n&&(0,p.jsx)(o.Text,{color:n.success?"green":"red",children:n.message}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:h,onSelect:r})})]}),w=({device:e,screenshot:r,loading:t,error:n,onSelect:i})=>{var l=r?.file?.meta,a=l?.originalWidth!=null&&l?.originalHeight!=null,s=l?.originalFileSize!=null;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&(0,p.jsx)(T,{text:"Loading screenshot..."}),n&&(0,p.jsx)(o.Box,{marginY:1,children:(0,p.jsx)(o.Text,{color:"red",children:String(n)})}),!t&&!n&&r&&(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Box,{height:30,children:(0,p.jsx)(D,{src:r.path,width:80,alt:"Device screenshot"})}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,p.jsxs)(o.Box,{marginY:1,children:[(0,p.jsx)(o.Text,{color:"green",children:"Screenshot saved to: "}),(0,p.jsx)(o.Text,{color:"cyan",children:String(r.path||"")})]}),a&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",String(l.originalWidth),"x",String(l.originalHeight)]}),s&&(0,p.jsxs)(o.Text,{color:"gray",children:["File: ",(Number(l.originalFileSize)/1024).toFixed(1)," KB"]}),r.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:["Updated: ",new Date(r.updatedAt).toLocaleString()]}),r.captureRequested&&!r.fresh&&(0,p.jsx)(o.Text,{color:"yellow",children:"No new capture arrived in time: this is the previous one, and it may not show the current screen."})]})]}),!t&&!n&&!r&&(0,p.jsx)(o.Box,{marginY:1,children:(0,p.jsx)(o.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})})]})},C=({apps:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{text:"Loading applications..."});if(!e?.length)return(0,p.jsx)(o.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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},k=({app:e,loading:r,error:t,onSelect:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading application..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Application not found"});var i=[{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"}],l=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Version"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,p.jsxs)(o.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Devices"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Total: ",l,l>0&&` (${a} online)`]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Features"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"\uD83D\uDD12 Locked":"\uD83D\uDD13 Unlocked"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:i,onSelect:n})]})},L=({modules:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No modules found"}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},O=({module:e,loading:r,error:t,onSelect:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading module..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Module not found"});var i=[{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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Version"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,p.jsxs)(o.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Usage"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Settings"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:i,onSelect:n})]})},P=({groups:e,loading:r,onSelect:t,countdown:n,lastRefreshTime:i})=>{if(r)return(0,p.jsx)(T,{text:"Loading device groups..."});var l=[...(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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{marginBottom:1,children:[(0,p.jsxs)(o.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]}),!e?.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No device groups found"}),(0,p.jsx)(_.Ay,{items:l,onSelect:t})]})},M=({loading:e,groupDevices:r})=>e?(0,p.jsx)(T,{text:"Loading devices..."}):r?.length?(0,p.jsxs)(p.Fragment,{children:[r.slice(0,10).map(e=>(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:" "}),(0,p.jsx)(b,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),r.length>10&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","... and ",r.length-10," more"]})]}):(0,p.jsx)(o.Text,{color:"gray",children:" No devices in this group"}),R=({group:e,groupDevices:r,loading:t,error:n,onSelect:i,countdown:l,lastRefreshTime:a})=>t&&!e?(0,p.jsx)(T,{text:"Loading device group..."}):n?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",n]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]}):e?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:l,lastRefreshTime:a})]}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsxs)(o.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,p.jsx)(M,{loading:t,groupDevices:r})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]}):(0,p.jsx)(o.Text,{color:"red",children:"Device group not found"}),N=({boxes:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{text:"Loading media boxes..."});if(!e?.length)return(0,p.jsx)(o.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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},U=({box:e,loading:r,error:t,onSelect:n})=>r&&!e?(0,p.jsx)(T,{text:"Loading media box..."}):t?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]}):e?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsxs)(o.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.name||"Passcode"," (",(e.permissions||[]).join(", "),e.enableExpired?`, expires ${e.expiredAt} UTC`:"",")"]},e.id)),e.passcodes.length>5&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]}):(0,p.jsx)(o.Text,{color:"red",children:"Media box not found"}),$=({files:e,loading:r,onSelect:t,box:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading media files..."});if(!e?.length)return(0,p.jsx)(o.Text,{color:"yellow",children:"No media files found"});var i=[...e.map(e=>{var r;return{label:`${"Image"===(r=e.fileType)?"\uD83D\uDDBC":"Video"===r?"\uD83C\uDF9E":"Audio"===r?"\uD83C\uDFB5":"\uD83D\uDCC4"} ${e.name||"Unnamed"}`,value:e.id,file:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",n?.name?` - ${n.name}`:""]}),(0,p.jsx)(_.Ay,{items:i,onSelect:t})]})},G=({file:e,loading:r,error:t,onSelect:n})=>{if(r&&!e)return(0,p.jsx)(T,{text:"Loading media file..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Media file not found"});var i=e.meta,l=(0,d.buildScreenshotUrl)(e),a=(0,d.buildScreenshotUrl)(e,{preferThumbnail:!0}),s=!!(a&&a!==l);return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e.id]}),(0,p.jsxs)(o.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,p.jsxs)(o.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),i?.originalWidth!=null&&i?.originalHeight!=null&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",i.originalWidth,"x",i.originalHeight]}),i?.originalFileSize!=null&&(0,p.jsxs)(o.Text,{color:"gray",children:["File: ",(Number(i.originalFileSize)/1024).toFixed(1)," KB"]}),l&&(0,p.jsxs)(o.Text,{color:"gray",children:["Original URL: ",l]}),s&&(0,p.jsxs)(o.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},F=t(88161),V=(e,r)=>{if(!e)return"";var t="string"==typeof e?e:JSON.stringify(e);return t.length>r?t.slice(0,r-1)+"…":t},H=({onBack:e})=>{var r=a((0,l.useState)([]),2),t=r[0],n=r[1],s=a((0,l.useState)(!0),2),d=s[0],x=s[1],h=a((0,l.useState)(null),2),f=h[0],m=h[1];return(0,l.useEffect)(()=>{var e,r=(0,c.getCurrentProfile)(),t=(0,u.getConnectionContext)(r),l=t.auth,o=t.activityLogBaseUrl;if(!l){m("Not logged in. Run `bricks auth login` first."),x(!1);return}if(!o){m("Activity log URL not configured."),x(!1);return}var a=(0,F.createActivityLogClient)(o,l),s=new Date(Date.now()-36e5).toISOString(),d=new Date().toISOString(),h=new AbortController;return(e=i(function*(){try{var e=yield a.collectEvents({start_time:s,end_time:d},{limit:50,signal:h.signal});n(e)}catch(e){"AbortError"!==e.name&&m(e.message)}x(!1)}),function(){return e.apply(this,arguments)})(),()=>h.abort()},[]),(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),d&&(0,p.jsx)(T,{text:"Fetching events..."}),f&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",f]}),!d&&!f&&0===t.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No events found in the last hour"}),!d&&t.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginBottom:1,children:[(0,p.jsxs)(o.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),t.map((e,r)=>(0,p.jsxs)(o.Text,{children:[new Date(e.timestamp).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z").padEnd(22)," ",V(e.event_type||"",12).padEnd(12)," ",V(e.device_id||"",14).padEnd(14)," ",V(e.event_name||"",24).padEnd(24)," ",V(e.sender||"",16)]},r)),t.length>=50&&(0,p.jsxs)(o.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:r=>"back"===r.value&&e()})]})},z=t(29253),q=t(44618),Y=["B","C","G","D"],W=({instanceType:e,instance:r,client:t,onDone:n,onCancel:s})=>{var c,u=(0,o.useApp)().exit,d=a((0,l.useState)("select_ref"),2),x=d[0],h=d[1],f=a((0,l.useState)(""),2),m=f[0],y=f[1],g=a((0,l.useState)("search"),2),v=g[0],j=g[1],b=a((0,l.useState)(null),2),S=b[0],E=b[1],D=a((0,l.useState)(null),2),I=D[0],A=D[1],B=a((0,l.useState)(""),2),w=B[0],C=B[1],k=a((0,l.useState)(""),2),L=k[0],O=k[1],P=a((0,l.useState)(null),2),M=P[0],R=P[1],N=r?.short_edit?.ref_map||{},U=Object.entries(N).filter(([,e])=>e&&!e.hide),$=(0,q.V)(N,{keyword:m,types:Y}),G=$.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:r})=>({label:`${r.title||e} (${e})`,value:e,ref:r}))]),F=[...m?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],V=G.length>0?[...G,...F]:F,H=V.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,o.useInput)((e,r)=>{r.tab&&"select_ref"===x?j(e=>"search"===e?"list":"search"):(r.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)&&u())},{isActive:!0});var W=(c=i(function*(){if(t&&r?._id&&S){h("submitting"),R(null);try{var i={shortId:S,path:w.trim(),content:(e=>{var r=e.trim();if(""===r)return null;try{return JSON.parse(r)}catch{return r}})(L),forwardDataLink:!0};I?.inner_ref?.pid&&(i.innerRefParentShortId=I.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:r._id,list:[i]}):yield t.shortEditModule({id:r._id,list:[i]}),yield n(),h("done")}catch(e){R(e.message),h("confirm")}}}),function(){return c.apply(this,arguments)});return r?.short_edit?.enabled?0===U.length?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"yellow",children:"No Short Edit references found."}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,children:"Short Edit References"}),(0,p.jsx)(o.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,p.jsxs)(o.Box,{marginTop:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"gray",children:"Search (title or shortId)"}),(0,p.jsx)(z.A,{value:m,placeholder:"type to filter, Enter to focus list",onChange:e=>y(e),onSubmit:()=>j("list"),focus:"search"===v}),(0,p.jsx)(o.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,p.jsxs)(o.Box,{marginTop:1,children:[0===$.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No references match your search."}),(0,p.jsx)(_.Ay,{items:V,isFocused:"list"===v,initialIndex:H>-1?H:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:r,isHeader:t})=>t?(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(o.Text,{bold:!0,color:"white",children:e})}):(0,p.jsxs)(o.Text,{color:r?"blue":void 0,children:[r?"❯":" "," ",e]}),onSelect:e=>{if("__back__"===e.value)return void s();if("__clear_search__"===e.value){y(""),j("search");return}e.isHeader||(E(e.value),A(e.ref),h("input_path"))}})]})]}):"input_path"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Reference:"," ",(0,p.jsxs)(o.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,p.jsx)(o.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(z.A,{value:w,placeholder:"path",onChange:e=>{C(e),M&&R(null)},onSubmit:e=>{var r=e.trim();r?(C(r),h("input_content")):R("Path is required")},focus:!0})]}):"input_content"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:w})]}),(0,p.jsx)(o.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(z.A,{value:L,placeholder:"content",onChange:e=>{O(e),M&&R(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===x?(0,p.jsx)(T,{text:"Applying short edit..."}):"done"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"green",children:"Short edit applied successfully."}),(0,p.jsx)(_.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),E(null),A(null),C(""),O(""),R(null)):s()}})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,p.jsxs)(o.Text,{children:["Reference:"," ",(0,p.jsxs)(o.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:w})]}),(0,p.jsxs)(o.Text,{children:["Content: ",(0,p.jsx)(o.Text,{color:"cyan",children:L||"<empty>"})]}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(_.Ay,{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&&W(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},J=t(16928),K=t(79896),X=t(10750),Q=t(77768),Z="options",ee="output_dir",er="confirm",et="generating",en="post_install",ei="done",el=({type:e,instance:r,client:t,onDone:n,onCancel:s})=>{var c,u=(0,o.useApp)().exit,d=a((0,l.useState)(Z),2),x=d[0],h=d[1],m=a((0,l.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),2),y=m[0],g=m[1],v=a((0,l.useState)(process.cwd()),2),j=v[0],T=v[1],b=a((0,l.useState)(""),2),S=b[0],E=b[1],D=a((0,l.useState)(null),2),I=D[0],A=D[1],B=a((0,l.useState)(null),2),w=B[0],C=B[1],k=X(r?.name||"bricks-ctor"),L=J.resolve(j,k),O=(0,l.useCallback)(e=>{"back"===e.value?s():"continue"===e.value?h(ee):g(r=>({...r,[e.value]:!r[e.value]}))},[s]),P=(0,l.useCallback)(()=>{K.existsSync(L)?A(`Directory already exists: ${L}`):(A(null),h(er))},[L]),M=(0,l.useCallback)((c=i(function*(n){if("back"===n.value)return void h(ee);if("cancel"===n.value)return void s();if("confirm"===n.value){h(et);try{E("Fetching project from BRICKS...");var i="application"===e,l=i?t.queries.applicationProject:t.queries.moduleProject,o=(yield t.query(l,{id:r._id,buildApplicationOnly:!1,setupGitHubActions:y.setupGitHubActions,setupAgents:y.setupAgents,setupClaudeCode:y.setupClaudeCode,setupGeminiCLI:y.setupGeminiCLI}))[i?"applicationProject":"moduleProject"];if(!o?.files)throw Error("Failed to fetch project files");E("Creating project directory..."),K.mkdirSync(L,{recursive:!0}),E(`Writing ${o.files.length} files...`);var a=yield(0,Q.KN)(o.files,L);(0,Q.oz)(a),h(en);var c={path:L,files:o.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(c,(yield(0,Q.o0)(L,{install:y.runBunInstall,git:y.initGit,onStatus:E}))),C(c),h(ei)}catch(e){A(e.message),h(Z)}}}),function(e){return c.apply(this,arguments)}),[t,r,e,y,L,s]),R=(0,l.useCallback)(e=>{"exit"===e.value?u():n()},[u,n]);if(x===Z){var N=[{label:`${y.setupGitHubActions?"[x]":"[ ]"} GitHub Actions workflow`,value:"setupGitHubActions"},{label:`${y.setupAgents?"[x]":"[ ]"} AGENTS.md`,value:"setupAgents"},{label:`${y.setupClaudeCode?"[x]":"[ ]"} CLAUDE.md`,value:"setupClaudeCode"},{label:`${y.setupGeminiCLI?"[x]":"[ ]"} GEMINI.md`,value:"setupGeminiCLI"},{label:`${y.runBunInstall?"[x]":"[ ]"} Run bun install after generation`,value:"runBunInstall"},{label:`${y.initGit?"[x]":"[ ]"} Initialize git repository`,value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",r?.name||"Untitled"]}),(0,p.jsx)(o.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),I&&(0,p.jsxs)(o.Text,{color:"red",marginBottom:1,children:["Error: ",I]}),(0,p.jsx)(_.Ay,{items:N,onSelect:O})]})}return x===ee?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,p.jsx)(o.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),I&&(0,p.jsx)(o.Text,{color:"red",marginBottom:1,children:I}),(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{children:"Directory: "}),(0,p.jsx)(z.A,{value:j,onChange:T,onSubmit:P})]}),(0,p.jsxs)(o.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",L]})]}):x===er?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Name: ",(0,p.jsx)(o.Text,{color:"green",children:r?.name||"Untitled"})]}),(0,p.jsxs)(o.Text,{children:["Type: ",(0,p.jsx)(o.Text,{color:"yellow",children:e})]}),(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:L})]}),(0,p.jsx)(o.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - GitHub Actions: ",y.setupGitHubActions?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - AGENTS.md: ",y.setupAgents?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - CLAUDE.md: ",y.setupClaudeCode?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - GEMINI.md: ",y.setupGeminiCLI?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - Run bun install: ",y.runBunInstall?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - Initialize git: ",y.initGit?"Yes":"No"]})]}),(0,p.jsx)(_.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:M})]}):x===et||x===en?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,p.jsxs)(o.Box,{marginY:1,children:[(0,p.jsx)(o.Text,{color:"green",children:(0,p.jsx)(f.A,{type:"dots"})}),(0,p.jsxs)(o.Text,{children:[" ",S]})]})]}):x===ei&&w?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:w.path})]}),(0,p.jsxs)(o.Text,{children:["Files: ",(0,p.jsx)(o.Text,{color:"green",children:w.files})]}),(0,p.jsxs)(o.Text,{children:["Dependencies:"," ",(0,p.jsx)(o.Text,{color:w.bunInstalled?"green":"yellow",children:w.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,p.jsxs)(o.Text,{children:["Git:"," ",(0,p.jsx)(o.Text,{color:w.gitInitialized?"green":"yellow",children:w.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,p.jsx)(o.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" cd ",k]}),!w.bunInstalled&&(0,p.jsx)(o.Text,{color:"gray",children:" bun install"}),(0,p.jsx)(o.Text,{color:"gray",children:" bun invoke-simulator"}),(0,p.jsxs)(o.Text,{color:"gray",marginTop:1,children:["For more information, see ",k,"/README.md"]}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:R})})]}):null};let eo=()=>{var e,r,t,n,h,f,m,g,b=(0,o.useApp)().exit,_=a((0,l.useState)(x.MAIN),2),E=_[0],D=_[1],M=a((0,l.useState)(null),2),F=M[0],V=M[1],z=a((0,l.useState)(null),2),q=z[0],Y=z[1],J=a((0,l.useState)(!0),2),K=J[0],X=J[1],Q=a((0,l.useState)(null),2),Z=Q[0],ee=Q[1],er=a((0,l.useState)(!1),2),et=er[0],en=er[1],ei=a((0,l.useState)([]),2),eo=ei[0],ea=ei[1],es=a((0,l.useState)(null),2),ec=es[0],eu=es[1],ed=a((0,l.useState)([]),2),ex=ed[0],eh=ed[1],ef=a((0,l.useState)(null),2),em=ef[0],ep=ef[1],ey=a((0,l.useState)([]),2),eg=ey[0],ev=ey[1],ej=a((0,l.useState)(null),2),eT=ej[0],eb=ej[1],e_=a((0,l.useState)([]),2),eS=e_[0],eE=e_[1],eD=a((0,l.useState)(null),2),eI=eD[0],eA=eD[1],eB=a((0,l.useState)([]),2),ew=eB[0],eC=eB[1],ek=a((0,l.useState)(!1),2),eL=ek[0],eO=ek[1],eP=a((0,l.useState)(null),2),eM=eP[0],eR=eP[1],eN=a((0,l.useState)(null),2),eU=eN[0],e$=eN[1],eG=a((0,l.useState)(null),2),eF=eG[0],eV=eG[1],eH=a((0,l.useState)(null),2),ez=eH[0],eq=eH[1],eY=a((0,l.useState)([]),2),eW=eY[0],eJ=eY[1],eK=a((0,l.useState)(null),2),eX=eK[0],eQ=eK[1],eZ=a((0,l.useState)([]),2),e0=eZ[0],e1=eZ[1],e2=a((0,l.useState)(null),2),e4=e2[0],e6=e2[1],e8=E===x.DEVICES,e9=E===x.DEVICE_DETAIL,e5=E===x.GROUPS,e7=E===x.GROUP_DETAIL;(0,l.useEffect)(()=>{var e=(0,c.getCurrentProfile)(),r=(0,u.getConnectionContext)(e),t=r.auth,n=r.baseUrl;if(en(!!r.activityLogBaseUrl),!t){ee("Not logged in. Run `bricks auth login` first."),X(!1);return}var i=(0,s.createClient)(n,t);V(i),i.workspace().then(e=>{Y(e),X(!1)}).catch(e=>{ee(e.message),X(!1)})},[]),(0,o.useInput)((e,r)=>{"q"===e&&b(),r.escape&&(E===x.DEVICE_CONTROL?(D(x.DEVICE_DETAIL),eR(null)):E===x.DEVICE_SCREENSHOT?(D(x.DEVICE_DETAIL),eV(null),eq(null)):E===x.DEVICE_DETAIL?(D(x.DEVICES),eu(null)):E===x.APP_DETAIL?(D(x.APPS),ep(null)):E===x.MODULE_DETAIL?(D(x.MODULES),eb(null)):E===x.GROUP_DETAIL?(D(x.GROUPS),eA(null),eC([])):E===x.MEDIA_FILE_DETAIL?(D(x.MEDIA_FILES),e6(null)):E===x.MEDIA_FILES?(D(x.MEDIA_BOX_DETAIL),e6(null)):E===x.MEDIA_BOX_DETAIL?(D(x.MEDIA_BOXES),eQ(null),e1([])):E===x.MEDIA_BOXES?D(x.MAIN):E!==x.MAIN&&D(x.MAIN))},{isActive:E!==x.APP_SHORT_EDIT&&E!==x.MODULE_SHORT_EDIT&&E!==x.APP_PROJECT_INIT&&E!==x.MODULE_PROJECT_INIT});var e3=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.devices({});ea(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),re=(0,l.useCallback)((e=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.device({id:e});eu(r)}catch(e){e$(e.message)}X(!1)}}),function(r){return e.apply(this,arguments)}),[F]),rr=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.applications({});eh(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),rt=(0,l.useCallback)((r=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.application({id:e});ep(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return r.apply(this,arguments)}),[F]),rn=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.modules({});ev(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),ri=(0,l.useCallback)((t=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.module({id:e});eb(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return t.apply(this,arguments)}),[F]),rl=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.deviceGroups({});eE(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),ro=(0,l.useCallback)((n=i(function*(e){if(F){X(!0),e$(null);try{var r=yield Promise.all([F.deviceGroup({id:e}),F.devicesByGroup({id:e})]),t=a(r,2),n=t[0],i=t[1];eA(n),eC(i||[])}catch(e){e$(e.message)}X(!1)}}),function(e){return n.apply(this,arguments)}),[F]),ra=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.mediaBoxes();eJ(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),rs=(0,l.useCallback)((h=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.mediaBox({id:e});eQ(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return h.apply(this,arguments)}),[F]),rc=(0,l.useCallback)((f=i(function*(e){if(F){X(!0);try{var r=yield F.mediaFiles({boxId:e});e1(r||[])}catch(e){ee(e.message)}X(!1)}}),function(e){return f.apply(this,arguments)}),[F]),ru=(0,l.useCallback)((m=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.mediaFile({id:e});e6(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return m.apply(this,arguments)}),[F]),rd=(0,l.useCallback)((g=i(function*(e){if(F&&ec){eO(!0),eR(null);try{yield F.controlDevice({id:ec._id,type:e}),eR({success:!0,message:`Command sent: ${e}`})}catch(e){eR({success:!1,message:e.message})}eO(!1)}}),function(e){return g.apply(this,arguments)}),[F,ec]),rx=(0,l.useCallback)(i(function*(e=!1){if(F&&ec&&q){X(!0),eq(null),eV(null);try{var r=e?d.captureAndSaveScreenshot:d.fetchAndSaveScreenshot,t=yield r(F,q,ec._id,null,{preferThumbnail:!0});t.error?eq(t.error):eV(t)}catch(e){eq(e.message)}X(!1)}}),[F,ec,q]),rh=y((0,l.useCallback)(()=>{F&&e3()},[F,e3]),e8),rf=y((0,l.useCallback)(()=>{F&&ec&&re(ec._id)},[F,ec,re]),e9),rm=y((0,l.useCallback)(()=>{F&&rl()},[F,rl]),e5),rp=y((0,l.useCallback)(()=>{F&&eI&&ro(eI._id)},[F,eI,ro]),e7);return K&&!q?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),(0,p.jsx)(T,{text:"Connecting to workspace..."})]}):Z&&!q?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",Z]}),(0,p.jsx)(j,{})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),E===x.MAIN&&(0,p.jsx)(S,{onSelect:e=>{"exit"===e.value?b():(D(e.value),e.value===x.DEVICES?e3():e.value===x.APPS?rr():e.value===x.MODULES?rn():e.value===x.GROUPS?rl():e.value===x.MEDIA_BOXES&&ra())},mediaEnabled:(0,d.isMediaEnabled)(q),activityLogEnabled:et}),E===x.DEVICES&&(0,p.jsx)(I,{devices:eo,loading:K,onSelect:e=>{if("back"===e.value)return void D(x.MAIN);if("refresh"===e.value){e3(),rh.resetCountdown();return}eu(null),X(!0),D(x.DEVICE_DETAIL),re(e.value)},countdown:rh.countdown,lastRefreshTime:rh.lastRefreshTime}),E===x.DEVICE_DETAIL&&(0,p.jsx)(A,{device:ec,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.DEVICES),eu(null);return}if("refresh"===e.value){re(ec._id),rf.resetCountdown();return}"control"===e.value&&(D(x.DEVICE_CONTROL),eR(null)),"screenshot"===e.value&&(D(x.DEVICE_SCREENSHOT),eV(null),eq(null),rx(!1))},mediaEnabled:(0,d.isMediaEnabled)(q),countdown:rf.countdown,lastRefreshTime:rf.lastRefreshTime}),E===x.DEVICE_CONTROL&&(0,p.jsx)(B,{device:ec,onSelect:e=>{if("back"===e.value){D(x.DEVICE_DETAIL),eR(null);return}rd(e.value)},controlling:eL,controlResult:eM}),E===x.DEVICE_SCREENSHOT&&(0,p.jsx)(w,{device:ec,screenshot:eF,loading:K,error:ez,onSelect:e=>{if("back"===e.value){D(x.DEVICE_DETAIL),eV(null),eq(null);return}"refresh"===e.value?rx(!1):"take"===e.value&&rx(!0)}}),E===x.APPS&&(0,p.jsx)(C,{apps:ex,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?rr():(ep(null),X(!0),D(x.APP_DETAIL),rt(e.value))}}),E===x.APP_DETAIL&&(0,p.jsx)(k,{app:em,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.APPS),ep(null);return}"refresh"===e.value?rt(em._id):("short_edit"===e.value&&(D(x.APP_SHORT_EDIT),e$(null)),"project_init"===e.value&&(D(x.APP_PROJECT_INIT),e$(null)))}}),E===x.APP_SHORT_EDIT&&(0,p.jsx)(W,{instanceType:"application",instance:em,client:F,onDone:i(function*(){return rt(em._id)}),onCancel:()=>D(x.APP_DETAIL)}),E===x.APP_PROJECT_INIT&&(0,p.jsx)(el,{type:"application",instance:em,client:F,onDone:()=>D(x.APP_DETAIL),onCancel:()=>D(x.APP_DETAIL)}),E===x.MODULES&&(0,p.jsx)(L,{modules:eg,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?rn():(eb(null),X(!0),D(x.MODULE_DETAIL),ri(e.value))}}),E===x.MODULE_DETAIL&&(0,p.jsx)(O,{module:eT,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MODULES),eb(null);return}"refresh"===e.value?ri(eT._id):("short_edit"===e.value&&(D(x.MODULE_SHORT_EDIT),e$(null)),"project_init"===e.value&&(D(x.MODULE_PROJECT_INIT),e$(null)))}}),E===x.MODULE_SHORT_EDIT&&(0,p.jsx)(W,{instanceType:"module",instance:eT,client:F,onDone:i(function*(){return ri(eT._id)}),onCancel:()=>D(x.MODULE_DETAIL)}),E===x.MODULE_PROJECT_INIT&&(0,p.jsx)(el,{type:"module",instance:eT,client:F,onDone:()=>D(x.MODULE_DETAIL),onCancel:()=>D(x.MODULE_DETAIL)}),E===x.GROUPS&&(0,p.jsx)(P,{groups:eS,loading:K,onSelect:e=>{if("back"===e.value)return void D(x.MAIN);if("refresh"===e.value){rl(),rm.resetCountdown();return}eA(null),eC([]),X(!0),D(x.GROUP_DETAIL),ro(e.value)},countdown:rm.countdown,lastRefreshTime:rm.lastRefreshTime}),E===x.GROUP_DETAIL&&(0,p.jsx)(R,{group:eI,groupDevices:ew,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.GROUPS),eA(null),eC([]);return}"refresh"===e.value&&(ro(eI._id),rp.resetCountdown())},countdown:rp.countdown,lastRefreshTime:rp.lastRefreshTime}),E===x.ACTIVITY_LOG&&(0,p.jsx)(H,{onBack:()=>D(x.MAIN)}),E===x.MEDIA_BOXES&&(0,p.jsx)(N,{boxes:eW,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?ra():(eQ(null),e1([]),X(!0),D(x.MEDIA_BOX_DETAIL),rs(e.value))}}),E===x.MEDIA_BOX_DETAIL&&(0,p.jsx)(U,{box:eX,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MEDIA_BOXES),eQ(null),e1([]);return}"refresh"===e.value?rs(eX.id):"files"===e.value&&(e1([]),e6(null),D(x.MEDIA_FILES),rc(eX.id))}}),E===x.MEDIA_FILES&&(0,p.jsx)($,{files:e0,box:eX,loading:K,onSelect:e=>{if("back"===e.value){D(x.MEDIA_BOX_DETAIL),e6(null);return}"refresh"===e.value?rc(eX.id):(e6(null),X(!0),D(x.MEDIA_FILE_DETAIL),ru(e.value))}}),E===x.MEDIA_FILE_DETAIL&&(0,p.jsx)(G,{file:e4,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MEDIA_FILES),e6(null);return}"refresh"===e.value&&ru(e4.id)}}),(0,p.jsx)(j,{})]})};var ea="1"===process.env.BRICKS_CLI_DISTRIBUTION,es=(n=i(function*(){if(ea)return void(0,o.render)((0,p.jsx)(eo,{}));var e=(yield t.e(8166).then(t.bind(t,29557))).TerminalInfoProvider;(0,o.render)((0,p.jsx)(e,{children:(0,p.jsx)(eo,{})}))}),function(){return n.apply(this,arguments)})},88161(e,r,t){t.r(r),t.d(r,{ActivityLogClient:()=>k,createActivityLogClient:()=>L});var n,i,l,o,a,s=t(67996),c=t(99436),u=t(5018),d=t(44668),x=t(4275),h=t(32235),f=t(62192),m=t(79657),p=t(64007);function y(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new g(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}function g(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(g=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new g(e)}function*v(e){if(e.errors?.length)throw Error(e.errors.map(e=>e.message).join("\n"));if(e.data){for(var r of Object.values(e.data))if(Array.isArray(r))for(var t of r)yield t}if(Array.isArray(e.incremental)){for(var n of e.incremental)if(Array.isArray(n.items))for(var i of n.items)yield i}}function j(){return(j=x(function*(e){var r=e.headers.get("content-type")||"";if(r.includes("application/json")){var t=yield h(e.json());if(t.errors?.length)throw Error(t.errors.map(e=>e.message).join("\n"));var n=Object.keys(t.data||{})[0];if(n&&Array.isArray(t.data[n]))for(var i of t.data[n])yield i;return}var l=r.match(/boundary="?([^";]+)"?/),o=l?l[1]:"-",a=`--${o}`,s="",c=!1,u=new TextDecoder,d=e=>{for(var r=0;-1!==(r=e.indexOf(a,r));){if(0===r||"\n"===e[r-1])return r;r+=a.length}return -1},x=function*(){for(var e;-1!==(e=d(s));){var r=s.slice(0,e);(s=s.slice(e+a.length)).startsWith("\r\n")?s=s.slice(2):s.startsWith("\n")&&(s=s.slice(1));var t=r.indexOf("\r\n\r\n"),n=-1!==t?r.slice(t+4).trim():r.trim();if(n){var i=void 0;try{i=JSON.parse(n)}catch{continue}if(yield*v(i),!1===i.hasNext){c=!0;return}}}};try{var m=!1,p=!1;try{for(var g,j,T=y(e.body);m=!(j=yield h(T.next())).done;m=!1){var b=j.value;if(s+=u.decode(b,{stream:!0}),yield*f(y(x()),h),c)break}}catch(e){p=!0,g=e}finally{try{m&&null!=T.return&&(yield h(T.return()))}finally{if(p)throw g}}}catch(e){if(!e.message?.includes("Premature close")||!c)throw e}if(!c&&s.trim()){var _,S=s.indexOf("\r\n\r\n"),E=-1!==S?s.slice(S+4).trim():s.trim();if(E&&!E.startsWith("--")){try{_=JSON.parse(E)}catch{}_&&(yield*f(y(v(_)),h),!1===_.hasNext&&(c=!0))}}e.body?.destroy()})).apply(this,arguments)}function T(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(T=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new T(e)}var b=Buffer.from("\r\n\r\n"),_=Buffer.from("\n\n"),S=e=>{var r=e.indexOf(b),t=b.length;if(-1===r&&(r=e.indexOf(_),t=_.length),-1===r)return null;var n=(e=>{var r={};for(var t of e.toString("latin1").split(/\r?\n/)){var n=t.indexOf(":");n<=0||(r[t.slice(0,n).trim().toLowerCase()]=t.slice(n+1).trim())}return r})(e.subarray(0,r)),i=e.subarray(r+t);if(!i.length)return null;var l=Number.parseInt(n["content-length"],10);return(Number.isInteger(l)&&l>=0&&l<=i.length?i=i.subarray(0,l):i.length>=2&&13===i[i.length-2]&&10===i[i.length-1]?i=i.subarray(0,i.length-2):i.length>=1&&10===i[i.length-1]&&(i=i.subarray(0,i.length-1)),i.length)?{headers:n,body:i}:null},E=(e,r)=>{for(var t=0;-1!==(t=e.indexOf(r,t));){if(0===t||10===e[t-1])return t;t+=r.length}return -1};function D(){return(D=x(function*(e){var r=e.headers.get("content-type")||"",t=r.match(/boundary="?([^";]+)"?/);if(!t)throw Error(`Expected a multipart stream, got "${r||"no content-type"}"`);var n=Buffer.from(`--${t[1]}`),i=Buffer.alloc(0);try{var l=!1,o=!1;try{for(var a,s,c=function(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new T(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}(e.body);l=!(s=yield h(c.next())).done;l=!1){var u=s.value;i=i.length?Buffer.concat([i,u]):Buffer.from(u);for(var d=void 0;-1!==(d=E(i,n));){var x=i.subarray(0,d);i=i.subarray(d+n.length);var f=x.length>4?S(x):null;if(f){var m=f.headers["x-timestamp"],p=m?Date.parse(m):NaN;yield{...f,timestamp:Number.isNaN(p)?null:p}}}}}catch(e){o=!0,a=e}finally{try{l&&null!=c.return&&(yield h(c.return()))}finally{if(o)throw a}}}finally{e.body?.destroy?.()}var y=i.length>4?S(i):null;if(y){var g=y.headers["x-timestamp"],v=g?Date.parse(g):NaN;yield{...y,timestamp:Number.isNaN(v)?null:v}}})).apply(this,arguments)}var I=`
1
+ import*as e from"ink";import*as r from"react";import*as t from"react/jsx-runtime";export const __rspack_esm_id=7294;export const __rspack_esm_ids=[7294];export const __webpack_modules__={8498(r){r.exports=e},51649(e){e.exports=r},71178(e){e.exports=t},94685(e,r,t){t.r(r),t.d(r,{AppList:()=>C,CONTROL_ACTIONS:()=>h,MainMenu:()=>S,Header:()=>v,ModuleDetail:()=>O,ONLINE_THRESHOLD_MS:()=>m.RZ,ShortEditEditor:()=>W,MediaFileList:()=>$,App:()=>eo,DeviceDetail:()=>A,VIEWS:()=>x,runInteractiveMode:()=>es,DeviceList:()=>I,MediaBoxList:()=>N,Loading:()=>T,DeviceControl:()=>w,ProjectInitView:()=>el,GroupDetail:()=>R,ModuleList:()=>L,MediaBoxDetail:()=>U,GroupList:()=>P,Footer:()=>j,DeviceStatus:()=>b,AppDetail:()=>k,DeviceScreenshot:()=>B,MediaFileDetail:()=>G});var n,i=t(99436),l=t(51649),o=t(8498),a=t(68832),s=t(85382),c=t(47988),u=t(31802),d=t(60450),x={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",ACTIVITY_LOG:"activity_log"},h=[{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"}],f=t(47882),m=t(9683),p=t(71178),y=(e,r=!0)=>{var t=Math.floor(60),n=a((0,l.useState)(t),2),i=n[0],o=n[1],s=a((0,l.useState)(null),2),c=s[0],u=s[1],d=(0,l.useRef)(e);(0,l.useEffect)(()=>{d.current=e},[e]);var x=(0,l.useCallback)(()=>{o(t),u(Date.now())},[t]);return(0,l.useEffect)(()=>{if(r){var e=setInterval(()=>{o(e=>e<=1?(d.current?.(),u(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[r,t]),(0,l.useEffect)(()=>{r&&(o(t),u(Date.now()))},[r,t]),{countdown:i,lastRefreshTime:c,resetCountdown:x}},g=({countdown:e,lastRefreshTime:r})=>(0,p.jsx)(o.Box,{children:(0,p.jsxs)(o.Text,{color:"gray",children:["Next refresh in ",(0,p.jsxs)(o.Text,{color:"cyan",children:[e,"s"]}),r&&(0,p.jsxs)(o.Text,{color:"gray",children:[" (last: ",r?new Date(r).toLocaleTimeString():null,")"]})]})}),v=({workspace:e,view:r})=>(0,p.jsxs)(o.Box,{flexDirection:"column",marginBottom:1,children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),(0,p.jsx)(o.Text,{color:"gray",children:" - Interactive Mode"})]}),(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:"Workspace: "}),(0,p.jsx)(o.Text,{color:"green",children:e?.name||"Not connected"}),(0,p.jsx)(o.Text,{color:"gray",children:" | View: "}),(0,p.jsx)(o.Text,{color:"yellow",children:r})]}),(0,p.jsx)(o.Text,{color:"gray",children:"─".repeat(60)})]}),j=()=>(0,p.jsxs)(o.Box,{marginTop:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"gray",children:"─".repeat(60)}),(0,p.jsxs)(o.Text,{color:"gray",children:["Press ",(0,p.jsx)(o.Text,{color:"cyan",children:"q"})," to quit, ",(0,p.jsx)(o.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),T=({text:e})=>(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"green",children:(0,p.jsx)(f.A,{type:"dots"})}),(0,p.jsxs)(o.Text,{children:[" ",e||"Loading..."]})]}),b=({lastAliveTime:e})=>{var r=(0,m.Ed)(e);return(0,p.jsx)(o.Text,{color:r.tone,children:(0,m.mz)(r)})},_=t(48724),S=({onSelect:e,mediaEnabled:r,activityLogEnabled:t})=>{var n=[{label:"Devices",value:x.DEVICES},{label:"Applications",value:x.APPS},{label:"Modules",value:x.MODULES},{label:"Device Groups",value:x.GROUPS},...r?[{label:"Media Flow",value:x.MEDIA_BOXES}]:[],...t?[{label:"Activity Log",value:x.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),(0,p.jsx)(_.Ay,{items:n,onSelect:e})]})},E="1"===process.env.BRICKS_CLI_DISTRIBUTION,D=e=>{var r=a((0,l.useState)(null),2),n=r[0],i=r[1];return((0,l.useEffect)(()=>{if(!E){var e=!0;return t.e(8166).then(t.bind(t,29557)).then(r=>{e&&i(()=>r.default)}).catch(()=>{e&&i(!1)}),()=>{e=!1}}},[]),E||!1===n)?(0,p.jsx)(o.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):n?(0,p.jsx)(n,{...e}):(0,p.jsx)(T,{text:"Preparing image preview..."})},I=({devices:e,loading:r,onSelect:t,countdown:n,lastRefreshTime:i})=>{if(r)return(0,p.jsx)(T,{text:"Loading devices..."});if(!e?.length)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"yellow",children:"No devices found"}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]});var l=[...e.map(e=>{var r,t,n,i,l=(r=e.entry_detail?.watch_dog_timer?.last_alive_time,n=(t=(0,m.Ed)(r)).glyph,i=t.label,`${n} ${i}`);return{label:`${l} - ${e.name||e.device_name}`,value:e._id,device:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{marginBottom:1,children:[(0,p.jsxs)(o.Text,{bold:!0,children:["Devices (",e.length,")"]}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]}),(0,p.jsx)(_.Ay,{items:l,onSelect:t})]})},A=({device:e,loading:r,error:t,onSelect:n,mediaEnabled:i,countdown:l,lastRefreshTime:a})=>{if(r)return(0,p.jsx)(T,{text:"Loading device..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...i?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],c=e.entry_detail,u=c?.screen,d=c?.update,x=c?.local_sync;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:l,lastRefreshTime:a})]}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:"Status: "}),(0,p.jsx)(b,{lastAliveTime:c?.watch_dog_timer?.last_alive_time})]}),(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),c?.application&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Application"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" Name: ",c.application.name]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" Mode: ",c.operation_mode||"N/A"]})]}),u&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Screen"}),u.resolution&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Resolution: ",u.resolution.width,"x",u.resolution.height,u.resolution.scale&&` @${u.resolution.scale}x`]}),u.orientation&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Orientation: ",u.orientation]}),u.touch&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Touch:"," ",u.touch.available?`Yes (${u.touch.touch_point} points)`:"No"]})]}),(c?.memory_usage||c?.disk_usage)&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"System"}),c.memory_usage&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Memory: ",Math.round(100*c.memory_usage),"%"]}),c.disk_usage&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Disk: ",Math.round(100*c.disk_usage),"%"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Capabilities"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Sound: ",c?.sound?.available?"✓":"✗"," | ","Camera: ",c?.camera?.available?"✓":"✗"," | ","Audio In: ",c?.audio_in?.available?"✓":"✗"]})]}),x&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Local Sync"}),(0,p.jsxs)(o.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`]})]}),d&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Update"}),(0,p.jsxs)(o.Text,{color:d.need_update?"yellow":"gray",children:[" ","Status: ",d.need_update?"⚠ Update available":"✓ Up to date"]}),d.current_version&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Version: ",d.current_version]})]})]}),(0,p.jsx)(_.Ay,{items:s,onSelect:n})]})},w=({device:e,onSelect:r,controlling:t,controlResult:n})=>(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&(0,p.jsx)(T,{text:"Sending command..."}),n&&(0,p.jsx)(o.Text,{color:n.success?"green":"red",children:n.message}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:h,onSelect:r})})]}),B=({device:e,screenshot:r,loading:t,error:n,onSelect:i})=>{var l=r?.file?.meta,a=l?.originalWidth!=null&&l?.originalHeight!=null,s=l?.originalFileSize!=null;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&(0,p.jsx)(T,{text:"Loading screenshot..."}),n&&(0,p.jsx)(o.Box,{marginY:1,children:(0,p.jsx)(o.Text,{color:"red",children:String(n)})}),!t&&!n&&r&&(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Box,{height:30,children:(0,p.jsx)(D,{src:r.path,width:80,alt:"Device screenshot"})}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Screenshot Details"}),(0,p.jsxs)(o.Box,{marginY:1,children:[(0,p.jsx)(o.Text,{color:"green",children:"Screenshot saved to: "}),(0,p.jsx)(o.Text,{color:"cyan",children:String(r.path||"")})]}),a&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",String(l.originalWidth),"x",String(l.originalHeight)]}),s&&(0,p.jsxs)(o.Text,{color:"gray",children:["File: ",(Number(l.originalFileSize)/1024).toFixed(1)," KB"]}),r.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:["Updated: ",new Date(r.updatedAt).toLocaleString()]}),r.captureRequested&&!r.fresh&&(0,p.jsx)(o.Text,{color:"yellow",children:"No new capture arrived in time: this is the previous one, and it may not show the current screen."})]})]}),!t&&!n&&!r&&(0,p.jsx)(o.Box,{marginY:1,children:(0,p.jsx)(o.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})})]})},C=({apps:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{text:"Loading applications..."});if(!e?.length)return(0,p.jsx)(o.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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},k=({app:e,loading:r,error:t,onSelect:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading application..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Application not found"});var i=[{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"}],l=e.devices?.length||0,a=e.devices?.filter(e=>"online"===e.status)?.length||0;return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Version"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,p.jsxs)(o.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Devices"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Total: ",l,l>0&&` (${a} online)`]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Features"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),(0,p.jsxs)(o.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"\uD83D\uDD12 Locked":"\uD83D\uDD13 Unlocked"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:i,onSelect:n})]})},L=({modules:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No modules found"}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},O=({module:e,loading:r,error:t,onSelect:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading module..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Module not found"});var i=[{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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Version"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),(0,p.jsxs)(o.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Usage"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Settings"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Exposed Properties"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:i,onSelect:n})]})},P=({groups:e,loading:r,onSelect:t,countdown:n,lastRefreshTime:i})=>{if(r)return(0,p.jsx)(T,{text:"Loading device groups..."});var l=[...(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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{marginBottom:1,children:[(0,p.jsxs)(o.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:n,lastRefreshTime:i})]}),!e?.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No device groups found"}),(0,p.jsx)(_.Ay,{items:l,onSelect:t})]})},M=({loading:e,groupDevices:r})=>e?(0,p.jsx)(T,{text:"Loading devices..."}):r?.length?(0,p.jsxs)(p.Fragment,{children:[r.slice(0,10).map(e=>(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{color:"gray",children:" "}),(0,p.jsx)(b,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),r.length>10&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","... and ",r.length-10," more"]})]}):(0,p.jsx)(o.Text,{color:"gray",children:" No devices in this group"}),R=({group:e,groupDevices:r,loading:t,error:n,onSelect:i,countdown:l,lastRefreshTime:a})=>t&&!e?(0,p.jsx)(T,{text:"Loading device group..."}):n?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",n]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]}):e?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name}),(0,p.jsx)(o.Text,{color:"gray",children:" - "}),(0,p.jsx)(g,{countdown:l,lastRefreshTime:a})]}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsxs)(o.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),(0,p.jsx)(M,{loading:t,groupDevices:r})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&(0,p.jsxs)(o.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]}):(0,p.jsx)(o.Text,{color:"red",children:"Device group not found"}),N=({boxes:e,loading:r,onSelect:t})=>{if(r)return(0,p.jsx)(T,{text:"Loading media boxes..."});if(!e?.length)return(0,p.jsx)(o.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,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),(0,p.jsx)(_.Ay,{items:n,onSelect:t})]})},U=({box:e,loading:r,error:t,onSelect:n})=>r&&!e?(0,p.jsx)(T,{text:"Loading media box..."}):t?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]}):e?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsxs)(o.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>(0,p.jsxs)(o.Text,{color:"gray",children:[" ",e.name||"Passcode"," (",(e.permissions||[]).join(", "),e.enableExpired?`, expires ${e.expiredAt} UTC`:"",")"]},e.id)),e.passcodes.length>5&&(0,p.jsxs)(o.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]}):(0,p.jsx)(o.Text,{color:"red",children:"Media box not found"}),$=({files:e,loading:r,onSelect:t,box:n})=>{if(r)return(0,p.jsx)(T,{text:"Loading media files..."});if(!e?.length)return(0,p.jsx)(o.Text,{color:"yellow",children:"No media files found"});var i=[...e.map(e=>{var r;return{label:`${"Image"===(r=e.fileType)?"\uD83D\uDDBC":"Video"===r?"\uD83C\uDF9E":"Audio"===r?"\uD83C\uDFB5":"\uD83D\uDCC4"} ${e.name||"Unnamed"}`,value:e.id,file:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",n?.name?` - ${n.name}`:""]}),(0,p.jsx)(_.Ay,{items:i,onSelect:t})]})},G=({file:e,loading:r,error:t,onSelect:n})=>{if(r&&!e)return(0,p.jsx)(T,{text:"Loading media file..."});if(t)return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",t]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:n})]});if(!e)return(0,p.jsx)(o.Text,{color:"red",children:"Media file not found"});var i=e.meta,l=(0,d.buildScreenshotUrl)(e),a=(0,d.buildScreenshotUrl)(e,{preferThumbnail:!0}),s=!!(a&&a!==l);return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&(0,p.jsx)(o.Text,{color:"gray",children:e.description}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"gray",children:["ID: ",e.id]}),(0,p.jsxs)(o.Text,{color:"gray",children:["Box ID: ",e.boxId]}),(0,p.jsxs)(o.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&(0,p.jsxs)(o.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),i?.originalWidth!=null&&i?.originalHeight!=null&&(0,p.jsxs)(o.Text,{color:"gray",children:["Size: ",i.originalWidth,"x",i.originalHeight]}),i?.originalFileSize!=null&&(0,p.jsxs)(o.Text,{color:"gray",children:["File: ",(Number(i.originalFileSize)/1024).toFixed(1)," KB"]}),l&&(0,p.jsxs)(o.Text,{color:"gray",children:["Original URL: ",l]}),s&&(0,p.jsxs)(o.Text,{color:"gray",children:["Thumbnail URL: ",a]}),(0,p.jsxs)(o.Box,{flexDirection:"column",marginTop:1,children:[(0,p.jsx)(o.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&(0,p.jsxs)(o.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),(0,p.jsx)(_.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:n})]})},F=t(88161),V=(e,r)=>{if(!e)return"";var t="string"==typeof e?e:JSON.stringify(e);return t.length>r?t.slice(0,r-1)+"…":t},H=({onBack:e})=>{var r=a((0,l.useState)([]),2),t=r[0],n=r[1],s=a((0,l.useState)(!0),2),d=s[0],x=s[1],h=a((0,l.useState)(null),2),f=h[0],m=h[1];return(0,l.useEffect)(()=>{var e,r=(0,c.getCurrentProfile)(),t=(0,u.getConnectionContext)(r),l=t.auth,o=t.activityLogBaseUrl;if(!l){m("Not logged in. Run `bricks auth login` first."),x(!1);return}if(!o){m("Activity log URL not configured."),x(!1);return}var a=(0,F.createActivityLogClient)(o,l),s=new Date(Date.now()-36e5).toISOString(),d=new Date().toISOString(),h=new AbortController;return(e=i(function*(){try{var e=yield a.collectEvents({start_time:s,end_time:d},{limit:50,signal:h.signal});n(e)}catch(e){"AbortError"!==e.name&&m(e.message)}x(!1)}),function(){return e.apply(this,arguments)})(),()=>h.abort()},[]),(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),d&&(0,p.jsx)(T,{text:"Fetching events..."}),f&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",f]}),!d&&!f&&0===t.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No events found in the last hour"}),!d&&t.length>0&&(0,p.jsxs)(o.Box,{flexDirection:"column",marginBottom:1,children:[(0,p.jsxs)(o.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),t.map((e,r)=>(0,p.jsxs)(o.Text,{children:[new Date(e.timestamp).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z").padEnd(22)," ",V(e.event_type||"",12).padEnd(12)," ",V(e.device_id||"",14).padEnd(14)," ",V(e.event_name||"",24).padEnd(24)," ",V(e.sender||"",16)]},r)),t.length>=50&&(0,p.jsxs)(o.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:r=>"back"===r.value&&e()})]})},z=t(29253),q=t(44618),Y=["B","C","G","D"],W=({instanceType:e,instance:r,client:t,onDone:n,onCancel:s})=>{var c,u=(0,o.useApp)().exit,d=a((0,l.useState)("select_ref"),2),x=d[0],h=d[1],f=a((0,l.useState)(""),2),m=f[0],y=f[1],g=a((0,l.useState)("search"),2),v=g[0],j=g[1],b=a((0,l.useState)(null),2),S=b[0],E=b[1],D=a((0,l.useState)(null),2),I=D[0],A=D[1],w=a((0,l.useState)(""),2),B=w[0],C=w[1],k=a((0,l.useState)(""),2),L=k[0],O=k[1],P=a((0,l.useState)(null),2),M=P[0],R=P[1],N=r?.short_edit?.ref_map||{},U=Object.entries(N).filter(([,e])=>e&&!e.hide),$=(0,q.V)(N,{keyword:m,types:Y}),G=$.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:r})=>({label:`${r.title||e} (${e})`,value:e,ref:r}))]),F=[...m?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],V=G.length>0?[...G,...F]:F,H=V.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,o.useInput)((e,r)=>{r.tab&&"select_ref"===x?j(e=>"search"===e?"list":"search"):(r.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)&&u())},{isActive:!0});var W=(c=i(function*(){if(t&&r?._id&&S){h("submitting"),R(null);try{var i={shortId:S,path:B.trim(),content:(e=>{var r=e.trim();if(""===r)return null;try{return JSON.parse(r)}catch{return r}})(L),forwardDataLink:!0};I?.inner_ref?.pid&&(i.innerRefParentShortId=I.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:r._id,list:[i]}):yield t.shortEditModule({id:r._id,list:[i]}),yield n(),h("done")}catch(e){R(e.message),h("confirm")}}}),function(){return c.apply(this,arguments)});return r?.short_edit?.enabled?0===U.length?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"yellow",children:"No Short Edit references found."}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]}):"select_ref"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,children:"Short Edit References"}),(0,p.jsx)(o.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),(0,p.jsxs)(o.Box,{marginTop:1,flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"gray",children:"Search (title or shortId)"}),(0,p.jsx)(z.A,{value:m,placeholder:"type to filter, Enter to focus list",onChange:e=>y(e),onSubmit:()=>j("list"),focus:"search"===v}),(0,p.jsx)(o.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),(0,p.jsxs)(o.Box,{marginTop:1,children:[0===$.length&&(0,p.jsx)(o.Text,{color:"yellow",children:"No references match your search."}),(0,p.jsx)(_.Ay,{items:V,isFocused:"list"===v,initialIndex:H>-1?H:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:r,isHeader:t})=>t?(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(o.Text,{bold:!0,color:"white",children:e})}):(0,p.jsxs)(o.Text,{color:r?"blue":void 0,children:[r?"❯":" "," ",e]}),onSelect:e=>{if("__back__"===e.value)return void s();if("__clear_search__"===e.value){y(""),j("search");return}e.isHeader||(E(e.value),A(e.ref),h("input_path"))}})]})]}):"input_path"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Reference:"," ",(0,p.jsxs)(o.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,p.jsx)(o.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(z.A,{value:B,placeholder:"path",onChange:e=>{C(e),M&&R(null)},onSubmit:e=>{var r=e.trim();r?(C(r),h("input_content")):R("Path is required")},focus:!0})]}):"input_content"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:B})]}),(0,p.jsx)(o.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(z.A,{value:L,placeholder:"content",onChange:e=>{O(e),M&&R(null)},onSubmit:()=>h("confirm"),focus:!0})]}):"submitting"===x?(0,p.jsx)(T,{text:"Applying short edit..."}):"done"===x?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{color:"green",children:"Short edit applied successfully."}),(0,p.jsx)(_.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(h("select_ref"),E(null),A(null),C(""),O(""),R(null)):s()}})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),(0,p.jsxs)(o.Text,{children:["Reference:"," ",(0,p.jsxs)(o.Text,{color:"cyan",children:[I?.title||S," (",S,")"]})]}),(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:B})]}),(0,p.jsxs)(o.Text,{children:["Content: ",(0,p.jsx)(o.Text,{color:"cyan",children:L||"<empty>"})]}),M&&(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",M]}),(0,p.jsx)(_.Ay,{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&&W(),"edit_path"===e.value&&h("input_path"),"edit_content"===e.value&&h("input_content"),"back"===e.value&&s()}})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),(0,p.jsx)(_.Ay,{items:[{label:"← Back",value:"back"}],onSelect:s})]})},J=t(16928),K=t(79896),X=t(10750),Q=t(77768),Z="options",ee="output_dir",er="confirm",et="generating",en="post_install",ei="done",el=({type:e,instance:r,client:t,onDone:n,onCancel:s})=>{var c,u=(0,o.useApp)().exit,d=a((0,l.useState)(Z),2),x=d[0],h=d[1],m=a((0,l.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),2),y=m[0],g=m[1],v=a((0,l.useState)(process.cwd()),2),j=v[0],T=v[1],b=a((0,l.useState)(""),2),S=b[0],E=b[1],D=a((0,l.useState)(null),2),I=D[0],A=D[1],w=a((0,l.useState)(null),2),B=w[0],C=w[1],k=X(r?.name||"bricks-ctor"),L=J.resolve(j,k),O=(0,l.useCallback)(e=>{"back"===e.value?s():"continue"===e.value?h(ee):g(r=>({...r,[e.value]:!r[e.value]}))},[s]),P=(0,l.useCallback)(()=>{K.existsSync(L)?A(`Directory already exists: ${L}`):(A(null),h(er))},[L]),M=(0,l.useCallback)((c=i(function*(n){if("back"===n.value)return void h(ee);if("cancel"===n.value)return void s();if("confirm"===n.value){h(et);try{E("Fetching project from BRICKS...");var i="application"===e,l=i?t.queries.applicationProject:t.queries.moduleProject,o=(yield t.query(l,{id:r._id,buildApplicationOnly:!1,setupGitHubActions:y.setupGitHubActions,setupAgents:y.setupAgents,setupClaudeCode:y.setupClaudeCode,setupGeminiCLI:y.setupGeminiCLI}))[i?"applicationProject":"moduleProject"];if(!o?.files)throw Error("Failed to fetch project files");E("Creating project directory..."),K.mkdirSync(L,{recursive:!0}),E(`Writing ${o.files.length} files...`);var a=yield(0,Q.KN)(o.files,L);(0,Q.oz)(a),h(en);var c={path:L,files:o.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(c,(yield(0,Q.o0)(L,{install:y.runBunInstall,git:y.initGit,onStatus:E}))),C(c),h(ei)}catch(e){A(e.message),h(Z)}}}),function(e){return c.apply(this,arguments)}),[t,r,e,y,L,s]),R=(0,l.useCallback)(e=>{"exit"===e.value?u():n()},[u,n]);if(x===Z){var N=[{label:`${y.setupGitHubActions?"[x]":"[ ]"} GitHub Actions workflow`,value:"setupGitHubActions"},{label:`${y.setupAgents?"[x]":"[ ]"} AGENTS.md`,value:"setupAgents"},{label:`${y.setupClaudeCode?"[x]":"[ ]"} CLAUDE.md`,value:"setupClaudeCode"},{label:`${y.setupGeminiCLI?"[x]":"[ ]"} GEMINI.md`,value:"setupGeminiCLI"},{label:`${y.runBunInstall?"[x]":"[ ]"} Run bun install after generation`,value:"runBunInstall"},{label:`${y.initGit?"[x]":"[ ]"} Initialize git repository`,value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsxs)(o.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",r?.name||"Untitled"]}),(0,p.jsx)(o.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),I&&(0,p.jsxs)(o.Text,{color:"red",marginBottom:1,children:["Error: ",I]}),(0,p.jsx)(_.Ay,{items:N,onSelect:O})]})}return x===ee?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Output Directory"}),(0,p.jsx)(o.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),I&&(0,p.jsx)(o.Text,{color:"red",marginBottom:1,children:I}),(0,p.jsxs)(o.Box,{children:[(0,p.jsx)(o.Text,{children:"Directory: "}),(0,p.jsx)(z.A,{value:j,onChange:T,onSubmit:P})]}),(0,p.jsxs)(o.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",L]})]}):x===er?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Name: ",(0,p.jsx)(o.Text,{color:"green",children:r?.name||"Untitled"})]}),(0,p.jsxs)(o.Text,{children:["Type: ",(0,p.jsx)(o.Text,{color:"yellow",children:e})]}),(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:L})]}),(0,p.jsx)(o.Text,{color:"gray",marginTop:1,children:"Options:"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - GitHub Actions: ",y.setupGitHubActions?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - AGENTS.md: ",y.setupAgents?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - CLAUDE.md: ",y.setupClaudeCode?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - GEMINI.md: ",y.setupGeminiCLI?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - Run bun install: ",y.runBunInstall?"Yes":"No"]}),(0,p.jsxs)(o.Text,{color:"gray",children:[" - Initialize git: ",y.initGit?"Yes":"No"]})]}),(0,p.jsx)(_.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:M})]}):x===et||x===en?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),(0,p.jsxs)(o.Box,{marginY:1,children:[(0,p.jsx)(o.Text,{color:"green",children:(0,p.jsx)(f.A,{type:"dots"})}),(0,p.jsxs)(o.Text,{children:[" ",S]})]})]}):x===ei&&B?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(o.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),(0,p.jsxs)(o.Box,{marginY:1,flexDirection:"column",children:[(0,p.jsxs)(o.Text,{children:["Path: ",(0,p.jsx)(o.Text,{color:"cyan",children:B.path})]}),(0,p.jsxs)(o.Text,{children:["Files: ",(0,p.jsx)(o.Text,{color:"green",children:B.files})]}),(0,p.jsxs)(o.Text,{children:["Dependencies:"," ",(0,p.jsx)(o.Text,{color:B.bunInstalled?"green":"yellow",children:B.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),(0,p.jsxs)(o.Text,{children:["Git:"," ",(0,p.jsx)(o.Text,{color:B.gitInitialized?"green":"yellow",children:B.gitInitialized?"Initialized":"Not initialized"})]})]}),(0,p.jsx)(o.Text,{bold:!0,marginY:1,children:"Next steps:"}),(0,p.jsxs)(o.Text,{color:"gray",children:[" cd ",k]}),!B.bunInstalled&&(0,p.jsx)(o.Text,{color:"gray",children:" bun install"}),(0,p.jsx)(o.Text,{color:"gray",children:" bun invoke-simulator"}),(0,p.jsxs)(o.Text,{color:"gray",marginTop:1,children:["For more information, see ",k,"/README.md"]}),(0,p.jsx)(o.Box,{marginTop:1,children:(0,p.jsx)(_.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:R})})]}):null};let eo=()=>{var e,r,t,n,h,f,m,g,b=(0,o.useApp)().exit,_=a((0,l.useState)(x.MAIN),2),E=_[0],D=_[1],M=a((0,l.useState)(null),2),F=M[0],V=M[1],z=a((0,l.useState)(null),2),q=z[0],Y=z[1],J=a((0,l.useState)(!0),2),K=J[0],X=J[1],Q=a((0,l.useState)(null),2),Z=Q[0],ee=Q[1],er=a((0,l.useState)(!1),2),et=er[0],en=er[1],ei=a((0,l.useState)([]),2),eo=ei[0],ea=ei[1],es=a((0,l.useState)(null),2),ec=es[0],eu=es[1],ed=a((0,l.useState)([]),2),ex=ed[0],eh=ed[1],ef=a((0,l.useState)(null),2),em=ef[0],ep=ef[1],ey=a((0,l.useState)([]),2),eg=ey[0],ev=ey[1],ej=a((0,l.useState)(null),2),eT=ej[0],eb=ej[1],e_=a((0,l.useState)([]),2),eS=e_[0],eE=e_[1],eD=a((0,l.useState)(null),2),eI=eD[0],eA=eD[1],ew=a((0,l.useState)([]),2),eB=ew[0],eC=ew[1],ek=a((0,l.useState)(!1),2),eL=ek[0],eO=ek[1],eP=a((0,l.useState)(null),2),eM=eP[0],eR=eP[1],eN=a((0,l.useState)(null),2),eU=eN[0],e$=eN[1],eG=a((0,l.useState)(null),2),eF=eG[0],eV=eG[1],eH=a((0,l.useState)(null),2),ez=eH[0],eq=eH[1],eY=a((0,l.useState)([]),2),eW=eY[0],eJ=eY[1],eK=a((0,l.useState)(null),2),eX=eK[0],eQ=eK[1],eZ=a((0,l.useState)([]),2),e0=eZ[0],e1=eZ[1],e2=a((0,l.useState)(null),2),e4=e2[0],e6=e2[1],e8=E===x.DEVICES,e9=E===x.DEVICE_DETAIL,e5=E===x.GROUPS,e7=E===x.GROUP_DETAIL;(0,l.useEffect)(()=>{var e=(0,c.getCurrentProfile)(),r=(0,u.getConnectionContext)(e),t=r.auth,n=r.baseUrl;if(en(!!r.activityLogBaseUrl),!t){ee("Not logged in. Run `bricks auth login` first."),X(!1);return}var i=(0,s.createClient)(n,t);V(i),i.workspace().then(e=>{Y(e),X(!1)}).catch(e=>{ee(e.message),X(!1)})},[]),(0,o.useInput)((e,r)=>{"q"===e&&b(),r.escape&&(E===x.DEVICE_CONTROL?(D(x.DEVICE_DETAIL),eR(null)):E===x.DEVICE_SCREENSHOT?(D(x.DEVICE_DETAIL),eV(null),eq(null)):E===x.DEVICE_DETAIL?(D(x.DEVICES),eu(null)):E===x.APP_DETAIL?(D(x.APPS),ep(null)):E===x.MODULE_DETAIL?(D(x.MODULES),eb(null)):E===x.GROUP_DETAIL?(D(x.GROUPS),eA(null),eC([])):E===x.MEDIA_FILE_DETAIL?(D(x.MEDIA_FILES),e6(null)):E===x.MEDIA_FILES?(D(x.MEDIA_BOX_DETAIL),e6(null)):E===x.MEDIA_BOX_DETAIL?(D(x.MEDIA_BOXES),eQ(null),e1([])):E===x.MEDIA_BOXES?D(x.MAIN):E!==x.MAIN&&D(x.MAIN))},{isActive:E!==x.APP_SHORT_EDIT&&E!==x.MODULE_SHORT_EDIT&&E!==x.APP_PROJECT_INIT&&E!==x.MODULE_PROJECT_INIT});var e3=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.devices({});ea(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),re=(0,l.useCallback)((e=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.device({id:e});eu(r)}catch(e){e$(e.message)}X(!1)}}),function(r){return e.apply(this,arguments)}),[F]),rr=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.applications({});eh(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),rt=(0,l.useCallback)((r=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.application({id:e});ep(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return r.apply(this,arguments)}),[F]),rn=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.modules({});ev(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),ri=(0,l.useCallback)((t=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.module({id:e});eb(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return t.apply(this,arguments)}),[F]),rl=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.deviceGroups({});eE(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),ro=(0,l.useCallback)((n=i(function*(e){if(F){X(!0),e$(null);try{var r=yield Promise.all([F.deviceGroup({id:e}),F.devicesByGroup({id:e})]),t=a(r,2),n=t[0],i=t[1];eA(n),eC(i||[])}catch(e){e$(e.message)}X(!1)}}),function(e){return n.apply(this,arguments)}),[F]),ra=(0,l.useCallback)(i(function*(){if(F){X(!0);try{var e=yield F.mediaBoxes();eJ(e||[])}catch(e){ee(e.message)}X(!1)}}),[F]),rs=(0,l.useCallback)((h=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.mediaBox({id:e});eQ(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return h.apply(this,arguments)}),[F]),rc=(0,l.useCallback)((f=i(function*(e){if(F){X(!0);try{var r=yield F.mediaFiles({boxId:e});e1(r||[])}catch(e){ee(e.message)}X(!1)}}),function(e){return f.apply(this,arguments)}),[F]),ru=(0,l.useCallback)((m=i(function*(e){if(F){X(!0),e$(null);try{var r=yield F.mediaFile({id:e});e6(r)}catch(e){e$(e.message)}X(!1)}}),function(e){return m.apply(this,arguments)}),[F]),rd=(0,l.useCallback)((g=i(function*(e){if(F&&ec){eO(!0),eR(null);try{yield F.controlDevice({id:ec._id,type:e}),eR({success:!0,message:`Command sent: ${e}`})}catch(e){eR({success:!1,message:e.message})}eO(!1)}}),function(e){return g.apply(this,arguments)}),[F,ec]),rx=(0,l.useCallback)(i(function*(e=!1){if(F&&ec&&q){X(!0),eq(null),eV(null);try{var r=e?d.captureAndSaveScreenshot:d.fetchAndSaveScreenshot,t=yield r(F,q,ec._id,null,{preferThumbnail:!0});t.error?eq(t.error):eV(t)}catch(e){eq(e.message)}X(!1)}}),[F,ec,q]),rh=y((0,l.useCallback)(()=>{F&&e3()},[F,e3]),e8),rf=y((0,l.useCallback)(()=>{F&&ec&&re(ec._id)},[F,ec,re]),e9),rm=y((0,l.useCallback)(()=>{F&&rl()},[F,rl]),e5),rp=y((0,l.useCallback)(()=>{F&&eI&&ro(eI._id)},[F,eI,ro]),e7);return K&&!q?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),(0,p.jsx)(T,{text:"Connecting to workspace..."})]}):Z&&!q?(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),(0,p.jsxs)(o.Text,{color:"red",children:["Error: ",Z]}),(0,p.jsx)(j,{})]}):(0,p.jsxs)(o.Box,{flexDirection:"column",children:[(0,p.jsx)(v,{workspace:q,view:E}),E===x.MAIN&&(0,p.jsx)(S,{onSelect:e=>{"exit"===e.value?b():(D(e.value),e.value===x.DEVICES?e3():e.value===x.APPS?rr():e.value===x.MODULES?rn():e.value===x.GROUPS?rl():e.value===x.MEDIA_BOXES&&ra())},mediaEnabled:(0,d.isMediaEnabled)(q),activityLogEnabled:et}),E===x.DEVICES&&(0,p.jsx)(I,{devices:eo,loading:K,onSelect:e=>{if("back"===e.value)return void D(x.MAIN);if("refresh"===e.value){e3(),rh.resetCountdown();return}eu(null),X(!0),D(x.DEVICE_DETAIL),re(e.value)},countdown:rh.countdown,lastRefreshTime:rh.lastRefreshTime}),E===x.DEVICE_DETAIL&&(0,p.jsx)(A,{device:ec,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.DEVICES),eu(null);return}if("refresh"===e.value){re(ec._id),rf.resetCountdown();return}"control"===e.value&&(D(x.DEVICE_CONTROL),eR(null)),"screenshot"===e.value&&(D(x.DEVICE_SCREENSHOT),eV(null),eq(null),rx(!1))},mediaEnabled:(0,d.isMediaEnabled)(q),countdown:rf.countdown,lastRefreshTime:rf.lastRefreshTime}),E===x.DEVICE_CONTROL&&(0,p.jsx)(w,{device:ec,onSelect:e=>{if("back"===e.value){D(x.DEVICE_DETAIL),eR(null);return}rd(e.value)},controlling:eL,controlResult:eM}),E===x.DEVICE_SCREENSHOT&&(0,p.jsx)(B,{device:ec,screenshot:eF,loading:K,error:ez,onSelect:e=>{if("back"===e.value){D(x.DEVICE_DETAIL),eV(null),eq(null);return}"refresh"===e.value?rx(!1):"take"===e.value&&rx(!0)}}),E===x.APPS&&(0,p.jsx)(C,{apps:ex,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?rr():(ep(null),X(!0),D(x.APP_DETAIL),rt(e.value))}}),E===x.APP_DETAIL&&(0,p.jsx)(k,{app:em,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.APPS),ep(null);return}"refresh"===e.value?rt(em._id):("short_edit"===e.value&&(D(x.APP_SHORT_EDIT),e$(null)),"project_init"===e.value&&(D(x.APP_PROJECT_INIT),e$(null)))}}),E===x.APP_SHORT_EDIT&&(0,p.jsx)(W,{instanceType:"application",instance:em,client:F,onDone:i(function*(){return rt(em._id)}),onCancel:()=>D(x.APP_DETAIL)}),E===x.APP_PROJECT_INIT&&(0,p.jsx)(el,{type:"application",instance:em,client:F,onDone:()=>D(x.APP_DETAIL),onCancel:()=>D(x.APP_DETAIL)}),E===x.MODULES&&(0,p.jsx)(L,{modules:eg,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?rn():(eb(null),X(!0),D(x.MODULE_DETAIL),ri(e.value))}}),E===x.MODULE_DETAIL&&(0,p.jsx)(O,{module:eT,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MODULES),eb(null);return}"refresh"===e.value?ri(eT._id):("short_edit"===e.value&&(D(x.MODULE_SHORT_EDIT),e$(null)),"project_init"===e.value&&(D(x.MODULE_PROJECT_INIT),e$(null)))}}),E===x.MODULE_SHORT_EDIT&&(0,p.jsx)(W,{instanceType:"module",instance:eT,client:F,onDone:i(function*(){return ri(eT._id)}),onCancel:()=>D(x.MODULE_DETAIL)}),E===x.MODULE_PROJECT_INIT&&(0,p.jsx)(el,{type:"module",instance:eT,client:F,onDone:()=>D(x.MODULE_DETAIL),onCancel:()=>D(x.MODULE_DETAIL)}),E===x.GROUPS&&(0,p.jsx)(P,{groups:eS,loading:K,onSelect:e=>{if("back"===e.value)return void D(x.MAIN);if("refresh"===e.value){rl(),rm.resetCountdown();return}eA(null),eC([]),X(!0),D(x.GROUP_DETAIL),ro(e.value)},countdown:rm.countdown,lastRefreshTime:rm.lastRefreshTime}),E===x.GROUP_DETAIL&&(0,p.jsx)(R,{group:eI,groupDevices:eB,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.GROUPS),eA(null),eC([]);return}"refresh"===e.value&&(ro(eI._id),rp.resetCountdown())},countdown:rp.countdown,lastRefreshTime:rp.lastRefreshTime}),E===x.ACTIVITY_LOG&&(0,p.jsx)(H,{onBack:()=>D(x.MAIN)}),E===x.MEDIA_BOXES&&(0,p.jsx)(N,{boxes:eW,loading:K,onSelect:e=>{"back"===e.value?D(x.MAIN):"refresh"===e.value?ra():(eQ(null),e1([]),X(!0),D(x.MEDIA_BOX_DETAIL),rs(e.value))}}),E===x.MEDIA_BOX_DETAIL&&(0,p.jsx)(U,{box:eX,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MEDIA_BOXES),eQ(null),e1([]);return}"refresh"===e.value?rs(eX.id):"files"===e.value&&(e1([]),e6(null),D(x.MEDIA_FILES),rc(eX.id))}}),E===x.MEDIA_FILES&&(0,p.jsx)($,{files:e0,box:eX,loading:K,onSelect:e=>{if("back"===e.value){D(x.MEDIA_BOX_DETAIL),e6(null);return}"refresh"===e.value?rc(eX.id):(e6(null),X(!0),D(x.MEDIA_FILE_DETAIL),ru(e.value))}}),E===x.MEDIA_FILE_DETAIL&&(0,p.jsx)(G,{file:e4,loading:K,error:eU,onSelect:e=>{if("back"===e.value){D(x.MEDIA_FILES),e6(null);return}"refresh"===e.value&&ru(e4.id)}}),(0,p.jsx)(j,{})]})};var ea="1"===process.env.BRICKS_CLI_DISTRIBUTION,es=(n=i(function*(){if(ea)return void(0,o.render)((0,p.jsx)(eo,{}));var e=(yield t.e(8166).then(t.bind(t,29557))).TerminalInfoProvider;(0,o.render)((0,p.jsx)(e,{children:(0,p.jsx)(eo,{})}))}),function(){return n.apply(this,arguments)})},88161(e,r,t){t.r(r),t.d(r,{ActivityLogClient:()=>k,createActivityLogClient:()=>L});var n,i,l,o,a,s=t(67996),c=t(99436),u=t(5018),d=t(44668),x=t(4275),h=t(32235),f=t(62192),m=t(79657),p=t(64007);function y(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new g(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}function g(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(g=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new g(e)}function*v(e){if(e.errors?.length)throw Error(e.errors.map(e=>e.message).join("\n"));if(e.data){for(var r of Object.values(e.data))if(Array.isArray(r))for(var t of r)yield t}if(Array.isArray(e.incremental)){for(var n of e.incremental)if(Array.isArray(n.items))for(var i of n.items)yield i}}function j(){return(j=x(function*(e){var r=e.headers.get("content-type")||"";if(r.includes("application/json")){var t=yield h(e.json());if(t.errors?.length)throw Error(t.errors.map(e=>e.message).join("\n"));var n=Object.keys(t.data||{})[0];if(n&&Array.isArray(t.data[n]))for(var i of t.data[n])yield i;return}var l=r.match(/boundary="?([^";]+)"?/),o=l?l[1]:"-",a=`--${o}`,s="",c=!1,u=new TextDecoder,d=e=>{for(var r=0;-1!==(r=e.indexOf(a,r));){if(0===r||"\n"===e[r-1])return r;r+=a.length}return -1},x=function*(){for(var e;-1!==(e=d(s));){var r=s.slice(0,e);(s=s.slice(e+a.length)).startsWith("\r\n")?s=s.slice(2):s.startsWith("\n")&&(s=s.slice(1));var t=r.indexOf("\r\n\r\n"),n=-1!==t?r.slice(t+4).trim():r.trim();if(n){var i=void 0;try{i=JSON.parse(n)}catch{continue}if(yield*v(i),!1===i.hasNext){c=!0;return}}}};try{var m=!1,p=!1;try{for(var g,j,T=y(e.body);m=!(j=yield h(T.next())).done;m=!1){var b=j.value;if(s+=u.decode(b,{stream:!0}),yield*f(y(x()),h),c)break}}catch(e){p=!0,g=e}finally{try{m&&null!=T.return&&(yield h(T.return()))}finally{if(p)throw g}}}catch(e){if(!e.message?.includes("Premature close")||!c)throw e}if(!c&&s.trim()){var _,S=s.indexOf("\r\n\r\n"),E=-1!==S?s.slice(S+4).trim():s.trim();if(E&&!E.startsWith("--")){try{_=JSON.parse(E)}catch{}_&&(yield*f(y(v(_)),h),!1===_.hasNext&&(c=!0))}}e.body?.destroy()})).apply(this,arguments)}function T(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(T=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new T(e)}var b=Buffer.from("\r\n\r\n"),_=Buffer.from("\n\n"),S=e=>{var r=e.indexOf(b),t=b.length;if(-1===r&&(r=e.indexOf(_),t=_.length),-1===r)return null;var n=(e=>{var r={};for(var t of e.toString("latin1").split(/\r?\n/)){var n=t.indexOf(":");n<=0||(r[t.slice(0,n).trim().toLowerCase()]=t.slice(n+1).trim())}return r})(e.subarray(0,r)),i=e.subarray(r+t);if(!i.length)return null;var l=Number.parseInt(n["content-length"],10);return(Number.isInteger(l)&&l>=0&&l<=i.length?i=i.subarray(0,l):i.length>=2&&13===i[i.length-2]&&10===i[i.length-1]?i=i.subarray(0,i.length-2):i.length>=1&&10===i[i.length-1]&&(i=i.subarray(0,i.length-1)),i.length)?{headers:n,body:i}:null},E=(e,r)=>{for(var t=0;-1!==(t=e.indexOf(r,t));){if(0===t||10===e[t-1])return t;t+=r.length}return -1};function D(){return(D=x(function*(e){var r=e.headers.get("content-type")||"",t=r.match(/boundary="?([^";]+)"?/);if(!t)throw Error(`Expected a multipart stream, got "${r||"no content-type"}"`);var n=Buffer.from(`--${t[1]}`),i=Buffer.alloc(0);try{var l=!1,o=!1;try{for(var a,s,c=function(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new T(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}(e.body);l=!(s=yield h(c.next())).done;l=!1){var u=s.value;i=i.length?Buffer.concat([i,u]):Buffer.from(u);for(var d=void 0;-1!==(d=E(i,n));){var x=i.subarray(0,d);i=i.subarray(d+n.length);var f=x.length>4?S(x):null;if(f){var m=f.headers["x-timestamp"],p=m?Date.parse(m):NaN;yield{...f,timestamp:Number.isNaN(p)?null:p}}}}}catch(e){o=!0,a=e}finally{try{l&&null!=c.return&&(yield h(c.return()))}finally{if(o)throw a}}}finally{e.body?.destroy?.()}var y=i.length>4?S(i):null;if(y){var g=y.headers["x-timestamp"],v=g?Date.parse(g):NaN;yield{...y,timestamp:Number.isNaN(v)?null:v}}})).apply(this,arguments)}var I=`
2
2
  query AL_events($filter: EventsFilter!) {
3
3
  events(filter: $filter) @stream {
4
4
  device_id
@@ -16,4 +16,4 @@ import*as e from"ink";import*as r from"react";import*as t from"react/jsx-runtime
16
16
  timestamp
17
17
  }
18
18
  }
19
- `,B=["authorization"];function w(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new C(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}function C(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(C=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new C(e)}var k=d(function e(r,t){var n;u(this,e),this.baseUrl=r,this.auth="string"==typeof t?{kind:"token",token:t,getHeaders:(n=c(function*(){return{authorization:`Bearer ${t}`}}),function(){return n.apply(this,arguments)})}:t,this.token=this.auth?.token,this.graphqlUrl=`${r}/api/graphql`,this.fetch=function(e){var r=process.env.HTTPS_PROXY||process.env.https_proxy;if(!r||!e.startsWith("https://"))return m.Ay;var t=new p(r);return(e,r={})=>(0,m.Ay)(e,{...r,agent:t})}(r)},[{key:"authHeaders",value:(n=c(function*(){var e=yield this.auth.getHeaders();return{Authorization:e.authorization,...s(e,B)}}),function(){return n.apply(this,arguments)})},{key:"authenticatedFetch",value:(i=c(function*(e,r={}){var t,n=this,i=(t=c(function*(){return n.fetch(e,{...r,headers:{...r.headers,...yield n.authHeaders()}})}),function(){return t.apply(this,arguments)}),l=yield i();return 401!==l.status||"function"!=typeof this.auth.refresh?l:(l.body?.destroy?.(),yield this.auth.refresh(),i())}),function(e){return i.apply(this,arguments)})},{key:"streamQuery",value:function(e,r){var t=this;return x(function*(e,r,{signal:n}={}){var i=yield h(t.authenticatedFetch(t.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:'multipart/mixed; boundary="-", application/json'},body:JSON.stringify({query:e,variables:r}),signal:n}));if(!i.ok){var l=yield h(i.text().catch(()=>""));throw Error(`Activity-log query failed (${i.status}): ${l}`)}yield*f(w(function(e){return j.apply(this,arguments)}(i)),h)}).apply(this,arguments)}},{key:"events",value:function(e,r){var t=this;return x(function*(){yield*f(w(t.streamQuery(I,{filter:e},r)),h)})()}},{key:"screenshots",value:function(e,r){var t=this;return x(function*(){yield*f(w(t.streamQuery(A,{filter:e},r)),h)})()}},{key:"collectEvents",value:(l=c(function*(e,{limit:r,signal:t}={}){var n=[],i=!1,l=!1;try{for(var o,a,s=w(this.events(e,{signal:t}));i=!(a=yield s.next()).done;i=!1){var c=a.value;if(n.push(c),r&&n.length>=r)break}}catch(e){l=!0,o=e}finally{try{i&&null!=s.return&&(yield s.return())}finally{if(l)throw o}}return n}),function(e){return l.apply(this,arguments)})},{key:"collectScreenshots",value:(o=c(function*(e,{signal:r}={}){var t=[],n=!1,i=!1;try{for(var l,o,a=w(this.screenshots(e,{signal:r}));n=!(o=yield a.next()).done;n=!1){var s=o.value;t.push(s)}}catch(e){i=!0,l=e}finally{try{n&&null!=a.return&&(yield a.return())}finally{if(i)throw l}}return t}),function(e){return o.apply(this,arguments)})},{key:"downloadScreenshot",value:(a=c(function*(e,r,t,{signal:n}={}){var i=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot?ts=${encodeURIComponent(t)}`,l=yield this.authenticatedFetch(i,{signal:n});if(!l.ok){var o=yield l.text().catch(()=>"");throw Error(`Screenshot fetch failed (${l.status}): ${o}`)}return Buffer.from((yield l.arrayBuffer()))}),function(e,r,t){return a.apply(this,arguments)})},{key:"streamScreenshots",value:function(e,r,t,n){var i=this;return x(function*(e,r,t,n,{signal:l}={}){var o=`${i.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot/stream?from=${encodeURIComponent(t)}&to=${encodeURIComponent(n)}`,a=yield h(i.authenticatedFetch(o,{signal:l}));if(!a.ok){var s=yield h(a.text().catch(()=>""));throw Error(`Screenshot stream failed (${a.status}): ${s}`)}yield*f(w(function(e){return D.apply(this,arguments)}(a)),h)}).apply(this,arguments)}}]),L=(e,r)=>new k(e,r)},77768(e,r,t){t.d(r,{BZ:()=>v,KN:()=>p,kU:()=>m,o0:()=>g,oz:()=>y});var n,i,l,o,a=t(99436),s=t(16928),c=t(79896),u=t(35317),d=t(10750),x=e=>{try{return(0,u.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},h=(e,r,t)=>new Promise((n,i)=>{var l=[e,...r].join(" "),o=(0,u.spawn)(l,[],{cwd:t,stdio:["pipe","ignore","pipe"],shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{0===e?n():i(Error(Buffer.concat(a).toString().trim()||`Command failed with code ${e}`))}),o.on("error",i)}),f=(n=a(function*(e,r){try{var n=(yield t.e(7456).then(t.bind(t,79491))).format;return(yield n(r,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,r){return n.apply(this,arguments)}),m=(e=[])=>{var r=e.find(e=>"application.json"===e.name);if(!r)return"bricks-ctor";try{var t=JSON.parse(r.input);return d(t.name||"bricks-ctor")}catch{return"bricks-ctor"}},p=(i=a(function*(e,r){var t;return Promise.all(e.map((t=a(function*(e){var t=s.join(r,e.name),n=e.input;return e.formatable&&(n=yield f(n,t)),{...e,filePath:t,content:n}}),function(e){return t.apply(this,arguments)})))}),function(e,r){return i.apply(this,arguments)}),y=e=>{e.forEach(e=>{c.mkdirSync(s.dirname(e.filePath),{recursive:!0}),c.writeFileSync(e.filePath,e.content)})},g=(l=a(function*(e,r={}){var t="function"==typeof r.onStatus?r.onStatus:()=>{},n=!1,i=!1;if(!1!==r.install&&x("bun")){t("Installing dependencies (bun install)...");try{yield h("bun",["install"],e),n=!0}catch{}}if(!1!==r.git&&x("git")){t("Initializing git repository...");try{yield h("git",["init"],e),yield h("git",["add","."],e),yield h("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),i=!0}catch{}}return{bunInstalled:n,gitInitialized:i}}),function(e){return l.apply(this,arguments)}),v=(o=a(function*(e,r,t){var n=t.client,i=t.output,l=t.outputAsTarget;if(!n)throw Error("client is required");if(!i)throw Error("output directory is required");var o=(e=>{for(var r=s.resolve(e);;){if(c.existsSync(s.join(r,"application.json"))||c.existsSync(s.join(r,"module.json")))return r;var t=s.dirname(r);if(t===r)return null;r=t}})(l?s.dirname(s.resolve(i)):i);if(o)throw Error(`Cannot initialize a new BRICKS project inside an existing project (${o}). Choose a directory outside the project.`);var a="application"===e?n.applicationProject:n.moduleProject,u=yield a({id:r,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini});if(!u?.files)throw Error(`${e} project not found`);var d=m(u.files),x=l?s.resolve(i):s.resolve(i,d);if(c.existsSync(x))throw Error(`Directory already exists: ${x}`);c.mkdirSync(x,{recursive:!0}),y((yield p(u.files,x)));var h=yield g(x,t),f=h.bunInstalled,v=h.gitInitialized;return{success:!0,path:x,files:u.files.length,bunInstalled:f,gitInitialized:v}}),function(e,r,t){return o.apply(this,arguments)})},60450(e,r,t){t.r(r),t.d(r,{ScreenshotTimeoutError:()=>I,WorkspaceRateLimitError:()=>B,buildScreenshotUrl:()=>D,captureAndSaveScreenshot:()=>G,createScreenshotDeadline:()=>L,describeSavedImage:()=>M,detectImageFormat:()=>P,downloadScreenshot:()=>R,explainRateLimit:()=>C,fetchAndSaveScreenshot:()=>U,getDeviceScreenshot:()=>E,getSystemMediaBoxId:()=>S,isMediaEnabled:()=>_,rateLimitRetryAfterMs:()=>w,waitForNewScreenshot:()=>$,workspaceRateLimitMessage:()=>A});var n,i,l,o,a,s,c=t(44668),u=t(5018),d=t(63315),x=t(30409),h=t(40906),f=t(59410),m=t(99436),p=t(79657),y=t(73024),g=t(76760),v=t(48161),j=t(55872);function T(e,r,t){return r=x(r),d(e,b()?Reflect.construct(r,t||[],x(e).constructor):r.apply(e,t))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}var _=e=>e?.media_resource?.enable_media_workspace===!0,S=e=>_(e)&&e.media_resource?.system_media_box_id||null,E=(n=m(function*(e,r,t,n){var i=yield e.mediaFiles({boxId:r,userTags:[`bricks_screenshot_${t}`],limit:1},n);return i?.[0]||null}),function(e,r,t,i){return n.apply(this,arguments)}),D=(e,{preferThumbnail:r=!1}={})=>{if(!e?.meta?.storageEndpoint)return null;var t=e.meta,n=t.storageEndpoint,i=t.originalFileKey,l=(r?(e=>{var r=e?.meta;if(!r)return null;if("Video"===e.fileType&&r.videoThumbOriginalFileKey)return r.videoThumbOriginalFileKey;var t=r.imageVersions||[];if(!Array.isArray(t)||0===t.length)return null;var n=t.filter(e=>e?.strategy==="BOUNDED"&&"number"==typeof e.width).sort((e,r)=>e.width-r.width);return(n[0]||t[0])?.key||null})(e):null)||i;return l?`${n}/${l}`:null},I=function(e){function r(e,t){var n;return u(this,r),(n=T(this,r,[`Timed out after ${e} s while ${t}`])).name="ScreenshotTimeoutError",n}return h(r,e),c(r)}(f(Error)),A=e=>`The workspace request limit was reached (one budget for every CLI, CTOR and MCP client of the workspace); try again in ${Math.max(1,Math.ceil(e/1e3))} s`,B=function(e){function r(e,t){var n;return u(this,r),(n=T(this,r,[A(e),{cause:t}])).name="WorkspaceRateLimitError",n.retryAfterMs=e,n}return h(r,e),c(r)}(f(Error)),w=e=>{if(e instanceof B)return e.retryAfterMs;var r=e?.graphQLErrors?.find(e=>e?.extensions?.code==="rate_limited"),t=r?.extensions.retryAfterMs;if(Number.isFinite(t)&&t>0)return t;var n=/too many requests, please try again in (\d+) seconds?/i.exec(e?.message||"");return n?1e3*Number(n[1]):r?6e4:null},C=e=>{var r=w(e);return null===r||e instanceof B?e:new B(r,e)},k=Symbol("screenshot-timed-out"),L=(e,{signal:r}={})=>{var t=new AbortController,n=performance.now()+1e3*e,i=setTimeout(()=>t.abort(k),1e3*e),l=()=>t.abort(r.reason);r?.aborted?l():r?.addEventListener("abort",l,{once:!0});var o=t.signal,a=(r,t)=>new Promise((n,i)=>{var l=()=>i(o.reason===k?new I(e,t):o.reason);o.addEventListener("abort",l,{once:!0}),o.aborted&&l(),Promise.resolve(r).then(n,i).finally(()=>o.removeEventListener("abort",l))});return{seconds:e,signal:o,run:a,remainingMs:()=>Math.max(0,n-performance.now()),requestOptions:{context:{fetchOptions:{signal:o}}},sleep:(e,r)=>{var t;return a(new Promise(r=>{t=setTimeout(r,e)}),r).finally(()=>clearTimeout(t))},clear:()=>{clearTimeout(i),r?.removeEventListener("abort",l)}}},O=[{format:"PNG",contentType:"image/png",extensions:[".png"],test:e=>e.length>=8&&0x89504e47===e.readUInt32BE(0)&&0xd0a1a0a===e.readUInt32BE(4)},{format:"JPEG",contentType:"image/jpeg",extensions:[".jpg",".jpeg"],test:e=>e.length>=3&&255===e[0]&&216===e[1]&&255===e[2]},{format:"WebP",contentType:"image/webp",extensions:[".webp"],test:e=>e.length>=12&&"RIFF"===e.toString("latin1",0,4)&&"WEBP"===e.toString("latin1",8,12)},{format:"GIF",contentType:"image/gif",extensions:[".gif"],test:e=>e.length>=6&&/^GIF8[79]a$/.test(e.toString("latin1",0,6))}],P=e=>{var r=O.find(({test:r})=>r(e));if(!r)return null;var t=r.format;return{format:t,contentType:r.contentType,extensions:r.extensions}},M=(e,r)=>{if(!r)return{extensionMatches:null,warning:null};var t=g.extname(e).toLowerCase();return r.extensions.includes(t)?{extensionMatches:!0,warning:null}:{extensionMatches:!1,warning:`Saved ${r.format} data to ${e}; use a ${r.extensions[0]} name to match`}},R=(i=m(function*(e,r=null,{signal:t}={}){var n,i=new AbortController,l=()=>i.abort();t?.addEventListener("abort",l,{once:!0});try{var o=yield(0,p.Ay)(e,{signal:i.signal});if(!o.ok)throw Error(`Failed to download screenshot: ${o.statusText}`);n=yield o.buffer()}finally{t?.removeEventListener("abort",l),i.abort()}var a=P(n),s=a?a.extensions[0]:".bin",c=r||g.join(v.tmpdir(),`bricks-screenshot-${Date.now()}${s}`),u=g.dirname(c);return y.existsSync(u)||y.mkdirSync(u,{recursive:!0}),y.writeFileSync(c,n),{path:c,buffer:n,detected:a}}),function(e){return i.apply(this,arguments)}),N=(l=m(function*(e,r,{deadline:t,preferThumbnail:n}){var i=D(e,{preferThumbnail:n});if(!i)return{error:"Could not build screenshot URL"};var l=R(i,r,{signal:t?.signal}),o=yield t?t.run(l,"downloading the screenshot"):l;return{path:o.path,file:e,url:i,bytes:o.buffer.length,format:o.detected?.format||null,contentType:o.detected?.contentType||null,...M(o.path,o.detected)}}),function(e,r,t){return l.apply(this,arguments)}),U=(o=m(function*(e,r,t,n=null,i={}){var l=i.deadline,o=S(r);if(!o)return{error:"Media workspace not enabled for this workspace"};var a=E(e,o,t,l?.requestOptions),s=yield l?l.run(a,"fetching the screenshot"):a;if(!s)return{error:"No screenshot available for this device"};var c=yield N(s,n,i);return c.error?c:{...c,captureRequested:!1,fresh:!1,updatedAt:(0,j.__)(s,null)}}),function(e,r,t){return o.apply(this,arguments)}),$=(a=m(function*({latest:e,baseline:r,deadline:t,maxWaitMs:n=1/0}){var i="waiting for the device to capture";yield t.sleep(j.Gp,i);for(var l=j.Gp,o=r;;){var a=void 0,s=null;try{if(o=yield e(),(0,j.Jc)(o,r))return{file:o,rateLimitRetryAfterMs:null};a=(0,j.DQ)(l)}catch(e){if(null===(s=w(e)))throw e;a=s}if(!(l+a<=n&&t.remainingMs()>j.SB+a))return{file:o,rateLimitRetryAfterMs:s};yield t.sleep(a,i),l+=a}}),function(e){return a.apply(this,arguments)}),G=(s=m(function*(e,r,t,n=null,i={}){var l=i.preferThumbnail,o=i.timeoutSeconds,a=void 0===o?j.t8:o,s=i.maxWaitSeconds,c=i.signal,u=i.onStep,d=void 0===u?()=>{}:u,x=S(r);if(!x)return{error:"Media workspace not enabled for this workspace"};var h=i.deadline||L(a,{signal:c}),f=()=>h.run(E(e,x,t,h.requestOptions),"fetching the screenshot");try{try{m=yield f(),d("Sending screenshot request to device..."),yield h.run(e.controlDevice({id:t,type:"take-screenshot"},h.requestOptions),"sending the screenshot request")}catch(e){throw C(e)}d("Waiting for device to capture screenshot...");var m,p=yield $({latest:f,baseline:m,deadline:h,maxWaitMs:1e3*(void 0===s?1/0:s)}),y=p.file,g=p.rateLimitRetryAfterMs;if(!y)return{error:null===g?"No screenshot available for this device":A(g)};var v=(0,j.Jc)(y,m);d("Fetching screenshot...");var T=yield N(y,n,{deadline:h,preferThumbnail:l&&!v});if(T.error)return T;return{...T,captureRequested:!0,fresh:v,updatedAt:(0,j.__)(y,m),rateLimitRetryAfterMs:g}}finally{i.deadline||h.clear()}}),function(e,r,t){return s.apply(this,arguments)})}};
19
+ `,w=["authorization"];function B(e){var r,t,n,i=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);i--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new C(r.call(e));t="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}function C(e){function r(e){if(Object(e)!==e)return Promise.reject(TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return(C=function(e){this.s=e,this.n=e.next}).prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new C(e)}var k=d(function e(r,t){var n;u(this,e),this.baseUrl=r,this.auth="string"==typeof t?{kind:"token",token:t,getHeaders:(n=c(function*(){return{authorization:`Bearer ${t}`}}),function(){return n.apply(this,arguments)})}:t,this.token=this.auth?.token,this.graphqlUrl=`${r}/api/graphql`,this.fetch=function(e){var r=process.env.HTTPS_PROXY||process.env.https_proxy;if(!r||!e.startsWith("https://"))return m.Ay;var t=new p(r);return(e,r={})=>(0,m.Ay)(e,{...r,agent:t})}(r)},[{key:"authHeaders",value:(n=c(function*(){var e=yield this.auth.getHeaders();return{Authorization:e.authorization,...s(e,w)}}),function(){return n.apply(this,arguments)})},{key:"authenticatedFetch",value:(i=c(function*(e,r={}){var t,n=this,i=(t=c(function*(){return n.fetch(e,{...r,headers:{...r.headers,...yield n.authHeaders()}})}),function(){return t.apply(this,arguments)}),l=yield i();return 401!==l.status||"function"!=typeof this.auth.refresh?l:(l.body?.destroy?.(),yield this.auth.refresh(),i())}),function(e){return i.apply(this,arguments)})},{key:"streamQuery",value:function(e,r){var t=this;return x(function*(e,r,{signal:n}={}){var i=yield h(t.authenticatedFetch(t.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:'multipart/mixed; boundary="-", application/json'},body:JSON.stringify({query:e,variables:r}),signal:n}));if(!i.ok){var l=yield h(i.text().catch(()=>""));throw Error(`Activity-log query failed (${i.status}): ${l}`)}yield*f(B(function(e){return j.apply(this,arguments)}(i)),h)}).apply(this,arguments)}},{key:"events",value:function(e,r){var t=this;return x(function*(){yield*f(B(t.streamQuery(I,{filter:e},r)),h)})()}},{key:"screenshots",value:function(e,r){var t=this;return x(function*(){yield*f(B(t.streamQuery(A,{filter:e},r)),h)})()}},{key:"collectEvents",value:(l=c(function*(e,{limit:r,signal:t}={}){var n=[],i=!1,l=!1;try{for(var o,a,s=B(this.events(e,{signal:t}));i=!(a=yield s.next()).done;i=!1){var c=a.value;if(n.push(c),r&&n.length>=r)break}}catch(e){l=!0,o=e}finally{try{i&&null!=s.return&&(yield s.return())}finally{if(l)throw o}}return n}),function(e){return l.apply(this,arguments)})},{key:"collectScreenshots",value:(o=c(function*(e,{signal:r}={}){var t=[],n=!1,i=!1;try{for(var l,o,a=B(this.screenshots(e,{signal:r}));n=!(o=yield a.next()).done;n=!1){var s=o.value;t.push(s)}}catch(e){i=!0,l=e}finally{try{n&&null!=a.return&&(yield a.return())}finally{if(i)throw l}}return t}),function(e){return o.apply(this,arguments)})},{key:"downloadScreenshot",value:(a=c(function*(e,r,t,{signal:n}={}){var i=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot?ts=${encodeURIComponent(t)}`,l=yield this.authenticatedFetch(i,{signal:n});if(!l.ok){var o=yield l.text().catch(()=>"");throw Error(`Screenshot fetch failed (${l.status}): ${o}`)}return Buffer.from((yield l.arrayBuffer()))}),function(e,r,t){return a.apply(this,arguments)})},{key:"streamScreenshots",value:function(e,r,t,n){var i=this;return x(function*(e,r,t,n,{signal:l}={}){var o=`${i.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot/stream?from=${encodeURIComponent(t)}&to=${encodeURIComponent(n)}`,a=yield h(i.authenticatedFetch(o,{signal:l}));if(!a.ok){var s=yield h(a.text().catch(()=>""));throw Error(`Screenshot stream failed (${a.status}): ${s}`)}yield*f(B(function(e){return D.apply(this,arguments)}(a)),h)}).apply(this,arguments)}}]),L=(e,r)=>new k(e,r)},77768(e,r,t){t.d(r,{BZ:()=>v,KN:()=>p,kU:()=>m,o0:()=>g,oz:()=>y});var n,i,l,o,a=t(99436),s=t(16928),c=t(79896),u=t(35317),d=t(10750),x=e=>{try{return(0,u.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},h=(e,r,t)=>new Promise((n,i)=>{var l=[e,...r].join(" "),o=(0,u.spawn)(l,[],{cwd:t,stdio:["pipe","ignore","pipe"],shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{0===e?n():i(Error(Buffer.concat(a).toString().trim()||`Command failed with code ${e}`))}),o.on("error",i)}),f=(n=a(function*(e,r){try{var n=(yield t.e(7456).then(t.bind(t,79491))).format;return(yield n(r,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,r){return n.apply(this,arguments)}),m=(e=[])=>{var r=e.find(e=>"application.json"===e.name);if(!r)return"bricks-ctor";try{var t=JSON.parse(r.input);return d(t.name||"bricks-ctor")}catch{return"bricks-ctor"}},p=(i=a(function*(e,r){var t;return Promise.all(e.map((t=a(function*(e){var t=s.join(r,e.name),n=e.input;return e.formatable&&(n=yield f(n,t)),{...e,filePath:t,content:n}}),function(e){return t.apply(this,arguments)})))}),function(e,r){return i.apply(this,arguments)}),y=e=>{e.forEach(e=>{c.mkdirSync(s.dirname(e.filePath),{recursive:!0}),c.writeFileSync(e.filePath,e.content)})},g=(l=a(function*(e,r={}){var t="function"==typeof r.onStatus?r.onStatus:()=>{},n=!1,i=!1;if(!1!==r.install&&x("bun")){t("Installing dependencies (bun install)...");try{yield h("bun",["install"],e),n=!0}catch{}}if(!1!==r.git&&x("git")){t("Initializing git repository...");try{yield h("git",["init"],e),yield h("git",["add","."],e),yield h("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),i=!0}catch{}}return{bunInstalled:n,gitInitialized:i}}),function(e){return l.apply(this,arguments)}),v=(o=a(function*(e,r,t){var n=t.client,i=t.output,l=t.outputAsTarget;if(!n)throw Error("client is required");if(!i)throw Error("output directory is required");var o=(e=>{for(var r=s.resolve(e);;){if(c.existsSync(s.join(r,"application.json"))||c.existsSync(s.join(r,"module.json")))return r;var t=s.dirname(r);if(t===r)return null;r=t}})(l?s.dirname(s.resolve(i)):i);if(o)throw Error(`Cannot initialize a new BRICKS project inside an existing project (${o}). Choose a directory outside the project.`);var a="application"===e?n.applicationProject:n.moduleProject,u=yield a({id:r,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini});if(!u?.files)throw Error(`${e} project not found`);var d=m(u.files),x=l?s.resolve(i):s.resolve(i,d);if(c.existsSync(x))throw Error(`Directory already exists: ${x}`);c.mkdirSync(x,{recursive:!0}),y((yield p(u.files,x)));var h=yield g(x,t),f=h.bunInstalled,v=h.gitInitialized;return{success:!0,path:x,files:u.files.length,warnings:u.warnings||[],bunInstalled:f,gitInitialized:v}}),function(e,r,t){return o.apply(this,arguments)})},60450(e,r,t){t.r(r),t.d(r,{ScreenshotTimeoutError:()=>I,WorkspaceRateLimitError:()=>w,buildScreenshotUrl:()=>D,captureAndSaveScreenshot:()=>G,createScreenshotDeadline:()=>L,describeSavedImage:()=>M,detectImageFormat:()=>P,downloadScreenshot:()=>R,explainRateLimit:()=>C,fetchAndSaveScreenshot:()=>U,getDeviceScreenshot:()=>E,getSystemMediaBoxId:()=>S,isMediaEnabled:()=>_,rateLimitRetryAfterMs:()=>B,waitForNewScreenshot:()=>$,workspaceRateLimitMessage:()=>A});var n,i,l,o,a,s,c=t(44668),u=t(5018),d=t(63315),x=t(30409),h=t(40906),f=t(59410),m=t(99436),p=t(79657),y=t(73024),g=t(76760),v=t(48161),j=t(55872);function T(e,r,t){return r=x(r),d(e,b()?Reflect.construct(r,t||[],x(e).constructor):r.apply(e,t))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}var _=e=>e?.media_resource?.enable_media_workspace===!0,S=e=>_(e)&&e.media_resource?.system_media_box_id||null,E=(n=m(function*(e,r,t,n){var i=yield e.mediaFiles({boxId:r,userTags:[`bricks_screenshot_${t}`],limit:1},n);return i?.[0]||null}),function(e,r,t,i){return n.apply(this,arguments)}),D=(e,{preferThumbnail:r=!1}={})=>{if(!e?.meta?.storageEndpoint)return null;var t=e.meta,n=t.storageEndpoint,i=t.originalFileKey,l=(r?(e=>{var r=e?.meta;if(!r)return null;if("Video"===e.fileType&&r.videoThumbOriginalFileKey)return r.videoThumbOriginalFileKey;var t=r.imageVersions||[];if(!Array.isArray(t)||0===t.length)return null;var n=t.filter(e=>e?.strategy==="BOUNDED"&&"number"==typeof e.width).sort((e,r)=>e.width-r.width);return(n[0]||t[0])?.key||null})(e):null)||i;return l?`${n}/${l}`:null},I=function(e){function r(e,t){var n;return u(this,r),(n=T(this,r,[`Timed out after ${e} s while ${t}`])).name="ScreenshotTimeoutError",n}return h(r,e),c(r)}(f(Error)),A=e=>`The workspace request limit was reached (one budget for every CLI, CTOR and MCP client of the workspace); try again in ${Math.max(1,Math.ceil(e/1e3))} s`,w=function(e){function r(e,t){var n;return u(this,r),(n=T(this,r,[A(e),{cause:t}])).name="WorkspaceRateLimitError",n.retryAfterMs=e,n}return h(r,e),c(r)}(f(Error)),B=e=>{if(e instanceof w)return e.retryAfterMs;var r=e?.graphQLErrors?.find(e=>e?.extensions?.code==="rate_limited"),t=r?.extensions.retryAfterMs;if(Number.isFinite(t)&&t>0)return t;var n=/too many requests, please try again in (\d+) seconds?/i.exec(e?.message||"");return n?1e3*Number(n[1]):r?6e4:null},C=e=>{var r=B(e);return null===r||e instanceof w?e:new w(r,e)},k=Symbol("screenshot-timed-out"),L=(e,{signal:r}={})=>{var t=new AbortController,n=performance.now()+1e3*e,i=setTimeout(()=>t.abort(k),1e3*e),l=()=>t.abort(r.reason);r?.aborted?l():r?.addEventListener("abort",l,{once:!0});var o=t.signal,a=(r,t)=>new Promise((n,i)=>{var l=()=>i(o.reason===k?new I(e,t):o.reason);o.addEventListener("abort",l,{once:!0}),o.aborted&&l(),Promise.resolve(r).then(n,i).finally(()=>o.removeEventListener("abort",l))});return{seconds:e,signal:o,run:a,remainingMs:()=>Math.max(0,n-performance.now()),requestOptions:{context:{fetchOptions:{signal:o}}},sleep:(e,r)=>{var t;return a(new Promise(r=>{t=setTimeout(r,e)}),r).finally(()=>clearTimeout(t))},clear:()=>{clearTimeout(i),r?.removeEventListener("abort",l)}}},O=[{format:"PNG",contentType:"image/png",extensions:[".png"],test:e=>e.length>=8&&0x89504e47===e.readUInt32BE(0)&&0xd0a1a0a===e.readUInt32BE(4)},{format:"JPEG",contentType:"image/jpeg",extensions:[".jpg",".jpeg"],test:e=>e.length>=3&&255===e[0]&&216===e[1]&&255===e[2]},{format:"WebP",contentType:"image/webp",extensions:[".webp"],test:e=>e.length>=12&&"RIFF"===e.toString("latin1",0,4)&&"WEBP"===e.toString("latin1",8,12)},{format:"GIF",contentType:"image/gif",extensions:[".gif"],test:e=>e.length>=6&&/^GIF8[79]a$/.test(e.toString("latin1",0,6))}],P=e=>{var r=O.find(({test:r})=>r(e));if(!r)return null;var t=r.format;return{format:t,contentType:r.contentType,extensions:r.extensions}},M=(e,r)=>{if(!r)return{extensionMatches:null,warning:null};var t=g.extname(e).toLowerCase();return r.extensions.includes(t)?{extensionMatches:!0,warning:null}:{extensionMatches:!1,warning:`Saved ${r.format} data to ${e}; use a ${r.extensions[0]} name to match`}},R=(i=m(function*(e,r=null,{signal:t}={}){var n,i=new AbortController,l=()=>i.abort();t?.addEventListener("abort",l,{once:!0});try{var o=yield(0,p.Ay)(e,{signal:i.signal});if(!o.ok)throw Error(`Failed to download screenshot: ${o.statusText}`);n=yield o.buffer()}finally{t?.removeEventListener("abort",l),i.abort()}var a=P(n),s=a?a.extensions[0]:".bin",c=r||g.join(v.tmpdir(),`bricks-screenshot-${Date.now()}${s}`),u=g.dirname(c);return y.existsSync(u)||y.mkdirSync(u,{recursive:!0}),y.writeFileSync(c,n),{path:c,buffer:n,detected:a}}),function(e){return i.apply(this,arguments)}),N=(l=m(function*(e,r,{deadline:t,preferThumbnail:n}){var i=D(e,{preferThumbnail:n});if(!i)return{error:"Could not build screenshot URL"};var l=R(i,r,{signal:t?.signal}),o=yield t?t.run(l,"downloading the screenshot"):l;return{path:o.path,file:e,url:i,bytes:o.buffer.length,format:o.detected?.format||null,contentType:o.detected?.contentType||null,...M(o.path,o.detected)}}),function(e,r,t){return l.apply(this,arguments)}),U=(o=m(function*(e,r,t,n=null,i={}){var l=i.deadline,o=S(r);if(!o)return{error:"Media workspace not enabled for this workspace"};var a=E(e,o,t,l?.requestOptions),s=yield l?l.run(a,"fetching the screenshot"):a;if(!s)return{error:"No screenshot available for this device"};var c=yield N(s,n,i);return c.error?c:{...c,captureRequested:!1,fresh:!1,updatedAt:(0,j.__)(s,null)}}),function(e,r,t){return o.apply(this,arguments)}),$=(a=m(function*({latest:e,baseline:r,deadline:t,maxWaitMs:n=1/0}){var i="waiting for the device to capture";yield t.sleep(j.Gp,i);for(var l=j.Gp,o=r;;){var a=void 0,s=null;try{if(o=yield e(),(0,j.Jc)(o,r))return{file:o,rateLimitRetryAfterMs:null};a=(0,j.DQ)(l)}catch(e){if(null===(s=B(e)))throw e;a=s}if(!(l+a<=n&&t.remainingMs()>j.SB+a))return{file:o,rateLimitRetryAfterMs:s};yield t.sleep(a,i),l+=a}}),function(e){return a.apply(this,arguments)}),G=(s=m(function*(e,r,t,n=null,i={}){var l=i.preferThumbnail,o=i.timeoutSeconds,a=void 0===o?j.t8:o,s=i.maxWaitSeconds,c=i.signal,u=i.onStep,d=void 0===u?()=>{}:u,x=S(r);if(!x)return{error:"Media workspace not enabled for this workspace"};var h=i.deadline||L(a,{signal:c}),f=()=>h.run(E(e,x,t,h.requestOptions),"fetching the screenshot");try{try{m=yield f(),d("Sending screenshot request to device..."),yield h.run(e.controlDevice({id:t,type:"take-screenshot"},h.requestOptions),"sending the screenshot request")}catch(e){throw C(e)}d("Waiting for device to capture screenshot...");var m,p=yield $({latest:f,baseline:m,deadline:h,maxWaitMs:1e3*(void 0===s?1/0:s)}),y=p.file,g=p.rateLimitRetryAfterMs;if(!y)return{error:null===g?"No screenshot available for this device":A(g)};var v=(0,j.Jc)(y,m);d("Fetching screenshot...");var T=yield N(y,n,{deadline:h,preferThumbnail:l&&!v});if(T.error)return T;return{...T,captureRequested:!0,fresh:v,updatedAt:(0,j.__)(y,m),rateLimitRetryAfterMs:g}}finally{i.deadline||h.clear()}}),function(e,r,t){return s.apply(this,arguments)})}};