@camstack/addon-admin-ui 1.2.285 → 1.2.287

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.
Files changed (85) hide show
  1. package/dist/assets/{AddonCollectionPage-BaYjX_BC.js → AddonCollectionPage-BRkmer9m.js} +1 -1
  2. package/dist/assets/{Addons-CbwX1Jg9.js → Addons-D23vcxfd.js} +1 -1
  3. package/dist/assets/{AdminTabs-C3CQmF24.js → AdminTabs-CzT7WhHB.js} +1 -1
  4. package/dist/assets/{AiProfiles-D_31zYaa.js → AiProfiles-MEzRvpYm.js} +1 -1
  5. package/dist/assets/{BrokerForm-ChDffKL6.js → BrokerForm-CHpebnKe.js} +1 -1
  6. package/dist/assets/{Build-Bu9OKFz1.js → Build-BFHGxwIC.js} +4 -4
  7. package/dist/assets/{Capabilities-BnRvyVjC.js → Capabilities-BlQogG7e.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-e3BNcYh4.js → CapabilityBadges-nxvISwbm.js} +1 -1
  9. package/dist/assets/{Cluster-UPrVcNjh.js → Cluster-CHm111ym.js} +1 -1
  10. package/dist/assets/{Data-CCm8rqj2.js → Data-B1Mvd86g.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-CB_NkkXn.js → DetectionIntelligence-CcIrTUhq.js} +1 -1
  12. package/dist/assets/{DeviceAggregateSection-CJlNJqG7.js → DeviceAggregateSection-BYmNNqcl.js} +1 -1
  13. package/dist/assets/{DeviceDetail-CSS7rpSy.js → DeviceDetail-DMJviKA5.js} +2 -2
  14. package/dist/assets/{Devices-fpOwBJza.js → Devices-Lpgtxjey.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-Cqhb2DH3.js → EmbedPlayerPage-H5N3h5m3.js} +1 -1
  16. package/dist/assets/{Events-KHptSNL4.js → Events-BuOZG68i.js} +1 -1
  17. package/dist/assets/{FormBuilder-BRt8GbH-.js → FormBuilder-DUMIYgBj.js} +1 -1
  18. package/dist/assets/{Identity-sWYNijD_.js → Identity--z-4dNtl.js} +1 -1
  19. package/dist/assets/{IntegrationDetail-BnWRGDCz.js → IntegrationDetail-xNqv2nVj.js} +1 -1
  20. package/dist/assets/{Integrations-B4oMdNSv.js → Integrations-BzpUPZH0.js} +1 -1
  21. package/dist/assets/{Integrations-0Loa-i0u.js → Integrations-CmgSUwov.js} +1 -1
  22. package/dist/assets/{Locations-BOQD0Epi.js → Locations-CILw3jT0.js} +2 -2
  23. package/dist/assets/{Logs-BZwsfGfp.js → Logs-CnswdbE4.js} +1 -1
  24. package/dist/assets/{ModelLicenses-BipYaAxN.js → ModelLicenses-BEujKTim.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-BzFnL6nP.js → MotionZonesSettings-Drvx4R1U.js} +1 -1
  26. package/dist/assets/{MyAccess-BX0gORi2.js → MyAccess-D1l5oHoh.js} +1 -1
  27. package/dist/assets/{Network-BmwYAu6V.js → Network-DAYu5Xg1.js} +1 -1
  28. package/dist/assets/{NodeAddonsSettingsPanel-BLWKskjV.js → NodeAddonsSettingsPanel-Cau7HAff.js} +1 -1
  29. package/dist/assets/{NodeInferenceDevices-IsInHRAN.js → NodeInferenceDevices-DP858HE-.js} +1 -1
  30. package/dist/assets/Notifications-b9dxEhKX.js +1 -0
  31. package/dist/assets/Pipeline-Cd2lrZsE.js +1 -0
  32. package/dist/assets/{Plates-b0jWR4CZ.js → Plates-CnINlB8o.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-DVRZDkyf.js → PrivacyMaskSettings-CFL6aiIr.js} +1 -1
  34. package/dist/assets/{ProviderIcon-CSjq0REw.js → ProviderIcon-BNBwa3yq.js} +1 -1
  35. package/dist/assets/{Recordings-CPfAhM8-.js → Recordings-BM_ckg4M.js} +1 -1
  36. package/dist/assets/{ScanNetworkModal-DhOHzQ9L.js → ScanNetworkModal-FrDsuHup.js} +1 -1
  37. package/dist/assets/{SceneMonitorEditor-Csb4QawZ.js → SceneMonitorEditor-Byix-fz8.js} +1 -1
  38. package/dist/assets/{Scenes-CJcglTr5.js → Scenes-Dzz93ehu.js} +1 -1
  39. package/dist/assets/{Settings-j69FxT67.js → Settings-DxhPorLM.js} +1 -1
  40. package/dist/assets/{Showroom-gXLnptQe.js → Showroom-C2941arf.js} +1 -1
  41. package/dist/assets/{StorageLocationsPanel-BIC6Jjc3.js → StorageLocationsPanel-ChSMY974.js} +1 -1
  42. package/dist/assets/{Terminal-DBGH7apl.js → Terminal-BB5okFe0.js} +1 -1
  43. package/dist/assets/{Viewer-CChC9Dc0.js → Viewer-Bp33KoAL.js} +1 -1
  44. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dy1DvWN0.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-rGH0onjb.js} +1 -1
  45. package/dist/assets/{archive-BqMfcePL.js → archive-5Mas2QN5.js} +1 -1
  46. package/dist/assets/{authed-media-BGNGCsDJ.js → authed-media-C-GdW4sR.js} +1 -1
  47. package/dist/assets/{boxes-DlSvjy26.js → boxes-DmRzx92a.js} +1 -1
  48. package/dist/assets/circle-slash-DHdMQpp8.js +1 -0
  49. package/dist/assets/{debounced-invalidate-Dvg9qkiy.js → debounced-invalidate-C0Q49rxZ.js} +1 -1
  50. package/dist/assets/{device-integration-icon-CAuS1To6.js → device-integration-icon-D3nzAdm6.js} +1 -1
  51. package/dist/assets/{dist-DuyD6V30.js → dist-CuEHZQOI.js} +1 -1
  52. package/dist/assets/dist-Dr13EzDY.js +349 -0
  53. package/dist/assets/{face-bbox-CwSLNvF3.js → face-bbox-BYO4eo_k.js} +1 -1
  54. package/dist/assets/{hard-drive-download-Cye1fTde.js → hard-drive-download-DUtle7hK.js} +1 -1
  55. package/dist/assets/{hostInit-BQ6k9-DW.js → hostInit-CRmeRRSx.js} +1 -1
  56. package/dist/assets/{index-C42eFxDD.js → index-BKYZ-A1k.js} +3 -3
  57. package/dist/assets/{layers-MKBKrVOo.js → layers-Bu-wqo7e.js} +1 -1
  58. package/dist/assets/{location-owned-usage-DPqIfW5v.js → location-owned-usage-CUmTWZIH.js} +1 -1
  59. package/dist/assets/{mf-entry-bootstrap-0-13ccb64f.js → mf-entry-bootstrap-0-7b59b3b3.js} +2 -2
  60. package/dist/assets/{player-overlays-BngvQ8RQ.js → player-overlays-C8jpTLX_.js} +1 -1
  61. package/dist/assets/remoteEntry-DK94qUFf.js +1 -0
  62. package/dist/assets/{send-CwxL3mU-.js → send-CgB9LX4Y.js} +1 -1
  63. package/dist/assets/{settings-2-BDnKvGUr.js → settings-2-DfegT-uU.js} +1 -1
  64. package/dist/assets/{square-check-big-BI7PwlaT.js → square-check-big-DnQVTScs.js} +1 -1
  65. package/dist/assets/src-Da4rZa8s.js +349 -0
  66. package/dist/assets/src-IZck_LzM.js +67 -0
  67. package/dist/assets/{use-scenes-feed-CVJObkZ5.js → use-scenes-feed-BnDc5eRe.js} +1 -1
  68. package/dist/assets/{use-stationary-objects-4PkZB1uZ.js → use-stationary-objects-qJRQpfXM.js} +1 -1
  69. package/dist/assets/{useDevice-LmLaYm8q.js → useDevice-BiMrRz5a.js} +1 -1
  70. package/dist/assets/useEventInvalidation-BzGQACgt.js +1 -0
  71. package/dist/assets/{useNodeUrlSelection-CId7iSTO.js → useNodeUrlSelection-Rjfa8iPB.js} +1 -1
  72. package/dist/assets/user-round-CF-78OTT.js +1 -0
  73. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CMIb2_8P.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DBJOco52.js} +2 -2
  74. package/dist/index.html +5 -5
  75. package/dist/server/addon.js +138 -159
  76. package/package.json +1 -1
  77. package/dist/assets/Notifications-CmujziuE.js +0 -1
  78. package/dist/assets/Pipeline-CEV8V3AL.js +0 -1
  79. package/dist/assets/circle-slash-qewnNTau.js +0 -1
  80. package/dist/assets/dist-DM0oBV4o.js +0 -349
  81. package/dist/assets/remoteEntry-BnHeUSS5.js +0 -1
  82. package/dist/assets/src-BOmxMoNr.js +0 -349
  83. package/dist/assets/src-CO9C_--0.js +0 -67
  84. package/dist/assets/useEventInvalidation-COyauhtM.js +0 -1
  85. package/dist/assets/user-round-BtuyF32Y.js +0 -1
