@camstack/addon-admin-ui 1.2.292 → 1.2.293
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-Dw_s0tAu.js → AddonCollectionPage-Dx74pSG0.js} +1 -1
- package/dist/assets/{Addons-DeOTNmoh.js → Addons-DtMEZhp9.js} +1 -1
- package/dist/assets/{AdminTabs-B7qQRc02.js → AdminTabs-C39IwOhd.js} +1 -1
- package/dist/assets/{AiProfiles-CzjABxBt.js → AiProfiles-DD6tuQV0.js} +1 -1
- package/dist/assets/{BrokerForm-CUCaMcFq.js → BrokerForm-CY2ZLSXv.js} +1 -1
- package/dist/assets/{Build-zDCFoO1o.js → Build-Ls0w_RJZ.js} +4 -4
- package/dist/assets/{Capabilities-B9kNGs2i.js → Capabilities-y6Z9oa38.js} +1 -1
- package/dist/assets/{CapabilityBadges-mm-TP2-4.js → CapabilityBadges-B3DsJCwL.js} +1 -1
- package/dist/assets/{Cluster-CGe5b6yl.js → Cluster-DBpHQvJy.js} +1 -1
- package/dist/assets/CompositionEditor-CF_9g_KZ.js +1 -0
- package/dist/assets/{CompositionEditorPage-CdYmw-mN.js → CompositionEditorPage-w46j9uCT.js} +1 -1
- package/dist/assets/{Data-gT3xohDf.js → Data-VQUNdoIO.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BkRKwDje.js → DetectionIntelligence-BmhzP-Id.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-C2uEmCok.js → DeviceAggregateSection-DWEAiLXQ.js} +1 -1
- package/dist/assets/{DeviceDetail-0QJGYULg.js → DeviceDetail-D9ha6iFz.js} +2 -2
- package/dist/assets/{Devices-BSr1bdFh.js → Devices-BsedvHwa.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Dlh708_N.js → EmbedPlayerPage-BTr1CJ7t.js} +1 -1
- package/dist/assets/{Events-Dr_WAoza.js → Events-BUJsr6Cu.js} +1 -1
- package/dist/assets/{FormBuilder-6IaHrdlA.js → FormBuilder-CTAZADCJ.js} +1 -1
- package/dist/assets/{Identity-CIfnhYiN.js → Identity-Bu8egKND.js} +1 -1
- package/dist/assets/{IntegrationDetail-R0QDmlI9.js → IntegrationDetail-DNchj2iX.js} +1 -1
- package/dist/assets/{Integrations-7cffUbq3.js → Integrations-BgymmAkh.js} +1 -1
- package/dist/assets/{Integrations-DLQUvtxP.js → Integrations-Cl19QOjq.js} +1 -1
- package/dist/assets/{Locations-Dr6R3uck.js → Locations-8QKgaE9S.js} +2 -2
- package/dist/assets/{Logs-BMYNs0yh.js → Logs-BDXStwjn.js} +1 -1
- package/dist/assets/{ModelLicenses-CuvFQmbU.js → ModelLicenses-oXF2a8y2.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Bz_Qdfpp.js → MotionZonesSettings-lkOgR1Ri.js} +1 -1
- package/dist/assets/{MyAccess-CPmIAKtP.js → MyAccess-D5sXOPD5.js} +1 -1
- package/dist/assets/{Network-BNDnM7h_.js → Network-Cee4akbs.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D9m0jYk9.js → NodeAddonsSettingsPanel-BuE0DHPB.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-B1Ep4Zlo.js → NodeInferenceDevices-BBy40g62.js} +1 -1
- package/dist/assets/Notifications-BFeBBPcD.js +1 -0
- package/dist/assets/{Pipeline-DCQvGJPk.js → Pipeline-C5w9evWB.js} +1 -1
- package/dist/assets/{Plates-DVY5is4q.js → Plates-C7GcJxtV.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CbDYhk2o.js → PrivacyMaskSettings-DUdnv3rk.js} +1 -1
- package/dist/assets/{ProviderIcon-CXZJxx4S.js → ProviderIcon-D8A_iNQ3.js} +1 -1
- package/dist/assets/{Recordings-CN8Er5mw.js → Recordings-CzP8erAD.js} +1 -1
- package/dist/assets/{ScanNetworkModal-D1fVlqwM.js → ScanNetworkModal-jwqfb-H2.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DMCML24R.js → SceneMonitorEditor-BPDP5-9d.js} +1 -1
- package/dist/assets/{Scenes-7GSmYBE_.js → Scenes-B6z24QGy.js} +1 -1
- package/dist/assets/{Settings-C_YK-1WB.js → Settings-BhYH9Lt-.js} +1 -1
- package/dist/assets/{Showroom-D6fEOCY-.js → Showroom-BXgOAaYo.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-CP4soml4.js → StorageLocationsPanel-CB2Dlb8k.js} +1 -1
- package/dist/assets/{Terminal-DyfVYesh.js → Terminal-BupLWdZj.js} +1 -1
- package/dist/assets/{Viewer-BJIjxIRv.js → Viewer-BcjlzUS_.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cb9fHmff.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C5ZjCz5f.js} +1 -1
- package/dist/assets/{archive-BUE32U7F.js → archive-BXxB23Wm.js} +1 -1
- package/dist/assets/{authed-media-0-hZyKYF.js → authed-media-Dd13rrLy.js} +1 -1
- package/dist/assets/{boxes-CNe0g7jU.js → boxes-C6pcozLY.js} +1 -1
- package/dist/assets/circle-slash-Bgl1OdUE.js +1 -0
- package/dist/assets/{debounced-invalidate-KFSScH_S.js → debounced-invalidate-CEToGBNW.js} +1 -1
- package/dist/assets/{device-integration-icon-GOXwaoFs.js → device-integration-icon-_K9RH1BG.js} +1 -1
- package/dist/assets/{dist-CUNGowXS.js → dist-BWHl2Wvn.js} +1 -1
- package/dist/assets/dist-NPzpP0BK.js +349 -0
- package/dist/assets/{face-bbox-DAY4Nlok.js → face-bbox-CUCQL0uw.js} +1 -1
- package/dist/assets/{hard-drive-download-BwgF6zZo.js → hard-drive-download-CrmDflbp.js} +1 -1
- package/dist/assets/{hostInit-Ps1dtPIw.js → hostInit-iAue1eDB.js} +1 -1
- package/dist/assets/index-B1mlJXAi.css +2 -0
- package/dist/assets/{index-xBLZKqTX.js → index-BIcFiIU1.js} +3 -3
- package/dist/assets/{layers-DH10EL_n.js → layers-C2Q3YNOk.js} +1 -1
- package/dist/assets/{location-owned-usage-CLcax6wn.js → location-owned-usage-CiwJp0SZ.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-9ae66e69.js → mf-entry-bootstrap-0-b1a5ba6a.js} +2 -2
- package/dist/assets/{player-overlays-gbZ2vznV.js → player-overlays-CNyXe5mk.js} +1 -1
- package/dist/assets/remoteEntry-Bp60y2_R.js +1 -0
- package/dist/assets/{send-BO7aVZEW.js → send-BSyjMGai.js} +1 -1
- package/dist/assets/{settings-2-CYX3Zwgy.js → settings-2-DWcUfPKl.js} +1 -1
- package/dist/assets/{square-check-big-BhfLbxK8.js → square-check-big-9EojkMGR.js} +1 -1
- package/dist/assets/{src-DxdTI837.js → src-CijuRqy3.js} +8 -8
- package/dist/assets/src-lIpPC3rn.js +349 -0
- package/dist/assets/{use-scenes-feed-SUwBnIQt.js → use-scenes-feed-BHpACBNV.js} +1 -1
- package/dist/assets/{use-stationary-objects--DTNKUuW.js → use-stationary-objects-BPedHja9.js} +1 -1
- package/dist/assets/{useDevice-ByIy3FMo.js → useDevice-DVYVbvPK.js} +1 -1
- package/dist/assets/useEventInvalidation-xAOO2HSe.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Bt6smdEd.js → useNodeUrlSelection-CkUk0sXo.js} +1 -1
- package/dist/assets/user-round-B0jTSjmj.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-emXFInOs.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CbRMvKYd.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +40 -3
- package/package.json +1 -1
- package/dist/assets/CompositionEditor-BVDKw1Gg.js +0 -1
- package/dist/assets/Notifications-VoQjr4oG.js +0 -1
- package/dist/assets/circle-slash-fCLxXnZu.js +0 -1
- package/dist/assets/dist-B4mIz_Rx.js +0 -349
- package/dist/assets/index-C8vIAU5v.css +0 -2
- package/dist/assets/remoteEntry-C40lUg7I.js +0 -1
- package/dist/assets/src-4fqKwwai.js +0 -349
- package/dist/assets/useEventInvalidation-CnlNqWBt.js +0 -1
- package/dist/assets/user-round-DMTk-6Io.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-
|
|
2
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Qe(){return{kind:`expression`,expr:``,bindings:{}}}function $e(e,t,n){return e.map((e,r)=>r===t?n:e)}function et(e,t){return e.filter((e,n)=>n!==t)}function tt(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=et(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function nt(e,t){return{...e,triggers:[...t]}}function rt(e,t){return{...e,actions:[...t]}}var it=`deviceId`,at=`$trigger`,ot=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function st({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(R,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(V,{children:`Step`}),d(L,{value:r.kind,onChange:t=>n($e(e,a,Xe(ct(t.target.value)))),options:ot.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(M,{variant:`ghost`,disabled:a===0,onClick:()=>n(tt(e,a,a-1)),title:`Run this step earlier`,children:d(ae,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(tt(e,a,a+1)),title:`Run this step later`,children:d(P,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,onClick:()=>n(et(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(V,{children:`Seconds`}),d(b,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n($e(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(V,{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($e(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(lt,{action:r,devices:t,onChange:t=>n($e(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>n([...e,Xe(`cap`)]),children:[d(S,{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 ct(e){return ot.find(t=>t.value===e)?.value??`cap`}function lt({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Fe(a),s=r?Re():o.data??[],c=ze(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`Device`}),d(L,{value:r?at:String(a),onChange:t=>n({...e,deviceId:t.target.value===at?{$var:it}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:at,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(V,{children:`Capability`}),d(L,{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(V,{children:`Method`}),d(L,{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(V,{children:`Arguments (JSON)`}),d(b,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ut(e,t.target.value))})]})]})}function ut(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 dt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(L,{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(L,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(b,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(b,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ft({value:e,field:t,onChange:n}){return d(b,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function pt(e){return typeof e==`object`}function mt(e){return pt(e)?e[0]??``:e}function ht(e){return pt(e)?e:typeof e==`boolean`?[]:[e]}function gt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(r),o=Ke(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=_t(t,o);n({...e,operator:r,value:r===`in`?ht(e.value):mt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Ve,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(V,{children:`Comparison`}),d(L,{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(V,{children:`Value`}),s?d(ft,{value:ht(e.value),field:a,onChange:t=>n({...e,value:t})}):d(dt,{value:mt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function _t(e,t){return t.find(t=>t.value===e)?.value??`eq`}var vt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function yt({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(V,{children:`Expression`}),d(b,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(bt,{alias:n,source:r,devices:t,onRename:t=>a(Et(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Dt(e.bindings,n))},n)),i(M,{variant:`ghost`,onClick:()=>a({...e.bindings,[Tt(e.bindings)]:vt}),children:[d(S,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function bt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Ct(n,St(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(V,{children:`Name`}),d(b,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(V,{children:`Reads`}),d(L,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:vt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Constant`}),d(b,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:xt(e.target.value)})})]}):d(Ve,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:wt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(M,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function xt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function St(e){return e.kind===`global`?e.sourceStableId:``}function Ct(e,t){return e.find(e=>e.stableId===t)?.id??0}function wt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Tt(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 Et(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Dt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function H(e){return e.kind===`all`||e.kind===`any`}function U(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:H(t)?t:{kind:`all`,children:[t]}}function Ot(e,t){return t===null||H(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function kt(e){return Ot(e,U(e))}function W(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?W(e.child,r):null;if(!H(e))return null;let i=e.children[n];return i===void 0?null:W(i,r)}function G(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=G(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!H(e))return e;let a=e.children[r];if(a===void 0)return e;let o=G(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 At(e){return e===null?null:he({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function jt(e){let t=U(e);return{depth:t.children.length===0?0:_e(t),leaves:t.children.length===0?0:ge(t),depthLimit:3,leafLimit:32}}function Mt(e,t){let n=At(t);return n===null?{ok:!0,recipe:Ot(e,t)}:{ok:!1,reason:n}}function Nt(e,t){let n=U(e);return Mt(e,{kind:n.kind,children:[...n.children,t]})}function Pt(e,t,n){return Ot(e,G(U(e),t,()=>n))}function Ft(e,t){return Ot(e,G(U(e),t,()=>null))}function It(e,t,n){return Ot(e,G(U(e),t,e=>H(e)?{kind:n,children:e.children}:e))}function Lt(e,t){return W(U(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Mt(e,G(U(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Rt(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 zt(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=Rt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=U(e),a=W(i,r.path);if(a===null||!H(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 Mt(e,G(i,r.path,()=>d))}function Bt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=U(e),r=W(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Mt(e,G(n,t,()=>r.child));if(!H(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Rt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=W(n,i.path);if(a===null||!H(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 Mt(e,G(n,i.path,()=>o))}r();var Vt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Ht(e){return e.join(`/`)}function Ut(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Wt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=U(e),f=jt(e),p=o(()=>r.map(Ut),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=zt(e,p,`all`),g=zt(e,p,`any`),_=p.length===1?Lt(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(Pt(e,t,r)),onRemove:t=>{a([]),n(Ft(e,t))},onSetKind:(t,r)=>n(It(e,t,r)),onUngroup:t=>m(Bt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(R,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(L,{value:u.kind,onChange:t=>n(It(e,[],Gt(t.target.value))),options:Vt})}),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(Kt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>m(Nt(e,Ze())),title:`Compare one device field to a value`,children:[d(S,{className:`h-4 w-4`}),` Condition`]}),i(M,{variant:`outline`,onClick:()=>m(Nt(e,Qe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(je,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(M,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(M,{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(M,{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 Gt(e){return e===`any`?`any`:`all`}function Kt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(qt,{node:e,path:[...t,r],handlers:n},Ht([...t,r])))})}function qt({node:e,path:t,handlers:n}){let r=Ht(t),a=d(pe,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return H(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(L,{value:e.kind,onChange:e=>n.onSetKind(t,Gt(e.target.value)),options:Vt})}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(M,{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(Kt,{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(R,{variant:`warning`,children:`NOT`}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(qt,{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(gt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(yt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Jt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=ue(),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(M,{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(M,{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(Oe,{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(I,{maxHeight:420,children:e})})]})}var Yt=[`device-state`,`device-event`,`schedule`,`manual`],Xt=Object.values(be).sort((e,t)=>e.localeCompare(t));function Zt({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(Qt,{trigger:r,devices:t,position:i,onChange:t=>n($e(e,i,t)),onRemove:()=>n(et(e,i))},`${r.kind}-${String(i)}`)),i(M,{variant:`outline`,onClick:()=>n([...e,Ye(`device-state`)]),title:`Add another way this automation can start`,children:[d(S,{className:`h-4 w-4`}),` Trigger`]})]})}function Qt({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(R,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(V,{children:`Trigger`}),d(L,{value:e.kind,onChange:e=>r(Ye($t(e.target.value))),options:Yt.map(e=>({value:e,label:qe(e)}))})]}),d(M,{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(en,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(nn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(V,{children:`Cron expression`}),d(b,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function $t(e){return Yt.find(t=>t===e)??`manual`}function K(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 en({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(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(Ve,{value:r,devices:t,onChange:e=>n(K(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(V,{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(pe,{checked:e.becomes===void 0,onChange:e=>n(K(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(dt,{value:e.becomes,field:a,onChange:e=>n(K(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(pe,{checked:e.edge===!0,onChange:e=>n(K(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Held for (s)`}),d(b,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,forMs:tn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Debounce (s)`}),d(b,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,debounceMs:tn(e.target.value)}))})]})]})}function tn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function nn({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(V,{children:`Event category`}),d(L,{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…`},...Xt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`From device`}),d(L,{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 rn=`hub`;function an({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(()=>kt(t)),[g,_]=l(!1),y=Pe(),x=he(m),S=o(()=>sn(m),[m]),C=o(()=>cn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||x!==null||S!==null||C.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(R,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(on,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Zt,{triggers:m.triggers,devices:y,onChange:e=>h(nt(m,e))})}),d(on,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Wt,{recipe:m,devices:y,onChange:h})}),d(on,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(st,{actions:m.actions,devices:y,onChange:e=>h(rt(m,e))})}),d(Jt,{code:C.code,error:C.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:rn})},disabled:n||T,children:[n&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{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(v,{className:`h-4 w-4`}),` Logs`]}),d(M,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(R,{variant:`warning`,children:`Name required`})]})]})})}function on({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 sn(e){let t=Se.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 cn(e,t){try{return{code:me({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function q(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 ln(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function un(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function dn(e){let t=e=>{let t=q(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 fn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>q(e).tone===`error`).length,n=e.filter(e=>q(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 pn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=q(e),m=w(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(R,{variant:ln(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(M,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(O,{className:`h-4 w-4`})}),i(T,{children:[d(y,{children:d(M,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(D,{className:`h-4 w-4`})})}),d(te,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function mn({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(M,{onClick:e,children:`New automation`})]})})}var hn=`const AUTOMATION_RECIPE =`,gn=`// 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-CNyXe5mk.js";import{Al as v,At as y,Bt as b,Fl as x,Hl as S,Iu as C,J as w,Ot as T,St as E,Ul as D,Wl as O,_ as k,an as A,bt as j,cn as M,dt as N,fu as ee,id as P,kt as te,nn as F,nu as ne,ol as re,pt as I,rt as ie,sn as L,td as ae,tn as R,tt as oe,ut as se,vi as ce,xt as le,yn as ue,yt as de,zr as fe,zt as pe}from"./src-CijuRqy3.js";import{Dn as me,En as he,On as ge,Tn as _e,an as z,lt as ve,pn as ye,rr as be,vn as B,wn as xe,yn as Se}from"./src-lIpPC3rn.js";import{a as Ce,d as we,i as Te,m as Ee,s as De,y as Oe}from"./index-BIcFiIU1.js";import{t as ke}from"./AdminPage-CiKtOLQm.js";import{r as Ae}from"./useDevice-DVYVbvPK.js";var je=_(`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`}]]),Me=_(`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 Ne=6e4;function Pe(){let e=ce({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 Fe(e){let t=m();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Ne,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 Ie(e){let t=m();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Ne,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Le(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Re(){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 ze(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 V({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Be(e){let t=Ie(e.deviceId);if(t.data!==void 0)return Le(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ve({value:e,devices:t,onChange:n}){let r=Ie(e.deviceId),a=r.data??[],o=Le(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(V,{children:`Device`}),d(L,{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(V,{children:`Capability`}),d(L,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:He(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(V,{children:`Field`}),d(L,{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 He(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 Ue=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function We(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 Ue}}function Ge(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 Ke(e){return We(e).map(e=>({value:e,label:Ge(e)}))}function qe(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 Je={triggers:[],actions:[]};function Ye(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 Xe(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 Ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Qe(){return{kind:`expression`,expr:``,bindings:{}}}function $e(e,t,n){return e.map((e,r)=>r===t?n:e)}function et(e,t){return e.filter((e,n)=>n!==t)}function tt(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=et(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function nt(e,t){return{...e,triggers:[...t]}}function rt(e,t){return{...e,actions:[...t]}}var it=`deviceId`,at=`$trigger`,ot=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function st({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(R,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(V,{children:`Step`}),d(L,{value:r.kind,onChange:t=>n($e(e,a,Xe(ct(t.target.value)))),options:ot.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(M,{variant:`ghost`,disabled:a===0,onClick:()=>n(tt(e,a,a-1)),title:`Run this step earlier`,children:d(ae,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(tt(e,a,a+1)),title:`Run this step later`,children:d(P,{className:`h-3.5 w-3.5`})}),d(M,{variant:`ghost`,onClick:()=>n(et(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(V,{children:`Seconds`}),d(b,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n($e(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(V,{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($e(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(lt,{action:r,devices:t,onChange:t=>n($e(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>n([...e,Xe(`cap`)]),children:[d(S,{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 ct(e){return ot.find(t=>t.value===e)?.value??`cap`}function lt({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=Fe(a),s=r?Re():o.data??[],c=ze(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`Device`}),d(L,{value:r?at:String(a),onChange:t=>n({...e,deviceId:t.target.value===at?{$var:it}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:at,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(V,{children:`Capability`}),d(L,{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(V,{children:`Method`}),d(L,{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(V,{children:`Arguments (JSON)`}),d(b,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(ut(e,t.target.value))})]})]})}function ut(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 dt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(L,{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(L,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(b,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(b,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function ft({value:e,field:t,onChange:n}){return d(b,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function pt(e){return typeof e==`object`}function mt(e){return pt(e)?e[0]??``:e}function ht(e){return pt(e)?e:typeof e==`boolean`?[]:[e]}function gt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(r),o=Ke(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=_t(t,o);n({...e,operator:r,value:r===`in`?ht(e.value):mt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Ve,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(V,{children:`Comparison`}),d(L,{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(V,{children:`Value`}),s?d(ft,{value:ht(e.value),field:a,onChange:t=>n({...e,value:t})}):d(dt,{value:mt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function _t(e,t){return t.find(t=>t.value===e)?.value??`eq`}var vt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function yt({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(V,{children:`Expression`}),d(b,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(bt,{alias:n,source:r,devices:t,onRename:t=>a(Et(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Dt(e.bindings,n))},n)),i(M,{variant:`ghost`,onClick:()=>a({...e.bindings,[Tt(e.bindings)]:vt}),children:[d(S,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function bt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Ct(n,St(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(V,{children:`Name`}),d(b,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(V,{children:`Reads`}),d(L,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:vt),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(V,{children:`Constant`}),d(b,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:xt(e.target.value)})})]}):d(Ve,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:wt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(M,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function xt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function St(e){return e.kind===`global`?e.sourceStableId:``}function Ct(e,t){return e.find(e=>e.stableId===t)?.id??0}function wt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Tt(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 Et(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Dt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function H(e){return e.kind===`all`||e.kind===`any`}function U(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:H(t)?t:{kind:`all`,children:[t]}}function Ot(e,t){return t===null||H(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function kt(e){return Ot(e,U(e))}function W(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?W(e.child,r):null;if(!H(e))return null;let i=e.children[n];return i===void 0?null:W(i,r)}function G(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=G(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!H(e))return e;let a=e.children[r];if(a===void 0)return e;let o=G(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 At(e){return e===null?null:ge({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function jt(e){let t=U(e);return{depth:t.children.length===0?0:he(t),leaves:t.children.length===0?0:me(t),depthLimit:3,leafLimit:32}}function Mt(e,t){let n=At(t);return n===null?{ok:!0,recipe:Ot(e,t)}:{ok:!1,reason:n}}function Nt(e,t){let n=U(e);return Mt(e,{kind:n.kind,children:[...n.children,t]})}function Pt(e,t,n){return Ot(e,G(U(e),t,()=>n))}function Ft(e,t){return Ot(e,G(U(e),t,()=>null))}function It(e,t,n){return Ot(e,G(U(e),t,e=>H(e)?{kind:n,children:e.children}:e))}function Lt(e,t){return W(U(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Mt(e,G(U(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Rt(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 zt(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=Rt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=U(e),a=W(i,r.path);if(a===null||!H(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 Mt(e,G(i,r.path,()=>d))}function Bt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=U(e),r=W(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Mt(e,G(n,t,()=>r.child));if(!H(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Rt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=W(n,i.path);if(a===null||!H(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 Mt(e,G(n,i.path,()=>o))}r();var Vt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Ht(e){return e.join(`/`)}function Ut(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Wt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=U(e),f=jt(e),p=o(()=>r.map(Ut),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=zt(e,p,`all`),g=zt(e,p,`any`),_=p.length===1?Lt(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(Pt(e,t,r)),onRemove:t=>{a([]),n(Ft(e,t))},onSetKind:(t,r)=>n(It(e,t,r)),onUngroup:t=>m(Bt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(R,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(L,{value:u.kind,onChange:t=>n(It(e,[],Gt(t.target.value))),options:Vt})}),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(Kt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>m(Nt(e,Ze())),title:`Compare one device field to a value`,children:[d(S,{className:`h-4 w-4`}),` Condition`]}),i(M,{variant:`outline`,onClick:()=>m(Nt(e,Qe())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(je,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(M,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(M,{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(M,{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 Gt(e){return e===`any`?`any`:`all`}function Kt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(qt,{node:e,path:[...t,r],handlers:n},Ht([...t,r])))})}function qt({node:e,path:t,handlers:n}){let r=Ht(t),a=d(pe,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return H(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(L,{value:e.kind,onChange:e=>n.onSetKind(t,Gt(e.target.value)),options:Vt})}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(M,{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(Kt,{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(R,{variant:`warning`,children:`NOT`}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Me,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(qt,{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(gt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(yt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function Jt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=ue(),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(M,{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(M,{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(Oe,{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(I,{maxHeight:420,children:e})})]})}var Yt=[`device-state`,`device-event`,`schedule`,`manual`],Xt=Object.values(be).sort((e,t)=>e.localeCompare(t));function Zt({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(Qt,{trigger:r,devices:t,position:i,onChange:t=>n($e(e,i,t)),onRemove:()=>n(et(e,i))},`${r.kind}-${String(i)}`)),i(M,{variant:`outline`,onClick:()=>n([...e,Ye(`device-state`)]),title:`Add another way this automation can start`,children:[d(S,{className:`h-4 w-4`}),` Trigger`]})]})}function Qt({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(R,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(V,{children:`Trigger`}),d(L,{value:e.kind,onChange:e=>r(Ye($t(e.target.value))),options:Yt.map(e=>({value:e,label:qe(e)}))})]}),d(M,{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(en,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(nn,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(V,{children:`Cron expression`}),d(b,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function $t(e){return Yt.find(t=>t===e)??`manual`}function K(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 en({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Be(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(Ve,{value:r,devices:t,onChange:e=>n(K(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(V,{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(pe,{checked:e.becomes===void 0,onChange:e=>n(K(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(dt,{value:e.becomes,field:a,onChange:e=>n(K(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(pe,{checked:e.edge===!0,onChange:e=>n(K(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Held for (s)`}),d(b,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,forMs:tn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(V,{children:`Debounce (s)`}),d(b,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(K(r,{...o,debounceMs:tn(e.target.value)}))})]})]})}function tn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function nn({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(V,{children:`Event category`}),d(L,{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…`},...Xt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(V,{children:`From device`}),d(L,{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 rn=`hub`;function an({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(()=>kt(t)),[g,_]=l(!1),y=Pe(),x=ge(m),S=o(()=>sn(m),[m]),C=o(()=>cn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),w=f.trim()===``,T=w||x!==null||S!==null||C.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(R,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(on,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Zt,{triggers:m.triggers,devices:y,onChange:e=>h(nt(m,e))})}),d(on,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Wt,{recipe:m,devices:y,onChange:h})}),d(on,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(st,{actions:m.actions,devices:y,onChange:e=>h(rt(m,e))})}),d(Jt,{code:C.code,error:C.error,canEject:e!==null,ejecting:a,onEject:c}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:z(e.id)})]}),d(oe,{addonId:z(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),x!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&S!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:S}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{onClick:()=>{C.code!==null&&s({name:f.trim(),code:C.code,enabled:e?.enabled??!0,placement:rn})},disabled:n||T,children:[n&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{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(v,{className:`h-4 w-4`}),` Logs`]}),d(M,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),w&&d(R,{variant:`warning`,children:`Name required`})]})]})})}function on({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 sn(e){let t=_e.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 cn(e,t){try{return{code:xe({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function q(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 ln(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function un(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function dn(e){let t=e=>{let t=q(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 fn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>q(e).tone===`error`).length,n=e.filter(e=>q(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 pn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=q(e),m=w(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(R,{variant:ln(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(M,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(O,{className:`h-4 w-4`})}),i(T,{children:[d(y,{children:d(M,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(D,{className:`h-4 w-4`})})}),d(te,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{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:z(e.id)})]}),d(oe,{addonId:z(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function mn({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(M,{onClick:e,children:`New automation`})]})})}var hn=`const AUTOMATION_RECIPE =`,gn=`// 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 _n(e){return e.includes(hn)}function vn(e){let t=e.indexOf(hn);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 yn(e){let t=vn(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=Se.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 bn(e){let t=vn(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)}${gn}${e.slice(i)}`}r();var xn=[`coreBlocks`,`list`],Sn=5e3;function J(e){return e instanceof Error?e.message:String(e)}function Cn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:xn,refetchInterval:Sn,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:bn(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,C=dn((x??[]).filter(e=>_n(e.code))),w=x!==void 0&&C.length===0,T=n.mode===`edit`&&n.block!==null?un(C,n.block):null,E=T===null?null:yn(T.code),D=g.error===null?_.error===null?b.error===null?null:J(b.error):J(_.error):J(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?``:fn(C)}),i(M,{onClick:()=>r({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(A,{title:`Could not read the automations`,message:J(p.error),onRetry:h}),n.mode===`edit`&&d(an,{existing:T,initialRecipe:E!==null&&E.ok?E.recipe:Je,saving:g.isPending||_.isPending,saveError:D,ejecting:b.isPending,onSave:e=>{T===null?g.mutate(e):_.mutate({blockId:T.id,block:e})},onEject:()=>{T!==null&&b.mutate(T)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},T?.id??`new`),w&&d(mn,{onCreate:()=>r({mode:`edit`,block:null})}),C.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:C.map(e=>{let t=yn(e.code);return d(pn,{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(A,{message:J(v.error)}),y.error!=null&&d(A,{message:J(y.error)})]})}function wn(e){return{state:`answered`,byRef:new Map(e.map(e=>[z(e),e]))}}function Tn(e,t){if(e.state!==`unanswered`)return e.byRef.get(z(t))??null}function En(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Dn(e){return xe(e).map(e=>e.source)}function On(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(...Dn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Dn(e))}let r=new Set;return n.filter(e=>{let t=z(e);return r.has(t)?!1:(r.add(t),!0)})}function kn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function An(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?[`${kn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${kn(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 jn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return An(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 Mn(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}`}).`}:jn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Nn(e){return z(e)}function Pn(e,t){let n=Tn(t,e);return{key:z(e),label:n?n.name:Nn(e),presence:En(n),deviceId:n?n.id:null}}function Fn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function In(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=z(i),o=On(e).filter(e=>z(e)!==a).map(e=>Pn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Tn(t,i),l=Fn(e),u=Mn(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=En(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Nn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Ln(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Rn(e,t){return Ln(e)-Ln(t)||e.name.localeCompare(t.name)}function zn(e,t){let n=e.flatMap(e=>{let n=In(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Rn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Rn)}}var Bn=1e4;function Vn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Hn(){let e=Ae();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 (${Vn(e.error)})`}:wn(e.data)}function Un(){let e=fe({},{refetchInterval:Bn}),t=Hn(),n=e.data;if(e.error!=null&&n===void 0)return d(A,{title:`Could not read the compositions`,message:Vn(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:Vn(e.error);return d(Wn,{lists:zn(n.views,t),fleet:t,refreshError:r})}function Wn({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(Gn,{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(we,{to:Te,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Gn,{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 Gn({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(se,{columns:Kn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:N,emptyMessage:a})})]})}function Kn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(qn,{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(R,{variant:ln(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(Yn,{sources:e.sources})}]}function qn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Jn,{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 Jn({row:e}){return e.kind===`composed`?d(we,{to:Ce(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(we,{to:De(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Yn({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(we,{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 Xn(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 Zn(e){if(Array.isArray(e))return e}function Qn(e,t,n){return(t=sr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $n(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 er(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
4
|
+
// here the editor could re-open this block and overwrite everything below.`;function _n(e){return e.includes(hn)}function vn(e){let t=e.indexOf(hn);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 yn(e){let t=vn(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=_e.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 bn(e){let t=vn(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)}${gn}${e.slice(i)}`}r();var xn=[`coreBlocks`,`list`],Sn=5e3;function J(e){return e instanceof Error?e.message:String(e)}function Cn({onOpenScripts:e}){let t=m(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),p=s({queryKey:xn,refetchInterval:Sn,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:bn(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,C=dn((x??[]).filter(e=>_n(e.code))),w=x!==void 0&&C.length===0,T=n.mode===`edit`&&n.block!==null?un(C,n.block):null,E=T===null?null:yn(T.code),D=g.error===null?_.error===null?b.error===null?null:J(b.error):J(_.error):J(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?``:fn(C)}),i(M,{onClick:()=>r({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New automation`]})]}),p.error!=null&&d(A,{title:`Could not read the automations`,message:J(p.error),onRetry:h}),n.mode===`edit`&&d(an,{existing:T,initialRecipe:E!==null&&E.ok?E.recipe:Je,saving:g.isPending||_.isPending,saveError:D,ejecting:b.isPending,onSave:e=>{T===null?g.mutate(e):_.mutate({blockId:T.id,block:e})},onEject:()=>{T!==null&&b.mutate(T)},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}},T?.id??`new`),w&&d(mn,{onCreate:()=>r({mode:`edit`,block:null})}),C.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:C.map(e=>{let t=yn(e.code);return d(pn,{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(A,{message:J(v.error)}),y.error!=null&&d(A,{message:J(y.error)})]})}function wn(e){return{state:`answered`,byRef:new Map(e.map(e=>[B(e),e]))}}function Tn(e,t){if(e.state!==`unanswered`)return e.byRef.get(B(t))??null}function En(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Dn(e){return Se(e).map(e=>e.source)}function On(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(...Dn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Dn(e))}let r=new Set;return n.filter(e=>{let t=B(e);return r.has(t)?!1:(r.add(t),!0)})}function kn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function An(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?[`${kn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${kn(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 jn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return An(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 Mn(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}`}).`}:jn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Nn(e){return B(e)}function Pn(e,t){let n=Tn(t,e);return{key:B(e),label:n?n.name:Nn(e),presence:En(n),deviceId:n?n.id:null}}function Fn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function In(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=B(i),o=On(e).filter(e=>B(e)!==a).map(e=>Pn(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Tn(t,i),l=Fn(e),u=Mn(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=En(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Nn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Ln(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Rn(e,t){return Ln(e)-Ln(t)||e.name.localeCompare(t.name)}function zn(e,t){let n=e.flatMap(e=>{let n=In(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Rn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Rn)}}var Bn=1e4;function Vn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Hn(){let e=Ae();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 (${Vn(e.error)})`}:wn(e.data)}function Un(){let e=fe({},{refetchInterval:Bn}),t=Hn(),n=e.data;if(e.error!=null&&n===void 0)return d(A,{title:`Could not read the compositions`,message:Vn(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:Vn(e.error);return d(Wn,{lists:zn(n.views,t),fleet:t,refreshError:r})}function Wn({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(Gn,{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(we,{to:Te,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(Gn,{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 Gn({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(se,{columns:Kn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:N,emptyMessage:a})})]})}function Kn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(qn,{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(R,{variant:ln(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(Yn,{sources:e.sources})}]}function qn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Jn,{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 Jn({row:e}){return e.kind===`composed`?d(we,{to:Ce(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(we,{to:De(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Yn({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(we,{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 Xn(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 Zn(e){if(Array.isArray(e))return e}function Qn(e,t,n){return(t=sr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $n(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 er(){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 tr(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 nr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?tr(Object(n),!0).forEach(function(t){Qn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function rr(e,t){if(e==null)return{};var n,r,i=ir(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 ir(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 ar(e,t){return Zn(e)||$n(e,t)||cr(e,t)||er()}function or(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 sr(e){var t=or(e,`string`);return typeof t==`symbol`?t:t+``}function cr(e,t){if(e){if(typeof e==`string`)return Xn(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)?Xn(e,t):void 0}}function lr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ur(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 dr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ur(Object(n),!0).forEach(function(t){lr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ur(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function fr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function pr(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 mr(e){return{}.toString.call(e).includes(`Object`)}function hr(e){return!Object.keys(e).length}function gr(e){return typeof e==`function`}function _r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function vr(e,t){return mr(t)||Y(`changeType`),Object.keys(t).some(function(t){return!_r(e,t)})&&Y(`changeField`),t}function yr(e){gr(e)||Y(`selectorType`)}function br(e){gr(e)||mr(e)||Y(`handlerType`),mr(e)&&Object.values(e).some(function(e){return!gr(e)})&&Y(`handlersType`)}function xr(e){e||Y(`initialIsRequired`),mr(e)||Y(`initialType`),hr(e)&&Y(`initialContent`)}function Sr(e,t){throw Error(e[t]||e.default)}var Y=pr(Sr)({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"}),Cr={changes:vr,selector:yr,handler:br,initial:xr};function wr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Cr.initial(e),Cr.handler(t);var n={current:e},r=pr(Dr)(n,t),i=pr(Er)(n),a=pr(Cr.changes)(e),o=pr(Tr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Cr.selector(e),e(n.current)}function c(e){fr(r,i,a,o)(e)}return[s,c]}function Tr(e,t){return gr(t)?t(e.current):t}function Er(e,t){return e.current=dr(dr({},e.current),t),t}function Dr(e,t,n){return gr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Or={create:wr},kr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Ar(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 jr(e){return{}.toString.call(e).includes(`Object`)}function Mr(e){return e||Ir(`configIsRequired`),jr(e)||Ir(`configType`),e.urls?(Nr(),{paths:{vs:e.urls.monacoBase}}):e}function Nr(){console.warn(Fr.deprecation)}function Pr(e,t){throw Error(e[t]||e.default)}var Fr={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}=ie(),[S,w]=l(e?.name??``),[T,E]=l(e?.code??wi),[D,O]=l(e?.placement??Ei),[A,j]=l(e?.integrationId??``),[N,ee]=l([]),[P,te]=l(!1),I=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),L=o(()=>N.filter(e=>e.severity>=8),[N]),ae=Ci(N),se=S.trim()===``,ce=e===null||T!==e.code||S.trim()!==e.name||D!==e.placement||(A.trim()===``?void 0:A.trim())!==e.integrationId,le=()=>{I.reset(),h({name:S.trim(),code:T,enabled:e?.enabled??!0,placement:D,...A.trim()===``?{}:{integrationId:A.trim()}})},ue=e===null?null:q(e),de=Ti({existing:e,dirty:ce,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}`}),ue!==null&&d(R,{variant:ln(ue.tone),children:ue.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:S,onChange:e=>w(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(b,{className:`mt-1`,value:A,onChange:e=>j(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(k,{selectedNodeId:D,onSelect:O,label:`Runs on`,alwaysShow:!0}),D!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(re,{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:P?`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:T,onChange:E,extraLibs:t?.libs??[],onDiagnostics:ee,dark:y===`dark`,heightPx:420})}),P&&i(`div`,{className:`rounded border border-border`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:B(e.id)})]})}),e!==null&&d(oe,{addonId:B(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),L.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:[L.length,` error`,L.length===1?``:`s`,` — the block cannot be saved.`]}),L.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),L.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,L.length-5,` more.`]})]}),I.data!==void 0&&(I.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(C,{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:[I.data.line===void 0?``:`line ${String(I.data.line)}: `,I.data.error??`the code does not compile`]})),I.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(I.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(M,{variant:`outline`,onClick:()=>I.mutate(T),disabled:I.isPending||r,title:`Type-check on the node without saving`,children:[I.isPending&&d(ne,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(M,{onClick:le,disabled:r||ae||se,children:[r&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{variant:`outline`,onClick:()=>p?.(),disabled:de!==null||p===void 0,title:de??`Stop the process and let the supervisor bring it back`,children:[s?d(x,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`}),` `,`Restart`]}),i(M,{variant:`ghost`,onClick:()=>te(!P),title:`Show this script's process logs`,children:[d(v,{className:`h-4 w-4`}),` Logs `,P?`⇤`:`⇄`]}),d(M,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,L.length,ce&&e!==null?` · unsaved changes`:``]}),se&&d(R,{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()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),E=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),D=dn(g.data??[]),O=g.data!==void 0&&D.length===0,k=x.isPending||C.isPending,j=x.error===null?C.error===null?null:$(C.error):$(x.error),N=r.mode===`edit`&&r.block!==null?un(D,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?``:fn(D)}),i(M,{onClick:()=>a({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(A,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Di,{existing:N,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:k,saveError:j,restarting:E.isPending,restartError:E.error===null?null:$(E.error),onRestart:N===null?void 0:()=>E.mutate(N.id),onSave:e=>{let t=N;t===null?x.mutate(e):C.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),C.reset(),E.reset(),a({mode:`closed`})}}),O&&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.`})]})}),D.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:D.map(e=>d(Ni,{block:e,busy:T.isPending||w.isPending,restarting:E.isPending&&E.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>T.mutate({blockId:e.id,enabled:t}),onRestart:()=>E.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:()=>w.mutate(e.id)},e.id))})}),w.error!=null&&d(A,{message:$(w.error)}),T.error!=null&&d(A,{message:$(T.error)}),E.error!=null&&d(A,{message:$(E.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=q(e),h=w(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(R,{variant:ln(m.tone),children:m.label}),d(R,{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(M,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:l,title:`Edit`,children:d(O,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(x,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:B(e.id)})]}),d(oe,{addonId:B(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]=Ee(),n=e.get(`tab`);return d(ke,{icon:ee,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(de,{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(le,{children:[d(E,{value:`automations`,children:`Automations`}),d(E,{value:`scripts`,children:`Scripts`}),d(E,{value:`custom-device`,children:`Custom Device`})]}),d(j,{value:`automations`,children:d(Cn,{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(j,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(j,{value:`custom-device`,children:d(Un,{})})]})})}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}=ie(),[S,w]=l(e?.name??``),[T,E]=l(e?.code??wi),[D,O]=l(e?.placement??Ei),[A,j]=l(e?.integrationId??``),[N,ee]=l([]),[P,te]=l(!1),I=u({mutationFn:e=>_.trpcClient.coreBlocks.compile.mutate({code:e})}),L=o(()=>N.filter(e=>e.severity>=8),[N]),ae=Ci(N),se=S.trim()===``,ce=e===null||T!==e.code||S.trim()!==e.name||D!==e.placement||(A.trim()===``?void 0:A.trim())!==e.integrationId,le=()=>{I.reset(),h({name:S.trim(),code:T,enabled:e?.enabled??!0,placement:D,...A.trim()===``?{}:{integrationId:A.trim()}})},ue=e===null?null:q(e),de=Ti({existing:e,dirty:ce,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}`}),ue!==null&&d(R,{variant:ln(ue.tone),children:ue.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(b,{className:`mt-1`,value:S,onChange:e=>w(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(b,{className:`mt-1`,value:A,onChange:e=>j(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),i(`div`,{children:[d(k,{selectedNodeId:D,onSelect:O,label:`Runs on`,alwaysShow:!0}),D!==Ei&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(re,{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:P?`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:T,onChange:E,extraLibs:t?.libs??[],onDiagnostics:ee,dark:y===`dark`,heightPx:420})}),P&&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:z(e.id)})]})}),e!==null&&d(oe,{addonId:z(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.`}),L.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:[L.length,` error`,L.length===1?``:`s`,` — the block cannot be saved.`]}),L.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),L.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,L.length-5,` more.`]})]}),I.data!==void 0&&(I.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(C,{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:[I.data.line===void 0?``:`line ${String(I.data.line)}: `,I.data.error??`the code does not compile`]})),I.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(I.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(M,{variant:`outline`,onClick:()=>I.mutate(T),disabled:I.isPending||r,title:`Type-check on the node without saving`,children:[I.isPending&&d(ne,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(M,{onClick:le,disabled:r||ae||se,children:[r&&d(ne,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{variant:`outline`,onClick:()=>p?.(),disabled:de!==null||p===void 0,title:de??`Stop the process and let the supervisor bring it back`,children:[s?d(x,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`}),` `,`Restart`]}),i(M,{variant:`ghost`,onClick:()=>te(!P),title:`Show this script's process logs`,children:[d(v,{className:`h-4 w-4`}),` Logs `,P?`⇤`:`⇄`]}),d(M,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,L.length,ce&&e!==null?` · unsaved changes`:``]}),se&&d(R,{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()}}),C=u({mutationFn:e=>n.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{a({mode:`edit`,block:e.block}),v()}}),w=u({mutationFn:e=>n.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{c(null),v()}}),T=u({mutationFn:e=>n.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:v}),E=u({mutationFn:e=>n.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:v}),D=dn(g.data??[]),O=g.data!==void 0&&D.length===0,k=x.isPending||C.isPending,j=x.error===null?C.error===null?null:$(C.error):$(x.error),N=r.mode===`edit`&&r.block!==null?un(D,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?``:fn(D)}),i(M,{onClick:()=>a({mode:`edit`,block:null}),children:[d(S,{className:`h-4 w-4`}),` New script`]})]}),g.error!=null&&d(A,{title:`Could not read the scripts`,message:$(g.error),onRetry:v}),r.mode===`edit`&&d(Di,{existing:N,typeDefs:_.data,typeDefsLoading:_.isLoading,saving:k,saveError:j,restarting:E.isPending,restartError:E.error===null?null:$(E.error),onRestart:N===null?void 0:()=>E.mutate(N.id),onSave:e=>{let t=N;t===null?x.mutate(e):C.mutate({blockId:t.id,block:e})},onCancel:()=>{x.reset(),C.reset(),E.reset(),a({mode:`closed`})}}),O&&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.`})]})}),D.length>0&&d(F,{children:d(`ul`,{className:`divide-y divide-border`,children:D.map(e=>d(Ni,{block:e,busy:T.isPending||w.isPending,restarting:E.isPending&&E.variables===e.id,confirming:o===e.id,logsOpen:p===e.id,onToggle:t=>T.mutate({blockId:e.id,enabled:t}),onRestart:()=>E.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:()=>w.mutate(e.id)},e.id))})}),w.error!=null&&d(A,{message:$(w.error)}),T.error!=null&&d(A,{message:$(T.error)}),E.error!=null&&d(A,{message:$(E.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=q(e),h=w(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(R,{variant:ln(m.tone),children:m.label}),d(R,{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(M,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(M,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(M,{variant:`ghost`,onClick:l,title:`Edit`,children:d(O,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(x,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(M,{variant:`ghost`,onClick:c,title:`Logs`,children:d(v,{className:`h-4 w-4`})}),d(M,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(M,{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:z(e.id)})]}),d(oe,{addonId:z(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]=Ee(),n=e.get(`tab`);return d(ke,{icon:ee,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:i(de,{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(le,{children:[d(E,{value:`automations`,children:`Automations`}),d(E,{value:`scripts`,children:`Scripts`}),d(E,{value:`custom-device`,children:`Custom Device`})]}),d(j,{value:`automations`,children:d(Cn,{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(j,{value:`scripts`,children:d(Mi,{initialBlockId:e.get(`block`)??void 0})}),d(j,{value:`custom-device`,children:d(Un,{})})]})})}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-gbZ2vznV.js";import{Lu as c,Ru as l,an as u,nu as d,yl as f}from"./src-DxdTI837.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(c,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[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:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(c,{className:`h-3.5 w-3.5 shrink-0`}):o(l,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(u,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as s}from"./player-overlays-CNyXe5mk.js";import{Lu as c,Ru as l,an as u,nu as d,yl as f}from"./src-CijuRqy3.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(c,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[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:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(c,{className:`h-3.5 w-3.5 shrink-0`}):o(l,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(u,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{pt as n,ut as r,vt as i,yt as a}from"./player-overlays-
|
|
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-CNyXe5mk.js";import{$c as o,Dl as s,Eu as c,Fu as l,Gu as u,Il as d,Ju as f,Ll as p,Qu as m,Sl as h,Wc as g,hl as _,yu as v}from"./src-CijuRqy3.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:o,label:`Streaming`},detection:{icon:v,label:`Detection`},recording:{icon:l,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:i,label:`Snapshot`},motion:{icon:g,label:`Motion`},ptz:{icon:s,label:`PTZ`},webrtc:{icon:p,label:`WebRTC`},onvif:{icon:h,label:`ONVIF`},analytics:{icon:c,label:`Analytics`},"battery-operated":{icon:m,label:`Battery`},"native-snapshot":{icon:i,label:`Native Snapshot`},"pan-tilt-zoom":{icon:s,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:f,label:`Doorbell`},rebootable:{icon:d,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:_,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:n,label:`Targeted Mowing`}},x=u;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-gbZ2vznV.js";import{Al as g,As as _,Bc as v,Dn as y,En as b,Eu as x,Fl as S,Ga as C,Gc as w,Gu as ee,Il as T,Ka as E,La as D,Ll as O,Ms as te,No as k,Ns as ne,Ol as re,On as ie,Ra as ae,Tn as oe,Vu as se,Wa as ce,Wl as le,ad as A,dt as ue,ec as de,et as fe,js as pe,kl as me,nu as j,ol as he,qa as ge,ts as _e,tt as ve,ut as ye,vi as be,yn as xe,zc as Se}from"./src-DxdTI837.js";import{t as Ce}from"./hard-drive-download-BwgF6zZo.js";import{Bn as we}from"./src-4fqKwwai.js";import{l as M}from"./index-xBLZKqTX.js";import{t as N}from"./format-size-DIxKXxtj.js";import{t as Te}from"./NodeAddonsSettingsPanel-D9m0jYk9.js";import{n as Ee,r as De,t as Oe}from"./useNodeUrlSelection-Bt6smdEd.js";var ke=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),[_,v]=c(`info`),x=e.name.includes(`(core)`),w=C(),T=E(),D=ge(),te=async e=>{h(e);try{await w.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},k=async()=>{h(e.name);try{await T.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},ne=async n=>{let r=`${t}/${e.name}`;try{await D.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`}),x?l(re,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(ee,{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:N(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!x&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(oe,{children:[l(ie,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:_}),l(b,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(y,{onClick:()=>ne(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===_?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:k,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(S,{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(g,{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:()=>te(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(S,{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(ve,{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(fe,{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=v(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=ae({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=>N(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(T,{className:`h-3 w-3`}),` Refresh`]})}),l(ye,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:ue,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},F=.8,I=Math.ceil(8*F-3)+1,L=P.width+34,R=P.height+I+1+11,ze=I+P.height+1+3+Math.ceil(8*F),Be=[1,2,5,10],Ve=[1,2,4,8,16,32,64,128,256,512,1024],He=[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 He.some(e=>Math.abs(t-e)<B)}let n=e/10**Math.floor(Math.log10(e));return He.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 Ve){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Be){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 K(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 Ge(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 Ke(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function qe(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-CNyXe5mk.js";import{Al as g,As as _,Bc as v,Dn as y,En as b,Eu as x,Fl as S,Ga as C,Gc as w,Gu as ee,Il as T,Ka as E,La as D,Ll as O,Ms as te,No as k,Ns as ne,Ol as re,On as ie,Ra as ae,Tn as oe,Vu as se,Wa as ce,Wl as le,ad as A,dt as ue,ec as de,et as fe,js as pe,kl as me,nu as j,ol as he,qa as ge,ts as _e,tt as ve,ut as ye,vi as be,yn as xe,zc as Se}from"./src-CijuRqy3.js";import{t as Ce}from"./hard-drive-download-CrmDflbp.js";import{Vn as we}from"./src-lIpPC3rn.js";import{l as M}from"./index-BIcFiIU1.js";import{t as N}from"./format-size-DIxKXxtj.js";import{t as Te}from"./NodeAddonsSettingsPanel-BuE0DHPB.js";import{n as Ee,r as De,t as Oe}from"./useNodeUrlSelection-CkUk0sXo.js";var ke=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),[_,v]=c(`info`),x=e.name.includes(`(core)`),w=C(),T=E(),D=ge(),te=async e=>{h(e);try{await w.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},k=async()=>{h(e.name);try{await T.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},ne=async n=>{let r=`${t}/${e.name}`;try{await D.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`}),x?l(re,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(ee,{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:N(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ae(e.uptimeSeconds)}),!x&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(oe,{children:[l(ie,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:_}),l(b,{align:`end`,className:`min-w-[70px] py-0.5`,children:Me.map(e=>l(y,{onClick:()=>ne(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===_?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:k,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(S,{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(g,{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:()=>te(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(S,{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(ve,{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(fe,{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=v(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=ae({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=>N(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(T,{className:`h-3 w-3`}),` Refresh`]})}),l(ye,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:ue,emptyMessage:`Scanning…`})]})}var P={width:320,height:64},F=.8,I=Math.ceil(8*F-3)+1,L=P.width+34,R=P.height+I+1+11,ze=I+P.height+1+3+Math.ceil(8*F),Be=[1,2,5,10],Ve=[1,2,4,8,16,32,64,128,256,512,1024],He=[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 He.some(e=>Math.abs(t-e)<B)}let n=e/10**Math.floor(Math.log10(e));return He.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 Ve){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Be){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 K(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 Ge(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 Ke(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function qe(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-CNyXe5mk.js";import{B as u,H as d,Rr as f,Vr as p,_i as m,an as h,c as g,cn as _,qi as v,tn as y,vi as b}from"./src-CijuRqy3.js";import{An as x,Cn as S,Et as C,Mn as w,Sn as T,Tt as ee,_n as E,dn as D,fn as te,gn as ne,hn as re,jn as ie,kn as O,mn as ae,sn as k,un as oe,vn as A,yn as j}from"./src-lIpPC3rn.js";import{l as M}from"./index-BIcFiIU1.js";r();function se(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ce(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function le(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 ue(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function de(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:ue(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 fe(e){let t=te.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 pe(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}function P(e){return{addonId:e.addonId,stableId:e.stableId}}function F(e){return new Map(e.map(e=>[A(P(e)),e]))}function me(e,t,n){return e.filter(e=>e.id!==n&&e.type!==S.Container&&t.includes(e.id)).toSorted((e,t)=>e.name.localeCompare(t.name))}function he(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 ge(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function _e(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 R(e,t){return L(e)===L(t)}function ve(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 H=ie.filter(e=>e!==`switch`&&e!==`motion`);function ye(e){let t=w[e.cap];return t===void 0||!H.includes(e.cap)?null:{kind:`fields`,cap:e.cap,fields:{[t]:{kind:`expression`,expr:`!v`,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:t}}}}}}function be(e){return e.from===e.to||!C(e.from,e.to)?null:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:{kind:`expression`,expr:`convert(v, ${JSON.stringify(e.from)}, ${JSON.stringify(e.to)})`,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},...e.unitField===null?{}:{[e.unitField]:B(JSON.stringify(e.to))}}}}function xe(e,t){let n=z(`number`,t.remaining);if(n===null||!D.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:{"remaining.value":n,"remaining.unit":B(JSON.stringify(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 Se(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function Ce(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=>[A(e),e])).values()]}function we(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 Te(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 Ee(e,t){let n=Te(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 U(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function De(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 W(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 Oe(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 ke(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:W(n[e.cap],t.path),source:Oe(i,e.cap,t,r)})))}function G(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 Ae=[];function K({title:e,targetKind:t,excludeDeviceIds:n=Ae,onPick:r,onCancel:a}){let{t:c}=M(),[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(q,{excludeDeviceIds:n,onSelect:u}):s(je,{device:l,targetKind:t,onPick:r,onBack:()=>u(null)}),s(`div`,{children:s(_,{variant:`ghost`,onClick:a,children:c(`customize.picker.cancel`)})})]})}function q({excludeDeviceIds:e,onSelect:t}){let{t:n}=M(),[r,c]=o(``),l=b({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(h,{title:n(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&s(`ul`,{className:`flex flex-col gap-1`,children:De(U(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 je({device:e,targetKind:t,onPick:n,onBack:r}){let{t:a}=M(),o=m({deviceId:e.id}),c=v({deviceId:e.id});if(o.status===`pending`)return s(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:a(`customize.picker.loadingFields`)});if(o.status===`error`)return s(h,{title:a(`customize.picker.fieldsFailed`),message:o.error?.message??``});let l=ke(e,o.data,c.status===`success`?c.data:null,t),u=l.filter(e=>e.source===null).length,d={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:r,children:[`← `,e.name]}),c.status===`error`&&s(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:a(`customize.picker.valuesFailed`,{reason:c.error?.message??``})}),s(`ul`,{role:`listbox`,"aria-label":a(`customize.picker.fields`),className:`flex flex-col gap-1`,children:l.map(t=>{let r=t.source;if(r===null)return null;let a=()=>n({device:e,ref:d,cap:t.cap,path:t.path,kind:t.kind,source:r,value:t.value});return i(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:a,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a()},children:[i(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),s(`span`,{children:G(t.value,c.status===`success`)})]},`${t.cap}.${t.path}`)})}),u>0&&t!==null&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`customize.picker.hidden`,{count:u,kind:a(`customize.kinds.${t}`)})})]})}var J=`integration`;function Y(e,t){switch(e.kind){case`from`:{let n=A(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Me(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 X(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Y(n,e.input.sourceNames),value:e.enabled?Me(e.input.state,r):{kind:`off`}}}function Ne(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>X(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function Pe(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>X(e,re(oe,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function Fe(e,t,n){if(e===null)return{kind:`unknown`,reason:`the device state could not be read`};let r=W(e[t],n),i=r===void 0?void 0:O(r);return i===void 0?{kind:`unknown`,reason:`not reported`}:{kind:`value`,value:i,staleReason:null}}function Ie(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:J,value:Fe(e.input.snapshot,t,n)}))}function Le(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:ae(t),input:e};return[...Ne(n),...Pe(n),...Ie(n)]})}var Re={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)`},Z=/[A-Za-z_][A-Za-z0-9_]*$/;function ze(e,t,n){let r=Z.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=[...x].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:Re[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function Be(e,t,n){let r=t-(Z.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 Ve({label:e,value:t,bindings:r,onChange:a}){let{t:c}=M(),l=n(null),[u,d]=o(t.length),f=ze(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=Be(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 He(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:`code fields arrive in slice 4`};if(e.kind===`expression`&&(k(e.expr,`rose`)||k(e.expr,`count`)))return{kind:`runtime-only`};let r=j(e).filter(e=>t.get(E(e.source,e.cap))?.kind!==`value`).map(ne);if(r.length>0)return{kind:`waiting`,missing:r};let i=ee({source:e,now:n,read:e=>{let n=t.get(E(e.source,e.cap)),r=n?.kind===`value`?W(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:O(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 Ue({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=g(l().trpcClient,t,n);return c(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function We(e,t){return[...new Map(j(e).map(e=>[E(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(A(n.source))}))}function Ge({source:e}){let{t:n}=M(),r=b({projection:`slim`}),[a,c]=o(new Map),l=t((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=We(e,F(r.status===`success`?U(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>A(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(Ue,{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(Ke,{preview:He(e,a,Date.now())})]})}function Ke({preview:e}){let{t}=M();switch(e.kind){case`value`:return i(`strong`,{children:[`→ `,G(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 qe({path:e,kind:t,required:n,source:r,onSet:c,onClear:l,sourceNames:u}){let{t:d}=M(),[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(_,{size:`sm`,variant:`outline`,onClick:()=>p(`take`),children:d(`compositionEditor.takeFrom`)}),s(_,{size:`sm`,variant:`outline`,"aria-pressed":m!==null,onClick:()=>c(m??{kind:`expression`,expr:`null`,bindings:{}}),children:d(`compositionEditor.formula`)}),r!==void 0&&s(_,{size:`sm`,variant:`ghost`,onClick:l,children:d(`compositionEditor.clear`)})]}),r?.kind===`from`&&s(`span`,{className:`text-[11px]`,children:Y(r,u)}),m!==null&&i(a,{children:[s(Ve,{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`?Y(t,u):JSON.stringify(t.value)})]},e))}),s(_,{size:`sm`,variant:`ghost`,onClick:()=>p(`add-binding`),children:d(`compositionEditor.addSource`)})]}),f!==`idle`&&s(K,{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=pe(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(Ge,{source:r})]})}r();function Q(e){return e===null||e.kind===`known`?null:e}function Je({draft:e,deviceType:t,nativeCaps:n,targetFields:r,dispatch:c}){let{t:l}=M(),u=f({deviceType:t}),d=b({projection:`slim`}),p=new Map([...F(d.status===`success`?U(d.data):[])].map(([e,t])=>[e,t.name])),[m,h]=o(null),g=Q(n)??Q(r),v=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)&&!v.has(e.cap)):[],C=[...v].filter(e=>!x.has(e)),w=e=>v.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 g===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(`customize.presets.checking`)}),u.status===`error`&&s(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`customize.presets.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(y,{variant:v.has(e.cap)?`default`:`info`,children:v.has(e.cap)?l(`compositionEditor.replaces`):l(`customize.fields.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(_,{size:`sm`,variant:`outline`,onClick:()=>c({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),C.map(e=>s(_,{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(_,{size:`sm`,variant:`outline`,onClick:()=>h(e.cap),children:l(`compositionEditor.copyFeature`)})]}),m===e.cap&&s(K,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>h(null),onPick:t=>{c({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:w(e.cap).map(e=>e.path)}),h(null)}}),w(e.cap).map(t=>s(qe,{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:g.kind===`unknown`?g.reason:l(`customize.fields.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function Ye({draft:e,targetName:t,dispatch:n}){let{t:r}=M(),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(`customize.identity.type`),s(`select`,{className:$,value:a.type,onChange:e=>{let t=Object.values(S).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(S).map(e=>s(`option`,{value:e,children:d(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(T).find(t=>t===e.target.value)??null}),children:[s(`option`,{value:``,children:r(`customize.identity.noRole`)}),Object.values(T).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 Xe({draft:e,blockId:t,saving:n,onSave:r,onCancel:a}){let{t:l}=M(),u=p(),d=fe(e),f=d.ok?JSON.stringify(d.composition):``,[m,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?m.key===f?m.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(_,{variant:`ghost`,onClick:a,children:l(`compositionEditor.cancel`)}),s(_,{disabled:g.kind!==`ok`||n||!d.ok,onClick:()=>d.ok&&r(d.composition),children:l(`compositionEditor.save`)})]})]})}r();function Ze({initial:t,blockId:n,deviceType:r,targetName:a=null,nativeCaps:c,targetFields:l,save:u,onCancel:d}){let[f,p]=e(de,t),[m,h]=o(!1),[g,_]=o(null),v=f.target.kind===`new`?f.target.type:r,y=async e=>{h(!0);let t=await u(e,f.name);h(!1),_(t.kind===`refused`?t.reason:null)};return i(`div`,{className:`flex flex-col gap-4`,children:[s(Ye,{draft:f,targetName:a,dispatch:p}),s(Je,{draft:f,deviceType:v,nativeCaps:c,targetFields:l,dispatch:p}),s(Xe,{draft:f,blockId:n,saving:m,onSave:e=>void y(e),onCancel:d}),g!==null&&s(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:g})]})}export{me as C,se as D,ce as E,F as S,le as T,_e as _,G as a,he as b,H as c,be as d,Ce as f,Se as g,Ee as h,K as i,V as l,ye as m,J as n,W as o,we as p,Le as r,U as s,Ze as t,xe as u,ve as v,P as w,ge as x,R as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{x as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Br as t,Ir as n,Pr as r,an as i}from"./src-
|
|
1
|
+
import{x as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Br as t,Ir as n,Pr as r,an as i}from"./src-CijuRqy3.js";import{t as a}from"./boxes-C6pcozLY.js";import{Cn as o,on as s}from"./src-lIpPC3rn.js";import{a as c,d as l,f as u,l as d,o as f,p}from"./index-BIcFiIU1.js";import{t as m}from"./AdminPage-CiKtOLQm.js";import{D as h,T as g,t as _}from"./CompositionEditor-CF_9g_KZ.js";var v=`new`;function y(e){return e instanceof Error?e.message:String(e)}function b(e){let t=e.trim();return t===``?{}:{name:t}}function x(){let{blockId:x}=p(),{t:S}=d(),C=u(),w=r(),T=t(),E=x===void 0||x===v,D=n({blockId:x??``},{enabled:!E}),O=t=>e(m,{icon:a,title:S(`compositionEditor.pageTitle`),children:t});if(E)return O(e(_,{initial:h(o.Sensor),blockId:null,deviceType:o.Sensor,nativeCaps:null,targetFields:null,onCancel:()=>C(-1),save:async(e,t)=>{try{let{block:n}=await w.mutateAsync({block:{...b(t),enabled:!0,composition:e}});return C(c(n.id),{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:y(e)}}}}));if(D.status===`pending`)return O(e(`p`,{role:`status`,children:S(`compositionEditor.loading`)}));if(D.status===`error`)return O(e(i,{title:S(`compositionEditor.loadFailed`),message:D.error.message}));if(D.data.state===`not-loaded`)return O(e(`p`,{role:`status`,children:S(`customize.status.notLoaded`,{reason:D.data.reason})}));let k=D.data.view;if(k===null)return O(e(`p`,{children:S(`compositionEditor.notFound`,{blockId:x})}));let A=s(k.block);if(A===null)return O(e(`p`,{children:S(`compositionEditor.notComposition`)}));if(A.target.kind===`existing`){let t=k.state.kind===`answered`?k.state.state?.deviceId??null:null;return O(t===null?e(`p`,{children:S(`compositionEditor.customizationUnknownDevice`)}):e(l,{className:`text-primary`,to:f(t),children:S(`compositionEditor.openOnDevice`)}))}return O(e(_,{initial:g(A,k.block.name),blockId:k.block.id,deviceType:A.target.type,nativeCaps:null,targetFields:null,onCancel:()=>C(-1),save:async(e,t)=>{try{return await T.mutateAsync({blockId:k.block.id,expectedUpdatedAt:k.block.updatedAt,block:{...b(t),composition:e}}),await D.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:y(e)}}}},`${k.block.id}@${k.block.updatedAt}`))}export{x as CompositionEditorPage};
|