@fugood/bricks-cli 2.25.0-beta.60 → 2.25.0-beta.62
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/10.js +1 -1
- package/lib/111.js +2 -0
- package/lib/117.js +1 -1
- package/lib/192.js +30 -0
- package/lib/209.js +112 -0
- package/lib/212.js +1 -0
- package/lib/215.js +1 -0
- package/lib/223.js +4 -4
- package/lib/247.js +1 -0
- package/lib/274.js +16 -0
- package/lib/306.js +1 -0
- package/lib/320.js +3 -0
- package/lib/332.js +13 -0
- package/lib/358.js +1 -0
- package/lib/370.js +1 -0
- package/lib/387.js +35 -0
- package/lib/405.js +1 -0
- package/lib/430.js +1 -0
- package/lib/456.js +2 -2
- package/lib/479.js +1231 -0
- package/lib/486.js +1 -0
- package/lib/511.js +1 -1
- package/lib/557.js +1 -0
- package/lib/563.js +4 -0
- package/lib/574.js +1 -0
- package/lib/583.js +22 -0
- package/lib/645.js +1 -0
- package/lib/648.js +1 -0
- package/lib/658.js +2 -0
- package/lib/663.js +1 -0
- package/lib/690.js +1 -0
- package/lib/708.js +9 -0
- package/lib/759.js +1 -0
- package/lib/785.js +1 -0
- package/lib/818.js +1 -0
- package/lib/831.js +1 -0
- package/lib/866.js +7 -0
- package/lib/907.js +872 -0
- package/lib/915.js +7 -0
- package/lib/917.js +1 -0
- package/lib/936.js +1 -0
- package/lib/940.js +19 -1
- package/lib/index.js +102 -1140
- package/lib/simulator-main.mjs +21 -0
- package/lib/simulator-preload.cjs +1 -0
- package/package.json +27 -7
- package/lib/249.js +0 -1
- package/lib/3.js +0 -1
- package/lib/587.js +0 -7
- package/lib/647.js +0 -30
package/lib/940.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import*as e from"ink";import*as l from"react";import{Fragment as r,jsx as t,jsxs as n}from"react/jsx-runtime";export const __rspack_esm_id=940;export const __rspack_esm_ids=[940];export const __webpack_modules__={8498(l){l.exports=e},51649(e){e.exports=l},92319(e,l,i){i.r(l),i.d(l,{AppList:()=>w,CONTROL_ACTIONS:()=>x,MainMenu:()=>S,Header:()=>y,ModuleDetail:()=>M,ONLINE_THRESHOLD_MS:()=>p,ShortEditEditor:()=>J,MediaFileList:()=>$,App:()=>ea,DeviceDetail:()=>C,VIEWS:()=>m,runInteractiveMode:()=>ed,DeviceList:()=>B,MediaBoxList:()=>G,Loading:()=>b,DeviceControl:()=>k,ProjectInitView:()=>eo,GroupDetail:()=>U,ModuleList:()=>P,MediaBoxDetail:()=>j,GroupList:()=>R,Footer:()=>_,DeviceStatus:()=>D,AppDetail:()=>O,DeviceScreenshot:()=>L,MediaFileDetail:()=>V});var o,a=i(99436),c=i(51649),d=i(8498),u=i(68832),s=i(85382),h=i(47988),g=i(60450),m={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"},x=[{label:"Refresh Application",value:"refresh"},{label:"Clear Cache",value:"clear-cache"},{label:"Take Screenshot",value:"take-screenshot"},{label:"Open System Menu",value:"system-menu-open"},{label:"Close System Menu",value:"system-menu-close"},{label:"Open Debug Panel",value:"debug-panel-open"},{label:"Close Debug Panel",value:"debug-panel-close"},{label:"Enable Logging",value:"logging-on"},{label:"Disable Logging",value:"logging-off"},{label:"← Back",value:"back"}],p=3e5,f=i(47882),T=(e,l=!0)=>{var r=Math.floor(60),t=u((0,c.useState)(r),2),n=t[0],i=t[1],o=u((0,c.useState)(null),2),a=o[0],d=o[1],s=(0,c.useRef)(e);(0,c.useEffect)(()=>{s.current=e},[e]);var h=(0,c.useCallback)(()=>{i(r),d(Date.now())},[r]);return(0,c.useEffect)(()=>{if(l){var e=setInterval(()=>{i(e=>e<=1?(s.current?.(),d(Date.now()),r):e-1)},1e3);return()=>clearInterval(e)}},[l,r]),(0,c.useEffect)(()=>{l&&(i(r),d(Date.now()))},[l,r]),{countdown:n,lastRefreshTime:a,resetCountdown:h}},v=({countdown:e,lastRefreshTime:l})=>t(d.Box,{children:n(d.Text,{color:"gray",children:["Next refresh in ",n(d.Text,{color:"cyan",children:[e,"s"]}),l&&n(d.Text,{color:"gray",children:[" (last: ",l?new Date(l).toLocaleTimeString():null,")"]})]})}),y=({workspace:e,view:l})=>n(d.Box,{flexDirection:"column",marginBottom:1,children:[n(d.Box,{children:[t(d.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),t(d.Text,{color:"gray",children:" - Interactive Mode"})]}),n(d.Box,{children:[t(d.Text,{color:"gray",children:"Workspace: "}),t(d.Text,{color:"green",children:e?.name||"Not connected"}),t(d.Text,{color:"gray",children:" | View: "}),t(d.Text,{color:"yellow",children:l})]}),t(d.Text,{color:"gray",children:"─".repeat(60)})]}),_=()=>n(d.Box,{marginTop:1,flexDirection:"column",children:[t(d.Text,{color:"gray",children:"─".repeat(60)}),n(d.Text,{color:"gray",children:["Press ",t(d.Text,{color:"cyan",children:"q"})," to quit, ",t(d.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),b=({text:e})=>n(d.Box,{children:[t(d.Text,{color:"green",children:t(f.A,{type:"dots"})}),n(d.Text,{children:[" ",e||"Loading..."]})]}),D=({lastAliveTime:e})=>{if(!e)return t(d.Text,{color:"gray",children:"○ Unknown"});var l=Date.now()-new Date(e).getTime();if(l<=p)return t(d.Text,{color:"green",children:"● Online"});var r=Math.floor(l/6e4);if(r<60)return n(d.Text,{color:"yellow",children:["○ Offline (",r,"m ago)"]});var i=Math.floor(r/60);if(i<24)return n(d.Text,{color:"red",children:["○ Offline (",i,"h ago)"]});var o=Math.floor(i/24);return n(d.Text,{color:"red",children:["○ Offline (",o,"d ago)"]})},E=i(48724),S=({onSelect:e,mediaEnabled:l,activityLogEnabled:r})=>{var i=[{label:"Devices",value:m.DEVICES},{label:"Applications",value:m.APPS},{label:"Modules",value:m.MODULES},{label:"Device Groups",value:m.GROUPS},...l?[{label:"Media Flow",value:m.MEDIA_BOXES}]:[],...r?[{label:"Activity Log",value:m.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),t(E.Ay,{items:i,onSelect:e})]})},I="1"===process.env.BRICKS_CLI_DISTRIBUTION,A=e=>{var l=u((0,c.useState)(null),2),r=l[0],n=l[1];return((0,c.useEffect)(()=>{if(!I){var e=!0;return i.e(166).then(i.bind(i,29557)).then(l=>{e&&n(()=>l.default)}).catch(()=>{e&&n(!1)}),()=>{e=!1}}},[]),I||!1===r)?t(d.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):r?t(r,{...e}):t(b,{text:"Preparing image preview..."})},B=({devices:e,loading:l,onSelect:r,countdown:i,lastRefreshTime:o})=>{if(l)return t(b,{text:"Loading devices..."});if(!e?.length)return n(d.Box,{flexDirection:"column",children:[t(d.Text,{color:"yellow",children:"No devices found"}),t(v,{countdown:i,lastRefreshTime:o})]});var a=[...e.map(e=>{var l=(e=>{if(!e)return"○ Unknown";var l=Date.now()-new Date(e).getTime();if(l<=p)return"● Online";var r=Math.floor(l/6e4);if(r<60)return`○ ${r}m ago`;var t=Math.floor(r/60);if(t<24)return`○ ${t}h ago`;var n=Math.floor(t/24);return`○ ${n}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time);return{label:`${l} - ${e.name||e.device_name}`,value:e._id,device:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Box,{marginBottom:1,children:[n(d.Text,{bold:!0,children:["Devices (",e.length,")"]}),t(d.Text,{color:"gray",children:" - "}),t(v,{countdown:i,lastRefreshTime:o})]}),t(E.Ay,{items:a,onSelect:r})]})},C=({device:e,loading:l,error:r,onSelect:i,mediaEnabled:o,countdown:a,lastRefreshTime:c})=>{if(l)return t(b,{text:"Loading device..."});if(r)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",r]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return t(d.Text,{color:"red",children:"Device not found"});var u=[{label:"Control Device",value:"control"},...o?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],s=e.entry_detail,h=s?.screen,g=s?.update,m=s?.local_sync;return n(d.Box,{flexDirection:"column",children:[n(d.Box,{children:[t(d.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),t(d.Text,{color:"gray",children:" - "}),t(v,{countdown:a,lastRefreshTime:c})]}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Box,{children:[t(d.Text,{color:"gray",children:"Status: "}),t(D,{lastAliveTime:s?.watch_dog_timer?.last_alive_time})]}),n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),s?.application&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Application"}),n(d.Text,{color:"gray",children:[" Name: ",s.application.name]}),n(d.Text,{color:"gray",children:[" Mode: ",s.operation_mode||"N/A"]})]}),h&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Screen"}),h.resolution&&n(d.Text,{color:"gray",children:[" ","Resolution: ",h.resolution.width,"x",h.resolution.height,h.resolution.scale&&` @${h.resolution.scale}x`]}),h.orientation&&n(d.Text,{color:"gray",children:[" Orientation: ",h.orientation]}),h.touch&&n(d.Text,{color:"gray",children:[" ","Touch:"," ",h.touch.available?`Yes (${h.touch.touch_point} points)`:"No"]})]}),(s?.memory_usage||s?.disk_usage)&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"System"}),s.memory_usage&&n(d.Text,{color:"gray",children:[" Memory: ",Math.round(100*s.memory_usage),"%"]}),s.disk_usage&&n(d.Text,{color:"gray",children:[" Disk: ",Math.round(100*s.disk_usage),"%"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Capabilities"}),n(d.Text,{color:"gray",children:[" ","Sound: ",s?.sound?.available?"✓":"✗"," | ","Camera: ",s?.camera?.available?"✓":"✗"," | ","Audio In: ",s?.audio_in?.available?"✓":"✗"]})]}),m&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Local Sync"}),n(d.Text,{color:"gray",children:[" ","Role: ",m.is_main?"Main":"Peer",m.peer_count>0&&` | Peers: ${m.peer_count}`,m.mean_latency&&` | Latency: ${m.mean_latency}ms`]})]}),g&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Update"}),n(d.Text,{color:g.need_update?"yellow":"gray",children:[" ","Status: ",g.need_update?"⚠ Update available":"✓ Up to date"]}),g.current_version&&n(d.Text,{color:"gray",children:[" Version: ",g.current_version]})]})]}),t(E.Ay,{items:u,onSelect:i})]})},k=({device:e,onSelect:l,controlling:r,controlResult:i})=>n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),r&&t(b,{text:"Sending command..."}),i&&t(d.Text,{color:i.success?"green":"red",children:i.message}),t(d.Box,{marginTop:1,children:t(E.Ay,{items:x,onSelect:l})})]}),L=({device:e,screenshot:l,loading:r,error:i,onSelect:o})=>{var a=l?.file?.meta,c=a?.originalWidth!=null&&a?.originalHeight!=null,u=a?.originalFileSize!=null;return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),r&&t(b,{text:"Loading screenshot..."}),i&&t(d.Box,{marginY:1,children:t(d.Text,{color:"red",children:String(i)})}),!r&&!i&&l&&n(d.Box,{flexDirection:"column",children:[t(d.Box,{height:30,children:t(A,{src:l.path,width:80,alt:"Device screenshot"})}),n(d.Box,{marginY:1,flexDirection:"column",children:[t(d.Text,{bold:!0,color:"white",children:"Screenshot Details"}),n(d.Box,{marginY:1,children:[t(d.Text,{color:"green",children:"Screenshot saved to: "}),t(d.Text,{color:"cyan",children:String(l.path||"")})]}),c&&n(d.Text,{color:"gray",children:["Size: ",String(a.originalWidth),"x",String(a.originalHeight)]}),u&&n(d.Text,{color:"gray",children:["File: ",(Number(a.originalFileSize)/1024).toFixed(1)," KB"]}),l.file?.updatedAt&&n(d.Text,{color:"gray",children:["Updated: ",new Date(l.file.updatedAt).toLocaleString()]})]})]}),!r&&!i&&!l&&t(d.Box,{marginY:1,children:t(d.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),t(d.Box,{marginTop:1,children:t(E.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})})]})},w=({apps:e,loading:l,onSelect:r})=>{if(l)return t(b,{text:"Loading applications..."});if(!e?.length)return t(d.Text,{color:"yellow",children:"No applications found"});var i=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),t(E.Ay,{items:i,onSelect:r})]})},O=({app:e,loading:l,error:r,onSelect:i})=>{if(l)return t(b,{text:"Loading application..."});if(r)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",r]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return t(d.Text,{color:"red",children:"Application not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],a=e.devices?.length||0,c=e.devices?.filter(e=>"online"===e.status)?.length||0;return n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Version"}),n(d.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),n(d.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&n(d.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Devices"}),n(d.Text,{color:"gray",children:[" ","Total: ",a,a>0&&` (${c} online)`]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Features"}),n(d.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"\uD83D\uDD12 Locked":"\uD83D\uDD13 Unlocked"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),t(E.Ay,{items:o,onSelect:i})]})},P=({modules:e,loading:l,onSelect:r})=>{if(l)return t(b,{text:"Loading modules..."});var i=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&t(d.Text,{color:"yellow",children:"No modules found"}),t(E.Ay,{items:i,onSelect:r})]})},M=({module:e,loading:l,error:r,onSelect:i})=>{if(l)return t(b,{text:"Loading module..."});if(r)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",r]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return t(d.Text,{color:"red",children:"Module not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Version"}),n(d.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),n(d.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Usage"}),n(d.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Settings"}),n(d.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),n(d.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),n(d.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Exposed Properties"}),n(d.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),t(E.Ay,{items:o,onSelect:i})]})},R=({groups:e,loading:l,onSelect:r,countdown:i,lastRefreshTime:o})=>{if(l)return t(b,{text:"Loading device groups..."});var a=[...(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 n(d.Box,{flexDirection:"column",children:[n(d.Box,{marginBottom:1,children:[n(d.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),t(d.Text,{color:"gray",children:" - "}),t(v,{countdown:i,lastRefreshTime:o})]}),!e?.length&&t(d.Text,{color:"yellow",children:"No device groups found"}),t(E.Ay,{items:a,onSelect:r})]})},N=({loading:e,groupDevices:l})=>e?t(b,{text:"Loading devices..."}):l?.length?n(r,{children:[l.slice(0,10).map(e=>n(d.Box,{children:[t(d.Text,{color:"gray",children:" "}),t(D,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),n(d.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),l.length>10&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","... and ",l.length-10," more"]})]}):t(d.Text,{color:"gray",children:" No devices in this group"}),U=({group:e,groupDevices:l,loading:r,error:i,onSelect:o,countdown:a,lastRefreshTime:c})=>r&&!e?t(b,{text:"Loading device group..."}):i?n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",i]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]}):e?n(d.Box,{flexDirection:"column",children:[n(d.Box,{children:[t(d.Text,{bold:!0,color:"cyan",children:e.name}),t(d.Text,{color:"gray",children:" - "}),t(v,{countdown:a,lastRefreshTime:c})]}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[n(d.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),t(N,{loading:r,groupDevices:l})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),t(E.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})]}):t(d.Text,{color:"red",children:"Device group not found"}),G=({boxes:e,loading:l,onSelect:r})=>{if(l)return t(b,{text:"Loading media boxes..."});if(!e?.length)return t(d.Text,{color:"yellow",children:"No media boxes found"});var i=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),t(E.Ay,{items:i,onSelect:r})]})},j=({box:e,loading:l,error:r,onSelect:i})=>l&&!e?t(b,{text:"Loading media box..."}):r?n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",r]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]}):e?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&n(d.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&n(d.Box,{flexDirection:"column",marginTop:1,children:[n(d.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>n(d.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&n(d.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),t(E.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]}):t(d.Text,{color:"red",children:"Media box not found"}),$=({files:e,loading:l,onSelect:r,box:i})=>{if(l)return t(b,{text:"Loading media files..."});if(!e?.length)return t(d.Text,{color:"yellow",children:"No media files found"});var o=[...e.map(e=>{var l;return{label:`${"Image"===(l=e.fileType)?"\uD83D\uDDBC":"Video"===l?"\uD83C\uDF9E":"Audio"===l?"\uD83C\uDFB5":"\uD83D\uDCC4"} ${e.name||"Unnamed"}`,value:e.id,file:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",i?.name?` - ${i.name}`:""]}),t(E.Ay,{items:o,onSelect:r})]})},V=({file:e,loading:l,error:r,onSelect:i})=>{if(l&&!e)return t(b,{text:"Loading media file..."});if(r)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",r]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return t(d.Text,{color:"red",children:"Media file not found"});var o=e.meta,a=(0,g.Gu)(e),c=(0,g.Gu)(e,{preferThumbnail:!0}),u=!!(c&&c!==a);return n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&t(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e.id]}),n(d.Text,{color:"gray",children:["Box ID: ",e.boxId]}),n(d.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),o?.originalWidth!=null&&o?.originalHeight!=null&&n(d.Text,{color:"gray",children:["Size: ",o.originalWidth,"x",o.originalHeight]}),o?.originalFileSize!=null&&n(d.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),a&&n(d.Text,{color:"gray",children:["Original URL: ",a]}),u&&n(d.Text,{color:"gray",children:["Thumbnail URL: ",c]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[t(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&n(d.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),t(E.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]})},F=i(92642),H=(e,l)=>{if(!e)return"";var r="string"==typeof e?e:JSON.stringify(e);return r.length>l?r.slice(0,l-1)+"…":r},z=({onBack:e})=>{var l=u((0,c.useState)([]),2),r=l[0],i=l[1],o=u((0,c.useState)(!0),2),s=o[0],g=o[1],m=u((0,c.useState)(null),2),x=m[0],p=m[1];return(0,c.useEffect)(()=>{var e,l=(0,h.getCurrentProfile)(),r=(0,h.getToken)(l),t=(0,h.getActivityLogBaseUrl)();if(!r){p("Not logged in. Run `bricks auth login` first."),g(!1);return}if(!t){p("Activity log URL not configured."),g(!1);return}var n=(0,F.W)(t,r),o=new Date(Date.now()-36e5).toISOString(),c=new Date().toISOString(),d=new AbortController;return(e=a(function*(){try{var e=yield n.collectEvents({start_time:o,end_time:c},{limit:50,signal:d.signal});i(e)}catch(e){"AbortError"!==e.name&&p(e.message)}g(!1)}),function(){return e.apply(this,arguments)})(),()=>d.abort()},[]),n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),s&&t(b,{text:"Fetching events..."}),x&&n(d.Text,{color:"red",children:["Error: ",x]}),!s&&!x&&0===r.length&&t(d.Text,{color:"yellow",children:"No events found in the last hour"}),!s&&r.length>0&&n(d.Box,{flexDirection:"column",marginBottom:1,children:[n(d.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),r.map((e,l)=>n(d.Text,{children:[new Date(e.timestamp).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z").padEnd(22)," ",H(e.event_type||"",12).padEnd(12)," ",H(e.device_id||"",14).padEnd(14)," ",H(e.event_name||"",24).padEnd(24)," ",H(e.sender||"",16)]},l)),r.length>=50&&n(d.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:l=>"back"===l.value&&e()})]})},Y=i(29253),q=i(44618),X=["B","C","G","D"],J=({instanceType:e,instance:l,client:r,onDone:i,onCancel:o})=>{var s,h=(0,d.useApp)().exit,g=u((0,c.useState)("select_ref"),2),m=g[0],x=g[1],p=u((0,c.useState)(""),2),f=p[0],T=p[1],v=u((0,c.useState)("search"),2),y=v[0],_=v[1],D=u((0,c.useState)(null),2),S=D[0],I=D[1],A=u((0,c.useState)(null),2),B=A[0],C=A[1],k=u((0,c.useState)(""),2),L=k[0],w=k[1],O=u((0,c.useState)(""),2),P=O[0],M=O[1],R=u((0,c.useState)(null),2),N=R[0],U=R[1],G=l?.short_edit?.ref_map||{},j=Object.entries(G).filter(([,e])=>e&&!e.hide),$=(0,q.V)(G,{keyword:f,types:X}),V=$.flatMap(e=>[{label:e.label,value:`__header_${e.prefix}__`,isHeader:!0},...e.refs.map(({shortId:e,ref:l})=>({label:`${l.title||e} (${e})`,value:e,ref:l}))]),F=[...f?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],H=V.length>0?[...V,...F]:F,z=H.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,d.useInput)((e,l)=>{l.tab&&"select_ref"===m?_(e=>"search"===e?"list":"search"):(l.escape&&("select_ref"===m&&o(),"input_path"===m&&x("select_ref"),"input_content"===m&&x("input_path"),"confirm"===m&&x("input_content"),"done"===m&&o()),"q"===e&&"input_path"!==m&&"input_content"!==m&&("select_ref"!==m||"search"!==y)&&h())},{isActive:!0});var J=(s=a(function*(){if(r&&l?._id&&S){x("submitting"),U(null);try{var t={shortId:S,path:L.trim(),content:(e=>{var l=e.trim();if(""===l)return null;try{return JSON.parse(l)}catch{return l}})(P),forwardDataLink:!0};B?.inner_ref?.pid&&(t.innerRefParentShortId=B.inner_ref.pid),"application"===e?yield r.shortEditApplication({id:l._id,list:[t]}):yield r.shortEditModule({id:l._id,list:[t]}),yield i(),x("done")}catch(e){U(e.message),x("confirm")}}}),function(){return s.apply(this,arguments)});return l?.short_edit?.enabled?0===j.length?n(d.Box,{flexDirection:"column",children:[t(d.Text,{color:"yellow",children:"No Short Edit references found."}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]}):"select_ref"===m?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,children:"Short Edit References"}),t(d.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),n(d.Box,{marginTop:1,flexDirection:"column",children:[t(d.Text,{color:"gray",children:"Search (title or shortId)"}),t(Y.A,{value:f,placeholder:"type to filter, Enter to focus list",onChange:e=>T(e),onSubmit:()=>_("list"),focus:"search"===y}),t(d.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),n(d.Box,{marginTop:1,children:[0===$.length&&t(d.Text,{color:"yellow",children:"No references match your search."}),t(E.Ay,{items:H,isFocused:"list"===y,initialIndex:z>-1?z:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:l,isHeader:r})=>r?t(d.Box,{marginTop:1,children:t(d.Text,{bold:!0,color:"white",children:e})}):n(d.Text,{color:l?"blue":void 0,children:[l?"❯":" "," ",e]}),onSelect:e=>{if("__back__"===e.value)return void o();if("__clear_search__"===e.value){T(""),_("search");return}e.isHeader||(I(e.value),C(e.ref),x("input_path"))}})]})]}):"input_path"===m?n(d.Box,{flexDirection:"column",children:[n(d.Text,{children:["Reference:"," ",n(d.Text,{color:"cyan",children:[B?.title||S," (",S,")"]})]}),t(d.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),t(Y.A,{value:L,placeholder:"path",onChange:e=>{w(e),N&&U(null)},onSubmit:e=>{var l=e.trim();l?(w(l),x("input_content")):U("Path is required")},focus:!0})]}):"input_content"===m?n(d.Box,{flexDirection:"column",children:[n(d.Text,{children:["Path: ",t(d.Text,{color:"cyan",children:L})]}),t(d.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),t(Y.A,{value:P,placeholder:"content",onChange:e=>{M(e),N&&U(null)},onSubmit:()=>x("confirm"),focus:!0})]}):"submitting"===m?t(b,{text:"Applying short edit..."}):"done"===m?n(d.Box,{flexDirection:"column",children:[t(d.Text,{color:"green",children:"Short edit applied successfully."}),t(E.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(x("select_ref"),I(null),C(null),w(""),M(""),U(null)):o()}})]}):n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),n(d.Text,{children:["Reference:"," ",n(d.Text,{color:"cyan",children:[B?.title||S," (",S,")"]})]}),n(d.Text,{children:["Path: ",t(d.Text,{color:"cyan",children:L})]}),n(d.Text,{children:["Content: ",t(d.Text,{color:"cyan",children:P||"<empty>"})]}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),t(E.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&&J(),"edit_path"===e.value&&x("input_path"),"edit_content"===e.value&&x("input_content"),"back"===e.value&&o()}})]}):n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),t(E.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]})},K=i(16928),W=i(79896),Z=i(10750),Q=i(77768),ee="options",el="output_dir",er="confirm",et="generating",en="post_install",ei="done",eo=({type:e,instance:l,client:r,onDone:i,onCancel:o})=>{var s,h=(0,d.useApp)().exit,g=u((0,c.useState)(ee),2),m=g[0],x=g[1],p=u((0,c.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),2),T=p[0],v=p[1],y=u((0,c.useState)(process.cwd()),2),_=y[0],b=y[1],D=u((0,c.useState)(""),2),S=D[0],I=D[1],A=u((0,c.useState)(null),2),B=A[0],C=A[1],k=u((0,c.useState)(null),2),L=k[0],w=k[1],O=Z(l?.name||"bricks-ctor"),P=K.resolve(_,O),M=(0,c.useCallback)(e=>{"back"===e.value?o():"continue"===e.value?x(el):v(l=>({...l,[e.value]:!l[e.value]}))},[o]),R=(0,c.useCallback)(()=>{W.existsSync(P)?C(`Directory already exists: ${P}`):(C(null),x(er))},[P]),N=(0,c.useCallback)((s=a(function*(t){if("back"===t.value)return void x(el);if("cancel"===t.value)return void o();if("confirm"===t.value){x(et);try{I("Fetching project from BRICKS...");var n="application"===e,i=n?r.queries.applicationProject:r.queries.moduleProject,a=(yield r.query(i,{id:l._id,buildApplicationOnly:!1,setupGitHubActions:T.setupGitHubActions,setupAgents:T.setupAgents,setupClaudeCode:T.setupClaudeCode,setupGeminiCLI:T.setupGeminiCLI}))[n?"applicationProject":"moduleProject"];if(!a?.files)throw Error("Failed to fetch project files");I("Creating project directory..."),W.mkdirSync(P,{recursive:!0}),I(`Writing ${a.files.length} files...`);var c=yield(0,Q.KN)(a.files,P);(0,Q.oz)(c),x(en);var d={path:P,files:a.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(d,(yield(0,Q.o0)(P,{install:T.runBunInstall,git:T.initGit,onStatus:I}))),w(d),x(ei)}catch(e){C(e.message),x(ee)}}}),function(e){return s.apply(this,arguments)}),[r,l,e,T,P,o]),U=(0,c.useCallback)(e=>{"exit"===e.value?h():i()},[h,i]);if(m===ee){var G=[{label:`${T.setupGitHubActions?"[x]":"[ ]"} GitHub Actions workflow`,value:"setupGitHubActions"},{label:`${T.setupAgents?"[x]":"[ ]"} AGENTS.md`,value:"setupAgents"},{label:`${T.setupClaudeCode?"[x]":"[ ]"} CLAUDE.md`,value:"setupClaudeCode"},{label:`${T.setupGeminiCLI?"[x]":"[ ]"} GEMINI.md`,value:"setupGeminiCLI"},{label:`${T.runBunInstall?"[x]":"[ ]"} Run bun install after generation`,value:"runBunInstall"},{label:`${T.initGit?"[x]":"[ ]"} Initialize git repository`,value:"initGit"},{label:"→ Continue",value:"continue"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",l?.name||"Untitled"]}),t(d.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),B&&n(d.Text,{color:"red",marginBottom:1,children:["Error: ",B]}),t(E.Ay,{items:G,onSelect:M})]})}return m===el?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:"Output Directory"}),t(d.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),B&&t(d.Text,{color:"red",marginBottom:1,children:B}),n(d.Box,{children:[t(d.Text,{children:"Directory: "}),t(Y.A,{value:_,onChange:b,onSubmit:R})]}),n(d.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",P]})]}):m===er?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{children:["Name: ",t(d.Text,{color:"green",children:l?.name||"Untitled"})]}),n(d.Text,{children:["Type: ",t(d.Text,{color:"yellow",children:e})]}),n(d.Text,{children:["Path: ",t(d.Text,{color:"cyan",children:P})]}),t(d.Text,{color:"gray",marginTop:1,children:"Options:"}),n(d.Text,{color:"gray",children:[" - GitHub Actions: ",T.setupGitHubActions?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - AGENTS.md: ",T.setupAgents?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - CLAUDE.md: ",T.setupClaudeCode?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - GEMINI.md: ",T.setupGeminiCLI?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - Run bun install: ",T.runBunInstall?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - Initialize git: ",T.initGit?"Yes":"No"]})]}),t(E.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:N})]}):m===et||m===en?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),n(d.Box,{marginY:1,children:[t(d.Text,{color:"green",children:t(f.A,{type:"dots"})}),n(d.Text,{children:[" ",S]})]})]}):m===ei&&L?n(d.Box,{flexDirection:"column",children:[t(d.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{children:["Path: ",t(d.Text,{color:"cyan",children:L.path})]}),n(d.Text,{children:["Files: ",t(d.Text,{color:"green",children:L.files})]}),n(d.Text,{children:["Dependencies:"," ",t(d.Text,{color:L.bunInstalled?"green":"yellow",children:L.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),n(d.Text,{children:["Git:"," ",t(d.Text,{color:L.gitInitialized?"green":"yellow",children:L.gitInitialized?"Initialized":"Not initialized"})]})]}),t(d.Text,{bold:!0,marginY:1,children:"Next steps:"}),n(d.Text,{color:"gray",children:[" cd ",O]}),!L.bunInstalled&&t(d.Text,{color:"gray",children:" bun install"}),t(d.Text,{color:"gray",children:" bun invoke-simulator"}),n(d.Text,{color:"gray",marginTop:1,children:["For more information, see ",O,"/README.md"]}),t(d.Box,{marginTop:1,children:t(E.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:U})})]}):null};let ea=()=>{var e,l,r,i,o,x,p,f,v=(0,d.useApp)().exit,D=u((0,c.useState)(m.MAIN),2),E=D[0],I=D[1],A=u((0,c.useState)(null),2),N=A[0],F=A[1],H=u((0,c.useState)(null),2),Y=H[0],q=H[1],X=u((0,c.useState)(!0),2),K=X[0],W=X[1],Z=u((0,c.useState)(null),2),Q=Z[0],ee=Z[1],el=u((0,c.useState)([]),2),er=el[0],et=el[1],en=u((0,c.useState)(null),2),ei=en[0],ea=en[1],ec=u((0,c.useState)([]),2),ed=ec[0],eu=ec[1],es=u((0,c.useState)(null),2),eh=es[0],eg=es[1],em=u((0,c.useState)([]),2),ex=em[0],ep=em[1],ef=u((0,c.useState)(null),2),eT=ef[0],ev=ef[1],ey=u((0,c.useState)([]),2),e_=ey[0],eb=ey[1],eD=u((0,c.useState)(null),2),eE=eD[0],eS=eD[1],eI=u((0,c.useState)([]),2),eA=eI[0],eB=eI[1],eC=u((0,c.useState)(!1),2),ek=eC[0],eL=eC[1],ew=u((0,c.useState)(null),2),eO=ew[0],eP=ew[1],eM=u((0,c.useState)(null),2),eR=eM[0],eN=eM[1],eU=u((0,c.useState)(null),2),eG=eU[0],ej=eU[1],e$=u((0,c.useState)(null),2),eV=e$[0],eF=e$[1],eH=u((0,c.useState)([]),2),ez=eH[0],eY=eH[1],eq=u((0,c.useState)(null),2),eX=eq[0],eJ=eq[1],eK=u((0,c.useState)([]),2),eW=eK[0],eZ=eK[1],eQ=u((0,c.useState)(null),2),e0=eQ[0],e1=eQ[1],e2=E===m.DEVICES,e4=E===m.DEVICE_DETAIL,e6=E===m.GROUPS,e9=E===m.GROUP_DETAIL;(0,c.useEffect)(()=>{var e=(0,h.getCurrentProfile)(),l=(0,h.getToken)(e);if(!l){ee("Not logged in. Run `bricks auth login` first."),W(!1);return}var r=(0,s.createClient)((0,h.getBaseUrl)(),l);F(r),r.workspace().then(e=>{q(e),W(!1)}).catch(e=>{ee(e.message),W(!1)})},[]),(0,d.useInput)((e,l)=>{"q"===e&&v(),l.escape&&(E===m.DEVICE_CONTROL?(I(m.DEVICE_DETAIL),eP(null)):E===m.DEVICE_SCREENSHOT?(I(m.DEVICE_DETAIL),ej(null),eF(null)):E===m.DEVICE_DETAIL?(I(m.DEVICES),ea(null)):E===m.APP_DETAIL?(I(m.APPS),eg(null)):E===m.MODULE_DETAIL?(I(m.MODULES),ev(null)):E===m.GROUP_DETAIL?(I(m.GROUPS),eS(null),eB([])):E===m.MEDIA_FILE_DETAIL?(I(m.MEDIA_FILES),e1(null)):E===m.MEDIA_FILES?(I(m.MEDIA_BOX_DETAIL),e1(null)):E===m.MEDIA_BOX_DETAIL?(I(m.MEDIA_BOXES),eJ(null),eZ([])):E===m.MEDIA_BOXES?I(m.MAIN):E!==m.MAIN&&I(m.MAIN))},{isActive:E!==m.APP_SHORT_EDIT&&E!==m.MODULE_SHORT_EDIT&&E!==m.APP_PROJECT_INIT&&E!==m.MODULE_PROJECT_INIT});var e5=(0,c.useCallback)(a(function*(){if(N){W(!0);try{var e=yield N.devices({});et(e||[])}catch(e){ee(e.message)}W(!1)}}),[N]),e8=(0,c.useCallback)((e=a(function*(e){if(N){W(!0),eN(null);try{var l=yield N.device({id:e});ea(l)}catch(e){eN(e.message)}W(!1)}}),function(l){return e.apply(this,arguments)}),[N]),e7=(0,c.useCallback)(a(function*(){if(N){W(!0);try{var e=yield N.applications({});eu(e||[])}catch(e){ee(e.message)}W(!1)}}),[N]),e3=(0,c.useCallback)((l=a(function*(e){if(N){W(!0),eN(null);try{var l=yield N.application({id:e});eg(l)}catch(e){eN(e.message)}W(!1)}}),function(e){return l.apply(this,arguments)}),[N]),le=(0,c.useCallback)(a(function*(){if(N){W(!0);try{var e=yield N.modules({});ep(e||[])}catch(e){ee(e.message)}W(!1)}}),[N]),ll=(0,c.useCallback)((r=a(function*(e){if(N){W(!0),eN(null);try{var l=yield N.module({id:e});ev(l)}catch(e){eN(e.message)}W(!1)}}),function(e){return r.apply(this,arguments)}),[N]),lr=(0,c.useCallback)(a(function*(){if(N){W(!0);try{var e=yield N.deviceGroups({});eb(e||[])}catch(e){ee(e.message)}W(!1)}}),[N]),lt=(0,c.useCallback)((i=a(function*(e){if(N){W(!0),eN(null);try{var l=yield Promise.all([N.deviceGroup({id:e}),N.devicesByGroup({id:e})]),r=u(l,2),t=r[0],n=r[1];eS(t),eB(n||[])}catch(e){eN(e.message)}W(!1)}}),function(e){return i.apply(this,arguments)}),[N]),ln=(0,c.useCallback)(a(function*(){if(N){W(!0);try{var e=yield N.mediaBoxes();eY(e||[])}catch(e){ee(e.message)}W(!1)}}),[N]),li=(0,c.useCallback)((o=a(function*(e){if(N){W(!0),eN(null);try{var l=yield N.mediaBox({id:e});eJ(l)}catch(e){eN(e.message)}W(!1)}}),function(e){return o.apply(this,arguments)}),[N]),lo=(0,c.useCallback)((x=a(function*(e){if(N){W(!0);try{var l=yield N.mediaFiles({boxId:e});eZ(l||[])}catch(e){ee(e.message)}W(!1)}}),function(e){return x.apply(this,arguments)}),[N]),la=(0,c.useCallback)((p=a(function*(e){if(N){W(!0),eN(null);try{var l=yield N.mediaFile({id:e});e1(l)}catch(e){eN(e.message)}W(!1)}}),function(e){return p.apply(this,arguments)}),[N]),lc=(0,c.useCallback)((f=a(function*(e){if(N&&ei){eL(!0),eP(null);try{yield N.controlDevice({id:ei._id,type:e}),eP({success:!0,message:`Command sent: ${e}`})}catch(e){eP({success:!1,message:e.message})}eL(!1)}}),function(e){return f.apply(this,arguments)}),[N,ei]),ld=(0,c.useCallback)(a(function*(e=!1){if(N&&ei&&Y){W(!0),eF(null),ej(null);try{e&&(yield N.controlDevice({id:ei._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var l=yield(0,g.he)(N,Y,ei._id,null,{preferThumbnail:!0});l.error?eF(l.error):ej(l)}catch(e){eF(e.message)}W(!1)}}),[N,ei,Y]),lu=T((0,c.useCallback)(()=>{N&&e5()},[N,e5]),e2),ls=T((0,c.useCallback)(()=>{N&&ei&&e8(ei._id)},[N,ei,e8]),e4),lh=T((0,c.useCallback)(()=>{N&&lr()},[N,lr]),e6),lg=T((0,c.useCallback)(()=>{N&&eE&<(eE._id)},[N,eE,lt]),e9);return K&&!Y?n(d.Box,{flexDirection:"column",children:[t(y,{workspace:Y,view:E}),t(b,{text:"Connecting to workspace..."})]}):Q&&!Y?n(d.Box,{flexDirection:"column",children:[t(y,{workspace:Y,view:E}),n(d.Text,{color:"red",children:["Error: ",Q]}),t(_,{})]}):n(d.Box,{flexDirection:"column",children:[t(y,{workspace:Y,view:E}),E===m.MAIN&&t(S,{onSelect:e=>{"exit"===e.value?v():(I(e.value),e.value===m.DEVICES?e5():e.value===m.APPS?e7():e.value===m.MODULES?le():e.value===m.GROUPS?lr():e.value===m.MEDIA_BOXES&&ln())},mediaEnabled:(0,g.wR)(Y),activityLogEnabled:!!(0,h.getActivityLogBaseUrl)()}),E===m.DEVICES&&t(B,{devices:er,loading:K,onSelect:e=>{if("back"===e.value)return void I(m.MAIN);if("refresh"===e.value){e5(),lu.resetCountdown();return}ea(null),W(!0),I(m.DEVICE_DETAIL),e8(e.value)},countdown:lu.countdown,lastRefreshTime:lu.lastRefreshTime}),E===m.DEVICE_DETAIL&&t(C,{device:ei,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.DEVICES),ea(null);return}if("refresh"===e.value){e8(ei._id),ls.resetCountdown();return}"control"===e.value&&(I(m.DEVICE_CONTROL),eP(null)),"screenshot"===e.value&&(I(m.DEVICE_SCREENSHOT),ej(null),eF(null),ld(!1))},mediaEnabled:(0,g.wR)(Y),countdown:ls.countdown,lastRefreshTime:ls.lastRefreshTime}),E===m.DEVICE_CONTROL&&t(k,{device:ei,onSelect:e=>{if("back"===e.value){I(m.DEVICE_DETAIL),eP(null);return}lc(e.value)},controlling:ek,controlResult:eO}),E===m.DEVICE_SCREENSHOT&&t(L,{device:ei,screenshot:eG,loading:K,error:eV,onSelect:e=>{if("back"===e.value){I(m.DEVICE_DETAIL),ej(null),eF(null);return}"refresh"===e.value?ld(!1):"take"===e.value&&ld(!0)}}),E===m.APPS&&t(w,{apps:ed,loading:K,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?e7():(eg(null),W(!0),I(m.APP_DETAIL),e3(e.value))}}),E===m.APP_DETAIL&&t(O,{app:eh,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.APPS),eg(null);return}"refresh"===e.value?e3(eh._id):("short_edit"===e.value&&(I(m.APP_SHORT_EDIT),eN(null)),"project_init"===e.value&&(I(m.APP_PROJECT_INIT),eN(null)))}}),E===m.APP_SHORT_EDIT&&t(J,{instanceType:"application",instance:eh,client:N,onDone:a(function*(){return e3(eh._id)}),onCancel:()=>I(m.APP_DETAIL)}),E===m.APP_PROJECT_INIT&&t(eo,{type:"application",instance:eh,client:N,onDone:()=>I(m.APP_DETAIL),onCancel:()=>I(m.APP_DETAIL)}),E===m.MODULES&&t(P,{modules:ex,loading:K,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?le():(ev(null),W(!0),I(m.MODULE_DETAIL),ll(e.value))}}),E===m.MODULE_DETAIL&&t(M,{module:eT,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.MODULES),ev(null);return}"refresh"===e.value?ll(eT._id):("short_edit"===e.value&&(I(m.MODULE_SHORT_EDIT),eN(null)),"project_init"===e.value&&(I(m.MODULE_PROJECT_INIT),eN(null)))}}),E===m.MODULE_SHORT_EDIT&&t(J,{instanceType:"module",instance:eT,client:N,onDone:a(function*(){return ll(eT._id)}),onCancel:()=>I(m.MODULE_DETAIL)}),E===m.MODULE_PROJECT_INIT&&t(eo,{type:"module",instance:eT,client:N,onDone:()=>I(m.MODULE_DETAIL),onCancel:()=>I(m.MODULE_DETAIL)}),E===m.GROUPS&&t(R,{groups:e_,loading:K,onSelect:e=>{if("back"===e.value)return void I(m.MAIN);if("refresh"===e.value){lr(),lh.resetCountdown();return}eS(null),eB([]),W(!0),I(m.GROUP_DETAIL),lt(e.value)},countdown:lh.countdown,lastRefreshTime:lh.lastRefreshTime}),E===m.GROUP_DETAIL&&t(U,{group:eE,groupDevices:eA,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.GROUPS),eS(null),eB([]);return}"refresh"===e.value&&(lt(eE._id),lg.resetCountdown())},countdown:lg.countdown,lastRefreshTime:lg.lastRefreshTime}),E===m.ACTIVITY_LOG&&t(z,{onBack:()=>I(m.MAIN)}),E===m.MEDIA_BOXES&&t(G,{boxes:ez,loading:K,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?ln():(eJ(null),eZ([]),W(!0),I(m.MEDIA_BOX_DETAIL),li(e.value))}}),E===m.MEDIA_BOX_DETAIL&&t(j,{box:eX,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.MEDIA_BOXES),eJ(null),eZ([]);return}"refresh"===e.value?li(eX.id):"files"===e.value&&(eZ([]),e1(null),I(m.MEDIA_FILES),lo(eX.id))}}),E===m.MEDIA_FILES&&t($,{files:eW,box:eX,loading:K,onSelect:e=>{if("back"===e.value){I(m.MEDIA_BOX_DETAIL),e1(null);return}"refresh"===e.value?lo(eX.id):(e1(null),W(!0),I(m.MEDIA_FILE_DETAIL),la(e.value))}}),E===m.MEDIA_FILE_DETAIL&&t(V,{file:e0,loading:K,error:eR,onSelect:e=>{if("back"===e.value){I(m.MEDIA_FILES),e1(null);return}"refresh"===e.value&&la(e0.id)}}),t(_,{})]})};var ec="1"===process.env.BRICKS_CLI_DISTRIBUTION,ed=(o=a(function*(){if(ec)return void(0,d.render)(t(ea,{}));var e=(yield i.e(166).then(i.bind(i,29557))).TerminalInfoProvider;(0,d.render)(t(e,{children:t(ea,{})}))}),function(){return o.apply(this,arguments)})},77768(e,l,r){r.d(l,{BZ:()=>v,KN:()=>p,kU:()=>x,o0:()=>T,oz:()=>f});var t,n,i,o,a=r(99436),c=r(16928),d=r(79896),u=r(35317),s=r(10750),h=e=>{try{return(0,u.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},g=(e,l,r)=>new Promise((t,n)=>{var i=[e,...l].join(" "),o=(0,u.spawn)(i,[],{cwd:r,stdio:"pipe",shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{0===e?t():n(Error(Buffer.concat(a).toString().trim()||`Command failed with code ${e}`))}),o.on("error",n)}),m=(t=a(function*(e,l){try{var t=(yield r.e(75).then(r.bind(r,79491))).format;return(yield t(l,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,l){return t.apply(this,arguments)}),x=(e=[])=>{var l=e.find(e=>"application.json"===e.name);if(!l)return"bricks-ctor";try{var r=JSON.parse(l.input);return s(r.name||"bricks-ctor")}catch{return"bricks-ctor"}},p=(n=a(function*(e,l){var r;return Promise.all(e.map((r=a(function*(e){var r=c.join(l,e.name),t=e.input;return e.formatable&&(t=yield m(t,r)),{...e,filePath:r,content:t}}),function(e){return r.apply(this,arguments)})))}),function(e,l){return n.apply(this,arguments)}),f=e=>{e.forEach(e=>{d.mkdirSync(c.dirname(e.filePath),{recursive:!0}),d.writeFileSync(e.filePath,e.content)})},T=(i=a(function*(e,l={}){var r="function"==typeof l.onStatus?l.onStatus:()=>{},t=!1,n=!1;if(!1!==l.install&&h("bun")){r("Installing dependencies (bun install)...");try{yield g("bun",["install"],e),t=!0}catch{}}if(!1!==l.git&&h("git")){r("Initializing git repository...");try{yield g("git",["init"],e),yield g("git",["add","."],e),yield g("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),n=!0}catch{}}return{bunInstalled:t,gitInitialized:n}}),function(e){return i.apply(this,arguments)}),v=(o=a(function*(e,l,r){var t=r.client,n=r.output,i=r.outputAsTarget;if(!t)throw Error("client is required");if(!n)throw Error("output directory is required");var o=(e=>{for(var l=c.resolve(e);;){if(d.existsSync(c.join(l,"application.json"))||d.existsSync(c.join(l,"module.json")))return l;var r=c.dirname(l);if(r===l)return null;l=r}})(i?c.dirname(c.resolve(n)):n);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,u=a?t.queries.applicationProject:t.queries.moduleProject,s=(yield t.query(u,{id:l,buildApplicationOnly:!1,setupGitHubActions:!1!==r.githubActions,setupAgents:!1!==r.agents,setupClaudeCode:!1!==r.claude,setupGeminiCLI:!0===r.gemini}))[a?"applicationProject":"moduleProject"];if(!s?.files)throw Error(`${e} project not found`);var h=x(s.files),g=i?c.resolve(n):c.resolve(n,h);if(d.existsSync(g))throw Error(`Directory already exists: ${g}`);d.mkdirSync(g,{recursive:!0}),f((yield p(s.files,g)));var m=yield T(g,r),v=m.bunInstalled,y=m.gitInitialized;return{success:!0,path:g,files:s.files.length,bunInstalled:v,gitInitialized:y}}),function(e,l,r){return o.apply(this,arguments)})}};
|
|
1
|
+
import*as e from"ink";import*as r from"react";import{Fragment as t,jsx as l,jsxs as n}from"react/jsx-runtime";export const __rspack_esm_id=940;export const __rspack_esm_ids=[940];export const __webpack_modules__={8498(r){r.exports=e},51649(e){e.exports=r},92319(e,r,i){i.r(r),i.d(r,{AppList:()=>L,CONTROL_ACTIONS:()=>g,MainMenu:()=>E,Header:()=>T,ModuleDetail:()=>M,ONLINE_THRESHOLD_MS:()=>p,ShortEditEditor:()=>K,MediaFileList:()=>G,App:()=>ea,DeviceDetail:()=>C,VIEWS:()=>m,runInteractiveMode:()=>ed,DeviceList:()=>B,MediaBoxList:()=>j,Loading:()=>_,DeviceControl:()=>k,ProjectInitView:()=>eo,GroupDetail:()=>U,ModuleList:()=>P,MediaBoxDetail:()=>$,GroupList:()=>R,Footer:()=>b,DeviceStatus:()=>D,AppDetail:()=>O,DeviceScreenshot:()=>w,MediaFileDetail:()=>F});var o,a=i(99436),c=i(51649),d=i(8498),s=i(68832),u=i(85382),h=i(47988),f=i(60450),m={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"},g=[{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"}],p=3e5,x=i(47882),y=(e,r=!0)=>{var t=Math.floor(60),l=s((0,c.useState)(t),2),n=l[0],i=l[1],o=s((0,c.useState)(null),2),a=o[0],d=o[1],u=(0,c.useRef)(e);(0,c.useEffect)(()=>{u.current=e},[e]);var h=(0,c.useCallback)(()=>{i(t),d(Date.now())},[t]);return(0,c.useEffect)(()=>{if(r){var e=setInterval(()=>{i(e=>e<=1?(u.current?.(),d(Date.now()),t):e-1)},1e3);return()=>clearInterval(e)}},[r,t]),(0,c.useEffect)(()=>{r&&(i(t),d(Date.now()))},[r,t]),{countdown:n,lastRefreshTime:a,resetCountdown:h}},v=({countdown:e,lastRefreshTime:r})=>l(d.Box,{children:n(d.Text,{color:"gray",children:["Next refresh in ",n(d.Text,{color:"cyan",children:[e,"s"]}),r&&n(d.Text,{color:"gray",children:[" (last: ",r?new Date(r).toLocaleTimeString():null,")"]})]})}),T=({workspace:e,view:r})=>n(d.Box,{flexDirection:"column",marginBottom:1,children:[n(d.Box,{children:[l(d.Text,{bold:!0,color:"cyan",children:"BRICKS CLI"}),l(d.Text,{color:"gray",children:" - Interactive Mode"})]}),n(d.Box,{children:[l(d.Text,{color:"gray",children:"Workspace: "}),l(d.Text,{color:"green",children:e?.name||"Not connected"}),l(d.Text,{color:"gray",children:" | View: "}),l(d.Text,{color:"yellow",children:r})]}),l(d.Text,{color:"gray",children:"─".repeat(60)})]}),b=()=>n(d.Box,{marginTop:1,flexDirection:"column",children:[l(d.Text,{color:"gray",children:"─".repeat(60)}),n(d.Text,{color:"gray",children:["Press ",l(d.Text,{color:"cyan",children:"q"})," to quit, ",l(d.Text,{color:"cyan",children:"Esc"})," to go back"]})]}),_=({text:e})=>n(d.Box,{children:[l(d.Text,{color:"green",children:l(x.A,{type:"dots"})}),n(d.Text,{children:[" ",e||"Loading..."]})]}),D=({lastAliveTime:e})=>{if(!e)return l(d.Text,{color:"gray",children:"○ Unknown"});var r=Date.now()-new Date(e).getTime();if(r<=p)return l(d.Text,{color:"green",children:"● Online"});var t=Math.floor(r/6e4);if(t<60)return n(d.Text,{color:"yellow",children:["○ Offline (",t,"m ago)"]});var i=Math.floor(t/60);if(i<24)return n(d.Text,{color:"red",children:["○ Offline (",i,"h ago)"]});var o=Math.floor(i/24);return n(d.Text,{color:"red",children:["○ Offline (",o,"d ago)"]})},S=i(48724),E=({onSelect:e,mediaEnabled:r,activityLogEnabled:t})=>{var i=[{label:"Devices",value:m.DEVICES},{label:"Applications",value:m.APPS},{label:"Modules",value:m.MODULES},{label:"Device Groups",value:m.GROUPS},...r?[{label:"Media Flow",value:m.MEDIA_BOXES}]:[],...t?[{label:"Activity Log",value:m.ACTIVITY_LOG}]:[],{label:"Exit",value:"exit"}];return n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,marginBottom:1,children:"Main Menu"}),l(S.Ay,{items:i,onSelect:e})]})},I="1"===process.env.BRICKS_CLI_DISTRIBUTION,A=e=>{var r=s((0,c.useState)(null),2),t=r[0],n=r[1];return((0,c.useEffect)(()=>{if(!I){var e=!0;return i.e(166).then(i.bind(i,29557)).then(r=>{e&&n(()=>r.default)}).catch(()=>{e&&n(!1)}),()=>{e=!1}}},[]),I||!1===t)?l(d.Text,{color:"gray",children:"Image preview is not available in this CLI build."}):t?l(t,{...e}):l(_,{text:"Preparing image preview..."})},B=({devices:e,loading:r,onSelect:t,countdown:i,lastRefreshTime:o})=>{if(r)return l(_,{text:"Loading devices..."});if(!e?.length)return n(d.Box,{flexDirection:"column",children:[l(d.Text,{color:"yellow",children:"No devices found"}),l(v,{countdown:i,lastRefreshTime:o})]});var a=[...e.map(e=>{var r=(e=>{if(!e)return"○ Unknown";var r=Date.now()-new Date(e).getTime();if(r<=p)return"● Online";var t=Math.floor(r/6e4);if(t<60)return`○ ${t}m ago`;var l=Math.floor(t/60);if(l<24)return`○ ${l}h ago`;var n=Math.floor(l/24);return`○ ${n}d ago`})(e.entry_detail?.watch_dog_timer?.last_alive_time);return{label:`${r} - ${e.name||e.device_name}`,value:e._id,device:e}}),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Box,{marginBottom:1,children:[n(d.Text,{bold:!0,children:["Devices (",e.length,")"]}),l(d.Text,{color:"gray",children:" - "}),l(v,{countdown:i,lastRefreshTime:o})]}),l(S.Ay,{items:a,onSelect:t})]})},C=({device:e,loading:r,error:t,onSelect:i,mediaEnabled:o,countdown:a,lastRefreshTime:c})=>{if(r)return l(_,{text:"Loading device..."});if(t)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",t]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return l(d.Text,{color:"red",children:"Device not found"});var s=[{label:"Control Device",value:"control"},...o?[{label:"View Screenshot",value:"screenshot"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],u=e.entry_detail,h=u?.screen,f=u?.update,m=u?.local_sync;return n(d.Box,{flexDirection:"column",children:[n(d.Box,{children:[l(d.Text,{bold:!0,color:"cyan",children:e.name||e.device_name}),l(d.Text,{color:"gray",children:" - "}),l(v,{countdown:a,lastRefreshTime:c})]}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Box,{children:[l(d.Text,{color:"gray",children:"Status: "}),l(D,{lastAliveTime:u?.watch_dog_timer?.last_alive_time})]}),n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),u?.application&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Application"}),n(d.Text,{color:"gray",children:[" Name: ",u.application.name]}),n(d.Text,{color:"gray",children:[" Mode: ",u.operation_mode||"N/A"]})]}),h&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Screen"}),h.resolution&&n(d.Text,{color:"gray",children:[" ","Resolution: ",h.resolution.width,"x",h.resolution.height,h.resolution.scale&&` @${h.resolution.scale}x`]}),h.orientation&&n(d.Text,{color:"gray",children:[" Orientation: ",h.orientation]}),h.touch&&n(d.Text,{color:"gray",children:[" ","Touch:"," ",h.touch.available?`Yes (${h.touch.touch_point} points)`:"No"]})]}),(u?.memory_usage||u?.disk_usage)&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"System"}),u.memory_usage&&n(d.Text,{color:"gray",children:[" Memory: ",Math.round(100*u.memory_usage),"%"]}),u.disk_usage&&n(d.Text,{color:"gray",children:[" Disk: ",Math.round(100*u.disk_usage),"%"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Capabilities"}),n(d.Text,{color:"gray",children:[" ","Sound: ",u?.sound?.available?"✓":"✗"," | ","Camera: ",u?.camera?.available?"✓":"✗"," | ","Audio In: ",u?.audio_in?.available?"✓":"✗"]})]}),m&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Local Sync"}),n(d.Text,{color:"gray",children:[" ","Role: ",m.is_main?"Main":"Peer",m.peer_count>0&&` | Peers: ${m.peer_count}`,m.mean_latency&&` | Latency: ${m.mean_latency}ms`]})]}),f&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Update"}),n(d.Text,{color:f.need_update?"yellow":"gray",children:[" ","Status: ",f.need_update?"⚠ Update available":"✓ Up to date"]}),f.current_version&&n(d.Text,{color:"gray",children:[" Version: ",f.current_version]})]})]}),l(S.Ay,{items:s,onSelect:i})]})},k=({device:e,onSelect:r,controlling:t,controlResult:i})=>n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Control: ",e?.name||e?.device_name]}),t&&l(_,{text:"Sending command..."}),i&&l(d.Text,{color:i.success?"green":"red",children:i.message}),l(d.Box,{marginTop:1,children:l(S.Ay,{items:g,onSelect:r})})]}),w=({device:e,screenshot:r,loading:t,error:i,onSelect:o})=>{var a=r?.file?.meta,c=a?.originalWidth!=null&&a?.originalHeight!=null,s=a?.originalFileSize!=null;return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Screenshot: ",e?.name||e?.device_name||"Unknown"]}),t&&l(_,{text:"Loading screenshot..."}),i&&l(d.Box,{marginY:1,children:l(d.Text,{color:"red",children:String(i)})}),!t&&!i&&r&&n(d.Box,{flexDirection:"column",children:[l(d.Box,{height:30,children:l(A,{src:r.path,width:80,alt:"Device screenshot"})}),n(d.Box,{marginY:1,flexDirection:"column",children:[l(d.Text,{bold:!0,color:"white",children:"Screenshot Details"}),n(d.Box,{marginY:1,children:[l(d.Text,{color:"green",children:"Screenshot saved to: "}),l(d.Text,{color:"cyan",children:String(r.path||"")})]}),c&&n(d.Text,{color:"gray",children:["Size: ",String(a.originalWidth),"x",String(a.originalHeight)]}),s&&n(d.Text,{color:"gray",children:["File: ",(Number(a.originalFileSize)/1024).toFixed(1)," KB"]}),r.file?.updatedAt&&n(d.Text,{color:"gray",children:["Updated: ",new Date(r.file.updatedAt).toLocaleString()]})]})]}),!t&&!i&&!r&&l(d.Box,{marginY:1,children:l(d.Text,{color:"yellow",children:"No screenshot available. Try taking a new one."})}),l(d.Box,{marginTop:1,children:l(S.Ay,{items:[{label:"Take New Screenshot",value:"take"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})})]})},L=({apps:e,loading:r,onSelect:t})=>{if(r)return l(_,{text:"Loading applications..."});if(!e?.length)return l(d.Text,{color:"yellow",children:"No applications found"});var i=[...e.map(e=>({label:`${e.has_unreleased_changes?"●":"○"} ${e.name}`,value:e._id,app:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Applications (",e.length,")"]}),l(S.Ay,{items:i,onSelect:t})]})},O=({app:e,loading:r,error:t,onSelect:i})=>{if(r)return l(_,{text:"Loading application..."});if(t)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",t]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return l(d.Text,{color:"red",children:"Application not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],a=e.devices?.length||0,c=e.devices?.filter(e=>"online"===e.status)?.length||0;return n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Version"}),n(d.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),n(d.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]}),e.current_version_details&&n(d.Text,{color:"gray",children:[" ","Released: v",e.current_version_details.version||"N/A"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Devices"}),n(d.Text,{color:"gray",children:[" ","Total: ",a,a>0&&` (${c} online)`]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Features"}),n(d.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:"gray",children:[" ","Canvas Control: ",e.canvas_control?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:"gray",children:[" ","Device Control: ",e.device_control?.enabled?"✓ Enabled":"✗ Disabled"]}),n(d.Text,{color:e.lock?.enabled?"yellow":"gray",children:[" ","Lock: ",e.lock?.enabled?"\uD83D\uDD12 Locked":"\uD83D\uDD13 Unlocked"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),l(S.Ay,{items:o,onSelect:i})]})},P=({modules:e,loading:r,onSelect:t})=>{if(r)return l(_,{text:"Loading modules..."});var i=[...(e||[]).map(e=>({label:`${e.current_version?"●":"○"} ${e.name}`,value:e._id,module:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Modules (",e?.length||0,")"]}),!e?.length&&l(d.Text,{color:"yellow",children:"No modules found"}),l(S.Ay,{items:i,onSelect:t})]})},M=({module:e,loading:r,error:t,onSelect:i})=>{if(r)return l(_,{text:"Loading module..."});if(t)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",t]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return l(d.Text,{color:"red",children:"Module not found"});var o=[{label:"⚡ Initialize Project",value:"project_init"},...e.short_edit?.enabled&&e.short_edit.ref_map?[{label:"Short Edit",value:"short_edit"}]:[],{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:e.name}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Version"}),n(d.Text,{color:"gray",children:[" ","Current: ",e.current_version?`v${e.current_version}`:"N/A"]}),n(d.Text,{color:e.has_unreleased_changes?"yellow":"gray",children:[" ","Changes:"," ",e.has_unreleased_changes?"● Unreleased changes":"○ No pending changes"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Usage"}),n(d.Text,{color:"gray",children:[" ","Used in: ",e.use_count?.total_count||0," application(s)"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Settings"}),n(d.Text,{color:"gray",children:[" ","Public: ",e.is_public?"✓ Yes":"✗ No"]}),n(d.Text,{color:"gray",children:[" ","Modifiable: ",e.is_allow_modify?"✓ Yes":"✗ No"]}),n(d.Text,{color:"gray",children:[" ","Short Edit: ",e.short_edit?.enabled?"✓ Enabled":"✗ Disabled"]})]}),e.expose_properties?.length>0&&n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Exposed Properties"}),n(d.Text,{color:"gray",children:[" ",e.expose_properties.length," properties exposed"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),l(S.Ay,{items:o,onSelect:i})]})},R=({groups:e,loading:r,onSelect:t,countdown:i,lastRefreshTime:o})=>{if(r)return l(_,{text:"Loading device groups..."});var a=[...(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 n(d.Box,{flexDirection:"column",children:[n(d.Box,{marginBottom:1,children:[n(d.Text,{bold:!0,children:["Device Groups (",e?.length||0,")"]}),l(d.Text,{color:"gray",children:" - "}),l(v,{countdown:i,lastRefreshTime:o})]}),!e?.length&&l(d.Text,{color:"yellow",children:"No device groups found"}),l(S.Ay,{items:a,onSelect:t})]})},N=({loading:e,groupDevices:r})=>e?l(_,{text:"Loading devices..."}):r?.length?n(t,{children:[r.slice(0,10).map(e=>n(d.Box,{children:[l(d.Text,{color:"gray",children:" "}),l(D,{lastAliveTime:e.entry_detail?.watch_dog_timer?.last_alive_time}),n(d.Text,{color:"gray",children:[" ",e.name||e.device_name]}),e.device_target_name&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","(",e.device_target_name,")"]})]},e._id)),r.length>10&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","... and ",r.length-10," more"]})]}):l(d.Text,{color:"gray",children:" No devices in this group"}),U=({group:e,groupDevices:r,loading:t,error:i,onSelect:o,countdown:a,lastRefreshTime:c})=>t&&!e?l(_,{text:"Loading device group..."}):i?n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",i]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]}):e?n(d.Box,{flexDirection:"column",children:[n(d.Box,{children:[l(d.Text,{bold:!0,color:"cyan",children:e.name}),l(d.Text,{color:"gray",children:" - "}),l(v,{countdown:a,lastRefreshTime:c})]}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e._id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[n(d.Text,{bold:!0,color:"white",children:["Devices (",e.devices?.length||0,")"]}),l(N,{loading:t,groupDevices:r})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.create_datetime&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.create_datetime).toLocaleString()]}),e.last_modify_datetime&&n(d.Text,{color:"gray",children:[" ","Modified: ",new Date(e.last_modify_datetime).toLocaleString()]})]})]}),l(S.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:o})]}):l(d.Text,{color:"red",children:"Device group not found"}),j=({boxes:e,loading:r,onSelect:t})=>{if(r)return l(_,{text:"Loading media boxes..."});if(!e?.length)return l(d.Text,{color:"yellow",children:"No media boxes found"});var i=[...e.map(e=>({label:`📦 ${e.name||"Unnamed"}`,value:e.id,box:e})),{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}];return n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Media Boxes (",e.length,")"]}),l(S.Ay,{items:i,onSelect:t})]})},$=({box:e,loading:r,error:t,onSelect:i})=>r&&!e?l(_,{text:"Loading media box..."}):t?n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",t]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]}):e?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e.id]}),e.tags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.tags.join(", ")]}),null!=e.size&&n(d.Text,{color:"gray",children:["Size: ",e.size]}),e.passcodes?.length>0&&n(d.Box,{flexDirection:"column",marginTop:1,children:[n(d.Text,{bold:!0,color:"white",children:["Passcodes (",e.passcodes.length,")"]}),e.passcodes.slice(0,5).map(e=>n(d.Text,{color:"gray",children:[" ",e.name||"Passcode",": ",e.code]},e.id)),e.passcodes.length>5&&n(d.Text,{color:"gray",dimColor:!0,children:[" ","... and ",e.passcodes.length-5," more"]})]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&n(d.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),l(S.Ay,{items:[{label:"List Files",value:"files"},{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]}):l(d.Text,{color:"red",children:"Media box not found"}),G=({files:e,loading:r,onSelect:t,box:i})=>{if(r)return l(_,{text:"Loading media files..."});if(!e?.length)return l(d.Text,{color:"yellow",children:"No media files found"});var o=[...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 n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,marginBottom:1,children:["Media Files (",e.length,")",i?.name?` - ${i.name}`:""]}),l(S.Ay,{items:o,onSelect:t})]})},F=({file:e,loading:r,error:t,onSelect:i})=>{if(r&&!e)return l(_,{text:"Loading media file..."});if(t)return n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"red",children:["Error: ",t]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:i})]});if(!e)return l(d.Text,{color:"red",children:"Media file not found"});var o=e.meta,a=(0,f.buildScreenshotUrl)(e),c=(0,f.buildScreenshotUrl)(e,{preferThumbnail:!0}),s=!!(c&&c!==a);return n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:e.name||"Unnamed"}),e.description&&l(d.Text,{color:"gray",children:e.description}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{color:"gray",children:["ID: ",e.id]}),n(d.Text,{color:"gray",children:["Box ID: ",e.boxId]}),n(d.Text,{color:"gray",children:["Type: ",e.fileType]}),e.userTags?.length>0&&n(d.Text,{color:"gray",children:["Tags: ",e.userTags.join(", ")]}),o?.originalWidth!=null&&o?.originalHeight!=null&&n(d.Text,{color:"gray",children:["Size: ",o.originalWidth,"x",o.originalHeight]}),o?.originalFileSize!=null&&n(d.Text,{color:"gray",children:["File: ",(Number(o.originalFileSize)/1024).toFixed(1)," KB"]}),a&&n(d.Text,{color:"gray",children:["Original URL: ",a]}),s&&n(d.Text,{color:"gray",children:["Thumbnail URL: ",c]}),n(d.Box,{flexDirection:"column",marginTop:1,children:[l(d.Text,{bold:!0,color:"white",children:"Timestamps"}),e.createdAt&&n(d.Text,{color:"gray",children:[" Created: ",new Date(e.createdAt).toLocaleString()]}),e.updatedAt&&n(d.Text,{color:"gray",children:[" Modified: ",new Date(e.updatedAt).toLocaleString()]})]})]}),l(S.Ay,{items:[{label:"↻ Refresh",value:"refresh"},{label:"← Back",value:"back"}],onSelect:i})]})},V=i(92642),H=(e,r)=>{if(!e)return"";var t="string"==typeof e?e:JSON.stringify(e);return t.length>r?t.slice(0,r-1)+"…":t},z=({onBack:e})=>{var r=s((0,c.useState)([]),2),t=r[0],i=r[1],o=s((0,c.useState)(!0),2),u=o[0],f=o[1],m=s((0,c.useState)(null),2),g=m[0],p=m[1];return(0,c.useEffect)(()=>{var e,r=(0,h.getCurrentProfile)(),t=(0,h.getToken)(r),l=(0,h.getActivityLogBaseUrl)();if(!t){p("Not logged in. Run `bricks auth login` first."),f(!1);return}if(!l){p("Activity log URL not configured."),f(!1);return}var n=(0,V.createActivityLogClient)(l,t),o=new Date(Date.now()-36e5).toISOString(),c=new Date().toISOString(),d=new AbortController;return(e=a(function*(){try{var e=yield n.collectEvents({start_time:o,end_time:c},{limit:50,signal:d.signal});i(e)}catch(e){"AbortError"!==e.name&&p(e.message)}f(!1)}),function(){return e.apply(this,arguments)})(),()=>d.abort()},[]),n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,marginBottom:1,children:"Activity Log (last 1h)"}),u&&l(_,{text:"Fetching events..."}),g&&n(d.Text,{color:"red",children:["Error: ",g]}),!u&&!g&&0===t.length&&l(d.Text,{color:"yellow",children:"No events found in the last hour"}),!u&&t.length>0&&n(d.Box,{flexDirection:"column",marginBottom:1,children:[n(d.Text,{color:"gray",children:["Timestamp".padEnd(22)," ","Type".padEnd(12)," ","Device".padEnd(14)," ","Event Name".padEnd(24)," Sender"]}),t.map((e,r)=>n(d.Text,{children:[new Date(e.timestamp).toISOString().replace("T"," ").replace(/\.\d+Z$/,"Z").padEnd(22)," ",H(e.event_type||"",12).padEnd(12)," ",H(e.device_id||"",14).padEnd(14)," ",H(e.event_name||"",24).padEnd(24)," ",H(e.sender||"",16)]},r)),t.length>=50&&n(d.Text,{color:"yellow",children:["Showing first ",50," events"]})]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:r=>"back"===r.value&&e()})]})},Y=i(29253),q=i(44618),J=["B","C","G","D"],K=({instanceType:e,instance:r,client:t,onDone:i,onCancel:o})=>{var u,h=(0,d.useApp)().exit,f=s((0,c.useState)("select_ref"),2),m=f[0],g=f[1],p=s((0,c.useState)(""),2),x=p[0],y=p[1],v=s((0,c.useState)("search"),2),T=v[0],b=v[1],D=s((0,c.useState)(null),2),E=D[0],I=D[1],A=s((0,c.useState)(null),2),B=A[0],C=A[1],k=s((0,c.useState)(""),2),w=k[0],L=k[1],O=s((0,c.useState)(""),2),P=O[0],M=O[1],R=s((0,c.useState)(null),2),N=R[0],U=R[1],j=r?.short_edit?.ref_map||{},$=Object.entries(j).filter(([,e])=>e&&!e.hide),G=(0,q.V)(j,{keyword:x,types:J}),F=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}))]),V=[...x?[{label:"↻ Clear Search",value:"__clear_search__"}]:[],{label:"← Back",value:"__back__"}],H=F.length>0?[...F,...V]:V,z=H.findIndex(e=>!e.isHeader&&!e.value?.startsWith("__"));(0,d.useInput)((e,r)=>{r.tab&&"select_ref"===m?b(e=>"search"===e?"list":"search"):(r.escape&&("select_ref"===m&&o(),"input_path"===m&&g("select_ref"),"input_content"===m&&g("input_path"),"confirm"===m&&g("input_content"),"done"===m&&o()),"q"===e&&"input_path"!==m&&"input_content"!==m&&("select_ref"!==m||"search"!==T)&&h())},{isActive:!0});var K=(u=a(function*(){if(t&&r?._id&&E){g("submitting"),U(null);try{var l={shortId:E,path:w.trim(),content:(e=>{var r=e.trim();if(""===r)return null;try{return JSON.parse(r)}catch{return r}})(P),forwardDataLink:!0};B?.inner_ref?.pid&&(l.innerRefParentShortId=B.inner_ref.pid),"application"===e?yield t.shortEditApplication({id:r._id,list:[l]}):yield t.shortEditModule({id:r._id,list:[l]}),yield i(),g("done")}catch(e){U(e.message),g("confirm")}}}),function(){return u.apply(this,arguments)});return r?.short_edit?.enabled?0===$.length?n(d.Box,{flexDirection:"column",children:[l(d.Text,{color:"yellow",children:"No Short Edit references found."}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]}):"select_ref"===m?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,children:"Short Edit References"}),l(d.Text,{color:"gray",dimColor:!0,children:"Showing: Brick, Canvas, Generator, Data"}),n(d.Box,{marginTop:1,flexDirection:"column",children:[l(d.Text,{color:"gray",children:"Search (title or shortId)"}),l(Y.A,{value:x,placeholder:"type to filter, Enter to focus list",onChange:e=>y(e),onSubmit:()=>b("list"),focus:"search"===T}),l(d.Text,{color:"gray",dimColor:!0,children:"Press Tab to switch focus"})]}),n(d.Box,{marginTop:1,children:[0===G.length&&l(d.Text,{color:"yellow",children:"No references match your search."}),l(S.Ay,{items:H,isFocused:"list"===T,initialIndex:z>-1?z:0,indicatorComponent:()=>null,itemComponent:({label:e,isSelected:r,isHeader:t})=>t?l(d.Box,{marginTop:1,children:l(d.Text,{bold:!0,color:"white",children:e})}):n(d.Text,{color:r?"blue":void 0,children:[r?"❯":" "," ",e]}),onSelect:e=>{if("__back__"===e.value)return void o();if("__clear_search__"===e.value){y(""),b("search");return}e.isHeader||(I(e.value),C(e.ref),g("input_path"))}})]})]}):"input_path"===m?n(d.Box,{flexDirection:"column",children:[n(d.Text,{children:["Reference:"," ",n(d.Text,{color:"cyan",children:[B?.title||E," (",E,")"]})]}),l(d.Text,{marginTop:1,children:"Enter property path (e.g. title, property.backgroundColor)"}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),l(Y.A,{value:w,placeholder:"path",onChange:e=>{L(e),N&&U(null)},onSubmit:e=>{var r=e.trim();r?(L(r),g("input_content")):U("Path is required")},focus:!0})]}):"input_content"===m?n(d.Box,{flexDirection:"column",children:[n(d.Text,{children:["Path: ",l(d.Text,{color:"cyan",children:w})]}),l(d.Text,{marginTop:1,children:"Enter new content (JSON or plain text). Empty to clear."}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),l(Y.A,{value:P,placeholder:"content",onChange:e=>{M(e),N&&U(null)},onSubmit:()=>g("confirm"),focus:!0})]}):"submitting"===m?l(_,{text:"Applying short edit..."}):"done"===m?n(d.Box,{flexDirection:"column",children:[l(d.Text,{color:"green",children:"Short edit applied successfully."}),l(S.Ay,{items:[{label:"Edit another property",value:"again"},{label:"← Back",value:"back"}],onSelect:e=>{"again"===e.value?(g("select_ref"),I(null),C(null),L(""),M(""),U(null)):o()}})]}):n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,marginBottom:1,children:"Confirm Short Edit"}),n(d.Text,{children:["Reference:"," ",n(d.Text,{color:"cyan",children:[B?.title||E," (",E,")"]})]}),n(d.Text,{children:["Path: ",l(d.Text,{color:"cyan",children:w})]}),n(d.Text,{children:["Content: ",l(d.Text,{color:"cyan",children:P||"<empty>"})]}),N&&n(d.Text,{color:"red",children:["Error: ",N]}),l(S.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&&K(),"edit_path"===e.value&&g("input_path"),"edit_content"===e.value&&g("input_content"),"back"===e.value&&o()}})]}):n(d.Box,{flexDirection:"column",children:[n(d.Text,{color:"yellow",children:["Short Edit is not enabled for this ",e,"."]}),l(S.Ay,{items:[{label:"← Back",value:"back"}],onSelect:o})]})},W=i(16928),X=i(79896),Q=i(10750),Z=i(77768),ee="options",er="output_dir",et="confirm",el="generating",en="post_install",ei="done",eo=({type:e,instance:r,client:t,onDone:i,onCancel:o})=>{var u,h=(0,d.useApp)().exit,f=s((0,c.useState)(ee),2),m=f[0],g=f[1],p=s((0,c.useState)({setupGitHubActions:!0,setupAgents:!0,setupClaudeCode:!0,setupGeminiCLI:!1,runBunInstall:!0,initGit:!0}),2),y=p[0],v=p[1],T=s((0,c.useState)(process.cwd()),2),b=T[0],_=T[1],D=s((0,c.useState)(""),2),E=D[0],I=D[1],A=s((0,c.useState)(null),2),B=A[0],C=A[1],k=s((0,c.useState)(null),2),w=k[0],L=k[1],O=Q(r?.name||"bricks-ctor"),P=W.resolve(b,O),M=(0,c.useCallback)(e=>{"back"===e.value?o():"continue"===e.value?g(er):v(r=>({...r,[e.value]:!r[e.value]}))},[o]),R=(0,c.useCallback)(()=>{X.existsSync(P)?C(`Directory already exists: ${P}`):(C(null),g(et))},[P]),N=(0,c.useCallback)((u=a(function*(l){if("back"===l.value)return void g(er);if("cancel"===l.value)return void o();if("confirm"===l.value){g(el);try{I("Fetching project from BRICKS...");var n="application"===e,i=n?t.queries.applicationProject:t.queries.moduleProject,a=(yield t.query(i,{id:r._id,buildApplicationOnly:!1,setupGitHubActions:y.setupGitHubActions,setupAgents:y.setupAgents,setupClaudeCode:y.setupClaudeCode,setupGeminiCLI:y.setupGeminiCLI}))[n?"applicationProject":"moduleProject"];if(!a?.files)throw Error("Failed to fetch project files");I("Creating project directory..."),X.mkdirSync(P,{recursive:!0}),I(`Writing ${a.files.length} files...`);var c=yield(0,Z.KN)(a.files,P);(0,Z.oz)(c),g(en);var d={path:P,files:a.files.length,bunInstalled:!1,gitInitialized:!1};Object.assign(d,(yield(0,Z.o0)(P,{install:y.runBunInstall,git:y.initGit,onStatus:I}))),L(d),g(ei)}catch(e){C(e.message),g(ee)}}}),function(e){return u.apply(this,arguments)}),[t,r,e,y,P,o]),U=(0,c.useCallback)(e=>{"exit"===e.value?h():i()},[h,i]);if(m===ee){var j=[{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 n(d.Box,{flexDirection:"column",children:[n(d.Text,{bold:!0,color:"cyan",children:["Initialize BRICKS Project: ",r?.name||"Untitled"]}),l(d.Text,{color:"gray",marginBottom:1,children:"Select options for project generation (press Enter to toggle)"}),B&&n(d.Text,{color:"red",marginBottom:1,children:["Error: ",B]}),l(S.Ay,{items:j,onSelect:M})]})}return m===er?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:"Output Directory"}),l(d.Text,{color:"gray",marginBottom:1,children:"Enter the parent directory for the project:"}),B&&l(d.Text,{color:"red",marginBottom:1,children:B}),n(d.Box,{children:[l(d.Text,{children:"Directory: "}),l(Y.A,{value:b,onChange:_,onSubmit:R})]}),n(d.Text,{color:"gray",marginTop:1,children:["Project will be created at: ",P]})]}):m===et?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:"Confirm Project Generation"}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{children:["Name: ",l(d.Text,{color:"green",children:r?.name||"Untitled"})]}),n(d.Text,{children:["Type: ",l(d.Text,{color:"yellow",children:e})]}),n(d.Text,{children:["Path: ",l(d.Text,{color:"cyan",children:P})]}),l(d.Text,{color:"gray",marginTop:1,children:"Options:"}),n(d.Text,{color:"gray",children:[" - GitHub Actions: ",y.setupGitHubActions?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - AGENTS.md: ",y.setupAgents?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - CLAUDE.md: ",y.setupClaudeCode?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - GEMINI.md: ",y.setupGeminiCLI?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - Run bun install: ",y.runBunInstall?"Yes":"No"]}),n(d.Text,{color:"gray",children:[" - Initialize git: ",y.initGit?"Yes":"No"]})]}),l(S.Ay,{items:[{label:"Confirm & Generate",value:"confirm"},{label:"← Change Directory",value:"back"},{label:"Cancel",value:"cancel"}],onSelect:N})]}):m===el||m===en?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"cyan",children:"Generating Project..."}),n(d.Box,{marginY:1,children:[l(d.Text,{color:"green",children:l(x.A,{type:"dots"})}),n(d.Text,{children:[" ",E]})]})]}):m===ei&&w?n(d.Box,{flexDirection:"column",children:[l(d.Text,{bold:!0,color:"green",children:"Project initialized successfully!"}),n(d.Box,{marginY:1,flexDirection:"column",children:[n(d.Text,{children:["Path: ",l(d.Text,{color:"cyan",children:w.path})]}),n(d.Text,{children:["Files: ",l(d.Text,{color:"green",children:w.files})]}),n(d.Text,{children:["Dependencies:"," ",l(d.Text,{color:w.bunInstalled?"green":"yellow",children:w.bunInstalled?"Installed":"Not installed (run bun install manually)"})]}),n(d.Text,{children:["Git:"," ",l(d.Text,{color:w.gitInitialized?"green":"yellow",children:w.gitInitialized?"Initialized":"Not initialized"})]})]}),l(d.Text,{bold:!0,marginY:1,children:"Next steps:"}),n(d.Text,{color:"gray",children:[" cd ",O]}),!w.bunInstalled&&l(d.Text,{color:"gray",children:" bun install"}),l(d.Text,{color:"gray",children:" bun invoke-simulator"}),n(d.Text,{color:"gray",marginTop:1,children:["For more information, see ",O,"/README.md"]}),l(d.Box,{marginTop:1,children:l(S.Ay,{items:[{label:"← Back to Detail",value:"back"},{label:"Exit CLI",value:"exit"}],onSelect:U})})]}):null};let ea=()=>{var e,r,t,i,o,g,p,x,v=(0,d.useApp)().exit,D=s((0,c.useState)(m.MAIN),2),S=D[0],I=D[1],A=s((0,c.useState)(null),2),N=A[0],V=A[1],H=s((0,c.useState)(null),2),Y=H[0],q=H[1],J=s((0,c.useState)(!0),2),W=J[0],X=J[1],Q=s((0,c.useState)(null),2),Z=Q[0],ee=Q[1],er=s((0,c.useState)([]),2),et=er[0],el=er[1],en=s((0,c.useState)(null),2),ei=en[0],ea=en[1],ec=s((0,c.useState)([]),2),ed=ec[0],es=ec[1],eu=s((0,c.useState)(null),2),eh=eu[0],ef=eu[1],em=s((0,c.useState)([]),2),eg=em[0],ep=em[1],ex=s((0,c.useState)(null),2),ey=ex[0],ev=ex[1],eT=s((0,c.useState)([]),2),eb=eT[0],e_=eT[1],eD=s((0,c.useState)(null),2),eS=eD[0],eE=eD[1],eI=s((0,c.useState)([]),2),eA=eI[0],eB=eI[1],eC=s((0,c.useState)(!1),2),ek=eC[0],ew=eC[1],eL=s((0,c.useState)(null),2),eO=eL[0],eP=eL[1],eM=s((0,c.useState)(null),2),eR=eM[0],eN=eM[1],eU=s((0,c.useState)(null),2),ej=eU[0],e$=eU[1],eG=s((0,c.useState)(null),2),eF=eG[0],eV=eG[1],eH=s((0,c.useState)([]),2),ez=eH[0],eY=eH[1],eq=s((0,c.useState)(null),2),eJ=eq[0],eK=eq[1],eW=s((0,c.useState)([]),2),eX=eW[0],eQ=eW[1],eZ=s((0,c.useState)(null),2),e0=eZ[0],e1=eZ[1],e2=S===m.DEVICES,e4=S===m.DEVICE_DETAIL,e6=S===m.GROUPS,e9=S===m.GROUP_DETAIL;(0,c.useEffect)(()=>{var e=(0,h.getCurrentProfile)(),r=(0,h.getToken)(e);if(!r){ee("Not logged in. Run `bricks auth login` first."),X(!1);return}var t=(0,u.createClient)((0,h.getBaseUrl)(),r);V(t),t.workspace().then(e=>{q(e),X(!1)}).catch(e=>{ee(e.message),X(!1)})},[]),(0,d.useInput)((e,r)=>{"q"===e&&v(),r.escape&&(S===m.DEVICE_CONTROL?(I(m.DEVICE_DETAIL),eP(null)):S===m.DEVICE_SCREENSHOT?(I(m.DEVICE_DETAIL),e$(null),eV(null)):S===m.DEVICE_DETAIL?(I(m.DEVICES),ea(null)):S===m.APP_DETAIL?(I(m.APPS),ef(null)):S===m.MODULE_DETAIL?(I(m.MODULES),ev(null)):S===m.GROUP_DETAIL?(I(m.GROUPS),eE(null),eB([])):S===m.MEDIA_FILE_DETAIL?(I(m.MEDIA_FILES),e1(null)):S===m.MEDIA_FILES?(I(m.MEDIA_BOX_DETAIL),e1(null)):S===m.MEDIA_BOX_DETAIL?(I(m.MEDIA_BOXES),eK(null),eQ([])):S===m.MEDIA_BOXES?I(m.MAIN):S!==m.MAIN&&I(m.MAIN))},{isActive:S!==m.APP_SHORT_EDIT&&S!==m.MODULE_SHORT_EDIT&&S!==m.APP_PROJECT_INIT&&S!==m.MODULE_PROJECT_INIT});var e5=(0,c.useCallback)(a(function*(){if(N){X(!0);try{var e=yield N.devices({});el(e||[])}catch(e){ee(e.message)}X(!1)}}),[N]),e7=(0,c.useCallback)((e=a(function*(e){if(N){X(!0),eN(null);try{var r=yield N.device({id:e});ea(r)}catch(e){eN(e.message)}X(!1)}}),function(r){return e.apply(this,arguments)}),[N]),e8=(0,c.useCallback)(a(function*(){if(N){X(!0);try{var e=yield N.applications({});es(e||[])}catch(e){ee(e.message)}X(!1)}}),[N]),e3=(0,c.useCallback)((r=a(function*(e){if(N){X(!0),eN(null);try{var r=yield N.application({id:e});ef(r)}catch(e){eN(e.message)}X(!1)}}),function(e){return r.apply(this,arguments)}),[N]),re=(0,c.useCallback)(a(function*(){if(N){X(!0);try{var e=yield N.modules({});ep(e||[])}catch(e){ee(e.message)}X(!1)}}),[N]),rr=(0,c.useCallback)((t=a(function*(e){if(N){X(!0),eN(null);try{var r=yield N.module({id:e});ev(r)}catch(e){eN(e.message)}X(!1)}}),function(e){return t.apply(this,arguments)}),[N]),rt=(0,c.useCallback)(a(function*(){if(N){X(!0);try{var e=yield N.deviceGroups({});e_(e||[])}catch(e){ee(e.message)}X(!1)}}),[N]),rl=(0,c.useCallback)((i=a(function*(e){if(N){X(!0),eN(null);try{var r=yield Promise.all([N.deviceGroup({id:e}),N.devicesByGroup({id:e})]),t=s(r,2),l=t[0],n=t[1];eE(l),eB(n||[])}catch(e){eN(e.message)}X(!1)}}),function(e){return i.apply(this,arguments)}),[N]),rn=(0,c.useCallback)(a(function*(){if(N){X(!0);try{var e=yield N.mediaBoxes();eY(e||[])}catch(e){ee(e.message)}X(!1)}}),[N]),ri=(0,c.useCallback)((o=a(function*(e){if(N){X(!0),eN(null);try{var r=yield N.mediaBox({id:e});eK(r)}catch(e){eN(e.message)}X(!1)}}),function(e){return o.apply(this,arguments)}),[N]),ro=(0,c.useCallback)((g=a(function*(e){if(N){X(!0);try{var r=yield N.mediaFiles({boxId:e});eQ(r||[])}catch(e){ee(e.message)}X(!1)}}),function(e){return g.apply(this,arguments)}),[N]),ra=(0,c.useCallback)((p=a(function*(e){if(N){X(!0),eN(null);try{var r=yield N.mediaFile({id:e});e1(r)}catch(e){eN(e.message)}X(!1)}}),function(e){return p.apply(this,arguments)}),[N]),rc=(0,c.useCallback)((x=a(function*(e){if(N&&ei){ew(!0),eP(null);try{yield N.controlDevice({id:ei._id,type:e}),eP({success:!0,message:`Command sent: ${e}`})}catch(e){eP({success:!1,message:e.message})}ew(!1)}}),function(e){return x.apply(this,arguments)}),[N,ei]),rd=(0,c.useCallback)(a(function*(e=!1){if(N&&ei&&Y){X(!0),eV(null),e$(null);try{e&&(yield N.controlDevice({id:ei._id,type:"take-screenshot"}),yield new Promise(e=>setTimeout(e,3e3)));var r=yield(0,f.fetchAndSaveScreenshot)(N,Y,ei._id,null,{preferThumbnail:!0});r.error?eV(r.error):e$(r)}catch(e){eV(e.message)}X(!1)}}),[N,ei,Y]),rs=y((0,c.useCallback)(()=>{N&&e5()},[N,e5]),e2),ru=y((0,c.useCallback)(()=>{N&&ei&&e7(ei._id)},[N,ei,e7]),e4),rh=y((0,c.useCallback)(()=>{N&&rt()},[N,rt]),e6),rf=y((0,c.useCallback)(()=>{N&&eS&&rl(eS._id)},[N,eS,rl]),e9);return W&&!Y?n(d.Box,{flexDirection:"column",children:[l(T,{workspace:Y,view:S}),l(_,{text:"Connecting to workspace..."})]}):Z&&!Y?n(d.Box,{flexDirection:"column",children:[l(T,{workspace:Y,view:S}),n(d.Text,{color:"red",children:["Error: ",Z]}),l(b,{})]}):n(d.Box,{flexDirection:"column",children:[l(T,{workspace:Y,view:S}),S===m.MAIN&&l(E,{onSelect:e=>{"exit"===e.value?v():(I(e.value),e.value===m.DEVICES?e5():e.value===m.APPS?e8():e.value===m.MODULES?re():e.value===m.GROUPS?rt():e.value===m.MEDIA_BOXES&&rn())},mediaEnabled:(0,f.isMediaEnabled)(Y),activityLogEnabled:!!(0,h.getActivityLogBaseUrl)()}),S===m.DEVICES&&l(B,{devices:et,loading:W,onSelect:e=>{if("back"===e.value)return void I(m.MAIN);if("refresh"===e.value){e5(),rs.resetCountdown();return}ea(null),X(!0),I(m.DEVICE_DETAIL),e7(e.value)},countdown:rs.countdown,lastRefreshTime:rs.lastRefreshTime}),S===m.DEVICE_DETAIL&&l(C,{device:ei,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.DEVICES),ea(null);return}if("refresh"===e.value){e7(ei._id),ru.resetCountdown();return}"control"===e.value&&(I(m.DEVICE_CONTROL),eP(null)),"screenshot"===e.value&&(I(m.DEVICE_SCREENSHOT),e$(null),eV(null),rd(!1))},mediaEnabled:(0,f.isMediaEnabled)(Y),countdown:ru.countdown,lastRefreshTime:ru.lastRefreshTime}),S===m.DEVICE_CONTROL&&l(k,{device:ei,onSelect:e=>{if("back"===e.value){I(m.DEVICE_DETAIL),eP(null);return}rc(e.value)},controlling:ek,controlResult:eO}),S===m.DEVICE_SCREENSHOT&&l(w,{device:ei,screenshot:ej,loading:W,error:eF,onSelect:e=>{if("back"===e.value){I(m.DEVICE_DETAIL),e$(null),eV(null);return}"refresh"===e.value?rd(!1):"take"===e.value&&rd(!0)}}),S===m.APPS&&l(L,{apps:ed,loading:W,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?e8():(ef(null),X(!0),I(m.APP_DETAIL),e3(e.value))}}),S===m.APP_DETAIL&&l(O,{app:eh,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.APPS),ef(null);return}"refresh"===e.value?e3(eh._id):("short_edit"===e.value&&(I(m.APP_SHORT_EDIT),eN(null)),"project_init"===e.value&&(I(m.APP_PROJECT_INIT),eN(null)))}}),S===m.APP_SHORT_EDIT&&l(K,{instanceType:"application",instance:eh,client:N,onDone:a(function*(){return e3(eh._id)}),onCancel:()=>I(m.APP_DETAIL)}),S===m.APP_PROJECT_INIT&&l(eo,{type:"application",instance:eh,client:N,onDone:()=>I(m.APP_DETAIL),onCancel:()=>I(m.APP_DETAIL)}),S===m.MODULES&&l(P,{modules:eg,loading:W,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?re():(ev(null),X(!0),I(m.MODULE_DETAIL),rr(e.value))}}),S===m.MODULE_DETAIL&&l(M,{module:ey,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.MODULES),ev(null);return}"refresh"===e.value?rr(ey._id):("short_edit"===e.value&&(I(m.MODULE_SHORT_EDIT),eN(null)),"project_init"===e.value&&(I(m.MODULE_PROJECT_INIT),eN(null)))}}),S===m.MODULE_SHORT_EDIT&&l(K,{instanceType:"module",instance:ey,client:N,onDone:a(function*(){return rr(ey._id)}),onCancel:()=>I(m.MODULE_DETAIL)}),S===m.MODULE_PROJECT_INIT&&l(eo,{type:"module",instance:ey,client:N,onDone:()=>I(m.MODULE_DETAIL),onCancel:()=>I(m.MODULE_DETAIL)}),S===m.GROUPS&&l(R,{groups:eb,loading:W,onSelect:e=>{if("back"===e.value)return void I(m.MAIN);if("refresh"===e.value){rt(),rh.resetCountdown();return}eE(null),eB([]),X(!0),I(m.GROUP_DETAIL),rl(e.value)},countdown:rh.countdown,lastRefreshTime:rh.lastRefreshTime}),S===m.GROUP_DETAIL&&l(U,{group:eS,groupDevices:eA,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.GROUPS),eE(null),eB([]);return}"refresh"===e.value&&(rl(eS._id),rf.resetCountdown())},countdown:rf.countdown,lastRefreshTime:rf.lastRefreshTime}),S===m.ACTIVITY_LOG&&l(z,{onBack:()=>I(m.MAIN)}),S===m.MEDIA_BOXES&&l(j,{boxes:ez,loading:W,onSelect:e=>{"back"===e.value?I(m.MAIN):"refresh"===e.value?rn():(eK(null),eQ([]),X(!0),I(m.MEDIA_BOX_DETAIL),ri(e.value))}}),S===m.MEDIA_BOX_DETAIL&&l($,{box:eJ,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.MEDIA_BOXES),eK(null),eQ([]);return}"refresh"===e.value?ri(eJ.id):"files"===e.value&&(eQ([]),e1(null),I(m.MEDIA_FILES),ro(eJ.id))}}),S===m.MEDIA_FILES&&l(G,{files:eX,box:eJ,loading:W,onSelect:e=>{if("back"===e.value){I(m.MEDIA_BOX_DETAIL),e1(null);return}"refresh"===e.value?ro(eJ.id):(e1(null),X(!0),I(m.MEDIA_FILE_DETAIL),ra(e.value))}}),S===m.MEDIA_FILE_DETAIL&&l(F,{file:e0,loading:W,error:eR,onSelect:e=>{if("back"===e.value){I(m.MEDIA_FILES),e1(null);return}"refresh"===e.value&&ra(e0.id)}}),l(b,{})]})};var ec="1"===process.env.BRICKS_CLI_DISTRIBUTION,ed=(o=a(function*(){if(ec)return void(0,d.render)(l(ea,{}));var e=(yield i.e(166).then(i.bind(i,29557))).TerminalInfoProvider;(0,d.render)(l(e,{children:l(ea,{})}))}),function(){return o.apply(this,arguments)})},92642(e,r,t){t.r(r),t.d(r,{ActivityLogClient:()=>_,createActivityLogClient:()=>D});var l,n,i,o=t(99436),a=t(5018),c=t(44668),d=t(4275),s=t(32235),u=t(62192),h=t(79657),f=t(64007);function m(e){var r,t,l,n=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,l=Symbol.iterator);n--;){if(t&&null!=(r=e[t]))return r.call(e);if(l&&null!=(r=e[l]))return new g(r.call(e));t="@@asyncIterator",l="@@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*p(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 l of e.incremental)if(Array.isArray(l.items))for(var n of l.items)yield n}}function x(){return(x=d(function*(e){var r=e.headers.get("content-type")||"";if(r.includes("application/json")){var t=yield s(e.json());if(t.errors?.length)throw Error(t.errors.map(e=>e.message).join("\n"));var l=Object.keys(t.data||{})[0];if(l&&Array.isArray(t.data[l]))for(var n of t.data[l])yield n;return}var i=r.match(/boundary="?([^";]+)"?/),o=i?i[1]:"-",a=`--${o}`,c="",d=!1,h=new TextDecoder,f=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},g=function*(){for(var e;-1!==(e=f(c));){var r=c.slice(0,e);(c=c.slice(e+a.length)).startsWith("\r\n")?c=c.slice(2):c.startsWith("\n")&&(c=c.slice(1));var t=r.indexOf("\r\n\r\n"),l=-1!==t?r.slice(t+4).trim():r.trim();if(l){var n=void 0;try{n=JSON.parse(l)}catch{continue}if(yield*p(n),!1===n.hasNext){d=!0;return}}}};try{var x=!1,y=!1;try{for(var v,T,b=m(e.body);x=!(T=yield s(b.next())).done;x=!1){var _=T.value;if(c+=h.decode(_,{stream:!0}),yield*u(m(g()),s),d)break}}catch(e){y=!0,v=e}finally{try{x&&null!=b.return&&(yield s(b.return()))}finally{if(y)throw v}}}catch(e){if(!e.message?.includes("Premature close")||!d)throw e}if(!d&&c.trim()){var D,S=c.indexOf("\r\n\r\n"),E=-1!==S?c.slice(S+4).trim():c.trim();if(E&&!E.startsWith("--")){try{D=JSON.parse(E)}catch{}D&&(yield*u(m(p(D)),s),!1===D.hasNext&&(d=!0))}}e.body?.destroy()})).apply(this,arguments)}var y=`
|
|
2
|
+
query AL_events($filter: EventsFilter!) {
|
|
3
|
+
events(filter: $filter) @stream {
|
|
4
|
+
device_id
|
|
5
|
+
event_type
|
|
6
|
+
event_name
|
|
7
|
+
subspace_id
|
|
8
|
+
sender
|
|
9
|
+
payload
|
|
10
|
+
timestamp
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`,v=`
|
|
14
|
+
query AL_screenshots($filter: ScreenshotFilter!) {
|
|
15
|
+
screenshots(filter: $filter) @stream {
|
|
16
|
+
timestamp
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;function T(e){var r,t,l,n=2;for("u">typeof Symbol&&(t=Symbol.asyncIterator,l=Symbol.iterator);n--;){if(t&&null!=(r=e[t]))return r.call(e);if(l&&null!=(r=e[l]))return new b(r.call(e));t="@@asyncIterator",l="@@iterator"}throw TypeError("Object is not async iterable")}function b(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(b=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 b(e)}var _=c(function e(r,t){a(this,e),this.baseUrl=r,this.token=t,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 h.Ay;var t=new f(r);return(e,r={})=>(0,h.Ay)(e,{...r,agent:t})}(r)},[{key:"streamQuery",value:function(e,r){var t=this;return d(function*(e,r,{signal:l}={}){var n=yield s(t.fetch(t.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`,Accept:'multipart/mixed; boundary="-", application/json'},body:JSON.stringify({query:e,variables:r}),signal:l}));if(!n.ok){var i=yield s(n.text().catch(()=>""));throw Error(`Activity-log query failed (${n.status}): ${i}`)}yield*u(T(function(e){return x.apply(this,arguments)}(n)),s)}).apply(this,arguments)}},{key:"events",value:function(e,r){var t=this;return d(function*(){yield*u(T(t.streamQuery(y,{filter:e},r)),s)})()}},{key:"screenshots",value:function(e,r){var t=this;return d(function*(){yield*u(T(t.streamQuery(v,{filter:e},r)),s)})()}},{key:"collectEvents",value:(l=o(function*(e,{limit:r,signal:t}={}){var l=[],n=!1,i=!1;try{for(var o,a,c=T(this.events(e,{signal:t}));n=!(a=yield c.next()).done;n=!1){var d=a.value;if(l.push(d),r&&l.length>=r)break}}catch(e){i=!0,o=e}finally{try{n&&null!=c.return&&(yield c.return())}finally{if(i)throw o}}return l}),function(e){return l.apply(this,arguments)})},{key:"collectScreenshots",value:(n=o(function*(e,{signal:r}={}){var t=[],l=!1,n=!1;try{for(var i,o,a=T(this.screenshots(e,{signal:r}));l=!(o=yield a.next()).done;l=!1){var c=o.value;t.push(c)}}catch(e){n=!0,i=e}finally{try{l&&null!=a.return&&(yield a.return())}finally{if(n)throw i}}return t}),function(e){return n.apply(this,arguments)})},{key:"downloadScreenshot",value:(i=o(function*(e,r,t,{signal:l}={}){var n=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(r)}/screenshot?ts=${encodeURIComponent(t)}`,i=yield this.fetch(n,{headers:{Authorization:`Bearer ${this.token}`},signal:l});if(!i.ok){var o=yield i.text().catch(()=>"");throw Error(`Screenshot fetch failed (${i.status}): ${o}`)}return Buffer.from((yield i.arrayBuffer()))}),function(e,r,t){return i.apply(this,arguments)})}]),D=(e,r)=>new _(e,r)},77768(e,r,t){t.d(r,{BZ:()=>v,KN:()=>p,kU:()=>g,o0:()=>y,oz:()=>x});var l,n,i,o,a=t(99436),c=t(16928),d=t(79896),s=t(35317),u=t(10750),h=e=>{try{return(0,s.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}},f=(e,r,t)=>new Promise((l,n)=>{var i=[e,...r].join(" "),o=(0,s.spawn)(i,[],{cwd:t,stdio:"pipe",shell:!0}),a=[];o.stderr.on("data",e=>a.push(e)),o.on("close",e=>{0===e?l():n(Error(Buffer.concat(a).toString().trim()||`Command failed with code ${e}`))}),o.on("error",n)}),m=(l=a(function*(e,r){try{var l=(yield t.e(75).then(t.bind(t,79491))).format;return(yield l(r,e,{trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100})).code}catch{}return e}),function(e,r){return l.apply(this,arguments)}),g=(e=[])=>{var r=e.find(e=>"application.json"===e.name);if(!r)return"bricks-ctor";try{var t=JSON.parse(r.input);return u(t.name||"bricks-ctor")}catch{return"bricks-ctor"}},p=(n=a(function*(e,r){var t;return Promise.all(e.map((t=a(function*(e){var t=c.join(r,e.name),l=e.input;return e.formatable&&(l=yield m(l,t)),{...e,filePath:t,content:l}}),function(e){return t.apply(this,arguments)})))}),function(e,r){return n.apply(this,arguments)}),x=e=>{e.forEach(e=>{d.mkdirSync(c.dirname(e.filePath),{recursive:!0}),d.writeFileSync(e.filePath,e.content)})},y=(i=a(function*(e,r={}){var t="function"==typeof r.onStatus?r.onStatus:()=>{},l=!1,n=!1;if(!1!==r.install&&h("bun")){t("Installing dependencies (bun install)...");try{yield f("bun",["install"],e),l=!0}catch{}}if(!1!==r.git&&h("git")){t("Initializing git repository...");try{yield f("git",["init"],e),yield f("git",["add","."],e),yield f("git",["-c 'user.name=BRICKS CLI'","-c 'user.email=cli@bricks.tools'","commit","-m 'chore: initialize commit'"],e),n=!0}catch{}}return{bunInstalled:l,gitInitialized:n}}),function(e){return i.apply(this,arguments)}),v=(o=a(function*(e,r,t){var l=t.client,n=t.output,i=t.outputAsTarget;if(!l)throw Error("client is required");if(!n)throw Error("output directory is required");var o=(e=>{for(var r=c.resolve(e);;){if(d.existsSync(c.join(r,"application.json"))||d.existsSync(c.join(r,"module.json")))return r;var t=c.dirname(r);if(t===r)return null;r=t}})(i?c.dirname(c.resolve(n)):n);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?l.applicationProject:l.moduleProject,s=yield a({id:r,buildApplicationOnly:!1,setupGitHubActions:!1!==t.githubActions,setupAgents:!1!==t.agents,setupClaudeCode:!1!==t.claude,setupGeminiCLI:!0===t.gemini});if(!s?.files)throw Error(`${e} project not found`);var u=g(s.files),h=i?c.resolve(n):c.resolve(n,u);if(d.existsSync(h))throw Error(`Directory already exists: ${h}`);d.mkdirSync(h,{recursive:!0}),x((yield p(s.files,h)));var f=yield y(h,t),m=f.bunInstalled,v=f.gitInitialized;return{success:!0,path:h,files:s.files.length,bunInstalled:m,gitInitialized:v}}),function(e,r,t){return o.apply(this,arguments)})},60450(e,r,t){t.r(r),t.d(r,{buildScreenshotUrl:()=>m,downloadScreenshot:()=>g,fetchAndSaveScreenshot:()=>p,getDeviceScreenshot:()=>f,getSystemMediaBoxId:()=>h,isMediaEnabled:()=>u});var l,n,i,o=t(99436),a=t(79657),c=t(73024),d=t(76760),s=t(48161),u=e=>e?.media_resource?.enable_media_workspace===!0,h=e=>u(e)&&e.media_resource?.system_media_box_id||null,f=(l=o(function*(e,r,t){var l=yield e.mediaFiles({boxId:r,userTags:[`bricks_screenshot_${t}`],limit:1});return l?.[0]||null}),function(e,r,t){return l.apply(this,arguments)}),m=(e,{preferThumbnail:r=!1}={})=>{if(!e?.meta?.storageEndpoint)return null;var t=e.meta,l=t.storageEndpoint,n=t.originalFileKey,i=(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 l=t.filter(e=>e?.strategy==="BOUNDED"&&"number"==typeof e.width).sort((e,r)=>e.width-r.width);return(l[0]||t[0])?.key||null})(e):null)||n;return i?`${l}/${i}`:null},g=(n=o(function*(e,r=null){var t=yield(0,a.Ay)(e);if(!t.ok)throw Error(`Failed to download screenshot: ${t.statusText}`);var l=yield t.buffer(),n=r||d.join(s.tmpdir(),`bricks-screenshot-${Date.now()}.png`),i=d.dirname(n);return c.existsSync(i)||c.mkdirSync(i,{recursive:!0}),c.writeFileSync(n,l),n}),function(e){return n.apply(this,arguments)}),p=(i=o(function*(e,r,t,l=null,n={}){var i=h(r);if(!i)return{error:"Media workspace not enabled for this workspace"};var o=yield f(e,i,t);if(!o)return{error:"No screenshot available for this device"};var a=m(o,n);return a?{path:yield g(a,l),file:o,url:a}:{error:"Could not build screenshot URL"}}),function(e,r,t){return i.apply(this,arguments)})}};
|