@@ -1,7 +1,7 @@
1
- import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as p,at as m,gt as h,st as g,yt as _}from"./player-overlays-BngvQ8RQ.js";import{$t as v,At as y,Bt as b,Dl as x,El as S,J as C,Mr as w,Ot as T,Ru as E,St as D,Tl as O,Uc as k,Vu as A,Yl as j,_ as ee,_n as M,an as N,bt as P,dt as F,en as I,kt as te,oi as L,on as R,pl as ne,pt as re,rn as z,rt as ie,tt as ae,ut as oe,vl as se,xt as ce,yt as le,yu as ue,zl as de,zt as fe}from"./src-CO9C_--0.js";import{$t as pe,Pn as me,Qt as B,Xt as V,Zt as he,an as ge,cn as _e,ft as ve,in as ye,on as be,sn as xe}from"./src-BOmxMoNr.js";import{f as Se,i as Ce,s as we}from"./index-C42eFxDD.js";import{t as Te}from"./AdminPage-CiKtOLQm.js";import{r as Ee}from"./useDevice-LmLaYm8q.js";var De=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Oe=_(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var ke=6e4;function Ae(){let e=L({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function je(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:ke,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Me(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:ke,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ne(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Pe(){let e=new Set;for(let t of Object.values(ve))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Fe(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(ve)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Ie(e){let t=Me(e.deviceId);if(t.data!==void 0)return Ne(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Le({value:e,devices:t,onChange:n}){let r=Me(e.deviceId),a=r.data??[],o=Ne(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Device`}),d(N,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Capability`}),d(N,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Re(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Field`}),d(N,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Re(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var ze=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Be(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return ze}}function Ve(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function He(e){return Be(e).map(e=>({value:e,label:Ve(e)}))}function Ue(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var We={triggers:[],actions:[]};function Ge(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Ke(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
- `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function qe(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Je(){return{kind:`expression`,expr:``,bindings:{}}}function Ye(e,t,n){return e.map((e,r)=>r===t?n:e)}function Xe(e,t){return e.filter((e,n)=>n!==t)}function Ze(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Xe(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Qe(e,t){return{...e,triggers:[...t]}}function $e(e,t){return{...e,actions:[...t]}}var et=`deviceId`,tt=`$trigger`,nt=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function rt({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(H,{children:`Step`}),d(N,{value:r.kind,onChange:t=>n(Ye(e,a,Ke(it(t.target.value)))),options:nt.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(R,{variant:`ghost`,disabled:a===0,onClick:()=>n(Ze(e,a,a-1)),title:`Run this step earlier`,children:d(E,{className:`h-3.5 w-3.5`})}),d(R,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Ze(e,a,a+1)),title:`Run this step later`,children:d(A,{className:`h-3.5 w-3.5`})}),d(R,{variant:`ghost`,onClick:()=>n(Xe(e,a)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(H,{children:`Seconds`}),d(b,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ye(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(H,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ye(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(at,{action:r,devices:t,onChange:t=>n(Ye(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>n([...e,Ke(`cap`)]),children:[d(O,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function it(e){return nt.find(t=>t.value===e)?.value??`cap`}function at({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=je(a),s=r?Pe():o.data??[],c=Fe(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Device`}),d(N,{value:r?tt:String(a),onChange:t=>n({...e,deviceId:t.target.value===tt?{$var:et}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:tt,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Capability`}),d(N,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Method`}),d(N,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Arguments (JSON)`}),d(b,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ot(e,t.target.value))})]})]})}function ot(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function st({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(N,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(N,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(b,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(b,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ct({value:e,field:t,onChange:n}){return d(b,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function lt(e){return typeof e==`object`}function ut(e){return lt(e)?e[0]??``:e}function dt(e){return lt(e)?e:typeof e==`boolean`?[]:[e]}function ft({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ie(r),o=He(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=pt(t,o);n({...e,operator:r,value:r===`in`?dt(e.value):ut(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Le,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(H,{children:`Comparison`}),d(N,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Value`}),s?d(ct,{value:dt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(st,{value:ut(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function pt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var mt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function ht({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(H,{children:`Expression`}),d(b,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(gt,{alias:n,source:r,devices:t,onRename:t=>a(St(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Ct(e.bindings,n))},n)),i(R,{variant:`ghost`,onClick:()=>a({...e.bindings,[xt(e.bindings)]:mt}),children:[d(O,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function gt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:yt(n,vt(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(H,{children:`Name`}),d(b,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(H,{children:`Reads`}),d(N,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:mt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Constant`}),d(b,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:_t(e.target.value)})})]}):d(Le,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:bt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(R,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function _t(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function vt(e){return e.kind===`global`?e.sourceStableId:``}function yt(e,t){return e.find(e=>e.stableId===t)?.id??0}function bt(e,t){return e.find(e=>e.id===t)?.stableId??``}function xt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function St(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Ct(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function wt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Tt(e){return wt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Et(e){return e===null?null:_e({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Dt(e){let t=W(e);return{depth:t.children.length===0?0:be(t),leaves:t.children.length===0?0:xe(t),depthLimit:3,leafLimit:32}}function Ot(e,t){let n=Et(t);return n===null?{ok:!0,recipe:wt(e,t)}:{ok:!1,reason:n}}function kt(e,t){let n=W(e);return Ot(e,{kind:n.kind,children:[...n.children,t]})}function At(e,t,n){return wt(e,K(W(e),t,()=>n))}function jt(e,t){return wt(e,K(W(e),t,()=>null))}function Mt(e,t,n){return wt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Nt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Ot(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Pt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Ft(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Pt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return Ot(e,K(i,r.path,()=>d))}function It(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Ot(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Pt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Ot(e,K(n,i.path,()=>o))}r();var Lt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Rt(e){return e.join(`/`)}function zt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Bt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=W(e),f=Dt(e),p=o(()=>r.map(zt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Ft(e,p,`all`),g=Ft(e,p,`any`),_=p.length===1?Nt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},y={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(At(e,t,r)),onRemove:t=>{a([]),n(jt(e,t))},onSetKind:(t,r)=>n(Mt(e,t,r)),onUngroup:t=>m(It(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(v,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(N,{value:u.kind,onChange:t=>n(Mt(e,[],Vt(t.target.value))),options:Lt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Ht,{container:u,path:[],handlers:y}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>m(kt(e,qe())),title:`Compare one device field to a value`,children:[d(O,{className:`h-4 w-4`}),` Condition`]}),i(R,{variant:`outline`,onClick:()=>m(kt(e,Je())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(De,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(R,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(R,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(R,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Vt(e){return e===`any`?`any`:`all`}function Ht({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Ut,{node:e,path:[...t,r],handlers:n},Rt([...t,r])))})}function Ut({node:e,path:t,handlers:n}){let r=Rt(t),a=d(fe,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(N,{value:e.kind,onChange:e=>n.onSetKind(t,Vt(e.target.value)),options:Lt})}),i(R,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Oe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(R,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Ht,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(v,{variant:`warning`,children:`NOT`}),i(R,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Oe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Ut,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(ft,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(ht,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(R,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Wt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=M(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(R,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?p:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(R,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(Se,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(re,{maxHeight:420,children:e})})]})}var Gt=[`device-state`,`device-event`,`schedule`,`manual`],Kt=Object.values(me).sort((e,t)=>e.localeCompare(t));function qt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Jt,{trigger:r,devices:t,position:i,onChange:t=>n(Ye(e,i,t)),onRemove:()=>n(Xe(e,i))},`${r.kind}-${String(i)}`)),i(R,{variant:`outline`,onClick:()=>n([...e,Ge(`device-state`)]),title:`Add another way this automation can start`,children:[d(O,{className:`h-4 w-4`}),` Trigger`]})]})}function Jt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(H,{children:`Trigger`}),d(N,{value:e.kind,onChange:e=>r(Ge(Yt(e.target.value))),options:Gt.map(e=>({value:e,label:Ue(e)}))})]}),d(R,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Xt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Qt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(H,{children:`Cron expression`}),d(b,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Yt(e){return Gt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Xt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ie(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(Le,{value:r,devices:t,onChange:e=>n(q(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(fe,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(st,{value:e.becomes,field:a,onChange:e=>n(q(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(fe,{checked:e.edge===!0,onChange:e=>n(q(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Held for (s)`}),d(b,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,forMs:Zt(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Debounce (s)`}),d(b,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,debounceMs:Zt(e.target.value)}))})]})]})}function Zt(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Qt({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(H,{children:`Event category`}),d(N,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Kt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`From device`}),d(N,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var $t=`hub`;function en({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Tt(t)),[g,_]=l(!1),y=Ae(),x=_e(m),S=o(()=>nn(m),[m]),C=o(()=>rn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||x!==null||S!==null||C.code===null;return d(I,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(v,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(tn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(qt,{triggers:m.triggers,devices:y,onChange:e=>h(Qe(m,e))})}),d(tn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Bt,{recipe:m,devices:y,onChange:h})}),d(tn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(rt,{actions:m.actions,devices:y,onChange:e=>h($e(m,e))})}),d(Wt,{code:C.code,error:C.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:V(e.id)})]}),d(ae,{addonId:V(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:$t})},disabled:n||T,children:[n&&d(de,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(R,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(ne,{className:`h-4 w-4`}),` Logs`]}),d(R,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function tn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function nn(e){let t=ge.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function rn(e,t){try{return{code:ye({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function an(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function on(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function sn(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function cn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function ln({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=J(e),m=C(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(v,{variant:an(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(R,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(R,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(R,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(x,{className:`h-4 w-4`})}),i(T,{children:[d(y,{children:d(R,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(S,{className:`h-4 w-4`})})}),d(te,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(R,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(R,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:V(e.id)})]}),d(ae,{addonId:V(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function un({onCreate:e}){return d(I,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(R,{onClick:e,children:`New automation`})]})})}var dn=`const AUTOMATION_RECIPE =`,fn=`// EJECTED from the visual automation editor — this file is now hand-owned.
1
+ import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as p,at as m,gt as h,st as g,yt as _}from"./player-overlays-C8jpTLX_.js";import{$t as v,At as y,Bt as b,Dl as x,El as S,J as C,Mr as w,Ot as T,Ru as E,St as D,Tl as O,Uc as k,Vu as A,Yl as j,_ as ee,_n as M,an as N,bt as P,dt as F,en as I,kt as te,oi as L,on as R,pl as ne,pt as re,rn as z,rt as ie,tt as ae,ut as oe,vl as se,xt as ce,yt as le,yu as ue,zl as de,zt as fe}from"./src-IZck_LzM.js";import{$t as pe,In as me,Qt as B,cn as he,en as V,ft as ge,ln as _e,on as ve,sn as ye,tn as be,un as xe}from"./src-Da4rZa8s.js";import{f as Se,i as Ce,s as we}from"./index-BKYZ-A1k.js";import{t as Te}from"./AdminPage-CiKtOLQm.js";import{r as Ee}from"./useDevice-BiMrRz5a.js";var De=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Oe=_(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var ke=6e4;function Ae(){let e=L({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function je(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:ke,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Me(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:ke,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ne(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Pe(){let e=new Set;for(let t of Object.values(ge))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Fe(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(ge)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Ie(e){let t=Me(e.deviceId);if(t.data!==void 0)return Ne(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Le({value:e,devices:t,onChange:n}){let r=Me(e.deviceId),a=r.data??[],o=Ne(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Device`}),d(N,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Capability`}),d(N,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Re(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Field`}),d(N,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Re(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var ze=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Be(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return ze}}function Ve(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function He(e){return Be(e).map(e=>({value:e,label:Ve(e)}))}function Ue(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var We={triggers:[],actions:[]};function Ge(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Ke(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
+ `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function qe(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Je(){return{kind:`expression`,expr:``,bindings:{}}}function Ye(e,t,n){return e.map((e,r)=>r===t?n:e)}function Xe(e,t){return e.filter((e,n)=>n!==t)}function Ze(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Xe(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Qe(e,t){return{...e,triggers:[...t]}}function $e(e,t){return{...e,actions:[...t]}}var et=`deviceId`,tt=`$trigger`,nt=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function rt({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(H,{children:`Step`}),d(N,{value:r.kind,onChange:t=>n(Ye(e,a,Ke(it(t.target.value)))),options:nt.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(R,{variant:`ghost`,disabled:a===0,onClick:()=>n(Ze(e,a,a-1)),title:`Run this step earlier`,children:d(E,{className:`h-3.5 w-3.5`})}),d(R,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(Ze(e,a,a+1)),title:`Run this step later`,children:d(A,{className:`h-3.5 w-3.5`})}),d(R,{variant:`ghost`,onClick:()=>n(Xe(e,a)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(H,{children:`Seconds`}),d(b,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ye(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(H,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ye(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(at,{action:r,devices:t,onChange:t=>n(Ye(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>n([...e,Ke(`cap`)]),children:[d(O,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function it(e){return nt.find(t=>t.value===e)?.value??`cap`}function at({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=je(a),s=r?Pe():o.data??[],c=Fe(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Device`}),d(N,{value:r?tt:String(a),onChange:t=>n({...e,deviceId:t.target.value===tt?{$var:et}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:tt,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Capability`}),d(N,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Method`}),d(N,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Arguments (JSON)`}),d(b,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ot(e,t.target.value))})]})]})}function ot(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function st({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(N,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(N,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(b,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(b,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ct({value:e,field:t,onChange:n}){return d(b,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function lt(e){return typeof e==`object`}function ut(e){return lt(e)?e[0]??``:e}function dt(e){return lt(e)?e:typeof e==`boolean`?[]:[e]}function ft({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ie(r),o=He(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=pt(t,o);n({...e,operator:r,value:r===`in`?dt(e.value):ut(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Le,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(H,{children:`Comparison`}),d(N,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Value`}),s?d(ct,{value:dt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(st,{value:ut(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function pt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var mt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function ht({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(H,{children:`Expression`}),d(b,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(gt,{alias:n,source:r,devices:t,onRename:t=>a(St(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Ct(e.bindings,n))},n)),i(R,{variant:`ghost`,onClick:()=>a({...e.bindings,[xt(e.bindings)]:mt}),children:[d(O,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function gt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:yt(n,vt(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(H,{children:`Name`}),d(b,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(H,{children:`Reads`}),d(N,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:mt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Constant`}),d(b,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:_t(e.target.value)})})]}):d(Le,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:bt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(R,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function _t(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function vt(e){return e.kind===`global`?e.sourceStableId:``}function yt(e,t){return e.find(e=>e.stableId===t)?.id??0}function bt(e,t){return e.find(e=>e.id===t)?.stableId??``}function xt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function St(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Ct(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function wt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Tt(e){return wt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function Et(e){return e===null?null:xe({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Dt(e){let t=W(e);return{depth:t.children.length===0?0:he(t),leaves:t.children.length===0?0:_e(t),depthLimit:3,leafLimit:32}}function Ot(e,t){let n=Et(t);return n===null?{ok:!0,recipe:wt(e,t)}:{ok:!1,reason:n}}function kt(e,t){let n=W(e);return Ot(e,{kind:n.kind,children:[...n.children,t]})}function At(e,t,n){return wt(e,K(W(e),t,()=>n))}function jt(e,t){return wt(e,K(W(e),t,()=>null))}function Mt(e,t,n){return wt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Nt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Ot(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Pt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Ft(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Pt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return Ot(e,K(i,r.path,()=>d))}function It(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Ot(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Pt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return Ot(e,K(n,i.path,()=>o))}r();var Lt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Rt(e){return e.join(`/`)}function zt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Bt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=W(e),f=Dt(e),p=o(()=>r.map(zt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Ft(e,p,`all`),g=Ft(e,p,`any`),_=p.length===1?Nt(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},y={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(At(e,t,r)),onRemove:t=>{a([]),n(jt(e,t))},onSetKind:(t,r)=>n(Mt(e,t,r)),onUngroup:t=>m(It(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(v,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(N,{value:u.kind,onChange:t=>n(Mt(e,[],Vt(t.target.value))),options:Lt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Ht,{container:u,path:[],handlers:y}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>m(kt(e,qe())),title:`Compare one device field to a value`,children:[d(O,{className:`h-4 w-4`}),` Condition`]}),i(R,{variant:`outline`,onClick:()=>m(kt(e,Je())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(De,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(R,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(R,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(R,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Vt(e){return e===`any`?`any`:`all`}function Ht({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Ut,{node:e,path:[...t,r],handlers:n},Rt([...t,r])))})}function Ut({node:e,path:t,handlers:n}){let r=Rt(t),a=d(fe,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(N,{value:e.kind,onChange:e=>n.onSetKind(t,Vt(e.target.value)),options:Lt})}),i(R,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Oe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(R,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Ht,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(v,{variant:`warning`,children:`NOT`}),i(R,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Oe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Ut,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(ft,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(ht,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(R,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Wt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=M(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(R,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?p:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(R,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(Se,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(re,{maxHeight:420,children:e})})]})}var Gt=[`device-state`,`device-event`,`schedule`,`manual`],Kt=Object.values(me).sort((e,t)=>e.localeCompare(t));function qt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Jt,{trigger:r,devices:t,position:i,onChange:t=>n(Ye(e,i,t)),onRemove:()=>n(Xe(e,i))},`${r.kind}-${String(i)}`)),i(R,{variant:`outline`,onClick:()=>n([...e,Ge(`device-state`)]),title:`Add another way this automation can start`,children:[d(O,{className:`h-4 w-4`}),` Trigger`]})]})}function Jt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(H,{children:`Trigger`}),d(N,{value:e.kind,onChange:e=>r(Ge(Yt(e.target.value))),options:Gt.map(e=>({value:e,label:Ue(e)}))})]}),d(R,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Xt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Qt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(H,{children:`Cron expression`}),d(b,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Yt(e){return Gt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Xt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ie(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(Le,{value:r,devices:t,onChange:e=>n(q(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(fe,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(st,{value:e.becomes,field:a,onChange:e=>n(q(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(fe,{checked:e.edge===!0,onChange:e=>n(q(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Held for (s)`}),d(b,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,forMs:Zt(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Debounce (s)`}),d(b,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,debounceMs:Zt(e.target.value)}))})]})]})}function Zt(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Qt({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(H,{children:`Event category`}),d(N,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Kt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`From device`}),d(N,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var $t=`hub`;function en({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Tt(t)),[g,_]=l(!1),y=Ae(),x=xe(m),S=o(()=>nn(m),[m]),C=o(()=>rn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||x!==null||S!==null||C.code===null;return d(I,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(v,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(tn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(qt,{triggers:m.triggers,devices:y,onChange:e=>h(Qe(m,e))})}),d(tn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Bt,{recipe:m,devices:y,onChange:h})}),d(tn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(rt,{actions:m.actions,devices:y,onChange:e=>h($e(m,e))})}),d(Wt,{code:C.code,error:C.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(ae,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:$t})},disabled:n||T,children:[n&&d(de,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(R,{variant:`ghost`,onClick:()=>_(!g),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(ne,{className:`h-4 w-4`}),` Logs`]}),d(R,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function tn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function nn(e){let t=ye.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function rn(e,t){try{return{code:ve({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function an(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function on(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function sn(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function cn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function ln({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=J(e),m=C(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(v,{variant:an(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(R,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(R,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(R,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(x,{className:`h-4 w-4`})}),i(T,{children:[d(y,{children:d(R,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(S,{className:`h-4 w-4`})})}),d(te,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(R,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(R,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(ae,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function un({onCreate:e}){return d(I,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(R,{onClick:e,children:`New automation`})]})})}var dn=`const AUTOMATION_RECIPE =`,fn=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
3
  // The recipe that produced it was removed with it, on purpose: while it was
4
- // here the editor could re-open this block and overwrite everything below.`;function pn(e){return e.includes(dn)}function mn(e){let t=e.indexOf(dn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function hn(e){let t=mn(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=ge.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function gn(e){let t=mn(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${fn}${e.slice(i)}`}r();var _n=[`coreBlocks`,`list`],vn=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function yn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:_n,refetchInterval:vn,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),h=()=>{p.refetch()},g=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),_=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),v=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),h()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:h}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:gn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),h(),e(t.block.id)}}),x=p.data,S=sn((x??[]).filter(e=>pn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?on(S,n.block):null,T=w===null?null:hn(w.code),E=g.error===null?_.error===null?b.error===null?null:Y(b.error):Y(_.error):Y(g.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:x===void 0?``:cn(S)}),i(R,{onClick:()=>r({mode:`edit`,block:null}),children:[d(O,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(z,{title:`Could not read the automations`,message:Y(p.error),onRetry:h}),n.mode===`edit`&&d(en,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:We,saving:g.isPending||_.isPending,saveError:E,ejecting:b.isPending,onSave:e=>{w===null?g.mutate(e):_.mutate({blockId:w.id,block:e})},onEject:()=>{w!==null&&b.mutate(w)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},w?.id??`new`),C&&d(un,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(I,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=hn(e.code);return d(ln,{block:e,busy:y.isPending||v.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>v.mutate(e.id)},e.id)})})}),v.error!=null&&d(z,{message:Y(v.error)}),y.error!=null&&d(z,{message:Y(y.error)})]})}function bn(e){return{state:`answered`,byRef:new Map(e.map(e=>[B(e),e]))}}function xn(e,t){if(e.state!==`unanswered`)return e.byRef.get(B(t))??null}function Sn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Cn(e){return pe(e).map(e=>e.source)}function wn(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...Cn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Cn(e))}let r=new Set;return n.filter(e=>{let t=B(e);return r.has(t)?!1:(r.add(t),!0)})}function Tn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function En(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${Tn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Tn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function Dn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return En(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function On(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:Dn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function kn(e){return B(e)}function An(e,t){let n=xn(t,e);return{key:B(e),label:n?n.name:kn(e),presence:Sn(n),deviceId:n?n.id:null}}function jn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Mn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:he(e.block.id),a=B(i),o=wn(e).filter(e=>B(e)!==a).map(e=>An(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=xn(t,i),l=jn(e)??(c?c.id:null),u=On(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,deviceId:l};let d=Sn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:kn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,deviceId:d===`missing`?null:l}}function Nn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Pn(e,t){return Nn(e)-Nn(t)||e.name.localeCompare(t.name)}function Fn(e,t){let n=e.flatMap(e=>{let n=Mn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Pn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Pn)}}var In=1e4;function Ln(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Rn(){let e=Ee();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Ln(e.error)})`}:bn(e.data)}function zn(){let e=w({},{refetchInterval:In}),t=Rn(),n=e.data;if(e.error!=null&&n===void 0)return d(z,{title:`Could not read the compositions`,message:Ln(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(I,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Ln(e.error);return d(Bn,{lists:Fn(n.views,t),fleet:t,refreshError:r})}function Bn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(Vn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`}),d(Vn,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`Compositions are created through the API for now; the editor comes next.`})]})}function Vn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),d(I,{variant:`flat`,className:`p-0`,children:d(oe,{columns:Hn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:F,emptyMessage:a})})]})}function Hn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Un,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(v,{variant:an(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Wn,{sources:e.sources})}]}function Un({row:e}){return i(`div`,{className:`space-y-0.5`,children:[e.deviceId===null?d(`span`,{className:`text-xs text-foreground`,children:e.name}):d(Ce,{to:`/devices/${String(e.deviceId)}`,className:`text-xs text-foreground hover:underline`,children:e.name}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Wn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Ce,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Gn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Kn(e){if(Array.isArray(e))return e}function qn(e,t,n){return(t=nr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Jn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Yn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4
+ // here the editor could re-open this block and overwrite everything below.`;function pn(e){return e.includes(dn)}function mn(e){let t=e.indexOf(dn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function hn(e){let t=mn(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=ye.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function gn(e){let t=mn(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${fn}${e.slice(i)}`}r();var _n=[`coreBlocks`,`list`],vn=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function yn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:_n,refetchInterval:vn,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),h=()=>{p.refetch()},g=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),_=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),h()}}),v=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),h()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:h}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:gn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),h(),e(t.block.id)}}),x=p.data,S=sn((x??[]).filter(e=>pn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?on(S,n.block):null,T=w===null?null:hn(w.code),E=g.error===null?_.error===null?b.error===null?null:Y(b.error):Y(_.error):Y(g.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:x===void 0?``:cn(S)}),i(R,{onClick:()=>r({mode:`edit`,block:null}),children:[d(O,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(z,{title:`Could not read the automations`,message:Y(p.error),onRetry:h}),n.mode===`edit`&&d(en,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:We,saving:g.isPending||_.isPending,saveError:E,ejecting:b.isPending,onSave:e=>{w===null?g.mutate(e):_.mutate({blockId:w.id,block:e})},onEject:()=>{w!==null&&b.mutate(w)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},w?.id??`new`),C&&d(un,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(I,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=hn(e.code);return d(ln,{block:e,busy:y.isPending||v.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>v.mutate(e.id)},e.id)})})}),v.error!=null&&d(z,{message:Y(v.error)}),y.error!=null&&d(z,{message:Y(y.error)})]})}function bn(e){return{state:`answered`,byRef:new Map(e.map(e=>[V(e),e]))}}function xn(e,t){if(e.state!==`unanswered`)return e.byRef.get(V(t))??null}function Sn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Cn(e){return be(e).map(e=>e.source)}function wn(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...Cn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Cn(e))}let r=new Set;return n.filter(e=>{let t=V(e);return r.has(t)?!1:(r.add(t),!0)})}function Tn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function En(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:`Running`,reason:null};let r=[...t.length>0?[`${Tn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Tn(n.length,`field`)} stale`]:[]].join(`, `),i=t[0]??n[0];return{tone:`pending`,label:`Running`,reason:`${r}${i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??`no reason recorded`}`}`}}function Dn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return En(e);case`degraded`:return{tone:`pending`,label:`Degraded`,reason:n??`Running with a field handed back to the device; no reason recorded.`};case`starting`:return{tone:`pending`,label:`Starting`,reason:n};case`failed`:return{tone:`error`,label:`Failed`,reason:n??`Failed with no reason recorded — check the composer logs.`};default:return{tone:`error`,label:`Not running`,reason:n??`Enabled but the composer is not running it.`}}}function On(e){let{block:t,state:n}=e;return t.enabled?n.kind===`unreachable`?{tone:`pending`,label:`Unknown`,reason:`The composer could not be asked: ${n.error}`}:n.state===null?{tone:`pending`,label:`Not reported yet`,reason:`The composer holds no record of this block yet (stored status: ${t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`}).`}:Dn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function kn(e){return V(e)}function An(e,t){let n=xn(t,e);return{key:V(e),label:n?n.name:kn(e),presence:Sn(n),deviceId:n?n.id:null}}function jn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Mn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:pe(e.block.id),a=V(i),o=wn(e).filter(e=>V(e)!==a).map(e=>An(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=xn(t,i),l=jn(e)??(c?c.id:null),u=On(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,deviceId:l};let d=Sn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:kn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,deviceId:d===`missing`?null:l}}function Nn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Pn(e,t){return Nn(e)-Nn(t)||e.name.localeCompare(t.name)}function Fn(e,t){let n=e.flatMap(e=>{let n=Mn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Pn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Pn)}}var In=1e4;function Ln(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Rn(){let e=Ee();return e.data===void 0?{state:`unanswered`,reason:e.error==null?`the device list has not answered yet`:`the device list could not be read (${Ln(e.error)})`}:bn(e.data)}function zn(){let e=w({},{refetchInterval:In}),t=Rn(),n=e.data;if(e.error!=null&&n===void 0)return d(z,{title:`Could not read the compositions`,message:Ln(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(I,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Ln(e.error);return d(Bn,{lists:Fn(n.views,t),fleet:t,refreshError:r})}function Bn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(Vn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`}),d(Vn,{title:`Customizations`,hint:`Fields added to or replaced on an existing device — one per device, edited from the device.`,rows:e.customizations,nameHeader:`Device`,emptyMessage:`No customizations.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`Compositions are created through the API for now; the editor comes next.`})]})}function Vn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),d(I,{variant:`flat`,className:`p-0`,children:d(oe,{columns:Hn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:F,emptyMessage:a})})]})}function Hn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Un,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(v,{variant:an(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Wn,{sources:e.sources})}]}function Un({row:e}){return i(`div`,{className:`space-y-0.5`,children:[e.deviceId===null?d(`span`,{className:`text-xs text-foreground`,children:e.name}):d(Ce,{to:`/devices/${String(e.deviceId)}`,className:`text-xs text-foreground hover:underline`,children:e.name}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Wn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Ce,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Gn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Kn(e){if(Array.isArray(e))return e}function qn(e,t,n){return(t=nr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Jn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Yn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
5
5
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Xn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Zn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Xn(Object(n),!0).forEach(function(t){qn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Xn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Qn(e,t){if(e==null)return{};var n,r,i=$n(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function $n(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function er(e,t){return Kn(e)||Jn(e,t)||rr(e,t)||Yn()}function tr(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function nr(e){var t=tr(e,`string`);return typeof t==`symbol`?t:t+``}function rr(e,t){if(e){if(typeof e==`string`)return Gn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gn(e,t):void 0}}function ir(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ar(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function or(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ar(Object(n),!0).forEach(function(t){ir(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ar(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function sr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function cr(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function lr(e){return{}.toString.call(e).includes(`Object`)}function ur(e){return!Object.keys(e).length}function dr(e){return typeof e==`function`}function fr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function pr(e,t){return lr(t)||X(`changeType`),Object.keys(t).some(function(t){return!fr(e,t)})&&X(`changeField`),t}function mr(e){dr(e)||X(`selectorType`)}function hr(e){dr(e)||lr(e)||X(`handlerType`),lr(e)&&Object.values(e).some(function(e){return!dr(e)})&&X(`handlersType`)}function gr(e){e||X(`initialIsRequired`),lr(e)||X(`initialType`),ur(e)&&X(`initialContent`)}function _r(e,t){throw Error(e[t]||e.default)}var X=cr(_r)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),vr={changes:pr,selector:mr,handler:hr,initial:gr};function yr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};vr.initial(e),vr.handler(t);var n={current:e},r=cr(Sr)(n,t),i=cr(xr)(n),a=cr(vr.changes)(e),o=cr(br)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return vr.selector(e),e(n.current)}function c(e){sr(r,i,a,o)(e)}return[s,c]}function br(e,t){return dr(t)?t(e.current):t}function xr(e,t){return e.current=or(or({},e.current),t),t}function Sr(e,t,n){return dr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Cr={create:yr},wr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Tr(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Er(e){return{}.toString.call(e).includes(`Object`)}function Dr(e){return e||jr(`configIsRequired`),Er(e)||jr(`configType`),e.urls?(Or(),{paths:{vs:e.urls.monacoBase}}):e}function Or(){console.warn(Ar.deprecation)}function kr(e,t){throw Error(e[t]||e.default)}var Ar={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
6
6
  You are using deprecated way of configuration.
7
7
 
@@ -29,4 +29,4 @@ export default function block(ctx: AddonContext) {
29
29
  clearInterval(timer)
30
30
  }
31
31
  }
32
- `;function xi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Si=`hub`;function Ci({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ie(),[x,S]=l(e?.name??``),[C,w]=l(e?.code??bi),[T,E]=l(e?.placement??Si),[D,O]=l(e?.integrationId??``),[A,j]=l([]),[M,N]=l(!1),P=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),F=o(()=>A.filter(e=>e.severity>=8),[A]),te=yi(A),L=x.trim()===``,re=e===null||C!==e.code||x.trim()!==e.name||T!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,z=()=>{P.reset(),h({name:x.trim(),code:C,enabled:e?.enabled??!0,placement:T,...D.trim()===``?{}:{integrationId:D.trim()}})},oe=e===null?null:J(e),ce=xi({existing:e,dirty:re,saving:r,restarting:s});return d(I,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),oe!==null&&d(v,{variant:an(oe.tone),children:oe.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:x,onChange:e=>S(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(b,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(ee,{selectedNodeId:T,onSelect:E,label:`Runs on`,alwaysShow:!0}),T!==Si&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(k,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:M?`grid gap-3 lg:grid-cols-2`:``,children:[d(`div`,{className:`rounded border border-border`,children:n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(vi,{value:C,onChange:w,extraLibs:t?.libs??[],onDiagnostics:j,dark:y===`dark`,heightPx:420})}),M&&i(`div`,{className:`rounded border border-border`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:V(e.id)})]})}),e!==null&&d(ae,{addonId:V(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),F.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[F.length,` error`,F.length===1?``:`s`,` — the block cannot be saved.`]}),F.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),F.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,F.length-5,` more.`]})]}),P.data!==void 0&&(P.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(ue,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[P.data.line===void 0?``:`line ${String(P.data.line)}: `,P.data.error??`the code does not compile`]})),P.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,wi(P.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>P.mutate(C),disabled:P.isPending||r,title:`Type-check on the node without saving`,children:[P.isPending&&d(de,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(R,{onClick:z,disabled:r||te||L,children:[r&&d(de,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(R,{variant:`outline`,onClick:()=>p?.(),disabled:ce!==null||p===void 0,title:ce??`Stop the process and let the supervisor bring it back`,children:[s?d(se,{className:`h-4 w-4 animate-spin`}):d(se,{className:`h-4 w-4`}),` `,`Restart`]}),i(R,{variant:`ghost`,onClick:()=>N(!M),title:`Show this script's process logs`,children:[d(ne,{className:`h-4 w-4`}),` Logs `,M?`⇤`:`⇄`]}),d(R,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,F.length,re&&e!==null?` · unsaved changes`:``]}),L&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function wi(e){return e instanceof Error?e.message:String(e)}r();var Ti=[`coreBlocks`,`list`],Ei=[`coreBlocks`,`getTypeDefs`],Di=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Oi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:Ti,refetchInterval:Di,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ei,enabled:r.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>n.trpcClient.coreBlocks.getTypeDefs.query({})}),v=()=>{g.refetch()},y=t(null),b=g.data;f(()=>{if(e===void 0||y.current===e)return;let t=b?.find(t=>t.id===e);t!==void 0&&(y.current=e,a({mode:`edit`,block:t}))},[e,b]);let x=u({mutationFn:e=>n.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),S=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),E=sn(g.data??[]),D=g.data!==void 0&&E.length===0,k=x.isPending||S.isPending,A=x.error===null?S.error===null?null:$(S.error):$(x.error),j=r.mode===`edit`&&r.block!==null?on(E,r.block):null;return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:g.data===void 0?``:cn(E)}),i(R,{onClick:()=>a({mode:`edit`,block:null}),children:[d(O,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(z,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Ci,{existing:j,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:k,saveError:A,restarting:T.isPending,restartError:T.error===null?null:$(T.error),onRestart:j===null?void 0:()=>T.mutate(j.id),onSave:e=>{let t=j;t===null?x.mutate(e):S.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),S.reset(),T.reset(),a({mode:`closed`})}}),D&&d(I,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),E.length>0&&d(I,{children:d(`ul`,{className:`divide-y divide-border`,children:E.map(e=>d(ki,{block:e,busy:w.isPending||C.isPending,restarting:T.isPending&&T.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>w.mutate({blockId:e.id,enabled:t}),onRestart:()=>T.mutate(e.id),onToggleLogs:()=>h(p===e.id?null:e.id),onEdit:()=>a({mode:`edit`,block:e}),onAskDelete:()=>c(e.id),onCancelDelete:()=>c(null),onConfirmDelete:()=>C.mutate(e.id)},e.id))})}),C.error!=null&&d(z,{message:$(C.error)}),w.error!=null&&d(z,{message:$(w.error)}),T.error!=null&&d(z,{message:$(T.error)})]})}function ki({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=J(e),h=C(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(v,{variant:an(m.tone),children:m.label}),d(v,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(R,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(R,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(R,{variant:`ghost`,onClick:l,title:`Edit`,children:d(x,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(se,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(R,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(R,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:V(e.id)})]}),d(ae,{addonId:V(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Ai=[`automations`,`scripts`,`custom-device`];function ji(e){return e!==null&&Ai.some(t=>t===e)}function Mi(){let[e,t]=we(),n=e.get(`tab`);return d(Te,{icon:j,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(le,{value:ji(n)?n:`automations`,onValueChange:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})},children:[i(ce,{children:[d(D,{value:`automations`,children:`Automations`}),d(D,{value:`scripts`,children:`Scripts`}),d(D,{value:`custom-device`,children:`Custom Device`})]}),d(P,{value:`automations`,children:d(yn,{onOpenScripts:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),d(P,{value:`scripts`,children:d(Oi,{initialBlockId:e.get(`block`)??void 0})}),d(P,{value:`custom-device`,children:d(zn,{})})]})})}export{Mi as BuildPage};
32
+ `;function xi({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}r();var Si=`hub`;function Ci({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ie(),[x,S]=l(e?.name??``),[C,w]=l(e?.code??bi),[T,E]=l(e?.placement??Si),[D,O]=l(e?.integrationId??``),[A,j]=l([]),[M,N]=l(!1),P=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),F=o(()=>A.filter(e=>e.severity>=8),[A]),te=yi(A),L=x.trim()===``,re=e===null||C!==e.code||x.trim()!==e.name||T!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,z=()=>{P.reset(),h({name:x.trim(),code:C,enabled:e?.enabled??!0,placement:T,...D.trim()===``?{}:{integrationId:D.trim()}})},oe=e===null?null:J(e),ce=xi({existing:e,dirty:re,saving:r,restarting:s});return d(I,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),oe!==null&&d(v,{variant:an(oe.tone),children:oe.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:x,onChange:e=>S(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(b,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(ee,{selectedNodeId:T,onSelect:E,label:`Runs on`,alwaysShow:!0}),T!==Si&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(k,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:M?`grid gap-3 lg:grid-cols-2`:``,children:[d(`div`,{className:`rounded border border-border`,children:n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(vi,{value:C,onChange:w,extraLibs:t?.libs??[],onDiagnostics:j,dark:y===`dark`,heightPx:420})}),M&&i(`div`,{className:`rounded border border-border`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:B(e.id)})]})}),e!==null&&d(ae,{addonId:B(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),F.length>0&&i(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[i(`p`,{className:`font-medium text-danger`,children:[F.length,` error`,F.length===1?``:`s`,` — the block cannot be saved.`]}),F.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),F.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,F.length-5,` more.`]})]}),P.data!==void 0&&(P.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(ue,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[P.data.line===void 0?``:`line ${String(P.data.line)}: `,P.data.error??`the code does not compile`]})),P.error!==null&&i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,wi(P.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(R,{variant:`outline`,onClick:()=>P.mutate(C),disabled:P.isPending||r,title:`Type-check on the node without saving`,children:[P.isPending&&d(de,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(R,{onClick:z,disabled:r||te||L,children:[r&&d(de,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(R,{variant:`outline`,onClick:()=>p?.(),disabled:ce!==null||p===void 0,title:ce??`Stop the process and let the supervisor bring it back`,children:[s?d(se,{className:`h-4 w-4 animate-spin`}):d(se,{className:`h-4 w-4`}),` `,`Restart`]}),i(R,{variant:`ghost`,onClick:()=>N(!M),title:`Show this script's process logs`,children:[d(ne,{className:`h-4 w-4`}),` Logs `,M?`⇤`:`⇄`]}),d(R,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,F.length,re&&e!==null?` · unsaved changes`:``]}),L&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function wi(e){return e instanceof Error?e.message:String(e)}r();var Ti=[`coreBlocks`,`list`],Ei=[`coreBlocks`,`getTypeDefs`],Di=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Oi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:Ti,refetchInterval:Di,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ei,enabled:r.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>n.trpcClient.coreBlocks.getTypeDefs.query({})}),v=()=>{g.refetch()},y=t(null),b=g.data;f(()=>{if(e===void 0||y.current===e)return;let t=b?.find(t=>t.id===e);t!==void 0&&(y.current=e,a({mode:`edit`,block:t}))},[e,b]);let x=u({mutationFn:e=>n.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),S=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),E=sn(g.data??[]),D=g.data!==void 0&&E.length===0,k=x.isPending||S.isPending,A=x.error===null?S.error===null?null:$(S.error):$(x.error),j=r.mode===`edit`&&r.block!==null?on(E,r.block):null;return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:g.data===void 0?``:cn(E)}),i(R,{onClick:()=>a({mode:`edit`,block:null}),children:[d(O,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(z,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Ci,{existing:j,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:k,saveError:A,restarting:T.isPending,restartError:T.error===null?null:$(T.error),onRestart:j===null?void 0:()=>T.mutate(j.id),onSave:e=>{let t=j;t===null?x.mutate(e):S.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),S.reset(),T.reset(),a({mode:`closed`})}}),D&&d(I,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),E.length>0&&d(I,{children:d(`ul`,{className:`divide-y divide-border`,children:E.map(e=>d(ki,{block:e,busy:w.isPending||C.isPending,restarting:T.isPending&&T.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>w.mutate({blockId:e.id,enabled:t}),onRestart:()=>T.mutate(e.id),onToggleLogs:()=>h(p===e.id?null:e.id),onEdit:()=>a({mode:`edit`,block:e}),onAskDelete:()=>c(e.id),onCancelDelete:()=>c(null),onConfirmDelete:()=>C.mutate(e.id)},e.id))})}),C.error!=null&&d(z,{message:$(C.error)}),w.error!=null&&d(z,{message:$(w.error)}),T.error!=null&&d(z,{message:$(T.error)})]})}function ki({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=J(e),h=C(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(v,{variant:an(m.tone),children:m.label}),d(v,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(R,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(R,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(R,{variant:`ghost`,onClick:l,title:`Edit`,children:d(x,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(se,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(R,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(R,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(R,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(ae,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Ai=[`automations`,`scripts`,`custom-device`];function ji(e){return e!==null&&Ai.some(t=>t===e)}function Mi(){let[e,t]=we(),n=e.get(`tab`);return d(Te,{icon:j,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(le,{value:ji(n)?n:`automations`,onValueChange:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})},children:[i(ce,{children:[d(D,{value:`automations`,children:`Automations`}),d(D,{value:`scripts`,children:`Scripts`}),d(D,{value:`custom-device`,children:`Custom Device`})]}),d(P,{value:`automations`,children:d(yn,{onOpenScripts:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),d(P,{value:`scripts`,children:d(Oi,{initialBlockId:e.get(`block`)??void 0})}),d(P,{value:`custom-device`,children:d(zn,{})})]})})}export{Mi as BuildPage};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-BngvQ8RQ.js";import{bu as c,nl as l,rn as u,xu as d,zl as f}from"./src-CO9C_--0.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(f,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(c,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[f,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return t(p,{icon:l,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(c,{className:`h-3.5 w-3.5 shrink-0`}):o(d,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(u,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
1
+ import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-C8jpTLX_.js";import{bu as c,nl as l,rn as u,xu as d,zl as f}from"./src-IZck_LzM.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(f,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(c,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[f,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return t(p,{icon:l,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(c,{className:`h-3.5 w-3.5 shrink-0`}):o(d,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(u,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +1 @@
1
- import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{pt as n,ut as r,vt as i,yt as a}from"./player-overlays-BngvQ8RQ.js";import{Dc as o,Fu as s,Ic as c,Ou as l,Qc as u,al as d,bl as f,ju as p,lu as m,nu as h,ul as g,vu as _,yl as v}from"./src-CO9C_--0.js";var y=a(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:c,label:`Streaming`},detection:{icon:h,label:`Detection`},recording:{icon:_,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:o,label:`Motion`},ptz:{icon:g,label:`PTZ`},webrtc:{icon:f,label:`WebRTC`},onvif:{icon:d,label:`ONVIF`},analytics:{icon:m,label:`Analytics`},"battery-operated":{icon:s,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:g,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:p,label:`Doorbell`},rebootable:{icon:v,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:u,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:n,label:`Targeted Mowing`}},x=l;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{pt as n,ut as r,vt as i,yt as a}from"./player-overlays-C8jpTLX_.js";import{Dc as o,Fu as s,Ic as c,Ou as l,Qc as u,al as d,bl as f,ju as p,lu as m,nu as h,ul as g,vu as _,yl as v}from"./src-IZck_LzM.js";var y=a(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:c,label:`Streaming`},detection:{icon:h,label:`Detection`},recording:{icon:_,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:o,label:`Motion`},ptz:{icon:g,label:`PTZ`},webrtc:{icon:f,label:`WebRTC`},onvif:{icon:d,label:`ONVIF`},analytics:{icon:m,label:`Analytics`},"battery-operated":{icon:s,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:g,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:p,label:`Doorbell`},rebootable:{icon:v,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:u,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:n,label:`Targeted Mowing`}},x=l;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
@@ -1,4 +1,4 @@
1
- import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as d,at as f,gt as p,st as m,yt as h}from"./player-overlays-BngvQ8RQ.js";import{Aa as g,Ca as _,Cc as v,Cn as y,Dl as b,En as x,Hu as S,Ls as C,Ma as ee,Oc as w,Ou as te,Ro as T,Sa as E,Sc as ne,Tn as re,Uc as ie,_n as ae,_o as oe,bl as se,dl as ce,dt as D,et as le,fl as ue,gs as de,hs as fe,ja as pe,ka as me,lu as he,ms as ge,oi as _e,pl as ve,ps as ye,tt as be,ut as xe,vl as O,wn as Se,wu as Ce,yl as we,zl as k}from"./src-CO9C_--0.js";import{t as Te}from"./hard-drive-download-Cye1fTde.js";import{vn as Ee}from"./src-BOmxMoNr.js";import{n as A}from"./index-C42eFxDD.js";import{t as j}from"./format-size-DIxKXxtj.js";import{t as De}from"./NodeAddonsSettingsPanel-BLWKskjV.js";import{n as Oe,r as ke,t as Ae}from"./useNodeUrlSelection-CId7iSTO.js";var M=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();function je(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function Me({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Ne=[`trace`,`debug`,`info`,`warn`,`error`];function Pe({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,f]=c(s||n),[m,h]=c(null),[_,v]=c(`info`),b=e.name.includes(`(core)`),S=g(),C=pe(),w=ee(),T=async e=>{h(e);try{await S.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},E=async()=>{h(e.name);try{await C.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},ne=async n=>{let r=`${t}/${e.name}`;try{await w.mutateAsync({nodeId:r,level:n}),v(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>f(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&f(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?d:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?l(ce,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(te,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(Me,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:j(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:je(e.uptimeSeconds)}),!b&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(y,{children:[l(x,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:_}),l(Se,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ne.map(e=>l(re,{onClick:()=>ne(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===_?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:E,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(O,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(ve,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(se,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>T(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(O,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(be,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(le,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Fe({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Pe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Ie={system:0,managed:1,root:2};n();function Le(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Re(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ze({nodeId:e}){let t=s(),n=v(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=_({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Ie[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Re(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>j(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Le(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(we,{className:`h-3 w-3`}),` Refresh`]})}),l(xe,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:D,emptyMessage:`Scanning…`})]})}var N={width:320,height:64},Be=.8,P=Math.ceil(8*Be-3)+1,F=N.width+34,I=N.height+P+1+11,Ve=P+N.height+1+3+Math.ceil(8*Be),He=[1,2,5,10],Ue=[1,2,4,8,16,32,64,128,256,512,1024],L=[1,1.5,2,2.5,3,4,5],R=[4,3,5,2],z=1e-9;function We(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return L.some(e=>Math.abs(t-e)<z)}let n=e/10**Math.floor(Math.log10(e));return L.some(e=>Math.abs(n-e)<z)}function B(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Ue){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of He){let t=e*i;if(t>=r)return t}return 10*i}function V(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=R.find(n=>We(e/n,t))??R[R.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var Ge=2.5;function H(e){return e*Ge}function U(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function W(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function G(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function Ke(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function qe(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function Je(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Ye(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var K={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Xe=`
1
+ import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as d,at as f,gt as p,st as m,yt as h}from"./player-overlays-C8jpTLX_.js";import{Aa as g,Ca as _,Cc as v,Cn as y,Dl as b,En as x,Hu as S,Ls as C,Ma as ee,Oc as w,Ou as te,Ro as T,Sa as E,Sc as ne,Tn as re,Uc as ie,_n as ae,_o as oe,bl as se,dl as ce,dt as D,et as le,fl as ue,gs as de,hs as fe,ja as pe,ka as me,lu as he,ms as ge,oi as _e,pl as ve,ps as ye,tt as be,ut as xe,vl as O,wn as Se,wu as Ce,yl as we,zl as k}from"./src-IZck_LzM.js";import{t as Te}from"./hard-drive-download-DUtle7hK.js";import{bn as Ee}from"./src-Da4rZa8s.js";import{n as A}from"./index-BKYZ-A1k.js";import{t as j}from"./format-size-DIxKXxtj.js";import{t as De}from"./NodeAddonsSettingsPanel-Cau7HAff.js";import{n as Oe,r as ke,t as Ae}from"./useNodeUrlSelection-Rjfa8iPB.js";var M=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();function je(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function Me({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Ne=[`trace`,`debug`,`info`,`warn`,`error`];function Pe({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,f]=c(s||n),[m,h]=c(null),[_,v]=c(`info`),b=e.name.includes(`(core)`),S=g(),C=pe(),w=ee(),T=async e=>{h(e);try{await S.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},E=async()=>{h(e.name);try{await C.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},ne=async n=>{let r=`${t}/${e.name}`;try{await w.mutateAsync({nodeId:r,level:n}),v(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>f(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&f(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?d:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?l(ce,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(te,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(Me,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:j(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:je(e.uptimeSeconds)}),!b&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(y,{children:[l(x,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:_}),l(Se,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ne.map(e=>l(re,{onClick:()=>ne(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===_?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:E,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(O,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(ve,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(se,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>T(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(O,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(be,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(le,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Fe({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Pe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Ie={system:0,managed:1,root:2};n();function Le(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Re(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ze({nodeId:e}){let t=s(),n=v(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=_({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Ie[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Re(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>j(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Le(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(we,{className:`h-3 w-3`}),` Refresh`]})}),l(xe,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:D,emptyMessage:`Scanning…`})]})}var N={width:320,height:64},Be=.8,P=Math.ceil(8*Be-3)+1,F=N.width+34,I=N.height+P+1+11,Ve=P+N.height+1+3+Math.ceil(8*Be),He=[1,2,5,10],Ue=[1,2,4,8,16,32,64,128,256,512,1024],L=[1,1.5,2,2.5,3,4,5],R=[4,3,5,2],z=1e-9;function We(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return L.some(e=>Math.abs(t-e)<z)}let n=e/10**Math.floor(Math.log10(e));return L.some(e=>Math.abs(n-e)<z)}function B(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Ue){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of He){let t=e*i;if(t>=r)return t}return 10*i}function V(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=R.find(n=>We(e/n,t))??R[R.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var Ge=2.5;function H(e){return e*Ge}function U(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function W(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function G(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function Ke(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function qe(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function Je(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Ye(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var K={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Xe=`
2
2
  .load-chart-scope { --load-series-main: #2a78d6; --load-series-gc: #e87ba4; }
3
3
  @media (prefers-color-scheme: dark) {
4
4
  :root:not([data-theme="light"]) .load-chart-scope {