@camstack/addon-admin-ui 1.2.313 → 1.2.315

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 (86) hide show
  1. package/dist/assets/{AddonCollectionPage-DX8FCaT6.js → AddonCollectionPage-pS-uTKIv.js} +1 -1
  2. package/dist/assets/{Addons-Dd7YigNw.js → Addons-9ZIvUT1K.js} +1 -1
  3. package/dist/assets/{AdminTabs-CkZ3HCsC.js → AdminTabs-jHFlbFwy.js} +1 -1
  4. package/dist/assets/{AiProfiles-Uqn4Xesj.js → AiProfiles-BhbohiJt.js} +1 -1
  5. package/dist/assets/{BrokerForm-BPKDqfep.js → BrokerForm-DgGM0_0c.js} +1 -1
  6. package/dist/assets/{Build-CkoCD5mN.js → Build-CUET0Iyz.js} +4 -4
  7. package/dist/assets/{Capabilities-De4yZ5_m.js → Capabilities-C3B2Cg8b.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-DHY8nHlI.js → CapabilityBadges-B4tAQqGd.js} +1 -1
  9. package/dist/assets/{Cluster-D2tcoqSj.js → Cluster-4QQw-L5J.js} +1 -1
  10. package/dist/assets/CompositionEditor-BPm2kx9Q.js +1 -0
  11. package/dist/assets/{CompositionEditorPage-CLdgB8to.js → CompositionEditorPage-VsLdAptk.js} +1 -1
  12. package/dist/assets/{Data-DIktVuyj.js → Data-jiTwAkwz.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-DNAAoRDp.js → DetectionIntelligence-z8Wi34J2.js} +1 -1
  14. package/dist/assets/{DeviceAggregateSection-DMd2WZT9.js → DeviceAggregateSection-CbiGOvpd.js} +1 -1
  15. package/dist/assets/{DeviceDetail-CjW-NXCI.js → DeviceDetail-XZGgHSZ7.js} +2 -2
  16. package/dist/assets/{Devices-CHM8pV35.js → Devices-BUSj9XZS.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-fB57a9gd.js → EmbedPlayerPage-HBoWc3RB.js} +1 -1
  18. package/dist/assets/{Events-DSictw2E.js → Events-CwwN-Ai4.js} +1 -1
  19. package/dist/assets/{FormBuilder-D3oSMJb_.js → FormBuilder-Bsir_-sl.js} +1 -1
  20. package/dist/assets/{Identity-d46-Z6Ye.js → Identity-Dybyl5R-.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-_s1jn10y.js → IntegrationDetail-BKdQfHsS.js} +1 -1
  22. package/dist/assets/{Integrations-SR0bANee.js → Integrations-B3j9mUgh.js} +1 -1
  23. package/dist/assets/{Integrations-BPLuDjht.js → Integrations-CM0m1Zef.js} +1 -1
  24. package/dist/assets/{Locations-CSdf0Sod.js → Locations-CyY2UiFp.js} +1 -1
  25. package/dist/assets/{Logs-BDzIjitK.js → Logs-D0IImY2Y.js} +1 -1
  26. package/dist/assets/{ModelLicenses-bF0wlw_A.js → ModelLicenses-q_i_PA1X.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-CKbKLkZx.js → MotionZonesSettings-CVxyo9hA.js} +1 -1
  28. package/dist/assets/{MyAccess-eaO3Ieug.js → MyAccess-FbdsZp4I.js} +1 -1
  29. package/dist/assets/{Network-CBV5e0t5.js → Network-Ba7GJPhZ.js} +1 -1
  30. package/dist/assets/{NodeAddonsSettingsPanel-C2dYg-1V.js → NodeAddonsSettingsPanel-DssU1eLJ.js} +1 -1
  31. package/dist/assets/{NodeInferenceDevices-Wlk8B-Nc.js → NodeInferenceDevices-4JgJwMA2.js} +1 -1
  32. package/dist/assets/Notifications-DOZJMvSa.js +1 -0
  33. package/dist/assets/{Pipeline-BHc381ud.js → Pipeline-CSVrOhDb.js} +1 -1
  34. package/dist/assets/{Plates-i21xtBfM.js → Plates-D3-W026o.js} +1 -1
  35. package/dist/assets/{PrivacyMaskSettings-BEhQwxlO.js → PrivacyMaskSettings-CLxBzwVu.js} +1 -1
  36. package/dist/assets/{ProviderIcon-ZrL8hgOi.js → ProviderIcon-dscfq54_.js} +1 -1
  37. package/dist/assets/{Recordings-WIOGSNTE.js → Recordings-Ccu6iaCk.js} +1 -1
  38. package/dist/assets/{ScanNetworkModal-D3914YtC.js → ScanNetworkModal-D8yxRM0Z.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-D5tzUVXi.js → SceneMonitorEditor-Cv2vE8HC.js} +1 -1
  40. package/dist/assets/{Scenes-Dvx2S8On.js → Scenes-BQ4CPMKw.js} +1 -1
  41. package/dist/assets/{Settings-DumVFDea.js → Settings-Dfcait6k.js} +1 -1
  42. package/dist/assets/{Showroom-DF-_wvzq.js → Showroom-_zi_fQzx.js} +1 -1
  43. package/dist/assets/{StorageLocationsPanel-DY2ZcvFK.js → StorageLocationsPanel-DNV_ZgVx.js} +1 -1
  44. package/dist/assets/{Terminal-nkSTSU7d.js → Terminal-BC9ErnQ1.js} +1 -1
  45. package/dist/assets/{Viewer-DKv0FjME.js → Viewer-6Aij0p3V.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B9aQEC0J.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-_ywvVYKV.js} +1 -1
  47. package/dist/assets/{archive-BhK62uND.js → archive-DnwqLvnq.js} +1 -1
  48. package/dist/assets/{authed-media-nsjri51Q.js → authed-media-BAASKB_9.js} +1 -1
  49. package/dist/assets/{boxes-DK8vMnI6.js → boxes-kF6UH6-_.js} +1 -1
  50. package/dist/assets/circle-slash-BbFEc4PR.js +1 -0
  51. package/dist/assets/{debounced-invalidate-B6XAyg8u.js → debounced-invalidate-2ngeH0FB.js} +1 -1
  52. package/dist/assets/{device-integration-icon-DepzDzE0.js → device-integration-icon-bqqGCRov.js} +1 -1
  53. package/dist/assets/dist-BXhzcrtM.js +349 -0
  54. package/dist/assets/{dist-By9GSmdO.js → dist-iiQuRL6W.js} +1 -1
  55. package/dist/assets/{face-bbox-nz-Y1fXw.js → face-bbox-zGQvxT6q.js} +1 -1
  56. package/dist/assets/{hard-drive-download-EjN5BuzT.js → hard-drive-download-CoG1t86A.js} +1 -1
  57. package/dist/assets/{hostInit-BKTPtHbx.js → hostInit-ClFPaQoK.js} +1 -1
  58. package/dist/assets/{index-M74_weOu.js → index-BKfjeM9L.js} +3 -3
  59. package/dist/assets/{layers-DWEHZvuc.js → layers-9n_eO6gY.js} +1 -1
  60. package/dist/assets/{location-owned-usage-DpGuVsmt.js → location-owned-usage-XFA4zrIz.js} +1 -1
  61. package/dist/assets/{mf-entry-bootstrap-0-fa7cb38b.js → mf-entry-bootstrap-0-aa4bc7ed.js} +2 -2
  62. package/dist/assets/{player-overlays-Cfcp6NgQ.js → player-overlays-BPnLENh-.js} +1 -1
  63. package/dist/assets/remoteEntry-Dc4is_2X.js +1 -0
  64. package/dist/assets/{send-CHSdt1bF.js → send-EIywGEfF.js} +1 -1
  65. package/dist/assets/{settings-2-DSHFlOLu.js → settings-2-C2jb3QFd.js} +1 -1
  66. package/dist/assets/{square-check-big-BM9cwujH.js → square-check-big-7kDS8B6S.js} +1 -1
  67. package/dist/assets/{src-BeGnyQUE.js → src-Ch2D4L9J.js} +8 -8
  68. package/dist/assets/src-DXUFbK1_.js +349 -0
  69. package/dist/assets/{use-scenes-feed-9RFRgjFo.js → use-scenes-feed-Dl7dI39g.js} +1 -1
  70. package/dist/assets/{use-stationary-objects-G14SHB2s.js → use-stationary-objects-BHIRg4zV.js} +1 -1
  71. package/dist/assets/{useDevice-DvOxHkK6.js → useDevice-BuSELuIc.js} +1 -1
  72. package/dist/assets/useEventInvalidation-C-bG2gYe.js +1 -0
  73. package/dist/assets/{useNodeUrlSelection-DaNJZDRb.js → useNodeUrlSelection-hGEaySeu.js} +1 -1
  74. package/dist/assets/user-round-DIcryj9b.js +1 -0
  75. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C8CtgfL2.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHst_gbg.js} +2 -2
  76. package/dist/index.html +5 -5
  77. package/dist/server/addon.js +71 -9
  78. package/package.json +1 -1
  79. package/dist/assets/CompositionEditor-CULEp5pb.js +0 -1
  80. package/dist/assets/Notifications-BHLLlwNj.js +0 -1
  81. package/dist/assets/circle-slash-Cc4MQ0p4.js +0 -1
  82. package/dist/assets/dist-B2fXVbOE.js +0 -349
  83. package/dist/assets/remoteEntry-otcBA5Lx.js +0 -1
  84. package/dist/assets/src-BQHqLKGc.js +0 -349
  85. package/dist/assets/useEventInvalidation-DPwzQ8Dt.js +0 -1
  86. package/dist/assets/user-round-DNkGWLTR.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-Cfcp6NgQ.js";import{$t as v,Ct as y,Et as b,Ft as x,Ht as S,Jl as C,Mn as w,Mt as T,Nt as E,Pt as D,Qr as O,Qt as k,Tu as A,Ul as j,Ut as M,Vt as ee,Yu as te,bn as N,gt as ne,hd as P,hn as F,hu as I,ji as re,k as ie,mn as L,mt as ae,nu as oe,ru as se,st as ce,tu as R,vd as le,vn as z,wt as ue,xn as B,yl as de}from"./src-BeGnyQUE.js";import{Bn as fe,Fn as pe,Hn as me,Pn as V,Un as he,Vn as ge,Wn as _e,kn as ve,mt as ye,xn as H,yr as be}from"./src-BQHqLKGc.js";import{a as xe,d as Se,i as Ce,m as we,s as Te,y as Ee}from"./index-M74_weOu.js";import{t as De}from"./AdminPage-CiKtOLQm.js";import{r as Oe}from"./useDevice-DvOxHkK6.js";var ke=_(`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`}]]),Ae=_(`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 je=6e4;function Me(){let e=re({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 Ne(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:je,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 Pe(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:je,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Fe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ie(){let e=new Set;for(let t of Object.values(ye))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Le(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(ye)){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 U({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Re(e){let t=Pe(e.deviceId);if(t.data!==void 0)return Fe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ze({value:e,devices:t,onChange:n}){let r=Pe(e.deviceId),a=r.data??[],o=Fe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(U,{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(U,{children:`Capability`}),d(N,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Be(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(U,{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 Be(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 Ve=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function He(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 Ve}}function Ue(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 We(e){return He(e).map(e=>({value:e,label:Ue(e)}))}function Ge(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 Ke={triggers:[],actions:[]};function qe(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 Je(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 Ye(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Xe(){return{kind:`expression`,expr:``,bindings:{}}}function Ze(e,t,n){return e.map((e,r)=>r===t?n:e)}function Qe(e,t){return e.filter((e,n)=>n!==t)}function $e(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=Qe(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function et(e,t){return{...e,triggers:[...t]}}function tt(e,t){return{...e,actions:[...t]}}var nt=`deviceId`,rt=`$trigger`,it=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function at({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(L,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(U,{children:`Step`}),d(N,{value:r.kind,onChange:t=>n(Ze(e,a,Je(ot(t.target.value)))),options:it.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(B,{variant:`ghost`,disabled:a===0,onClick:()=>n($e(e,a,a-1)),title:`Run this step earlier`,children:d(P,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n($e(e,a,a+1)),title:`Run this step later`,children:d(le,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,onClick:()=>n(Qe(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(U,{children:`Seconds`}),d(v,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ze(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(U,{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(Ze(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(st,{action:r,devices:t,onChange:t=>n(Ze(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>n([...e,Je(`cap`)]),children:[d(R,{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 ot(e){return it.find(t=>t.value===e)?.value??`cap`}function st({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Ne(a),s=r?Ie():o.data??[],c=Le(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{children:`Device`}),d(N,{value:r?rt:String(a),onChange:t=>n({...e,deviceId:t.target.value===rt?{$var:nt}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:rt,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(U,{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(U,{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(U,{children:`Arguments (JSON)`}),d(v,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ct(e,t.target.value))})]})]})}function ct(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 lt({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(v,{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(v,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ut({value:e,field:t,onChange:n}){return d(v,{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 dt(e){return typeof e==`object`}function ft(e){return dt(e)?e[0]??``:e}function pt(e){return dt(e)?e:typeof e==`boolean`?[]:[e]}function mt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(r),o=We(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=ht(t,o);n({...e,operator:r,value:r===`in`?pt(e.value):ft(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(ze,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(U,{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(U,{children:`Value`}),s?d(ut,{value:pt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(lt,{value:ft(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function ht(e,t){return t.find(t=>t.value===e)?.value??`eq`}var gt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function _t({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(U,{children:`Expression`}),d(v,{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(vt,{alias:n,source:r,devices:t,onRename:t=>a(wt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Tt(e.bindings,n))},n)),i(B,{variant:`ghost`,onClick:()=>a({...e.bindings,[Ct(e.bindings)]:gt}),children:[d(R,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function vt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:xt(n,bt(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(U,{children:`Name`}),d(v,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(U,{children:`Reads`}),d(N,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:gt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Constant`}),d(v,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:yt(e.target.value)})})]}):d(ze,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:St(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(B,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function yt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function bt(e){return e.kind===`global`?e.sourceStableId:``}function xt(e,t){return e.find(e=>e.stableId===t)?.id??0}function St(e,t){return e.find(e=>e.id===t)?.stableId??``}function Ct(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 wt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Tt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function W(e){return e.kind===`all`||e.kind===`any`}function G(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:W(t)?t:{kind:`all`,children:[t]}}function Et(e,t){return t===null||W(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Dt(e){return Et(e,G(e))}function K(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?K(e.child,r):null;if(!W(e))return null;let i=e.children[n];return i===void 0?null:K(i,r)}function q(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=q(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!W(e))return e;let a=e.children[r];if(a===void 0)return e;let o=q(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 Ot(e){return e===null?null:_e({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function kt(e){let t=G(e);return{depth:t.children.length===0?0:me(t),leaves:t.children.length===0?0:he(t),depthLimit:3,leafLimit:32}}function At(e,t){let n=Ot(t);return n===null?{ok:!0,recipe:Et(e,t)}:{ok:!1,reason:n}}function jt(e,t){let n=G(e);return At(e,{kind:n.kind,children:[...n.children,t]})}function Mt(e,t,n){return Et(e,q(G(e),t,()=>n))}function Nt(e,t){return Et(e,q(G(e),t,()=>null))}function Pt(e,t,n){return Et(e,q(G(e),t,e=>W(e)?{kind:n,children:e.children}:e))}function Ft(e,t){return K(G(e),t)===null?{ok:!1,reason:`that row is no longer there`}:At(e,q(G(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function It(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 Lt(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=It(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=G(e),a=K(i,r.path);if(a===null||!W(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 At(e,q(i,r.path,()=>d))}function Rt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=G(e),r=K(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return At(e,q(n,t,()=>r.child));if(!W(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=It(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=K(n,i.path);if(a===null||!W(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 At(e,q(n,i.path,()=>o))}r();var zt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Bt(e){return e.join(`/`)}function Vt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Ht({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=G(e),f=kt(e),p=o(()=>r.map(Vt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Lt(e,p,`all`),g=Lt(e,p,`any`),_=p.length===1?Ft(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Mt(e,t,r)),onRemove:t=>{a([]),n(Nt(e,t))},onSetKind:(t,r)=>n(Pt(e,t,r)),onUngroup:t=>m(Rt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(L,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(N,{value:u.kind,onChange:t=>n(Pt(e,[],Ut(t.target.value))),options:zt})}),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(Wt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>m(jt(e,Ye())),title:`Compare one device field to a value`,children:[d(R,{className:`h-4 w-4`}),` Condition`]}),i(B,{variant:`outline`,onClick:()=>m(jt(e,Xe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(ke,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(B,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(B,{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(B,{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 Ut(e){return e===`any`?`any`:`all`}function Wt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Gt,{node:e,path:[...t,r],handlers:n},Bt([...t,r])))})}function Gt({node:e,path:t,handlers:n}){let r=Bt(t),a=d(k,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return W(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,Ut(e.target.value)),options:zt})}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(B,{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(Wt,{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(L,{variant:`warning`,children:`NOT`}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Gt,{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(mt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(_t,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(B,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Kt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=w(),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(B,{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(B,{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(Ee,{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(b,{maxHeight:420,children:e})})]})}var qt=[`device-state`,`device-event`,`schedule`,`manual`],Jt=Object.values(be).sort((e,t)=>e.localeCompare(t));function Yt({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(Xt,{trigger:r,devices:t,position:i,onChange:t=>n(Ze(e,i,t)),onRemove:()=>n(Qe(e,i))},`${r.kind}-${String(i)}`)),i(B,{variant:`outline`,onClick:()=>n([...e,qe(`device-state`)]),title:`Add another way this automation can start`,children:[d(R,{className:`h-4 w-4`}),` Trigger`]})]})}function Xt({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(L,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(U,{children:`Trigger`}),d(N,{value:e.kind,onChange:e=>r(qe(Zt(e.target.value))),options:qt.map(e=>({value:e,label:Ge(e)}))})]}),d(B,{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(Qt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(en,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(U,{children:`Cron expression`}),d(v,{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 Zt(e){return qt.find(t=>t===e)??`manual`}function J(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 Qt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(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(ze,{value:r,devices:t,onChange:e=>n(J(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(U,{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(k,{checked:e.becomes===void 0,onChange:e=>n(J(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(lt,{value:e.becomes,field:a,onChange:e=>n(J(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(k,{checked:e.edge===!0,onChange:e=>n(J(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Held for (s)`}),d(v,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,forMs:$t(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Debounce (s)`}),d(v,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,debounceMs:$t(e.target.value)}))})]})]})}function $t(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function en({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(U,{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…`},...Jt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{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 tn=`hub`;function nn({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(()=>Dt(t)),[g,_]=l(!1),y=Me(),b=_e(m),x=o(()=>an(m),[m]),S=o(()=>on(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),C=f.trim()===``,w=C||b!==null||x!==null||S.code===null;return d(F,{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(L,{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(v,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(rn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Yt,{triggers:m.triggers,devices:y,onChange:e=>h(et(m,e))})}),d(rn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Ht,{recipe:m,devices:y,onChange:h})}),d(rn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(at,{actions:m.actions,devices:y,onChange:e=>h(tt(m,e))})}),d(Kt,{code:S.code,error:S.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:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),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(B,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:tn})},disabled:n||w,children:[n&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{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(j,{className:`h-4 w-4`}),` Logs`]}),d(B,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),C&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function rn({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 an(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 on(e,t){try{return{code:fe({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Y(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 sn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function cn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function ln(e){let t=e=>{let t=Y(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 un(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>Y(e).tone===`error`).length,n=e.filter(e=>Y(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 dn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=Y(e),m=ce(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(L,{variant:sn(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(B,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(se,{className:`h-4 w-4`})}),i(ee,{children:[d(M,{children:d(B,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(oe,{className:`h-4 w-4`})})}),d(S,{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(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{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:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function fn({onCreate:e}){return d(F,{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(B,{onClick:e,children:`New automation`})]})})}var pn=`const AUTOMATION_RECIPE =`,mn=`// 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-BPnLENh-.js";import{$t as v,Ct as y,Et as b,Ft as x,Ht as S,Jl as C,Mn as w,Mt as T,Nt as E,Pt as D,Qr as O,Qt as k,Tu as A,Ul as j,Ut as M,Vt as ee,Yu as te,bn as N,gt as ne,hd as P,hn as F,hu as I,ji as re,k as ie,mn as L,mt as ae,nu as oe,ru as se,st as ce,tu as R,vd as le,vn as z,wt as ue,xn as B,yl as de}from"./src-Ch2D4L9J.js";import{Cn as V,Gn as fe,Hn as pe,In as H,Kn as me,Ln as he,Un as ge,Wn as _e,gt as ve,jn as ye,xr as be}from"./src-DXUFbK1_.js";import{a as xe,d as Se,i as Ce,m as we,s as Te,y as Ee}from"./index-BKfjeM9L.js";import{t as De}from"./AdminPage-CiKtOLQm.js";import{r as Oe}from"./useDevice-BuSELuIc.js";var ke=_(`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`}]]),Ae=_(`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 je=6e4;function Me(){let e=re({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 Ne(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:je,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 Pe(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:je,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Fe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ie(){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 Le(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 U({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Re(e){let t=Pe(e.deviceId);if(t.data!==void 0)return Fe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ze({value:e,devices:t,onChange:n}){let r=Pe(e.deviceId),a=r.data??[],o=Fe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(U,{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(U,{children:`Capability`}),d(N,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Be(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(U,{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 Be(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 Ve=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function He(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 Ve}}function Ue(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 We(e){return He(e).map(e=>({value:e,label:Ue(e)}))}function Ge(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 Ke={triggers:[],actions:[]};function qe(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 Je(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 Ye(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Xe(){return{kind:`expression`,expr:``,bindings:{}}}function Ze(e,t,n){return e.map((e,r)=>r===t?n:e)}function Qe(e,t){return e.filter((e,n)=>n!==t)}function $e(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=Qe(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function et(e,t){return{...e,triggers:[...t]}}function tt(e,t){return{...e,actions:[...t]}}var nt=`deviceId`,rt=`$trigger`,it=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function at({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(L,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(U,{children:`Step`}),d(N,{value:r.kind,onChange:t=>n(Ze(e,a,Je(ot(t.target.value)))),options:it.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(B,{variant:`ghost`,disabled:a===0,onClick:()=>n($e(e,a,a-1)),title:`Run this step earlier`,children:d(P,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n($e(e,a,a+1)),title:`Run this step later`,children:d(le,{className:`h-3.5 w-3.5`})}),d(B,{variant:`ghost`,onClick:()=>n(Qe(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(U,{children:`Seconds`}),d(v,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ze(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(U,{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(Ze(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(st,{action:r,devices:t,onChange:t=>n(Ze(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>n([...e,Je(`cap`)]),children:[d(R,{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 ot(e){return it.find(t=>t.value===e)?.value??`cap`}function st({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Ne(a),s=r?Ie():o.data??[],c=Le(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{children:`Device`}),d(N,{value:r?rt:String(a),onChange:t=>n({...e,deviceId:t.target.value===rt?{$var:nt}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:rt,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(U,{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(U,{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(U,{children:`Arguments (JSON)`}),d(v,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ct(e,t.target.value))})]})]})}function ct(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 lt({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(v,{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(v,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ut({value:e,field:t,onChange:n}){return d(v,{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 dt(e){return typeof e==`object`}function ft(e){return dt(e)?e[0]??``:e}function pt(e){return dt(e)?e:typeof e==`boolean`?[]:[e]}function mt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(r),o=We(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=ht(t,o);n({...e,operator:r,value:r===`in`?pt(e.value):ft(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(ze,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(U,{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(U,{children:`Value`}),s?d(ut,{value:pt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(lt,{value:ft(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function ht(e,t){return t.find(t=>t.value===e)?.value??`eq`}var gt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function _t({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(U,{children:`Expression`}),d(v,{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(vt,{alias:n,source:r,devices:t,onRename:t=>a(wt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Tt(e.bindings,n))},n)),i(B,{variant:`ghost`,onClick:()=>a({...e.bindings,[Ct(e.bindings)]:gt}),children:[d(R,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function vt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:xt(n,bt(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(U,{children:`Name`}),d(v,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(U,{children:`Reads`}),d(N,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:gt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(U,{children:`Constant`}),d(v,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:yt(e.target.value)})})]}):d(ze,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:St(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(B,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function yt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function bt(e){return e.kind===`global`?e.sourceStableId:``}function xt(e,t){return e.find(e=>e.stableId===t)?.id??0}function St(e,t){return e.find(e=>e.id===t)?.stableId??``}function Ct(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 wt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Tt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function W(e){return e.kind===`all`||e.kind===`any`}function G(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:W(t)?t:{kind:`all`,children:[t]}}function Et(e,t){return t===null||W(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Dt(e){return Et(e,G(e))}function K(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?K(e.child,r):null;if(!W(e))return null;let i=e.children[n];return i===void 0?null:K(i,r)}function q(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=q(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!W(e))return e;let a=e.children[r];if(a===void 0)return e;let o=q(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 Ot(e){return e===null?null:me({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function kt(e){let t=G(e);return{depth:t.children.length===0?0:_e(t),leaves:t.children.length===0?0:fe(t),depthLimit:3,leafLimit:32}}function At(e,t){let n=Ot(t);return n===null?{ok:!0,recipe:Et(e,t)}:{ok:!1,reason:n}}function jt(e,t){let n=G(e);return At(e,{kind:n.kind,children:[...n.children,t]})}function Mt(e,t,n){return Et(e,q(G(e),t,()=>n))}function Nt(e,t){return Et(e,q(G(e),t,()=>null))}function Pt(e,t,n){return Et(e,q(G(e),t,e=>W(e)?{kind:n,children:e.children}:e))}function Ft(e,t){return K(G(e),t)===null?{ok:!1,reason:`that row is no longer there`}:At(e,q(G(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function It(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 Lt(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=It(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=G(e),a=K(i,r.path);if(a===null||!W(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 At(e,q(i,r.path,()=>d))}function Rt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=G(e),r=K(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return At(e,q(n,t,()=>r.child));if(!W(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=It(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=K(n,i.path);if(a===null||!W(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 At(e,q(n,i.path,()=>o))}r();var zt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Bt(e){return e.join(`/`)}function Vt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Ht({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=G(e),f=kt(e),p=o(()=>r.map(Vt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Lt(e,p,`all`),g=Lt(e,p,`any`),_=p.length===1?Ft(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},v={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Mt(e,t,r)),onRemove:t=>{a([]),n(Nt(e,t))},onSetKind:(t,r)=>n(Pt(e,t,r)),onUngroup:t=>m(Rt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(L,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(N,{value:u.kind,onChange:t=>n(Pt(e,[],Ut(t.target.value))),options:zt})}),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(Wt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(B,{variant:`outline`,onClick:()=>m(jt(e,Ye())),title:`Compare one device field to a value`,children:[d(R,{className:`h-4 w-4`}),` Condition`]}),i(B,{variant:`outline`,onClick:()=>m(jt(e,Xe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(ke,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(B,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(B,{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(B,{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 Ut(e){return e===`any`?`any`:`all`}function Wt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Gt,{node:e,path:[...t,r],handlers:n},Bt([...t,r])))})}function Gt({node:e,path:t,handlers:n}){let r=Bt(t),a=d(k,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return W(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,Ut(e.target.value)),options:zt})}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(B,{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(Wt,{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(L,{variant:`warning`,children:`NOT`}),i(B,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Ae,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Gt,{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(mt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(_t,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(B,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Kt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=w(),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(B,{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(B,{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(Ee,{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(b,{maxHeight:420,children:e})})]})}var qt=[`device-state`,`device-event`,`schedule`,`manual`],Jt=Object.values(be).sort((e,t)=>e.localeCompare(t));function Yt({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(Xt,{trigger:r,devices:t,position:i,onChange:t=>n(Ze(e,i,t)),onRemove:()=>n(Qe(e,i))},`${r.kind}-${String(i)}`)),i(B,{variant:`outline`,onClick:()=>n([...e,qe(`device-state`)]),title:`Add another way this automation can start`,children:[d(R,{className:`h-4 w-4`}),` Trigger`]})]})}function Xt({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(L,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(U,{children:`Trigger`}),d(N,{value:e.kind,onChange:e=>r(qe(Zt(e.target.value))),options:qt.map(e=>({value:e,label:Ge(e)}))})]}),d(B,{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(Qt,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(en,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(U,{children:`Cron expression`}),d(v,{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 Zt(e){return qt.find(t=>t===e)??`manual`}function J(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 Qt({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Re(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(ze,{value:r,devices:t,onChange:e=>n(J(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(U,{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(k,{checked:e.becomes===void 0,onChange:e=>n(J(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(lt,{value:e.becomes,field:a,onChange:e=>n(J(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(k,{checked:e.edge===!0,onChange:e=>n(J(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Held for (s)`}),d(v,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,forMs:$t(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(U,{children:`Debounce (s)`}),d(v,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(J(r,{...o,debounceMs:$t(e.target.value)}))})]})]})}function $t(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function en({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(U,{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…`},...Jt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(U,{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 tn=`hub`;function nn({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(()=>Dt(t)),[g,_]=l(!1),y=Me(),b=me(m),x=o(()=>an(m),[m]),S=o(()=>on(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),C=f.trim()===``,w=C||b!==null||x!==null||S.code===null;return d(F,{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(L,{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(v,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(rn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Yt,{triggers:m.triggers,devices:y,onChange:e=>h(et(m,e))})}),d(rn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Ht,{recipe:m,devices:y,onChange:h})}),d(rn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(at,{actions:m.actions,devices:y,onChange:e=>h(tt(m,e))})}),d(Kt,{code:S.code,error:S.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})]}),b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),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(B,{onClick:()=>{S.code!==null&&s({name:f.trim(),code:S.code,enabled:e?.enabled??!0,placement:tn})},disabled:n||w,children:[n&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{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(j,{className:`h-4 w-4`}),` Logs`]}),d(B,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),C&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function rn({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 an(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 on(e,t){try{return{code:pe({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Y(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 sn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function cn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function ln(e){let t=e=>{let t=Y(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 un(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>Y(e).tone===`error`).length,n=e.filter(e=>Y(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 dn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=Y(e),m=ce(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(L,{variant:sn(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(B,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(se,{className:`h-4 w-4`})}),i(ee,{children:[d(M,{children:d(B,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(oe,{className:`h-4 w-4`})})}),d(S,{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(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{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 fn({onCreate:e}){return d(F,{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(B,{onClick:e,children:`New automation`})]})})}var pn=`const AUTOMATION_RECIPE =`,mn=`// 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 hn(e){return e.includes(pn)}function gn(e){let t=e.indexOf(pn);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 _n(e){let t=gn(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 vn(e){let t=gn(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)}${mn}${e.slice(i)}`}r();var yn=[`coreBlocks`,`list`],bn=5e3;function X(e){return e instanceof Error?e.message:String(e)}function xn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:yn,refetchInterval:bn,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:vn(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=ln((x??[]).filter(e=>hn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?cn(S,n.block):null,T=w===null?null:_n(w.code),E=g.error===null?_.error===null?b.error===null?null:X(b.error):X(_.error):X(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?``:un(S)}),i(B,{onClick:()=>r({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(z,{title:`Could not read the automations`,message:X(p.error),onRetry:h}),n.mode===`edit`&&d(nn,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:Ke,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(fn,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=_n(e.code);return d(dn,{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:X(v.error)}),y.error!=null&&d(z,{message:X(y.error)})]})}function Sn(e){return{state:`answered`,byRef:new Map(e.map(e=>[V(e),e]))}}function Cn(e,t){if(e.state!==`unanswered`)return e.byRef.get(V(t))??null}function wn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Tn(e){return pe(e).map(e=>e.source)}function En(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(...Tn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Tn(e))}let r=new Set;return n.filter(e=>{let t=V(e);return r.has(t)?!1:(r.add(t),!0)})}function Dn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function On(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?[`${Dn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Dn(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 kn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return On(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 An(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}`}).`}:kn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function jn(e){return V(e)}function Mn(e,t){let n=Cn(t,e);return{key:V(e),label:n?n.name:jn(e),presence:wn(n),deviceId:n?n.id:null}}function Nn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Pn(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:ve(e.block.id),a=V(i),o=En(e).filter(e=>V(e)!==a).map(e=>Mn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Cn(t,i),l=Nn(e),u=An(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,reportedDeviceId:l};let d=wn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:jn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Fn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function In(e,t){return Fn(e)-Fn(t)||e.name.localeCompare(t.name)}function Ln(e,t){let n=e.flatMap(e=>{let n=Pn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(In),customizations:n.filter(e=>e.kind===`customization`).toSorted(In)}}var Rn=1e4;function zn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Bn(){let e=Oe();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 (${zn(e.error)})`}:Sn(e.data)}function Vn(){let e=O({},{refetchInterval:Rn}),t=Bn(),n=e.data;if(e.error!=null&&n===void 0)return d(z,{title:`Could not read the compositions`,message:zn(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(F,{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:zn(e.error);return d(Hn,{lists:Ln(n.views,t),fleet:t,refreshError:r})}function Hn({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(Un,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(Se,{to:Ce,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Un,{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.`})]})}function Un({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(F,{variant:`flat`,className:`p-0`,children:d(y,{columns:Wn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:ue,emptyMessage:a})})]})}function Wn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Gn,{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(L,{variant:sn(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(qn,{sources:e.sources})}]}function Gn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Kn,{row:e}),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 Kn({row:e}){return e.kind===`composed`?d(Se,{to:xe(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Se,{to:Te(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function qn({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(Se,{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 Jn(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 Yn(e){if(Array.isArray(e))return e}function Xn(e,t,n){return(t=ar(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zn(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 Qn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4
+ // here the editor could re-open this block and overwrite everything below.`;function hn(e){return e.includes(pn)}function gn(e){let t=e.indexOf(pn);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 _n(e){let t=gn(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 vn(e){let t=gn(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)}${mn}${e.slice(i)}`}r();var yn=[`coreBlocks`,`list`],bn=5e3;function X(e){return e instanceof Error?e.message:String(e)}function xn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:yn,refetchInterval:bn,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:vn(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=ln((x??[]).filter(e=>hn(e.code))),C=x!==void 0&&S.length===0,w=n.mode===`edit`&&n.block!==null?cn(S,n.block):null,T=w===null?null:_n(w.code),E=g.error===null?_.error===null?b.error===null?null:X(b.error):X(_.error):X(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?``:un(S)}),i(B,{onClick:()=>r({mode:`edit`,block:null}),children:[d(R,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(z,{title:`Could not read the automations`,message:X(p.error),onRetry:h}),n.mode===`edit`&&d(nn,{existing:w,initialRecipe:T!==null&&T.ok?T.recipe:Ke,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(fn,{onCreate:()=>r({mode:`edit`,block:null})}),S.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:S.map(e=>{let t=_n(e.code);return d(dn,{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:X(v.error)}),y.error!=null&&d(z,{message:X(y.error)})]})}function Sn(e){return{state:`answered`,byRef:new Map(e.map(e=>[H(e),e]))}}function Cn(e,t){if(e.state!==`unanswered`)return e.byRef.get(H(t))??null}function wn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Tn(e){return he(e).map(e=>e.source)}function En(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(...Tn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Tn(e))}let r=new Set;return n.filter(e=>{let t=H(e);return r.has(t)?!1:(r.add(t),!0)})}function Dn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function On(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?[`${Dn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Dn(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 kn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return On(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 An(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}`}).`}:kn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function jn(e){return H(e)}function Mn(e,t){let n=Cn(t,e);return{key:H(e),label:n?n.name:jn(e),presence:wn(n),deviceId:n?n.id:null}}function Nn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Pn(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:ye(e.block.id),a=H(i),o=En(e).filter(e=>H(e)!==a).map(e=>Mn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Cn(t,i),l=Nn(e),u=An(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,reportedDeviceId:l};let d=wn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:jn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Fn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function In(e,t){return Fn(e)-Fn(t)||e.name.localeCompare(t.name)}function Ln(e,t){let n=e.flatMap(e=>{let n=Pn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(In),customizations:n.filter(e=>e.kind===`customization`).toSorted(In)}}var Rn=1e4;function zn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Bn(){let e=Oe();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 (${zn(e.error)})`}:Sn(e.data)}function Vn(){let e=O({},{refetchInterval:Rn}),t=Bn(),n=e.data;if(e.error!=null&&n===void 0)return d(z,{title:`Could not read the compositions`,message:zn(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(F,{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:zn(e.error);return d(Hn,{lists:Ln(n.views,t),fleet:t,refreshError:r})}function Hn({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(Un,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(Se,{to:Ce,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Un,{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.`})]})}function Un({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(F,{variant:`flat`,className:`p-0`,children:d(y,{columns:Wn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:ue,emptyMessage:a})})]})}function Wn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Gn,{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(L,{variant:sn(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(qn,{sources:e.sources})}]}function Gn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Kn,{row:e}),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 Kn({row:e}){return e.kind===`composed`?d(Se,{to:xe(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Se,{to:Te(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function qn({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(Se,{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 Jn(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 Yn(e){if(Array.isArray(e))return e}function Xn(e,t,n){return(t=ar(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zn(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 Qn(){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 $n(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 er(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?$n(Object(n),!0).forEach(function(t){Xn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$n(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tr(e,t){if(e==null)return{};var n,r,i=nr(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 nr(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 rr(e,t){return Yn(e)||Zn(e,t)||or(e,t)||Qn()}function ir(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 ar(e){var t=ir(e,`string`);return typeof t==`symbol`?t:t+``}function or(e,t){if(e){if(typeof e==`string`)return Jn(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)?Jn(e,t):void 0}}function sr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function cr(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 lr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?cr(Object(n),!0).forEach(function(t){sr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):cr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ur(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function dr(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 fr(e){return{}.toString.call(e).includes(`Object`)}function pr(e){return!Object.keys(e).length}function mr(e){return typeof e==`function`}function hr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function gr(e,t){return fr(t)||Z(`changeType`),Object.keys(t).some(function(t){return!hr(e,t)})&&Z(`changeField`),t}function _r(e){mr(e)||Z(`selectorType`)}function vr(e){mr(e)||fr(e)||Z(`handlerType`),fr(e)&&Object.values(e).some(function(e){return!mr(e)})&&Z(`handlersType`)}function yr(e){e||Z(`initialIsRequired`),fr(e)||Z(`initialType`),pr(e)&&Z(`initialContent`)}function br(e,t){throw Error(e[t]||e.default)}var Z=dr(br)({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"}),xr={changes:gr,selector:_r,handler:vr,initial:yr};function Sr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};xr.initial(e),xr.handler(t);var n={current:e},r=dr(Tr)(n,t),i=dr(wr)(n),a=dr(xr.changes)(e),o=dr(Cr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return xr.selector(e),e(n.current)}function c(e){ur(r,i,a,o)(e)}return[s,c]}function Cr(e,t){return mr(t)?t(e.current):t}function wr(e,t){return e.current=lr(lr({},e.current),t),t}function Tr(e,t,n){return mr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Er={create:Sr},Dr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Or(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 kr(e){return{}.toString.call(e).includes(`Object`)}function Ar(e){return e||Pr(`configIsRequired`),kr(e)||Pr(`configType`),e.urls?(jr(),{paths:{vs:e.urls.monacoBase}}):e}function jr(){console.warn(Nr.deprecation)}function Mr(e,t){throw Error(e[t]||e.default)}var Nr={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 Ti({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 Ei=`hub`;function Di({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ne(),[b,x]=l(e?.name??``),[S,w]=l(e?.code??wi),[T,E]=l(e?.placement??Ei),[D,O]=l(e?.integrationId??``),[k,A]=l([]),[M,ee]=l(!1),N=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),P=o(()=>k.filter(e=>e.severity>=8),[k]),re=Ci(k),oe=b.trim()===``,se=e===null||S!==e.code||b.trim()!==e.name||T!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ce=()=>{N.reset(),h({name:b.trim(),code:S,enabled:e?.enabled??!0,placement:T,...D.trim()===``?{}:{integrationId:D.trim()}})},R=e===null?null:Y(e),le=Ti({existing:e,dirty:se,saving:r,restarting:s});return d(F,{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}`}),R!==null&&d(L,{variant:sn(R.tone),children:R.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(v,{className:`mt-1`,value:b,onChange:e=>x(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(v,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(ie,{selectedNodeId:T,onSelect:E,label:`Runs on`,alwaysShow:!0}),T!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(de,{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(Si,{value:S,onChange:w,extraLibs:t?.libs??[],onDiagnostics:A,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:H(e.id)})]})}),e!==null&&d(ae,{addonId:H(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.`}),P.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:[P.length,` error`,P.length===1?``:`s`,` — the block cannot be saved.`]}),P.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),P.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,P.length-5,` more.`]})]}),N.data!==void 0&&(N.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(te,{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:[N.data.line===void 0?``:`line ${String(N.data.line)}: `,N.data.error??`the code does not compile`]})),N.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: `,Oi(N.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(B,{variant:`outline`,onClick:()=>N.mutate(S),disabled:N.isPending||r,title:`Type-check on the node without saving`,children:[N.isPending&&d(I,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(B,{onClick:ce,disabled:r||re||oe,children:[r&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{variant:`outline`,onClick:()=>p?.(),disabled:le!==null||p===void 0,title:le??`Stop the process and let the supervisor bring it back`,children:[s?d(C,{className:`h-4 w-4 animate-spin`}):d(C,{className:`h-4 w-4`}),` `,`Restart`]}),i(B,{variant:`ghost`,onClick:()=>ee(!M),title:`Show this script's process logs`,children:[d(j,{className:`h-4 w-4`}),` Logs `,M?`⇤`:`⇄`]}),d(B,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,P.length,se&&e!==null?` · unsaved changes`:``]}),oe&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function Oi(e){return e instanceof Error?e.message:String(e)}r();var ki=[`coreBlocks`,`list`],Ai=[`coreBlocks`,`getTypeDefs`],ji=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Mi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:ki,refetchInterval:ji,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ai,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=ln(g.data??[]),D=g.data!==void 0&&E.length===0,O=x.isPending||S.isPending,k=x.error===null?S.error===null?null:$(S.error):$(x.error),A=r.mode===`edit`&&r.block!==null?cn(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?``:un(E)}),i(B,{onClick:()=>a({mode:`edit`,block:null}),children:[d(R,{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(Di,{existing:A,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:O,saveError:k,restarting:T.isPending,restartError:T.error===null?null:$(T.error),onRestart:A===null?void 0:()=>T.mutate(A.id),onSave:e=>{let t=A;t===null?x.mutate(e):S.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),S.reset(),T.reset(),a({mode:`closed`})}}),D&&d(F,{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(F,{children:d(`ul`,{className:`divide-y divide-border`,children:E.map(e=>d(Ni,{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 Ni({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=Y(e),h=ce(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(L,{variant:sn(m.tone),children:m.label}),d(L,{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(B,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:l,title:`Edit`,children:d(se,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(C,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{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:H(e.id)})]}),d(ae,{addonId:H(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Pi=[`automations`,`scripts`,`custom-device`];function Fi(e){return e!==null&&Pi.some(t=>t===e)}function Ii(){let[e,t]=we(),n=e.get(`tab`);return d(De,{icon:A,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(T,{value:Fi(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(D,{children:[d(x,{value:`automations`,children:`Automations`}),d(x,{value:`scripts`,children:`Scripts`}),d(x,{value:`custom-device`,children:`Custom Device`})]}),d(E,{value:`automations`,children:d(xn,{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(E,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(E,{value:`custom-device`,children:d(Vn,{})})]})})}export{Ii as BuildPage};
32
+ `;function Ti({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 Ei=`hub`;function Di({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:p,onSave:h,onCancel:g}){let _=m(),{resolvedMode:y}=ne(),[b,x]=l(e?.name??``),[S,w]=l(e?.code??wi),[T,E]=l(e?.placement??Ei),[D,O]=l(e?.integrationId??``),[k,A]=l([]),[M,ee]=l(!1),N=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),P=o(()=>k.filter(e=>e.severity>=8),[k]),re=Ci(k),oe=b.trim()===``,se=e===null||S!==e.code||b.trim()!==e.name||T!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ce=()=>{N.reset(),h({name:b.trim(),code:S,enabled:e?.enabled??!0,placement:T,...D.trim()===``?{}:{integrationId:D.trim()}})},R=e===null?null:Y(e),le=Ti({existing:e,dirty:se,saving:r,restarting:s});return d(F,{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}`}),R!==null&&d(L,{variant:sn(R.tone),children:R.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(v,{className:`mt-1`,value:b,onChange:e=>x(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(v,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(ie,{selectedNodeId:T,onSelect:E,label:`Runs on`,alwaysShow:!0}),T!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(de,{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(Si,{value:S,onChange:w,extraLibs:t?.libs??[],onDiagnostics:A,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.`}),P.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:[P.length,` error`,P.length===1?``:`s`,` — the block cannot be saved.`]}),P.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),P.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,P.length-5,` more.`]})]}),N.data!==void 0&&(N.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(te,{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:[N.data.line===void 0?``:`line ${String(N.data.line)}: `,N.data.error??`the code does not compile`]})),N.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: `,Oi(N.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(B,{variant:`outline`,onClick:()=>N.mutate(S),disabled:N.isPending||r,title:`Type-check on the node without saving`,children:[N.isPending&&d(I,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(B,{onClick:ce,disabled:r||re||oe,children:[r&&d(I,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(B,{variant:`outline`,onClick:()=>p?.(),disabled:le!==null||p===void 0,title:le??`Stop the process and let the supervisor bring it back`,children:[s?d(C,{className:`h-4 w-4 animate-spin`}):d(C,{className:`h-4 w-4`}),` `,`Restart`]}),i(B,{variant:`ghost`,onClick:()=>ee(!M),title:`Show this script's process logs`,children:[d(j,{className:`h-4 w-4`}),` Logs `,M?`⇤`:`⇄`]}),d(B,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,P.length,se&&e!==null?` · unsaved changes`:``]}),oe&&d(L,{variant:`warning`,children:`Name required`})]})]})})}function Oi(e){return e instanceof Error?e.message:String(e)}r();var ki=[`coreBlocks`,`list`],Ai=[`coreBlocks`,`getTypeDefs`],ji=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Mi({initialBlockId:e}={}){let n=m(),[r,a]=l({mode:`closed`}),[o,c]=l(null),[p,h]=l(null),g=s({queryKey:ki,refetchInterval:ji,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}),_=s({queryKey:Ai,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=ln(g.data??[]),D=g.data!==void 0&&E.length===0,O=x.isPending||S.isPending,k=x.error===null?S.error===null?null:$(S.error):$(x.error),A=r.mode===`edit`&&r.block!==null?cn(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?``:un(E)}),i(B,{onClick:()=>a({mode:`edit`,block:null}),children:[d(R,{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(Di,{existing:A,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:O,saveError:k,restarting:T.isPending,restartError:T.error===null?null:$(T.error),onRestart:A===null?void 0:()=>T.mutate(A.id),onSave:e=>{let t=A;t===null?x.mutate(e):S.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),S.reset(),T.reset(),a({mode:`closed`})}}),D&&d(F,{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(F,{children:d(`ul`,{className:`divide-y divide-border`,children:E.map(e=>d(Ni,{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 Ni({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=Y(e),h=ce(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(L,{variant:sn(m.tone),children:m.label}),d(L,{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(B,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(B,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(B,{variant:`ghost`,onClick:l,title:`Edit`,children:d(se,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(C,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(B,{variant:`ghost`,onClick:c,title:`Logs`,children:d(j,{className:`h-4 w-4`})}),d(B,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(B,{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 Pi=[`automations`,`scripts`,`custom-device`];function Fi(e){return e!==null&&Pi.some(t=>t===e)}function Ii(){let[e,t]=we(),n=e.get(`tab`);return d(De,{icon:A,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(T,{value:Fi(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(D,{children:[d(x,{value:`automations`,children:`Automations`}),d(x,{value:`scripts`,children:`Scripts`}),d(x,{value:`custom-device`,children:`Custom Device`})]}),d(E,{value:`automations`,children:d(xn,{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(E,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(E,{value:`custom-device`,children:d(Vn,{})})]})})}export{Ii 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-Cfcp6NgQ.js";import{Ml as c,Xu as l,Zu as u,hu as d,vn as f}from"./src-BeGnyQUE.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(d,{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(l,{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(),[d,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:d};return t(p,{icon:c,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(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{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(f,{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-BPnLENh-.js";import{Ml as c,Xu as l,Zu as u,hu as d,vn as f}from"./src-Ch2D4L9J.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(d,{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(l,{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(),[d,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:d};return t(p,{icon:c,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(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{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(f,{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-Cfcp6NgQ.js";import{Bl as o,Fl as s,Ju as c,Mu as l,Ol as u,Xl as d,Yl as f,fd as p,fl as m,id as h,rl as g,sd as _,zu as v}from"./src-BeGnyQUE.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:m,label:`Streaming`},detection:{icon:l,label:`Detection`},recording:{icon:c,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:g,label:`Motion`},ptz:{icon:o,label:`PTZ`},webrtc:{icon:d,label:`WebRTC`},onvif:{icon:s,label:`ONVIF`},analytics:{icon:v,label:`Analytics`},"battery-operated":{icon:p,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:o,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:_,label:`Doorbell`},rebootable:{icon:f,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=h;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-BPnLENh-.js";import{Bl as o,Fl as s,Ju as c,Mu as l,Ol as u,Xl as d,Yl as f,fd as p,fl as m,id as h,rl as g,sd as _,zu as v}from"./src-Ch2D4L9J.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:m,label:`Streaming`},detection:{icon:l,label:`Detection`},recording:{icon:c,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:g,label:`Motion`},ptz:{icon:o,label:`PTZ`},webrtc:{icon:d,label:`WebRTC`},onvif:{icon:s,label:`ONVIF`},analytics:{icon:v,label:`Analytics`},"battery-operated":{icon:p,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:o,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:_,label:`Doorbell`},rebootable:{icon:f,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=h;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-Cfcp6NgQ.js";import{$c as g,Bn as _,Ct as v,Gs as y,Hl as b,Jl as x,Ko as S,Ks as C,Mn as w,Qc as T,Rn as ee,Ul as te,Us as E,Vl as D,Vn as ne,Ws as re,Xa as ie,Xl as O,Yl as ae,Za as oe,ao as se,ed as ce,hu as k,id as le,il as ue,io as de,ji as fe,ms as pe,mt as me,oo as he,pc as ge,pt as _e,ro as ve,ru as ye,wt as be,yd as xe,yl as A,zn as Se,zu as Ce}from"./src-BeGnyQUE.js";import{t as we}from"./hard-drive-download-EjN5BuzT.js";import{rr as Te}from"./src-BQHqLKGc.js";import{l as j}from"./index-M74_weOu.js";import{t as M}from"./format-size-DIxKXxtj.js";import{t as Ee}from"./NodeAddonsSettingsPanel-C2dYg-1V.js";import{n as De,r as Oe,t as ke}from"./useNodeUrlSelection-DaNJZDRb.js";var N=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 Ae(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 je({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 Me=[`trace`,`debug`,`info`,`warn`,`error`];function Ne({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),[g,v]=c(`info`),y=e.name.includes(`(core)`),b=de(),S=se(),C=he(),w=async e=>{h(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},T=async()=>{h(e.name);try{await S.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await C.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`}),y?l(D,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(le,{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(je,{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:M(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!y&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ee,{children:[l(ne,{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:g}),l(Se,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(_,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,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(x,{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(te,{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(O,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(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(x,{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(me,{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(_e,{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 Pe({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(Ne,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Fe={system:0,managed:1,root:2};n();function Ie(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 Le(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Re({nodeId:e}){let t=s(),n=g(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=oe({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Fe[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:Le(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=>M(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Ie(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(ae,{className:`h-3 w-3`}),` Refresh`]})}),l(v,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:be,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},ze=.8,F=Math.ceil(8*ze-3)+1,I=P.width+34,L=P.height+F+1+11,Be=F+P.height+1+3+Math.ceil(8*ze),Ve=[1,2,5,10],He=[1,2,4,8,16,32,64,128,256,512,1024],R=[1,1.5,2,2.5,3,4,5],z=[4,3,5,2],B=1e-9;function Ue(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 R.some(e=>Math.abs(t-e)<B)}let n=e/10**Math.floor(Math.log10(e));return R.some(e=>Math.abs(n-e)<B)}function V(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 He){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ve){let t=e*i;if(t>=r)return t}return 10*i}function H(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=z.find(n=>Ue(e/n,t))??z[z.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var We=2.5;function U(e){return e*We}function W(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 G(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 Ge(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 K(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 Je(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 q={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Ye=`
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-BPnLENh-.js";import{$c as g,Bn as _,Ct as v,Gs as y,Hl as b,Jl as x,Ko as S,Ks as C,Mn as w,Qc as T,Rn as ee,Ul as te,Us as E,Vl as D,Vn as ne,Ws as re,Xa as ie,Xl as O,Yl as ae,Za as oe,ao as se,ed as ce,hu as k,id as le,il as ue,io as de,ji as fe,ms as pe,mt as me,oo as he,pc as ge,pt as _e,ro as ve,ru as ye,wt as be,yd as xe,yl as A,zn as Se,zu as Ce}from"./src-Ch2D4L9J.js";import{t as we}from"./hard-drive-download-CoG1t86A.js";import{ar as Te}from"./src-DXUFbK1_.js";import{l as j}from"./index-BKfjeM9L.js";import{t as M}from"./format-size-DIxKXxtj.js";import{t as Ee}from"./NodeAddonsSettingsPanel-DssU1eLJ.js";import{n as De,r as Oe,t as ke}from"./useNodeUrlSelection-hGEaySeu.js";var N=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 Ae(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 je({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 Me=[`trace`,`debug`,`info`,`warn`,`error`];function Ne({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),[g,v]=c(`info`),y=e.name.includes(`(core)`),b=de(),S=se(),C=he(),w=async e=>{h(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},T=async()=>{h(e.name);try{await S.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await C.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`}),y?l(D,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(le,{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(je,{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:M(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!y&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ee,{children:[l(ne,{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:g}),l(Se,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(_,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,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(x,{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(te,{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(O,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(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(x,{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(me,{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(_e,{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 Pe({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(Ne,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Fe={system:0,managed:1,root:2};n();function Ie(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 Le(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Re({nodeId:e}){let t=s(),n=g(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=oe({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Fe[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:Le(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=>M(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Ie(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(ae,{className:`h-3 w-3`}),` Refresh`]})}),l(v,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:be,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},ze=.8,F=Math.ceil(8*ze-3)+1,I=P.width+34,L=P.height+F+1+11,Be=F+P.height+1+3+Math.ceil(8*ze),Ve=[1,2,5,10],He=[1,2,4,8,16,32,64,128,256,512,1024],R=[1,1.5,2,2.5,3,4,5],z=[4,3,5,2],B=1e-9;function Ue(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 R.some(e=>Math.abs(t-e)<B)}let n=e/10**Math.floor(Math.log10(e));return R.some(e=>Math.abs(n-e)<B)}function V(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 He){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ve){let t=e*i;if(t>=r)return t}return 10*i}function H(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=z.find(n=>Ue(e/n,t))??z[z.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var We=2.5;function U(e){return e*We}function W(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 G(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 Ge(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 K(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 Je(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 q={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Ye=`
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 {
@@ -0,0 +1 @@
1
+ import{G as e,I as t,K as n,Q as r,S as i,b as a,q as o,x as s,z as c}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 l}from"./player-overlays-BPnLENh-.js";import{$ as u,Ai as d,Zr as f,c as p,ei as m,ji as h,mn as g,oa as _,tt as v,vn as y,xn as b}from"./src-Ch2D4L9J.js";import{An as x,Bn as S,Fn as C,Ft as w,In as T,It as ee,Jn as te,Ln as E,Lt as ne,Mn as re,Nn as ie,On as ae,Pn as oe,Rt as se,Tn as D,Vn as O,kn as ce,qn as k,qt as A,zt as le}from"./src-DXUFbK1_.js";import{l as j}from"./index-BKfjeM9L.js";r();function ue(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function de(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function M(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function N(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function fe(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function pe(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return N(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return N(e,t.cap,e=>({...e,fields:fe(e.fields,t.path)}));case`copy-feature`:return N(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function me(e){let t=x.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function he(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var ge=[`room`,`converted-sensor`,`derived-binary`],P={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function _e(){return M(se({temperatureSources:ee,motionSources:w,occupancyWindowMs:ne}),`Room`)}function ve(){return M({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:P,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function ye(){return M({target:{kind:`new`,type:O.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:P,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function be(e){switch(e){case`room`:return _e();case`converted-sensor`:return ve();case`derived-binary`:return ye()}}function xe(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}function Se(e){return{addonId:e.addonId,stableId:e.stableId}}function F(e){return new Map(e.map(e=>[T(Se(e)),e]))}function Ce(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function we(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Te(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function I(e){return Array.isArray(e)?e.map(I):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,I(t)]))}function L(e){return JSON.stringify(I(e))}function Ee(e,t){return L(e)===L(t)}function R(e,t){return L(e)===L(t)}function De(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:`the customization has not been read yet — try again`};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:L(t)===L(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function z(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function B(e){return{kind:`expression`,expr:e,bindings:{}}}function V(e){let t=z(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:B(`"unknown"`),sleeping:B(`false`),lastUpdated:B(`now`)}}}var Oe=[`percent`,...A.options];function H(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":B(JSON.stringify(t))}}function ke(e,t){let n=z(`number`,t.remaining);if(n===null||!ce.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:H(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:B(`now`),lastFetchedAt:B(`now`)},items:{...e?.items,[t.key]:r}}}function Ae(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=A.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function je(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Ae(t.fields),r=U(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:z(`number`,r);return n!==null&&i!==null&&Ee(H(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Me(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Ne(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Pe(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[T(e),e])).values()]}function Fe(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function U(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Ie(e,t){let n=U(e.fields.percentage);if(n===null)return!1;let r=V({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&R(a,r)}function W(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Le(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function G(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Re(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:z(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function ze(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:G(n[e.cap],t.path),source:Re(i,e.cap,t,r)})))}function K(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Be=[];function q({title:e,targetKind:t,excludeDeviceIds:n=Be,onPick:r,onCancel:a}){let{t:c}=j(),[l,u]=o(null);return i(`aside`,{"aria-label":e,className:`rounded-lg border border-border bg-surface p-3 flex flex-col gap-2`,children:[s(`h3`,{className:`text-xs font-semibold`,children:e}),l===null?s(J,{excludeDeviceIds:n,onSelect:u}):s(Y,{device:l,targetKind:t,onPick:r,onBack:()=>u(null)}),s(`div`,{children:s(b,{variant:`ghost`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function J({excludeDeviceIds:e,onSelect:t}){let{t:n}=j(),[r,c]=o(``),l=h({projection:`slim`});return i(a,{children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.picker.search`),s(`input`,{type:`search`,"aria-label":n(`customize.picker.search`),className:`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:r,onChange:e=>c(e.target.value)})]}),l.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:n(`customize.picker.loadingDevices`)}),l.status===`error`&&s(y,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:Le(W(l.data),r,e).map(e=>s(`li`,{children:i(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,i(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Y({device:e,targetKind:t,selected:n,onPick:r,onBack:a}){let{t:o}=j(),c=d({deviceId:e.id}),l=_({deviceId:e.id});if(c.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(c.status===`error`)return s(y,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``});let u=ze(e,c.data,l.status===`success`?l.data:null,t),f=u.filter(e=>e.source===null).length,p={addonId:e.addonId,stableId:e.stableId};return i(`div`,{className:`flex flex-col gap-1`,children:[i(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:a,children:[`← `,e.name]}),l.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let a=t.source;if(a===null)return null;let o=()=>r({device:e,ref:p,cap:t.cap,path:t.path,kind:t.kind,source:a,value:t.value});return i(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:K(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),f>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:f,kind:o(`customize.kinds.${t}`)})})]})}var Ve=`integration`;function X(e,t){switch(e.kind){case`from`:{let n=T(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function He(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:`the composer has not reported this customization yet`};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:`the composer reports no value for this field`}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??`unavailable`}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??`stale`:null}}function Z(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:X(n,e.input.sourceNames),value:e.enabled?He(e.input.state,r):{kind:`off`}}}function Ue(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Z(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function We(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Z(e,ie(ae,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function Ge(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=G(e[t],n),i=r===void 0?void 0:k(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function Ke(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ve,value:Ge(e.input.snapshot,t,n)}))}function qe(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:re(t),input:e};return[...Ue(n),...We(n),...Ke(n)]})}var Je={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},Q=/[A-Za-z_][A-Za-z0-9_]*$/;function Ye(e,t,n){let r=Q.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...te].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:Je[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function Xe(e,t,n){let r=t-(Q.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}r();function Ze({label:e,value:t,bindings:r,onChange:a}){let{t:c}=j(),l=n(null),[u,d]=o(t.length),f=Ye(t,u,r);return i(`div`,{className:`flex flex-col gap-1`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,s(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{a(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&s(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=Xe(t,u,e);a(n.text),d(n.cursor),l.current?.focus()},children:[s(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&s(`span`,{className:`text-foreground-subtle`,children:c(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function Qe(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(D(e.expr,`rose`)||D(e.expr,`count`)))return{kind:`runtime-only`};let r=E(e).filter(e=>t.get(C(e.source,e.cap))?.kind!==`value`).map(oe);if(r.length>0)return{kind:`waiting`,missing:r};let i=le({source:e,now:n,read:e=>{let n=t.get(C(e.source,e.cap)),r=n?.kind===`value`?G(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:k(r);return i===void 0?{state:`unavailable`,reason:`${e.cap}.${e.fieldPath} is not reported`,fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}r();function $e({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=p(l().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function et(e,t){return[...new Map(E(e).map(e=>[C(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(T(n.source))}))}function tt({source:e}){let{t:n}=j(),r=h({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=et(e,F(r.status===`success`?W(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>T(e.read.source)):[];return i(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:s($e,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),s(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),r.status===`error`?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?s(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):s(nt,{preview:Qe(e,a,Date.now())})]})}function nt({preview:e}){let{t}=j();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,K(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return s(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return s(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}r();function rt({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,sourceNames:u}){let{t:d}=j(),[f,p]=o(`idle`),m=r?.kind===`expression`?r:null;return i(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`span`,{className:`font-mono text-[11px]`,children:e}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[d(`customize.kinds.${t}`),n?` · ${d(`compositionEditor.required`)}`:``]}),s(b,{size:`sm`,variant:`outline`,onClick:()=>p(`take`),children:d(`compositionEditor.takeFrom`)}),s(b,{size:`sm`,variant:`outline`,"aria-pressed":m!==null,onClick:()=>c(m??{kind:`expression`,expr:`null`,bindings:{}}),children:d(`compositionEditor.formula`)}),r!==void 0&&s(b,{size:`sm`,variant:`ghost`,onClick:l,children:d(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:X(r,u)}),m!==null&&i(a,{children:[s(Ze,{label:d(`compositionEditor.formulaFor`,{path:e}),value:m.expr,bindings:Object.keys(m.bindings),onChange:e=>c({...m,expr:e})}),s(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(m.bindings).map(([e,t])=>i(`li`,{className:`flex gap-2`,children:[s(`span`,{className:`font-mono`,children:e}),s(`span`,{children:t.kind===`from`?X(t,u):JSON.stringify(t.value)})]},e))}),s(b,{size:`sm`,variant:`ghost`,onClick:()=>p(`add-binding`),children:d(`compositionEditor.addSource`)})]}),f!==`idle`&&s(q,{title:d(f===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:f===`take`?t:null,onCancel:()=>p(`idle`),onPick:e=>{if(f===`take`)c(e.source);else if(m!==null){let t=he(Object.keys(m.bindings));c({...m,bindings:{...m.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}p(`idle`)}}),r!==void 0&&s(tt,{source:r})]})}r();function it(e){return e===null||e.kind===`known`?null:e}function at({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=j(),u=f({deviceType:t}),d=h({projection:`slim`}),p=new Map([...F(d.status===`success`?W(d.data):[])].map(([e,t])=>[e,t.name])),[m,_]=o(null),v=it(n)??it(r),y=n?.kind===`known`?n.value:new Set,x=new Set(e.features.map(e=>e.cap)),S=u.status===`success`?u.data.caps.filter(e=>!x.has(e.cap)&&!y.has(e.cap)):[],C=[...y].filter(e=>!x.has(e)),w=e=>y.has(e)?((r?.kind===`known`?r.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return v===null?i(a,{children:[i(`section`,{"aria-labelledby":`editor-features`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),i(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>i(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,s(g,{variant:y.has(e.cap)?`default`:`info`,children:y.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),s(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>c({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),S.map(e=>i(b,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),C.map(e=>s(b,{size:`sm`,variant:`ghost`,onClick:()=>c({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>i(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`flex flex-col gap-2`,children:[i(`div`,{className:`flex items-center justify-between`,children:[s(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),s(b,{size:`sm`,variant:`outline`,onClick:()=>_(e.cap),children:l(`compositionEditor.copyFeature`)})]}),m===e.cap&&s(q,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>_(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:w(e.cap).map(e=>e.path)}),_(null)}}),w(e.cap).map(t=>s(rt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>c({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>c({type:`clear-field`,cap:e.cap,path:t.path}),sourceNames:p},t.path))]},e.cap))]}):i(`section`,{"aria-labelledby":`editor-features`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:v.kind===`unknown`?v.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function ot({draft:e,targetName:t,dispatch:n}){let{t:r}=j(),a=e.target;return i(`section`,{"aria-labelledby":`editor-target`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:r(`compositionEditor.steps.target`)}),a.kind===`existing`?s(`p`,{className:`text-[11px]`,children:r(`compositionEditor.existingTarget`,{name:t??`${a.device.addonId}/${a.device.stableId}`})}):i(`div`,{className:`grid grid-cols-3 gap-2`,children:[i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.targetType`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(O).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(O).map(e=>s(`option`,{value:e,children:v(e).label},e))})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`customize.identity.role`),i(`select`,{className:$,value:a.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(S).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(S).map(e=>s(`option`,{value:e,children:u(e).label},e))]})]}),i(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`compositionEditor.name`),s(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}r();function st({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=j(),u=m(),d=me(e),f=d.ok?JSON.stringify(d.composition):``,[p,h]=o({key:``,state:{kind:`checking`}});c(()=>{if(!d.ok)return;let e=d.composition,n=setTimeout(()=>{u.mutateAsync({composition:e,...t===null?{}:{blockId:t}}).then(e=>h({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>h({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(n)},[f,t]);let g=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return i(`section`,{"aria-labelledby":`editor-verify`,className:`flex flex-col gap-2`,children:[s(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),g.kind===`checking`&&s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),g.kind===`ok`&&s(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),g.kind===`unknown`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:g.reason})}),(g.kind===`invalid-draft`||g.kind===`refused`)&&s(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:g.kind===`invalid-draft`?g.problems.map(e=>s(`li`,{children:e},e)):g.problems.map(e=>i(`li`,{children:[s(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),i(`div`,{className:`flex gap-2`,children:[s(b,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(b,{disabled:g.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function ct({initial:e,blockId:t,deviceType:n,targetName:r=null,nativeCaps:i,targetFields:a,save:c,onCancel:l,showTemplates:u=!1}){let[d,f]=o(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return s(lt,{seed:d,blockId:t,deviceType:n,targetName:r,nativeCaps:i,targetFields:a,showTemplates:u,onApplyTemplate:e=>{f(be(e))},save:c,onCancel:l},p)}function lt({seed:t,blockId:n,deviceType:r,targetName:a,nativeCaps:c,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=j(),[h,g]=e(pe,t),[_,v]=o(!1),[y,x]=o(null),S=h.target.kind===`new`?h.target.type:r,C=async e=>{v(!0);let t=await f(e,h.name);v(!1),x(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[u&&h.target.kind===`new`&&i(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[s(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),ge.map(e=>s(b,{size:`sm`,variant:`outline`,onClick:()=>d(e),children:m(`compositionEditor.templates.${e}`)},e))]}),s(ot,{draft:h,targetName:a,dispatch:g}),s(at,{draft:h,deviceType:S,nativeCaps:c,targetFields:l,dispatch:g}),s(st,{draft:h,blockId:n,saving:_,onSave:e=>void C(e),onCancel:p}),y!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:y})]})}export{we as C,ue as D,de as E,Ce as S,M as T,U as _,Y as a,De as b,G as c,ke as d,je as f,Ne as g,Ie as h,qe as i,Oe as l,Fe as m,Qe as n,J as o,Pe as p,Ze as r,K as s,ct as t,V as u,Me as v,xe as w,R as x,Te as y};
@@ -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{$r as n,Yr as r,qr as i,vn as a}from"./src-BeGnyQUE.js";import{t as o}from"./boxes-DK8vMnI6.js";import{Sn as s,zn as c}from"./src-BQHqLKGc.js";import{d as l,f as u,l as d,o as f,p}from"./index-M74_weOu.js";import{t as m}from"./AdminPage-CiKtOLQm.js";import{D as h,T as g,t as _,w as v}from"./CompositionEditor-CULEp5pb.js";var y=`new`;function b(e){return e instanceof Error?e.message:String(e)}function x(e){let t=e.trim();return t===``?{}:{name:t}}function S(){let{blockId:S}=p(),{t:C}=d(),w=u(),T=i(),E=n(),D=S===void 0||S===y,O=r({blockId:S??``},{enabled:!D}),k=e=>t(m,{icon:o,title:C(`compositionEditor.pageTitle`),children:e});if(D)return k(t(_,{initial:h(c.Sensor),blockId:null,deviceType:c.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:()=>w(-1),save:async(e,t)=>{try{let{block:n}=await T.mutateAsync({block:{...x(t),enabled:!0,composition:e}});return w(v(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:b(e)}}}}));if(O.status===`pending`)return k(t(`p`,{role:`status`,children:C(`compositionEditor.loading`)}));if(O.status===`error`)return k(t(a,{title:C(`compositionEditor.loadFailed`),message:O.error.message}));if(O.data.state===`not-loaded`)return k(t(`p`,{role:`status`,children:C(`customize.status.notLoaded`,{reason:O.data.reason})}));let A=O.data.view;if(A===null)return k(t(`p`,{children:C(`compositionEditor.notFound`,{blockId:S})}));let j=s(A.block);if(j===null)return k(t(`p`,{children:C(`compositionEditor.notComposition`)}));if(j.target.kind===`existing`){let e=A.state.kind===`answered`?A.state.state?.deviceId??null:null;return k(e===null?t(`p`,{children:C(`compositionEditor.customizationUnknownDevice`)}):t(l,{className:`text-primary`,to:f(e),children:C(`compositionEditor.openOnDevice`)}))}let M=A.state.kind===`answered`?A.state.state?.deviceId??null:null,N=M===null?null:v(A.block.id,M);return k(e(`div`,{className:`flex flex-col gap-3`,children:[N!==null&&N.kind===`device`&&t(l,{className:`text-sm text-primary`,to:N.path,"data-testid":`open-composed-device`,children:C(`compositionEditor.openComposedDevice`,{id:M})}),t(_,{initial:g(j,A.block.name),blockId:A.block.id,deviceType:j.target.type,nativeCaps:null,targetFields:null,onCancel:()=>w(-1),save:async(e,t)=>{try{return await E.mutateAsync({blockId:A.block.id,expectedUpdatedAt:A.block.updatedAt,block:{...x(t),composition:e}}),await O.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:b(e)}}}},`${A.block.id}@${A.block.updatedAt}`)]}))}export{S as CompositionEditorPage};
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{$r as n,Yr as r,qr as i,vn as a}from"./src-Ch2D4L9J.js";import{t as o}from"./boxes-kF6UH6-_.js";import{Vn as s,wn as c}from"./src-DXUFbK1_.js";import{d as l,f as u,l as d,o as f,p}from"./index-BKfjeM9L.js";import{t as m}from"./AdminPage-CiKtOLQm.js";import{D as h,T as g,t as _,w as v}from"./CompositionEditor-BPm2kx9Q.js";var y=`new`;function b(e){return e instanceof Error?e.message:String(e)}function x(e){let t=e.trim();return t===``?{}:{name:t}}function S(){let{blockId:S}=p(),{t:C}=d(),w=u(),T=i(),E=n(),D=S===void 0||S===y,O=r({blockId:S??``},{enabled:!D}),k=e=>t(m,{icon:o,title:C(`compositionEditor.pageTitle`),children:e});if(D)return k(t(_,{initial:h(s.Sensor),blockId:null,deviceType:s.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:()=>w(-1),save:async(e,t)=>{try{let{block:n}=await T.mutateAsync({block:{...x(t),enabled:!0,composition:e}});return w(v(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:b(e)}}}}));if(O.status===`pending`)return k(t(`p`,{role:`status`,children:C(`compositionEditor.loading`)}));if(O.status===`error`)return k(t(a,{title:C(`compositionEditor.loadFailed`),message:O.error.message}));if(O.data.state===`not-loaded`)return k(t(`p`,{role:`status`,children:C(`customize.status.notLoaded`,{reason:O.data.reason})}));let A=O.data.view;if(A===null)return k(t(`p`,{children:C(`compositionEditor.notFound`,{blockId:S})}));let j=c(A.block);if(j===null)return k(t(`p`,{children:C(`compositionEditor.notComposition`)}));if(j.target.kind===`existing`){let e=A.state.kind===`answered`?A.state.state?.deviceId??null:null;return k(e===null?t(`p`,{children:C(`compositionEditor.customizationUnknownDevice`)}):t(l,{className:`text-primary`,to:f(e),children:C(`compositionEditor.openOnDevice`)}))}let M=A.state.kind===`answered`?A.state.state?.deviceId??null:null,N=M===null?null:v(A.block.id,M);return k(e(`div`,{className:`flex flex-col gap-3`,children:[N!==null&&N.kind===`device`&&t(l,{className:`text-sm text-primary`,to:N.path,"data-testid":`open-composed-device`,children:C(`compositionEditor.openComposedDevice`,{id:M})}),t(_,{initial:g(j,A.block.name),blockId:A.block.id,deviceType:j.target.type,nativeCaps:null,targetFields:null,onCancel:()=>w(-1),save:async(e,t)=>{try{return await E.mutateAsync({blockId:A.block.id,expectedUpdatedAt:A.block.updatedAt,block:{...x(t),composition:e}}),await O.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:b(e)}}}},`${A.block.id}@${A.block.updatedAt}`)]}))}export{S as CompositionEditorPage};