@camstack/addon-admin-ui 1.2.318 → 1.2.319
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-BN9l7eMZ.js → AddonCollectionPage-BrWgzLIU.js} +1 -1
- package/dist/assets/Addons-DYcAKvwk.js +1 -0
- package/dist/assets/{AdminTabs-lo1nGBvk.js → AdminTabs-ClzbjkxZ.js} +1 -1
- package/dist/assets/AiProfiles-Dov4FVsX.js +3 -0
- package/dist/assets/{BrokerForm-CjGqLtHB.js → BrokerForm-mZwFyC9C.js} +1 -1
- package/dist/assets/Build-60BV1diC.js +375 -0
- package/dist/assets/Calendars-DsHBCFwG.js +1 -0
- package/dist/assets/{Capabilities-Bid9B0aL.js → Capabilities-85W11SU9.js} +1 -1
- package/dist/assets/{CapabilityBadges-CFFfrQgk.js → CapabilityBadges-B6AnXa_t.js} +1 -1
- package/dist/assets/Cluster-qFRM7CZx.js +11 -0
- package/dist/assets/{CompositionEditor-DZT2LotJ.js → CompositionEditor-NRHG8SDd.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DgSroELQ.js → CompositionEditorPage-DdwhEMMN.js} +1 -1
- package/dist/assets/Data-CEGeZLbf.js +1 -0
- package/dist/assets/DetectionIntelligence-BwIpzk1h.js +1 -0
- package/dist/assets/{DeviceAggregateSection-CksIr7a0.js → DeviceAggregateSection-BJDp8r7c.js} +1 -1
- package/dist/assets/DeviceDetail-UwDyYgHs.js +2 -0
- package/dist/assets/DeviceDoActionFields-OJLes8SP.js +1 -0
- package/dist/assets/{Devices-BZ1ju_7C.js → Devices-C7EsO5uT.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-sP8pM1-2.js → EmbedPlayerPage-CLtx1qJu.js} +1 -1
- package/dist/assets/Events-CKB7LKgR.js +1 -0
- package/dist/assets/{FormBuilder-BBaiZSEO.js → FormBuilder-66XFP4SU.js} +1 -1
- package/dist/assets/Identity-B9buxNxL.js +1 -0
- package/dist/assets/IntegrationDetail-B7ZswH_j.js +1 -0
- package/dist/assets/{Integrations-BHzUYG6D.js → Integrations-B4u7dcBy.js} +1 -1
- package/dist/assets/Integrations-BiYfqDqX.js +1 -0
- package/dist/assets/Locations-wmUUv8Qt.js +3 -0
- package/dist/assets/{Logs-BWiH-JhS.js → Logs-8C77vt04.js} +1 -1
- package/dist/assets/{ModelLicenses-CecJNAUn.js → ModelLicenses-BpND7P2W.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CTQLlrhj.js → MotionZonesSettings-BgQQ-nih.js} +1 -1
- package/dist/assets/{MyAccess-BvG_1DW6.js → MyAccess-CfmkGGJr.js} +1 -1
- package/dist/assets/Network-DbOzHm2v.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-D7om0e1q.js → NodeAddonsSettingsPanel-CoGJcleE.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-V0xEVK63.js → NodeInferenceDevices-DEQLoFgS.js} +1 -1
- package/dist/assets/Notifications-q6l-TAXA.js +1 -0
- package/dist/assets/Pipeline-DD8w5812.js +1 -0
- package/dist/assets/{Plates-C8QmsKmj.js → Plates-p-NK9G1T.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-C9aBSVlv.js → PrivacyMaskSettings-CSIJ2V3u.js} +1 -1
- package/dist/assets/{ProviderIcon-DoIQ7DhJ.js → ProviderIcon-D3iThBBe.js} +1 -1
- package/dist/assets/Recordings-D25IxRNs.js +1 -0
- package/dist/assets/{ScanNetworkModal-C3WijDGp.js → ScanNetworkModal-DKFEtHT3.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-B958o6r1.js → SceneMonitorEditor-DwhUbtzq.js} +1 -1
- package/dist/assets/{Scenes-BQgvgzQs.js → Scenes-D1jX8kn5.js} +1 -1
- package/dist/assets/{Settings-9P3YIZMT.js → Settings-C2BKgOpm.js} +1 -1
- package/dist/assets/{Showroom-BHj5mXWK.js → Showroom-CtqBkiv2.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DCLsuF-C.js → StorageLocationsPanel-CVjEIApR.js} +1 -1
- package/dist/assets/{Terminal-DoJ_OZH4.js → Terminal-DecFUwef.js} +5 -5
- package/dist/assets/{Viewer-dRJuCLAa.js → Viewer-BPi2u3JT.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-mIcMabMK.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-cJ6EU7bN.js} +1 -1
- package/dist/assets/{archive-7wNcK2IS.js → archive-XCiszzxf.js} +1 -1
- package/dist/assets/{authed-media-DyZLbN-o.js → authed-media-DDqmA02K.js} +1 -1
- package/dist/assets/{boxes-DRYKdAp-.js → boxes-D4MIbXht.js} +1 -1
- package/dist/assets/circle-slash-Cy2rn5H3.js +1 -0
- package/dist/assets/{debounced-invalidate-BZmNPMY1.js → debounced-invalidate-Bz2popF9.js} +1 -1
- package/dist/assets/{device-integration-icon-LEPa0YVm.js → device-integration-icon-DzuJgcu0.js} +1 -1
- package/dist/assets/device-picker-model-5vHoWhVP.js +1 -0
- package/dist/assets/{dist-B657U48r.js → dist-BE0-lAbU.js} +1 -1
- package/dist/assets/dist-BlxQFw9d.js +349 -0
- package/dist/assets/{face-bbox-6G4c88_6.js → face-bbox-CQZeT16C.js} +1 -1
- package/dist/assets/{hard-drive-download-BFmQDsVh.js → hard-drive-download-BUvVfeCd.js} +1 -1
- package/dist/assets/{hostInit-CqKhA_sQ.js → hostInit-s2-vIzef.js} +1 -1
- package/dist/assets/index-BBheY5o3.css +2 -0
- package/dist/assets/{index-CwSbxED9.js → index-C1l1qzBm.js} +3 -3
- package/dist/assets/{layers-Nb3R5zd7.js → layers-CtOoDwSD.js} +1 -1
- package/dist/assets/{location-owned-usage-CEaVmhRl.js → location-owned-usage-C5plKvRg.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-b1ec185a.js → mf-entry-bootstrap-0-1c53a077.js} +2 -2
- package/dist/assets/{player-overlays-BcO9fxNP.js → player-overlays-27qhPy_v.js} +1 -1
- package/dist/assets/remoteEntry-C-HUzkdc.js +1 -0
- package/dist/assets/{send-Cxp-ZViK.js → send-BPGjlbSr.js} +1 -1
- package/dist/assets/{settings-2-Bnv0uVAN.js → settings-2-DYo9uOuF.js} +1 -1
- package/dist/assets/{square-check-big-BFhfY6Jd.js → square-check-big-CTL89hi8.js} +1 -1
- package/dist/assets/src-DxIAkBus.js +349 -0
- package/dist/assets/src-IJPkPeFt.js +67 -0
- package/dist/assets/{use-scenes-feed-CzL9nssG.js → use-scenes-feed-CPwa5B1D.js} +1 -1
- package/dist/assets/{use-stationary-objects-Df3ltX40.js → use-stationary-objects-Dq2GsPVr.js} +1 -1
- package/dist/assets/useDevice-CkN93PJ-.js +1 -0
- package/dist/assets/useEventInvalidation-5vHoWhVP.js +1 -0
- package/dist/assets/{useNodeUrlSelection-UzxaMEdr.js → useNodeUrlSelection-CUdqirJf.js} +1 -1
- package/dist/assets/user-round-C3AYvBKo.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3b4GvrC.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-yti5GZlu.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +5246 -4983
- package/package.json +1 -1
- package/dist/assets/Addons-wMbMeQOY.js +0 -1
- package/dist/assets/AiProfiles-Tm1kdnXr.js +0 -3
- package/dist/assets/Build-Dm6CXeaO.js +0 -32
- package/dist/assets/Calendars-BEIjf9xd.js +0 -1
- package/dist/assets/Cluster-DJP3Y97M.js +0 -11
- package/dist/assets/Data-Dmo4xd4g.js +0 -1
- package/dist/assets/DetectionIntelligence-DiHWFh0X.js +0 -1
- package/dist/assets/DeviceDetail-C-VhJOex.js +0 -2
- package/dist/assets/Events-DAb6Xigy.js +0 -1
- package/dist/assets/Identity-Bk15qu5d.js +0 -1
- package/dist/assets/IntegrationDetail-wcjbkQUB.js +0 -1
- package/dist/assets/Integrations-BkvkGuwJ.js +0 -1
- package/dist/assets/Locations-BSfdvsGe.js +0 -3
- package/dist/assets/Network-BhsxhFjD.js +0 -1
- package/dist/assets/Notifications-D5dhr2wH.js +0 -1
- package/dist/assets/Pipeline-lo8pqs0O.js +0 -1
- package/dist/assets/Recordings-C_KplJ3-.js +0 -1
- package/dist/assets/circle-slash-Jvk_TWqc.js +0 -1
- package/dist/assets/device-picker-model-DXiaooJB.js +0 -1
- package/dist/assets/dist-B1YvGzuM.js +0 -349
- package/dist/assets/index-DZYv56ZC.css +0 -2
- package/dist/assets/remoteEntry-CUHUArg_.js +0 -1
- package/dist/assets/src-BVYExcrk.js +0 -349
- package/dist/assets/src-C2nRzmKs.js +0 -67
- package/dist/assets/useDevice-CbY0qewJ.js +0 -1
- package/dist/assets/useEventInvalidation-DXiaooJB.js +0 -1
- package/dist/assets/user-round-BzsknipD.js +0 -1
|
@@ -0,0 +1,375 @@
|
|
|
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,o as l,q as u,t as d,x as f,z as p}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 m,at as h,gt as g,st as _,yt as v}from"./player-overlays-27qhPy_v.js";import{$l as y,$t as b,A as x,Ad as S,Dt as C,Ft as w,Ht as T,It as E,Nd as D,Nl as O,Nn as k,Nt as A,Pt as j,Sn as M,Tt as N,Ut as P,Vi as F,Wt as ee,_t as te,_u as I,ai as ne,ct as re,cu as ie,di as ae,ei as oe,en as L,gn as R,gu as se,hn as z,ht as ce,hu as le,ii as B,ir as V,ku as H,ld as ue,mi as de,pi as fe,ru as pe,wt as me,xn as U,yn as W,zu as he}from"./src-IJPkPeFt.js";import{An as ge,Dn as G,Dr as _e,Hn as K,Jn as ve,Ln as ye,Qn as be,Un as xe,Xn as Se,Yn as Ce,Zn as we,kn as Te}from"./src-DxIAkBus.js";import{a as Ee,d as De,i as Oe,m as ke,s as Ae,y as je}from"./index-C1l1qzBm.js";import{t as Me}from"./AdminPage-CiKtOLQm.js";import{t as Ne}from"./DeviceDoActionFields-OJLes8SP.js";import{r as Pe}from"./useDevice-CkN93PJ-.js";import{t as Fe}from"./FormBuilder-66XFP4SU.js";var Ie=v(`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`}]]),Le=v(`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`}]]),Re=`const AUTOMATION_RECIPE =`,ze=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
+
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
+
// here the editor could re-open this block and overwrite everything below.`;function Be(e){return e.includes(Re)}function Ve(e){let t=e.indexOf(Re);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 He(e){let t=Ve(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=Ce.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 Ue(e){let t=Ve(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)}${ze}${e.slice(i)}`}r();var We=6e4;function Ge(){let e=F({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function Ke(e){let t=h();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:We,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function qe(e,t){return e.find(e=>e.cap===t)?.fields??[]}function q({children:e}){return f(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Je(e){let t=Ke(e.deviceId);if(t.data!==void 0)return qe(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ye({value:e,devices:t,onChange:n}){let r=Ke(e.deviceId),a=r.data??[],o=qe(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[f(q,{children:`Device`}),f(U,{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:[f(q,{children:`Capability`}),f(U,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Xe(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[f(q,{children:`Field`}),f(U,{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 Xe(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Ze=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Qe(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Ze}}function $e(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 et(e){return Qe(e).map(e=>({value:e,label:$e(e)}))}function tt(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 nt={triggers:[],actions:[]};function rt(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 it(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
|
+
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function at(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function ot(){return{kind:`expression`,expr:``,bindings:{}}}function st(e,t,n){return e.map((e,r)=>r===t?n:e)}function ct(e,t){return e.filter((e,n)=>n!==t)}function lt(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=ct(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ut(e,t){return{...e,triggers:[...t]}}function dt(e,t){return{...e,actions:[...t]}}var ft=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function pt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&f(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((a,o)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(z,{variant:`default`,children:o+1}),i(`label`,{className:`w-40`,children:[f(q,{children:`Step`}),f(U,{value:a.kind,onChange:t=>r(st(e,o,it(mt(t.target.value)))),options:ft.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[f(M,{variant:`ghost`,disabled:o===0,onClick:()=>r(lt(e,o,o-1)),title:`Run this step earlier`,children:f(S,{className:`h-3.5 w-3.5`})}),f(M,{variant:`ghost`,disabled:o===e.length-1,onClick:()=>r(lt(e,o,o+1)),title:`Run this step later`,children:f(D,{className:`h-3.5 w-3.5`})}),f(M,{variant:`ghost`,onClick:()=>r(ct(e,o)),title:`Remove this step`,children:f(_,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&i(`label`,{className:`block w-32`,children:[f(q,{children:`Seconds`}),f(L,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(st(e,o,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&i(`label`,{className:`block`,children:[f(q,{children:`Code`}),f(`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:a.code,spellCheck:!1,onChange:t=>r(st(e,o,{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. `,f(`code`,{children:`ctx`}),` and `,f(`code`,{children:`vars`}),` are in scope.`]})]}),a.kind===`cap`&&f(ht,{action:a,devices:t,devicesState:n,onChange:t=>r(st(e,o,t))})]},`${a.kind}-${String(o)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>r([...e,it(`cap`)]),children:[f(le,{className:`h-4 w-4`}),` Step`]}),e.length>1&&f(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function mt(e){return ft.find(t=>t.value===e)?.value??`cap`}function ht({action:e,devices:t,devicesState:n,onChange:r}){return f(Ne,{value:e,allowTriggerDevice:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function gt({value:e,field:t,onChange:n}){return t?.kind===`boolean`?f(U,{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?f(U,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?f(L,{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)}}):f(L,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function _t({value:e,field:t,onChange:n}){return f(L,{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 vt(e){return typeof e==`object`}function yt(e){return vt(e)?e[0]??``:e}function bt(e){return vt(e)?e:typeof e==`boolean`?[]:[e]}function xt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Je(r),o=et(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=St(t,o);n({...e,operator:r,value:r===`in`?bt(e.value):yt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[f(Ye,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[f(q,{children:`Comparison`}),f(U,{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:[f(q,{children:`Value`}),s?f(_t,{value:bt(e.value),field:a,onChange:t=>n({...e,value:t})}):f(gt,{value:yt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function St(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Ct={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function wt({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:[f(q,{children:`Expression`}),f(L,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),f(`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&&f(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>f(Tt,{alias:n,source:r,devices:t,onRename:t=>a(jt(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(Mt(e.bindings,n))},n)),i(M,{variant:`ghost`,onClick:()=>a({...e.bindings,[At(e.bindings)]:Ct}),children:[f(le,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function Tt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Ot(n,Dt(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:[f(q,{children:`Name`}),f(L,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[f(q,{children:`Reads`}),f(U,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Ct),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[f(q,{children:`Constant`}),f(L,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Et(e.target.value)})})]}):f(Ye,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:kt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),f(M,{variant:`ghost`,onClick:o,title:`Remove this name`,children:f(_,{className:`h-3.5 w-3.5`})})]})}function Et(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Dt(e){return e.kind===`global`?e.sourceStableId:``}function Ot(e,t){return e.find(e=>e.stableId===t)?.id??0}function kt(e,t){return e.find(e=>e.id===t)?.stableId??``}function At(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 jt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Mt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function J(e){return e.kind===`all`||e.kind===`any`}function Y(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:J(t)?t:{kind:`all`,children:[t]}}function Nt(e,t){return t===null||J(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Pt(e){return Nt(e,Y(e))}function Ft(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?Ft(e.child,r):null;if(!J(e))return null;let i=e.children[n];return i===void 0?null:Ft(i,r)}function X(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=X(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!J(e))return e;let a=e.children[r];if(a===void 0)return e;let o=X(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 It(e){return e===null?null:be({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function Lt(e){let t=Y(e);return{depth:t.children.length===0?0:Se(t),leaves:t.children.length===0?0:we(t),depthLimit:3,leafLimit:32}}function Rt(e,t){let n=It(t);return n===null?{ok:!0,recipe:Nt(e,t)}:{ok:!1,reason:n}}function zt(e,t){let n=Y(e);return Rt(e,{kind:n.kind,children:[...n.children,t]})}function Bt(e,t,n){return Nt(e,X(Y(e),t,()=>n))}function Vt(e,t){return Nt(e,X(Y(e),t,()=>null))}function Ht(e,t,n){return Nt(e,X(Y(e),t,e=>J(e)?{kind:n,children:e.children}:e))}function Ut(e,t){return Ft(Y(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Rt(e,X(Y(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Wt(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 Gt(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=Wt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Y(e),a=Ft(i,r.path);if(a===null||!J(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 Rt(e,X(i,r.path,()=>d))}function Kt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=Y(e),r=Ft(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Rt(e,X(n,t,()=>r.child));if(!J(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Wt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Ft(n,i.path);if(a===null||!J(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 Rt(e,X(n,i.path,()=>o))}r();var qt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function Jt(e){return e.join(`/`)}function Yt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Xt({recipe:e,devices:t,onChange:n}){let[r,a]=u([]),[s,c]=u(null),l=Y(e),d=Lt(e),p=o(()=>r.map(Yt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Gt(e,p,`all`),g=Gt(e,p,`any`),_=p.length===1?Ut(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(Bt(e,t,r)),onRemove:t=>{a([]),n(Vt(e,t))},onSetKind:(t,r)=>n(Ht(e,t,r)),onUngroup:t=>m(Kt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(z,{variant:`default`,children:`And only if`}),f(`div`,{className:`w-32`,children:f(U,{value:l.kind,onChange:t=>n(Ht(e,[],Zt(t.target.value))),options:qt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,d.depth,`/`,d.depthLimit,` · `,d.leaves,`/`,d.leafLimit,` conditions`]})]}),l.children.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):f(Qt,{container:l,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>m(zt(e,at())),title:`Compare one device field to a value`,children:[f(le,{className:`h-4 w-4`}),` Condition`]}),i(M,{variant:`outline`,onClick:()=>m(zt(e,ot())),title:`Arithmetic across device fields — the bounded expression engine`,children:[f(Ie,{className:`h-4 w-4`}),` Expression`]}),f(`span`,{className:`mx-1 h-5 w-px bg-border`}),f(M,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),f(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`}),f(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&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Zt(e){return e===`any`?`any`:`all`}function Qt({container:e,path:t,handlers:n}){return f(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>f($t,{node:e,path:[...t,r],handlers:n},Jt([...t,r])))})}function $t({node:e,path:t,handlers:n}){let r=Jt(t),a=f(b,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return J(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,f(`div`,{className:`w-32`,children:f(U,{value:e.kind,onChange:e=>n.onSetKind(t,Zt(e.target.value)),options:qt})}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[f(Le,{className:`h-3.5 w-3.5`}),` Ungroup`]}),f(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:f(_,{className:`h-3.5 w-3.5`})})]}),f(`div`,{className:`pl-4`,children:f(Qt,{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,f(z,{variant:`warning`,children:`NOT`}),i(M,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[f(Le,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),f(`div`,{className:`pl-4`,children:f($t,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[f(`div`,{className:`pt-6`,children:a}),f(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?f(xt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):f(wt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),f(M,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:f(_,{className:`h-3.5 w-3.5`})})]})}r();function en({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=u(!1),c=k(),l=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:[f(o?m:g,{className:`h-4 w-4`}),`Generated code`]}),f(`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 l(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[f(je,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&f(`div`,{className:`border-t border-border p-3`,children:e===null?f(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):f(C,{maxHeight:420,children:e})})]})}var tn=[`device-state`,`device-event`,`schedule`,`manual`],nn=Object.values(_e).sort((e,t)=>e.localeCompare(t));function rn({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&f(`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)=>f(an,{trigger:r,devices:t,position:i,onChange:t=>n(st(e,i,t)),onRemove:()=>n(ct(e,i))},`${r.kind}-${String(i)}`)),i(M,{variant:`outline`,onClick:()=>n([...e,rt(`device-state`)]),title:`Add another way this automation can start`,children:[f(le,{className:`h-4 w-4`}),` Trigger`]})]})}function an({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:[f(z,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[f(q,{children:`Trigger`}),f(U,{value:e.kind,onChange:e=>r(rt(on(e.target.value))),options:tn.map(e=>({value:e,label:tt(e)}))})]}),f(M,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:f(_,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&f(cn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&f(un,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[f(q,{children:`Cron expression`}),f(L,{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. `,f(`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 `,f(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function on(e){return tn.find(t=>t===e)??`manual`}function sn(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 cn({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Je(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:[f(Ye,{value:r,devices:t,onChange:e=>n(sn(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[f(q,{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:[f(b,{checked:e.becomes===void 0,onChange:e=>n(sn(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&f(gt,{value:e.becomes,field:a,onChange:e=>n(sn(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[f(b,{checked:e.edge===!0,onChange:e=>n(sn(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[f(q,{children:`Held for (s)`}),f(L,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(sn(r,{...o,forMs:ln(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[f(q,{children:`Debounce (s)`}),f(L,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(sn(r,{...o,debounceMs:ln(e.target.value)}))})]})]})}function ln(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function un({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[f(q,{children:`Event category`}),f(U,{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…`},...nn.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[f(q,{children:`From device`}),f(U,{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 dn=`hub`;function fn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:l}){let[d,p]=u(e?.name??``),[m,h]=u(()=>Pt(t)),[g,_]=u(!1),v=Ge(),y=be(m),b=o(()=>mn(m),[m]),x=o(()=>hn(d.trim()===``?`Untitled automation`:d.trim(),m),[d,m]),S=d.trim()===``,C=S||y!==null||b!==null||x.code===null;return f(R,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),f(z,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:`Name`}),f(L,{className:`mt-1`,value:d,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),f(pn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:f(rn,{triggers:m.triggers,devices:v,onChange:e=>h(ut(m,e))})}),f(pn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:f(Xt,{recipe:m,devices:v,onChange:h})}),f(pn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:f(pt,{actions:m.actions,devices:v,onChange:e=>h(dt(m,e))})}),f(en,{code:x.code,error:x.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 — `,f(`code`,{children:G(e.id)})]}),f(ce,{addonId:G(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),y!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:y}),y===null&&b!==null&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),r!==null&&f(`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:()=>{x.code!==null&&s({name:d.trim(),code:x.code,enabled:e?.enabled??!0,placement:dn})},disabled:n||C,children:[n&&f(H,{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:[f(pe,{className:`h-4 w-4`}),` Logs`]}),f(M,{variant:`ghost`,onClick:l,disabled:n,children:`Close`}),S&&f(z,{variant:`warning`,children:`Name required`})]})]})})}function pn({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:[f(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),f(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),f(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function mn(e){let t=Ce.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 hn(e,t){try{return{code:ve({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function gn(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 _n(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function vn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function yn(e){let t=e=>{let t=gn(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 bn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>gn(e).tone===`error`).length,n=e.filter(e=>gn(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 xn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:d}){let p=gn(e),m=re(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:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(z,{variant:_n(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),f(`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:[f(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),f(M,{variant:`danger`,onClick:d,disabled:t,children:`Delete`}),f(M,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[f(M,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:f(I,{className:`h-4 w-4`})}),i(T,{children:[f(ee,{children:f(M,{variant:`ghost`,disabled:!0,title:`Run actions`,children:f(se,{className:`h-4 w-4`})})}),f(P,{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.`})]}),f(M,{variant:`ghost`,onClick:c,title:`Logs`,children:f(pe,{className:`h-4 w-4`})}),f(M,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),f(M,{variant:`ghost`,onClick:l,title:`Delete`,children:f(_,{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 — `,f(`code`,{children:G(e.id)})]}),f(ce,{addonId:G(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Sn({onCreate:e}){return f(R,{children:i(`div`,{className:`space-y-2 p-4`,children:[f(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),f(`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.`}),f(M,{onClick:e,children:`New automation`})]})})}r();var Cn=[`coreBlocks`,`list`],wn=5e3;function Tn(e){return e instanceof Error?e.message:String(e)}function En({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:o}){let c=h(),[l,m]=u({mode:`closed`}),[g,_]=u(null),[v,y]=u(null),b=t(null);p(()=>{a&&(m({mode:`edit`,block:null}),r?.(null),o?.())},[a,o,r]);let x=s({queryKey:Cn,refetchInterval:wn,queryFn:async()=>(await c.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{x.refetch()},C=x.data;p(()=>{if(n===void 0||b.current===n)return;let e=C?.find(e=>e.id===n&&Be(e.code));e!==void 0&&(b.current=n,m({mode:`edit`,block:e}))},[n,C]);let w=d({mutationFn:e=>c.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{m({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),T=d({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{m({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),E=d({mutationFn:e=>c.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{_(null),S()}}),D=d({mutationFn:e=>c.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),O=d({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Ue(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{m({mode:`closed`}),S(),e(t.block.id)}}),k=x.data,A=yn((k??[]).filter(e=>Be(e.code))),j=k!==void 0&&A.length===0,M=l.mode===`edit`&&l.block!==null?vn(A,l.block):null,N=M===null?null:He(M.code),P=w.error===null?T.error===null?O.error===null?null:Tn(O.error):Tn(T.error):Tn(w.error),F=l.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!F&&f(`p`,{className:`text-xs text-foreground-subtle`,children:k===void 0?``:bn(A)}),x.error!=null&&f(W,{title:`Could not read the automations`,message:Tn(x.error),onRetry:S}),F&&f(`div`,{className:`min-h-[70vh]`,"data-testid":`automation-editor-panel`,children:f(fn,{existing:M,initialRecipe:N!==null&&N.ok?N.recipe:nt,saving:w.isPending||T.isPending,saveError:P,ejecting:O.isPending,onSave:e=>{M===null?w.mutate(e):T.mutate({blockId:M.id,block:e})},onEject:()=>{M!==null&&O.mutate(M)},onCancel:()=>{w.reset(),T.reset(),O.reset(),m({mode:`closed`}),r?.(null)}},M?.id??`new`)}),!F&&j&&f(Sn,{onCreate:()=>{m({mode:`edit`,block:null}),r?.(null)}}),!F&&A.length>0&&f(R,{children:f(`ul`,{className:`divide-y divide-border`,children:A.map(e=>{let t=He(e.code);return f(xn,{block:e,busy:D.isPending||E.isPending,confirming:g===e.id,logsOpen:v===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{m({mode:`edit`,block:e}),r?.(e.id)},onToggle:t=>D.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>y(v===e.id?null:e.id),onAskDelete:()=>_(e.id),onCancelDelete:()=>_(null),onConfirmDelete:()=>E.mutate(e.id)},e.id)})})}),E.error!=null&&f(W,{message:Tn(E.error)}),D.error!=null&&f(W,{message:Tn(D.error)})]})}function Dn(e){return{state:`answered`,byRef:new Map(e.map(e=>[K(e),e]))}}function On(e,t){if(e.state!==`unanswered`)return e.byRef.get(K(t))??null}function kn(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function An(e){return xe(e).map(e=>e.source)}function jn(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(...An(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...An(e))}let r=new Set;return n.filter(e=>{let t=K(e);return r.has(t)?!1:(r.add(t),!0)})}function Mn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function Nn(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?[`${Mn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${Mn(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 Pn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Nn(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 Fn(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}`}).`}:Pn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function In(e){return K(e)}function Ln(e,t){let n=On(t,e);return{key:K(e),label:n?n.name:In(e),presence:kn(n),deviceId:n?n.id:null}}function Rn(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function zn(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=K(i),o=jn(e).filter(e=>K(e)!==a).map(e=>Ln(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=On(t,i),l=Rn(e),u=Fn(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=kn(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:In(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function Bn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Vn(e,t){return Bn(e)-Bn(t)||e.name.localeCompare(t.name)}function Hn(e,t){let n=e.flatMap(e=>{let n=zn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Vn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Vn)}}var Un=1e4;function Wn(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Gn(){let e=Pe();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 (${Wn(e.error)})`}:Dn(e.data)}function Kn(){let e=B({},{refetchInterval:Un}),t=Gn(),n=e.data;if(e.error!=null&&n===void 0)return f(W,{title:`Could not read the compositions`,message:Wn(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return f(R,{children:i(`div`,{className:`space-y-1 p-4`,children:[f(`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:Wn(e.error);return f(qn,{lists:Hn(n.views,t),fleet:t,refreshError:r})}function qn({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.`]}),f(Jn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:f(De,{to:Oe,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),f(Jn,{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 Jn({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:[f(`h3`,{className:`font-medium`,children:e}),f(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),f(R,{variant:`flat`,className:`p-0`,children:f(me,{columns:Yn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:N,emptyMessage:a})})]})}function Yn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>f(Xn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>f(`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:[f(z,{variant:_n(e.state.tone),children:e.state.label}),e.state.reason!==null&&f(`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=>f(Qn,{sources:e.sources})}]}function Xn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[f(Zn,{row:e}),e.namePresence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Zn({row:e}){return e.kind===`composed`?f(De,{to:Ee(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`]}):f(De,{to:Ae(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Qn({sources:e}){return e.length===0?f(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):f(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?f(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):f(De,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&f(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function $n(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 er(e){if(Array.isArray(e))return e}function tr(e,t,n){return(t=ur(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function nr(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 rr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ir(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 ar(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ir(Object(n),!0).forEach(function(t){tr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ir(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function or(e,t){if(e==null)return{};var n,r,i=sr(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 sr(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 cr(e,t){return er(e)||nr(e,t)||dr(e,t)||rr()}function lr(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 ur(e){var t=lr(e,`string`);return typeof t==`symbol`?t:t+``}function dr(e,t){if(e){if(typeof e==`string`)return $n(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)?$n(e,t):void 0}}function fr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function pr(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 mr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?pr(Object(n),!0).forEach(function(t){fr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):pr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function hr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function gr(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 _r(e){return{}.toString.call(e).includes(`Object`)}function vr(e){return!Object.keys(e).length}function yr(e){return typeof e==`function`}function br(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function xr(e,t){return _r(t)||Z(`changeType`),Object.keys(t).some(function(t){return!br(e,t)})&&Z(`changeField`),t}function Sr(e){yr(e)||Z(`selectorType`)}function Cr(e){yr(e)||_r(e)||Z(`handlerType`),_r(e)&&Object.values(e).some(function(e){return!yr(e)})&&Z(`handlersType`)}function wr(e){e||Z(`initialIsRequired`),_r(e)||Z(`initialType`),vr(e)&&Z(`initialContent`)}function Tr(e,t){throw Error(e[t]||e.default)}var Z=gr(Tr)({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"}),Er={changes:xr,selector:Sr,handler:Cr,initial:wr};function Dr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Er.initial(e),Er.handler(t);var n={current:e},r=gr(Ar)(n,t),i=gr(kr)(n),a=gr(Er.changes)(e),o=gr(Or)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Er.selector(e),e(n.current)}function c(e){hr(r,i,a,o)(e)}return[s,c]}function Or(e,t){return yr(t)?t(e.current):t}function kr(e,t){return e.current=mr(mr({},e.current),t),t}function Ar(e,t,n){return yr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var jr={create:Dr},Mr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Nr(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 Pr(e){return{}.toString.call(e).includes(`Object`)}function Fr(e){return e||zr(`configIsRequired`),Pr(e)||zr(`configType`),e.urls?(Ir(),{paths:{vs:e.urls.monacoBase}}):e}function Ir(){console.warn(Rr.deprecation)}function Lr(e,t){throw Error(e[t]||e.default)}var Rr={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
|
+
You are using deprecated way of configuration.
|
|
7
|
+
|
|
8
|
+
Instead of using
|
|
9
|
+
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
+
use
|
|
11
|
+
monaco.config({ paths: { vs: '...' } })
|
|
12
|
+
|
|
13
|
+
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
+
`},zr=Nr(Lr)(Rr),Br={config:Fr},Vr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Hr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Hr(e[n],t[n]))}),ar(ar({},e),t)}var Ur={type:`cancelation`,msg:`operation is manually canceled`};function Wr(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Ur):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Gr=[`monaco`],Kr=cr(jr.create({config:Mr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),qr=Kr[0],Jr=Kr[1];function Yr(e){var t=Br.config(e),n=t.monaco,r=or(t,Gr);Jr(function(e){return{config:Hr(e.config,r),monaco:n}})}function Xr(){var e=qr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Jr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Wr(ri);if(window.monaco&&window.monaco.editor)return ti(window.monaco),e.resolve(window.monaco),Wr(ri);Vr(Zr,$r)(ei)}return Wr(ri)}function Zr(e){return document.body.appendChild(e)}function Qr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function $r(e){var t=qr(function(e){return{config:e.config,reject:e.reject}}),n=Qr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function ei(){var e=qr(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;ti(n),e.resolve(n)},function(t){e.reject(t)})}function ti(e){qr().monaco||Jr({monaco:e})}function ni(){return qr(function(e){return e.monaco})}var ri=new Promise(function(e,t){return Jr({resolve:e,reject:t})}),ii={config:Yr,init:Xr,__getMonacoInstance:ni};r();var ai={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},oi={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function si({children:e}){return a.createElement(`div`,{style:oi.container},e)}var ci=si;function li({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...ai.wrapper,width:e,height:t},...s},!n&&a.createElement(ci,null,r),a.createElement(`div`,{ref:i,style:{...ai.fullWidth,...!n&&ai.hide},className:o}))}var ui=n(li);function di(e){p(e,[])}var fi=di;function pi(e,n,r=!0){let i=t(!0);p(i.current||!r?()=>{i.current=!1}:e,n)}var Q=pi;function mi(){}function hi(e,t,n,r){return gi(e,r)||_i(e,t,n,r)}function gi(e,t){return e.editor.getModel(vi(e,t))}function _i(e,t,n,r){return e.editor.createModel(t,n,r?vi(e,r):void 0)}function vi(e,t){return e.Uri.parse(t)}function yi({original:n,modified:r,language:i,originalLanguage:o,modifiedLanguage:s,originalModelPath:c,modifiedModelPath:l,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:f=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=mi,onMount:S=mi}){let[C,w]=u(!1),[T,E]=u(!0),D=t(null),O=t(null),k=t(null),A=t(S),j=t(x),M=t(!1);fi(()=>{let e=ii.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),Q(()=>{if(D.current&&O.current){let e=D.current.getOriginalEditor(),t=hi(O.current,n||``,o||i||`text`,c||``);t!==e.getModel()&&e.setModel(t)}},[c],C),Q(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=hi(O.current,r||``,s||i||`text`,l||``);t!==e.getModel()&&e.setModel(t)}},[l],C),Q(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),Q(()=>{D.current?.getModel()?.original.setValue(n||``)},[n],C),Q(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,s||i||`text`)},[i,o,s],C),Q(()=>{O.current?.editor.setTheme(m)},[m],C),Q(()=>{D.current?.updateOptions(g)},[g],C);let N=e(()=>{if(!O.current)return;j.current(O.current);let e=hi(O.current,n||``,o||i||`text`,c||``),t=hi(O.current,r||``,s||i||`text`,l||``);D.current?.setModel({original:e,modified:t})},[i,r,s,n,o,c,l]),P=e(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);p(()=>{C&&A.current(D.current,O.current)},[C]),p(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();d||e?.original?.dispose(),f||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(ui,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(yi);function bi(e){let n=t();return p(()=>{n.current=e},[e]),n.current}var xi=bi,Si=new Map;function Ci({defaultValue:n,defaultLanguage:r,defaultPath:i,value:o,language:s,path:c,theme:l=`light`,line:d,loading:f=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=mi,onMount:C=mi,onChange:w,onValidate:T=mi}){let[E,D]=u(!1),[O,k]=u(!0),A=t(null),j=t(null),M=t(null),N=t(C),P=t(S),F=t(),ee=t(o),te=xi(c),I=t(!1),ne=t(!1);fi(()=>{let e=ii.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?ie():e.cancel()}),Q(()=>{let e=hi(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&Si.set(te,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(Si.get(c)))},[c],E),Q(()=>{j.current?.updateOptions(m)},[m],E),Q(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(ne.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),ne.current=!1))},[o],E),Q(()=>{let e=j.current?.getModel();e&&s&&A.current?.editor.setModelLanguage(e,s)},[s],E),Q(()=>{d!==void 0&&j.current?.revealLine(d)},[d],E),Q(()=>{A.current?.editor.setTheme(l)},[l],E);let re=e(()=>{if(!(!M.current||!A.current)&&!I.current){P.current(A.current);let e=c||i,t=hi(A.current,o||n||``,r||s||``,e||``);j.current=A.current?.editor.create(M.current,{model:t,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(Si.get(e)),A.current.editor.setTheme(l),d!==void 0&&j.current.revealLine(d),D(!0),I.current=!0}},[n,r,i,o,s,c,m,h,g,l,d]);p(()=>{E&&N.current(j.current,A.current)},[E]),p(()=>{!O&&!E&&re()},[O,E,re]),ee.current=o,p(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{ne.current||w(j.current.getValue(),e)}))},[E,w]),p(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function ie(){F.current?.dispose(),_?g&&Si.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(ui,{width:v,height:y,isEditorReady:E,loading:f,_ref:M,className:b,wrapperProps:x})}var wi=n(Ci);r();var Ti={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Ei(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Ti}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Di({value:n,onChange:r,extraLibs:i=[],onDiagnostics:a,readOnly:o=!1,heightPx:s=420,dark:c=!0}){let l=t(null),u=e((e,t)=>{if(l.current=t,Ei(t,i),a===void 0)return;let n=e.getModel();if(n===null)return;let r=()=>{a(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(r),r()},[i,a]);return f(wi,{height:s,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:c?`vs-dark`:`vs`,value:n,onChange:e=>r(e??``),onMount:u,options:{readOnly:o,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Oi(e){return e.some(e=>e.severity>=8)}var ki=[{id:`blank`,name:`Blank script`,description:`Minimal hello + timer disposer`,entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
+
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
+
*
|
|
20
|
+
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
+
* '@camstack/types' and hang them off the shared Blocks integration (D97).
|
|
22
|
+
*/
|
|
23
|
+
export default function block(ctx: AddonContext) {
|
|
24
|
+
ctx.logger.info('hello from a core block')
|
|
25
|
+
|
|
26
|
+
const timer = setInterval(() => {
|
|
27
|
+
ctx.logger.info('tick')
|
|
28
|
+
}, 60_000)
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
clearInterval(timer)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`}},{id:`wan-ip-alert`,name:`WAN IP alert (UniFi)`,description:`Hourly UniFi last_wan_ip check; notify if the IP looks private`,entry:`main.ts`,files:{"main.ts":`import type { AddonContext, ConfigUISchema } from '@camstack/types'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* WAN IP alert — poll a UniFi gateway's last_wan_ip and notify when it looks
|
|
38
|
+
* like a private address (station not in bridge mode).
|
|
39
|
+
*
|
|
40
|
+
* Ported from scrypted-unifi \`checkLocalIp\`. Credentials + notifier live in
|
|
41
|
+
* settings (ConfigUISchema). No npm deps: Node fetch only.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
export const settingsSchema: ConfigUISchema = {
|
|
45
|
+
sections: [
|
|
46
|
+
{
|
|
47
|
+
id: 'unifi',
|
|
48
|
+
title: 'UniFi',
|
|
49
|
+
fields: [
|
|
50
|
+
{ type: 'text', key: 'host', label: 'Controller host', placeholder: '192.168.1.1' },
|
|
51
|
+
{ type: 'text', key: 'username', label: 'Username' },
|
|
52
|
+
{ type: 'password', key: 'password', label: 'Password', showToggle: true },
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
key: 'gatewayName',
|
|
56
|
+
label: 'Gateway device name',
|
|
57
|
+
default: 'USX Max',
|
|
58
|
+
description: 'Matched against UniFi \`stat/device\` name',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'notify',
|
|
64
|
+
title: 'Notification',
|
|
65
|
+
fields: [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
key: 'notifierAddonId',
|
|
69
|
+
label: 'Notifier addon id',
|
|
70
|
+
placeholder: 'notifiers',
|
|
71
|
+
description: 'Collection addon that owns the target (e.g. notifiers)',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'text',
|
|
75
|
+
key: 'targetId',
|
|
76
|
+
label: 'Target id',
|
|
77
|
+
description: 'From notification-output.listTargets',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'number',
|
|
81
|
+
key: 'intervalMinutes',
|
|
82
|
+
label: 'Poll interval (minutes)',
|
|
83
|
+
default: 60,
|
|
84
|
+
min: 5,
|
|
85
|
+
max: 1440,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface WanSettings {
|
|
93
|
+
readonly host?: string
|
|
94
|
+
readonly username?: string
|
|
95
|
+
readonly password?: string
|
|
96
|
+
readonly gatewayName?: string
|
|
97
|
+
readonly notifierAddonId?: string
|
|
98
|
+
readonly targetId?: string
|
|
99
|
+
readonly intervalMinutes?: number
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function readSettings(ctx: AddonContext): Promise<WanSettings> {
|
|
103
|
+
const raw = (await ctx.settings?.readAddonStore()) ?? {}
|
|
104
|
+
return raw
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function fetchWanIp(settings: WanSettings, logger: AddonContext['logger']): Promise<string | null> {
|
|
108
|
+
const host = settings.host?.trim()
|
|
109
|
+
const username = settings.username?.trim()
|
|
110
|
+
const password = settings.password
|
|
111
|
+
if (!host || !username || !password) {
|
|
112
|
+
logger.warn('WAN alert: host/username/password not configured')
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
const login = await fetch(\`https://\${host}/api/auth/login\`, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: { 'content-type': 'application/json' },
|
|
118
|
+
body: JSON.stringify({ username, password }),
|
|
119
|
+
// UniFi OS often uses a self-signed cert on LAN.
|
|
120
|
+
})
|
|
121
|
+
if (!login.ok) {
|
|
122
|
+
logger.warn('WAN alert: UniFi login failed', { meta: { status: login.status } })
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
125
|
+
const cookie = login.headers.getSetCookie?.().join('; ') ?? login.headers.get('set-cookie') ?? ''
|
|
126
|
+
const devices = await fetch(\`https://\${host}/proxy/network/api/s/default/stat/device\`, {
|
|
127
|
+
headers: { cookie },
|
|
128
|
+
})
|
|
129
|
+
if (!devices.ok) {
|
|
130
|
+
logger.warn('WAN alert: stat/device failed', { meta: { status: devices.status } })
|
|
131
|
+
return null
|
|
132
|
+
}
|
|
133
|
+
const body: unknown = await devices.json()
|
|
134
|
+
const dataField = body !== null && typeof body === 'object' ? Reflect.get(body, 'data') : null
|
|
135
|
+
const rows: readonly unknown[] = Array.isArray(dataField) ? dataField : []
|
|
136
|
+
const want = settings.gatewayName?.trim() || 'USX Max'
|
|
137
|
+
for (const row of rows) {
|
|
138
|
+
if (row === null || typeof row !== 'object') continue
|
|
139
|
+
const name = Reflect.get(row, 'name')
|
|
140
|
+
const ip = Reflect.get(row, 'last_wan_ip')
|
|
141
|
+
if (name === want && typeof ip === 'string') return ip
|
|
142
|
+
}
|
|
143
|
+
logger.warn('WAN alert: gateway not found in device list', { meta: { gatewayName: want } })
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function notify(
|
|
148
|
+
ctx: AddonContext,
|
|
149
|
+
settings: WanSettings,
|
|
150
|
+
title: string,
|
|
151
|
+
body: string,
|
|
152
|
+
): Promise<void> {
|
|
153
|
+
const addonId = settings.notifierAddonId?.trim()
|
|
154
|
+
const targetId = settings.targetId?.trim()
|
|
155
|
+
if (!addonId || !targetId) {
|
|
156
|
+
ctx.logger.warn('WAN alert: notifierAddonId/targetId not configured — skipping notify')
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
await ctx.api.notificationOutput.send.mutate({
|
|
160
|
+
addonId,
|
|
161
|
+
targetId,
|
|
162
|
+
notification: { title, body, format: 'text', priority: 4 },
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export default async function block(ctx: AddonContext) {
|
|
167
|
+
const tick = async (): Promise<void> => {
|
|
168
|
+
const settings = await readSettings(ctx)
|
|
169
|
+
const wanIp = await fetchWanIp(settings, ctx.logger)
|
|
170
|
+
if (wanIp === null) return
|
|
171
|
+
ctx.logger.info('WAN IP observed', { meta: { wanIp } })
|
|
172
|
+
if (wanIp.includes('192.')) {
|
|
173
|
+
await notify(
|
|
174
|
+
ctx,
|
|
175
|
+
settings,
|
|
176
|
+
'UniFi WAN IP',
|
|
177
|
+
'The WAN IP looks like a private address — the upstream station may not be in bridge mode.',
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
await tick()
|
|
183
|
+
const minutes = Math.max(5, (await readSettings(ctx)).intervalMinutes ?? 60)
|
|
184
|
+
const timer = setInterval(() => {
|
|
185
|
+
void tick()
|
|
186
|
+
}, minutes * 60_000)
|
|
187
|
+
|
|
188
|
+
return () => {
|
|
189
|
+
clearInterval(timer)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
`}},{id:`tv-schedule`,name:`Programmazione TV`,description:`Scrape staseraintv.com and send tonight’s filtered schedule to a notifier`,entry:`main.ts`,files:{"main.ts":`import type { AddonContext, ConfigUISchema } from '@camstack/types'
|
|
193
|
+
import { scrapeTonight } from './tv-scrape.js'
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Programmazione TV — scrape staseraintv.com and send tonight's filtered
|
|
197
|
+
* schedule to a notification-output target. Ported from scrypted-unifi
|
|
198
|
+
* \`sendProgrammation\` / \`loadChannelsData\`.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
export const settingsSchema: ConfigUISchema = {
|
|
202
|
+
sections: [
|
|
203
|
+
{
|
|
204
|
+
id: 'schedule',
|
|
205
|
+
title: 'Schedule',
|
|
206
|
+
fields: [
|
|
207
|
+
{
|
|
208
|
+
type: 'tags',
|
|
209
|
+
key: 'channels',
|
|
210
|
+
label: 'Channels',
|
|
211
|
+
suggestions: ['Rai 1', 'Rai 2', 'Canale 5', 'Italia 1', 'La7'],
|
|
212
|
+
description: 'Only these channels are included in the message',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: 'text',
|
|
216
|
+
key: 'cronHint',
|
|
217
|
+
label: 'When to send (local time HH:MM)',
|
|
218
|
+
default: '19:00',
|
|
219
|
+
description: 'Checked every minute; fires once when the clock matches',
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
id: 'notify',
|
|
225
|
+
title: 'Notification',
|
|
226
|
+
fields: [
|
|
227
|
+
{
|
|
228
|
+
type: 'text',
|
|
229
|
+
key: 'notifierAddonId',
|
|
230
|
+
label: 'Notifier addon id',
|
|
231
|
+
placeholder: 'notifiers',
|
|
232
|
+
},
|
|
233
|
+
{ type: 'text', key: 'targetId', label: 'Target id' },
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface TvSettings {
|
|
240
|
+
readonly channels?: readonly string[]
|
|
241
|
+
readonly cronHint?: string
|
|
242
|
+
readonly notifierAddonId?: string
|
|
243
|
+
readonly targetId?: string
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function readSettings(ctx: AddonContext): Promise<TvSettings> {
|
|
247
|
+
const raw = (await ctx.settings?.readAddonStore()) ?? {}
|
|
248
|
+
const channels = Reflect.get(raw, 'channels')
|
|
249
|
+
const cronHint = Reflect.get(raw, 'cronHint')
|
|
250
|
+
const notifierAddonId = Reflect.get(raw, 'notifierAddonId')
|
|
251
|
+
const targetId = Reflect.get(raw, 'targetId')
|
|
252
|
+
return {
|
|
253
|
+
...(Array.isArray(channels) ? { channels: channels.filter((c): c is string => typeof c === 'string') } : {}),
|
|
254
|
+
...(typeof cronHint === 'string' ? { cronHint } : {}),
|
|
255
|
+
...(typeof notifierAddonId === 'string' ? { notifierAddonId } : {}),
|
|
256
|
+
...(typeof targetId === 'string' ? { targetId } : {}),
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function nowMatches(hhmm: string, now: Date): boolean {
|
|
261
|
+
const [h, m] = hhmm.split(':').map((p) => Number.parseInt(p, 10))
|
|
262
|
+
if (!Number.isFinite(h) || !Number.isFinite(m)) return false
|
|
263
|
+
return now.getHours() === h && now.getMinutes() === m
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export default async function block(ctx: AddonContext) {
|
|
267
|
+
let lastFireDay = ''
|
|
268
|
+
|
|
269
|
+
const send = async (): Promise<void> => {
|
|
270
|
+
const settings = await readSettings(ctx)
|
|
271
|
+
const channels = settings.channels ?? []
|
|
272
|
+
if (channels.length === 0) {
|
|
273
|
+
ctx.logger.warn('TV schedule: no channels configured')
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
const rows = await scrapeTonight()
|
|
277
|
+
const filtered = rows.filter((r) => channels.includes(r.channel))
|
|
278
|
+
let body = '\\n'
|
|
279
|
+
for (const row of filtered) {
|
|
280
|
+
body += \`\${row.channel} - \${row.title} (\${row.time})\\n\`
|
|
281
|
+
}
|
|
282
|
+
ctx.logger.info('Programmazione TV', { meta: { lines: filtered.length } })
|
|
283
|
+
const addonId = settings.notifierAddonId?.trim()
|
|
284
|
+
const targetId = settings.targetId?.trim()
|
|
285
|
+
if (!addonId || !targetId) {
|
|
286
|
+
ctx.logger.warn('TV schedule: notifier not configured')
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
await ctx.api.notificationOutput.send.mutate({
|
|
290
|
+
addonId,
|
|
291
|
+
targetId,
|
|
292
|
+
notification: {
|
|
293
|
+
title: 'Programmazione TV serale',
|
|
294
|
+
body,
|
|
295
|
+
format: 'text',
|
|
296
|
+
priority: 3,
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const timer = setInterval(() => {
|
|
302
|
+
void (async () => {
|
|
303
|
+
const settings = await readSettings(ctx)
|
|
304
|
+
const hint = settings.cronHint?.trim() || '19:00'
|
|
305
|
+
const now = new Date()
|
|
306
|
+
const dayKey = \`\${now.getFullYear()}-\${now.getMonth()}-\${now.getDate()}\`
|
|
307
|
+
if (!nowMatches(hint, now)) return
|
|
308
|
+
if (lastFireDay === dayKey) return
|
|
309
|
+
lastFireDay = dayKey
|
|
310
|
+
await send()
|
|
311
|
+
})()
|
|
312
|
+
}, 60_000)
|
|
313
|
+
|
|
314
|
+
return () => {
|
|
315
|
+
clearInterval(timer)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
`,"tv-scrape.ts":`/** HTML scrape of staseraintv.com — Node fetch + light string parsing (no deps). */
|
|
319
|
+
|
|
320
|
+
export interface TvRow {
|
|
321
|
+
readonly channel: string
|
|
322
|
+
readonly time: string
|
|
323
|
+
readonly title: string
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function between(html: string, start: string, end: string): string | null {
|
|
327
|
+
const i = html.indexOf(start)
|
|
328
|
+
if (i < 0) return null
|
|
329
|
+
const from = i + start.length
|
|
330
|
+
const j = html.indexOf(end, from)
|
|
331
|
+
if (j < 0) return null
|
|
332
|
+
return html.slice(from, j)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function stripTags(html: string): string {
|
|
336
|
+
return html.replace(/<[^>]+>/g, '').replace(/\\s+/g, ' ').trim()
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function parsePage(html: string): TvRow[] {
|
|
340
|
+
const out: TvRow[] = []
|
|
341
|
+
const chunks = html.split('thumbprevbox')
|
|
342
|
+
for (let i = 1; i < chunks.length; i++) {
|
|
343
|
+
const chunk = chunks[i] ?? ''
|
|
344
|
+
const channelRaw = between(chunk, 'stb1', '</')
|
|
345
|
+
const bigs = [...chunk.matchAll(/<big[^>]*>([\\s\\S]*?)<\\/big>/gi)].map((m) =>
|
|
346
|
+
stripTags(m[1] ?? ''),
|
|
347
|
+
)
|
|
348
|
+
const span = between(chunk, '<span', '</span>')
|
|
349
|
+
const channel = channelRaw !== null ? stripTags(channelRaw.replace(/^[^>]*>/, '')) : ''
|
|
350
|
+
const time = bigs[1] ?? ''
|
|
351
|
+
const title = span !== null ? stripTags(span.replace(/^[^>]*>/, '')) : ''
|
|
352
|
+
if (channel !== '' && title !== '') out.push({ channel, time, title })
|
|
353
|
+
}
|
|
354
|
+
return out
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export async function scrapeTonight(): Promise<readonly TvRow[]> {
|
|
358
|
+
const pages = ['1', '2', '3', '4', '5', '6', '7', '8']
|
|
359
|
+
const all: TvRow[] = []
|
|
360
|
+
for (const page of pages) {
|
|
361
|
+
const url = \`https://www.staseraintv.com/index\${page}.html\`
|
|
362
|
+
const res = await fetch(url)
|
|
363
|
+
if (!res.ok) continue
|
|
364
|
+
const html = await res.text()
|
|
365
|
+
all.push(...parsePage(html))
|
|
366
|
+
}
|
|
367
|
+
return all
|
|
368
|
+
}
|
|
369
|
+
`}}],Ai=ki.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
370
|
+
|
|
371
|
+
export default function block(ctx: AddonContext) {
|
|
372
|
+
ctx.logger.info('hello from a core block')
|
|
373
|
+
return () => undefined
|
|
374
|
+
}
|
|
375
|
+
`;function ji({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 Mi=`device-export`,Ni=5e3;function Pi(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=Reflect.get(e,`name`);if(typeof t==`string`)return t}return null}function Fi(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function Ii(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`manifest`);if(typeof e!=`object`||!e)continue;let r=Reflect.get(e,`id`);if(typeof r!=`string`)continue;let i=Reflect.get(e,`capabilities`);if(!(Array.isArray(i)?i:[]).some(e=>Pi(e)===Mi))continue;let a=Reflect.get(e,`packageDisplayName`),o=Reflect.get(e,`name`),s=typeof a==`string`&&a||typeof o==`string`&&o||r;t.push({addonId:r,displayName:s})}return t.toSorted((e,t)=>e.displayName.localeCompare(t.displayName))}function Li(e){if(!Array.isArray(e))return new Set;let t=new Set;for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`deviceId`);typeof e==`string`&&t.add(e)}return t}function Ri({exporter:e,onIds:t}){let n=fe({nodeId:`hub`,addonId:e.addonId},{refetchInterval:Ni,retry:!1}),r=o(()=>Li(n.data),[n.data]);return p(()=>{t(e.addonId,r)},[e.addonId,r,t]),null}function zi({deviceId:e,exporters:t,exposedByExporter:n}){return t.length===0?f(`p`,{className:`text-xs text-foreground-subtle`,children:`No device-export addons installed — install HA / HAP / Alexa to expose.`}):f(`div`,{className:`flex flex-wrap gap-2`,children:t.map(t=>f(Bi,{deviceId:e,exporter:t,isExposed:n.get(t.addonId)?.has(String(e))??!1},t.addonId))})}function Bi({deviceId:t,exporter:n,isExposed:r}){let a=l(),o=String(t),s=ae({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceExport`]]})}}),c=de({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceExport`]]})}}),[d,p]=u(null),m=s.isPending||c.isPending,h=e(()=>{p(null),(r?c.mutateAsync({deviceId:o,nodeId:`hub`,addonId:n.addonId}):s.mutateAsync({deviceId:o,nodeId:`hub`,addonId:n.addonId})).catch(e=>{p(e instanceof Error?e.message:String(e))})},[o,s,n.addonId,r,c]);return i(`div`,{className:`flex flex-col gap-0.5`,children:[i(M,{type:`button`,size:`sm`,variant:r?`primary`:`outline`,disabled:m,onClick:h,title:r?`Unexpose from ${n.displayName}`:`Expose to ${n.displayName}`,"data-testid":`script-export-${t}-${n.addonId}`,children:[m?f(H,{className:`h-3.5 w-3.5 animate-spin`}):f(y,{className:`h-3.5 w-3.5`}),n.displayName,r?` · on`:` · off`]}),d!==null&&f(`span`,{className:`text-[11px] text-danger`,children:d})]})}function Vi({blockId:t}){let n=G(t),r=F({addonId:n,projection:`slim`},{refetchInterval:Ni}),a=V(void 0,{refetchInterval:Ni*6}),[s,c]=u(()=>new Map),l=o(()=>Fi(r.data),[r.data]),d=o(()=>Ii(a.data),[a.data]),p=e((e,t)=>{c(n=>{let r=n.get(e);if(r!==void 0&&r.size===t.size&&[...t].every(e=>r.has(e)))return n;let i=new Map(n);return i.set(e,t),i})},[]);return r.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(H,{className:`h-3.5 w-3.5 animate-spin`}),` Loading devices owned by this script…`]}):r.isError?i(`p`,{className:`text-xs text-danger`,children:[`Could not list devices:`,` `,r.error instanceof Error?r.error.message:String(r.error)]}):i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[d.map(e=>f(Ri,{exporter:e,onIds:p},e.addonId)),i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:`Devices`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script under the shared Blocks integration (`,f(`code`,{className:`text-[11px]`,children:n}),`).`]})]}),f(z,{variant:`default`,children:l.length})]}),l.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:[`No devices yet. Call `,f(`code`,{children:`reconcileBlockDevices(ctx, …)`}),` from the script (and Restart) to declare them. Use `,f(`code`,{children:`exposeBlockDevices`}),` or the toggles below to publish.`]}):f(`ul`,{className:`space-y-3`,children:l.map(e=>i(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${e.id}`,children:[i(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[f(De,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:`Open device detail`,children:e.name}),f(z,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,f(`code`,{children:e.stableId})]}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]}),i(`div`,{className:`mt-2`,children:[f(`p`,{className:`mb-1 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Exported to`}),f(zi,{deviceId:e.id,exporters:d,exposedByExporter:s})]})]},e.id))})]})}r();function Hi(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Ui(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Wi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=Hi(e);n!==null&&(t[n]=Ui(e))}return t}function Gi(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Ki({blockId:t}){let n=oe({blockId:t},{refetchInterval:1e4,retry:!1}),r=ne({onSuccess:()=>{n.refetch()}}),[a,s]=u(null),[c,l]=u(null),d=Gi(n.data)?n.data:null,p=o(()=>d===null?{}:Wi(d),[d]),m=a??p,h=e(e=>{s(e)},[]),g=a!==null,_=e(()=>{a!==null&&(l(null),r.mutate({blockId:t,patch:a},{onSuccess:()=>s(null),onError:e=>l(e instanceof Error?e.message:String(e))}))},[t,a,r]);return n.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[f(H,{className:`h-3.5 w-3.5 animate-spin`}),` Loading script settings…`]}):n.isError?i(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[`Could not load settings:`,` `,n.error instanceof Error?n.error.message:String(n.error)]}):d===null?null:i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[f(`h4`,{className:`text-sm font-medium`,children:`Settings`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script's `,f(`code`,{children:`settingsSchema`}),` export.`]})]}),i(M,{size:`sm`,variant:`primary`,onClick:_,disabled:!g||r.isPending,children:[r.isPending&&f(H,{className:`h-3.5 w-3.5 animate-spin`}),`Save settings`]})]}),f(Fe,{schema:d,values:m,onChange:h}),c!==null&&f(`p`,{className:`text-xs text-danger`,children:c})]})}r();var qi=`hub`;function Ji({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:l,onRestart:p,onSave:m,onCancel:g}){let _=h(),{resolvedMode:v}=te(),y=ge({code:e?.code??Ai,files:e?.files,entry:e?.entry}),[b,S]=u(e?.name??``),[C,w]=u(y.files),[T,E]=u(y.entry),[D,k]=u(y.entry),[A,j]=u(e?.placement??qi),[N,P]=u(e?.integrationId??``),[F,ee]=u([]),[I,ne]=u(!1),[re,ae]=u(`blank`),oe=C[D]??``,se=e=>{w(t=>({...t,[D]:e}))},le=Object.keys(C).toSorted(),B=d({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:C,entry:T})}),V=o(()=>F.filter(e=>e.severity>=8),[F]),de=Oi(F),fe=b.trim()===``,me=e===null?null:ge(e),U=e===null||me===null||JSON.stringify(C)!==JSON.stringify(me.files)||T!==me.entry||b.trim()!==e.name||A!==e.placement||(N.trim()===``?void 0:N.trim())!==e.integrationId,W=()=>{B.reset(),m({name:b.trim(),files:C,entry:T,enabled:e?.enabled??!0,placement:A,...N.trim()===``?{}:{integrationId:N.trim()}})},he=()=>{let e=window.prompt(`New file path (e.g. lib/util.ts)`);if(e===null||e.trim()===``)return;let t=e.trim();if(C[t]!==void 0){k(t);return}w(e=>({...e,[t]:``})),k(t)},_e=e=>{let t=ki.find(t=>t.id===e);if(t===void 0)return;let n=ki.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(C)===JSON.stringify(n.files)&&T===n.entry)&&!window.confirm(`Replace the current editor contents with this example?`)||(ae(e),w({...t.files}),E(t.entry),k(t.entry),(b.trim()===``||re===`blank`)&&S(t.id===`blank`?``:t.name))},K=e===null?null:gn(e),ve=ji({existing:e,dirty:U,saving:r,restarting:s});return f(R,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),K!==null&&f(z,{variant:_n(K.tone),children:K.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:`Name`}),f(L,{className:`mt-1`,value:b,onChange:e=>S(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),f(L,{className:`mt-1`,value:N,onChange:e=>P(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),e===null&&i(`label`,{className:`block text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:`Start from`}),f(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:re,onChange:e=>_e(e.target.value),"data-testid":`script-example-select`,children:ki.map(e=>i(`option`,{value:e.id,children:[e.name,` — `,e.description]},e.id))})]}),i(`div`,{children:[f(x,{selectedNodeId:A,onSelect:j,label:`Runs on`,alwaysShow:!0}),A!==qi&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[f(O,{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 `,f(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:I?`grid gap-3 lg:grid-cols-[1fr_minmax(0,22rem)]`:``,children:[i(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[le.map(e=>i(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===D?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>k(e),"data-testid":`script-file-tab-${e}`,children:[e,e===T?` · entry`:``]},e)),f(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:he,"data-testid":`script-file-add`,children:`+ file`}),D!==T&&f(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>E(D),title:`Use this file as the compile entry`,children:`Set as entry`})]}),n?f(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):f(Di,{value:oe,onChange:se,extraLibs:t?.libs??[],onDiagnostics:ee,dark:v===`dark`,heightPx:560})]}),I&&i(`div`,{className:`rounded border border-border`,children:[f(`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 — `,f(`code`,{children:G(e.id)})]})}),e!==null&&f(ce,{addonId:G(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&f(`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.`}),V.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:[V.length,` error`,V.length===1?``:`s`,` — the block cannot be saved.`]}),V.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),V.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,V.length-5,` more.`]})]}),B.data!==void 0&&(B.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[f(ue,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):i(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[B.data.line===void 0?``:`line ${String(B.data.line)}: `,B.data.error??`the code does not compile`]})),B.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: `,Yi(B.error)]}),a!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),l!==null&&f(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:l}),e!==null&&i(`div`,{className:`space-y-3`,children:[f(Ki,{blockId:e.id}),f(Vi,{blockId:e.id})]}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{variant:`outline`,onClick:()=>B.mutate(),disabled:B.isPending||r,title:`Type-check on the node without saving`,children:[B.isPending&&f(H,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(M,{onClick:W,disabled:r||de||fe,children:[r&&f(H,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(M,{variant:`outline`,onClick:()=>p?.(),disabled:ve!==null||p===void 0,title:ve??`Stop the process and let the supervisor bring it back`,children:[s?f(ie,{className:`h-4 w-4 animate-spin`}):f(ie,{className:`h-4 w-4`}),` `,`Restart`]}),i(M,{variant:`ghost`,onClick:()=>ne(!I),title:`Show this script's process logs`,children:[f(pe,{className:`h-4 w-4`}),` Logs `,I?`⇤`:`⇄`]}),f(M,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,V.length,U&&e!==null?` · unsaved changes`:``]}),fe&&f(z,{variant:`warning`,children:`Name required`})]})]})})}function Yi(e){return e instanceof Error?e.message:String(e)}r();var Xi=[`coreBlocks`,`list`],Zi=[`coreBlocks`,`getTypeDefs`],Qi=5e3;function $(e){return e instanceof Error?e.message:String(e)}function $i({initialBlockId:e,createRequested:n=!1,onCreateConsumed:r}={}){let a=h(),[o,c]=u({mode:`closed`}),[l,m]=u(null),[g,_]=u(null),v=s({queryKey:Xi,refetchInterval:Qi,queryFn:async()=>(await a.trpcClient.coreBlocks.list.query({})).blocks}),y=s({queryKey:Zi,enabled:o.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>a.trpcClient.coreBlocks.getTypeDefs.query({})}),b=()=>{v.refetch()},x=t(null),S=v.data;p(()=>{if(e===void 0||x.current===e)return;let t=S?.find(t=>t.id===e&&Te(t)===`code`);t!==void 0&&(x.current=e,c({mode:`edit`,block:t}))},[e,S]),p(()=>{n&&(c({mode:`edit`,block:null}),r?.())},[n,r]);let C=d({mutationFn:e=>a.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{c({mode:`edit`,block:e.block}),b()}}),w=d({mutationFn:e=>a.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{c({mode:`edit`,block:e.block}),b()}}),T=d({mutationFn:e=>a.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{m(null),b()}}),E=d({mutationFn:e=>a.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:b}),D=d({mutationFn:e=>a.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:b}),O=yn((v.data??[]).filter(e=>Te(e)===`code`)),k=v.data!==void 0&&O.length===0,A=C.isPending||w.isPending,j=C.error===null?w.error===null?null:$(w.error):$(C.error),M=o.mode===`edit`&&o.block!==null?vn(O,o.block):null,N=o.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!N&&f(`p`,{className:`text-xs text-foreground-subtle`,children:v.data===void 0?``:bn(O)}),v.error!=null&&f(W,{title:`Could not read the scripts`,message:$(v.error),onRetry:b}),N&&f(`div`,{className:`min-h-[70vh]`,"data-testid":`script-editor-panel`,children:f(Ji,{existing:M,typeDefs:y.data,typeDefsLoading:y.isLoading,saving:A,saveError:j,restarting:D.isPending,restartError:D.error===null?null:$(D.error),onRestart:M===null?void 0:()=>D.mutate(M.id),onSave:e=>{let t=M;t===null?C.mutate(e):w.mutate({blockId:t.id,block:e})},onCancel:()=>{C.reset(),w.reset(),D.reset(),c({mode:`closed`})}})}),!N&&k&&f(R,{children:i(`div`,{className:`space-y-1 p-4`,children:[f(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),f(`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.`})]})}),!N&&O.length>0&&f(R,{children:f(`ul`,{className:`divide-y divide-border`,"data-testid":`scripts-list`,children:O.map(e=>f(ea,{block:e,busy:E.isPending||T.isPending,restarting:D.isPending&&D.variables===e.id,confirming:l===e.id,logsOpen:g===e.id,onToggle:t=>E.mutate({blockId:e.id,enabled:t}),onRestart:()=>D.mutate(e.id),onToggleLogs:()=>_(g===e.id?null:e.id),onEdit:()=>c({mode:`edit`,block:e}),onAskDelete:()=>m(e.id),onCancelDelete:()=>m(null),onConfirmDelete:()=>T.mutate(e.id)},e.id))})}),T.error!=null&&f(W,{message:$(T.error)}),E.error!=null&&f(W,{message:$(E.error)}),D.error!=null&&f(W,{message:$(D.error)})]})}function ea({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:d,onConfirmDelete:p}){let m=gn(e),h=re(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:[f(`span`,{className:`truncate font-medium`,children:e.name}),f(z,{variant:_n(m.tone),children:m.label}),f(z,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),f(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[f(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),f(M,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),f(M,{variant:`ghost`,onClick:d,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[f(M,{variant:`ghost`,onClick:l,title:`Edit`,children:f(I,{className:`h-4 w-4`})}),f(M,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:f(ie,{className:`h-4 w-4${n?` animate-spin`:``}`})}),f(M,{variant:`ghost`,onClick:c,title:`Logs`,children:f(pe,{className:`h-4 w-4`})}),f(M,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),f(M,{variant:`ghost`,onClick:u,title:`Delete`,children:f(_,{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 — `,f(`code`,{children:G(e.id)})]}),f(ce,{addonId:G(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var ta=[`automations`,`scripts`,`custom-device`];function na(e){return e!==null&&ta.some(t=>t===e)}var ra=[`coreBlocks`,`list`,`build-counts`];function ia(e){return e.filter(e=>Te(e)===`code`).length}function aa(e){return e.filter(e=>Be(e.code)).length}function oa(){let e=h(),[t,n]=ke(),r=t.get(`tab`),a=na(r)?r:`automations`,o=t.get(`create`)===`1`,c=s({queryKey:ra,refetchInterval:5e3,queryFn:async()=>(await e.trpcClient.coreBlocks.list.query({})).blocks}).data,l=c===void 0?null:ia(c),u=c===void 0?null:aa(c),d=s({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>e.trpcClient.coreBlocks.listCompositions.query({})}),p=d.data?.state===`loaded`?d.data.views.length:null,m=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n.delete(`create`),n},{replace:!0})},g=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},_=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},v=()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},y=()=>{n(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})};return f(Me,{icon:he,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,actions:a===`custom-device`?void 0:i(M,{type:`button`,onClick:v,"data-testid":`build-new`,children:[f(le,{className:`h-4 w-4`}),` `,a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`]}),children:i(A,{value:a,onValueChange:m,children:[i(w,{children:[i(E,{value:`automations`,children:[`Automations`,u===null?``:` (${String(u)})`]}),i(E,{value:`scripts`,children:[`Scripts`,l===null?``:` (${String(l)})`]}),i(E,{value:`custom-device`,children:[`Custom Device`,p===null?``:` (${String(p)})`]})]}),f(j,{value:`automations`,children:f(En,{onOpenScripts:g,initialBlockId:a===`automations`?t.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`automations`&&o,onCreateConsumed:y})}),f(j,{value:`scripts`,children:f($i,{initialBlockId:t.get(`block`)??void 0,createRequested:a===`scripts`&&o,onCreateConsumed:y})}),f(j,{value:`custom-device`,children:f(Kn,{})})]})})}export{oa as BuildPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,q 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{gt as s}from"./player-overlays-27qhPy_v.js";import{Jr as c,Xr as l,Yr as u,Zr as d,gd as f,pd as p}from"./src-IJPkPeFt.js";import{t as m}from"./AdminPage-CiKtOLQm.js";t();var h=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function g(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function _(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function v(e){let t=e.getDay();return g(_(e,t===0?-6:1-t))}function y(e,t){if(t===`day`){let t=g(e);return{startMs:t.getTime(),endMs:_(t,1).getTime()}}if(t===`week`){let t=v(e);return{startMs:t.getTime(),endMs:_(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=v(n),a=_(v(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function b(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=v(e),n=_(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function x(e,t,n){return t===`day`?_(e,n):t===`week`?_(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function S(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function C(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function w(e){if(e.allDay===!0)return`All day`;let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function T(e,t){let n=t+1440*60*1e3;return e.filter(e=>e.startMs<n&&e.endMs>t)}function E(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function D({mode:e,onChange:t}){return o(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":`Calendar view`,children:[{id:`month`,label:`Month`},{id:`week`,label:`Week`},{id:`day`,label:`Day`}].map(n=>o(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function O({calendars:e,onToggleVisible:t,onColorChange:r,busy:i}){return n(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[o(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:`Calendars`}),o(`ul`,{className:`space-y-1`,children:e.map(e=>n(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[o(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:e.visible,disabled:i||!e.enabled,onChange:n=>t(e.id,n.target.checked),"aria-label":`Show ${e.name}`,"data-testid":`calendars-visible-${e.id}`}),o(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:e.color,disabled:i,onChange:t=>r(e.id,t.target.value.toUpperCase()),"aria-label":`Colour for ${e.name}`,"data-testid":`calendars-color-${e.id}`}),n(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`truncate text-sm font-medium ${e.visible?`text-foreground`:`text-foreground-subtle`}`,children:e.name}),n(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[C(e),e.enabled?``:` · disabled at source`]})]})]},e.id))})]})}function k({ev:e,color:t,compact:r}){return o(`div`,{className:r?`truncate rounded px-1 py-0.5 text-[10px] leading-tight text-white`:`rounded-md px-2 py-1.5 text-xs text-white`,style:{backgroundColor:t},title:e.title,children:r?e.title:n(i,{children:[o(`div`,{className:`font-medium`,children:e.title}),o(`div`,{className:`opacity-90`,children:w(e)})]})})}function A({anchor:e,events:t,colorById:r,today:i}){let{startMs:a,endMs:s}=y(e,`month`),c=[];for(let e=a;e<s;e+=1440*60*1e3)c.push(new Date(e));let l=e.getMonth();return n(`div`,{"data-testid":`calendars-month`,children:[o(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:h.map(e=>o(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),o(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:c.map(e=>{let a=g(e).getTime(),s=T(t,a),c=e.getMonth()!==l,u=E(e,i);return n(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${c?`opacity-45`:``}`,children:[o(`div`,{className:u?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:e.getDate()}),n(`div`,{className:`space-y-0.5`,children:[s.slice(0,3).map(e=>o(k,{ev:e,color:r.get(e.calendarId)??`#64748B`,compact:!0},e.id)),s.length>3?n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`+`,s.length-3,` more`]}):null]})]},a)})})]})}function j({anchor:e,events:t,colorById:r,today:i}){let a=v(e);return o(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>_(a,t)).map(e=>{let a=g(e).getTime(),s=T(t,a);return n(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[o(`div`,{className:E(e,i)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),o(`div`,{className:`space-y-1`,children:s.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):s.map(e=>o(k,{ev:e,color:r.get(e.calendarId)??`#64748B`},e.id))})]},a)})})}function M({anchor:e,events:t,colorById:r,calName:i}){let a=T(t,g(e).getTime());return a.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:`No events on this day.`}):o(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:a.map(e=>n(`li`,{className:`flex items-start gap-3 px-3 py-3`,children:[o(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:r.get(e.calendarId)??`#64748B`}}),n(`div`,{className:`min-w-0`,children:[o(`div`,{className:`font-medium text-sm text-foreground`,children:e.title}),n(`div`,{className:`text-xs text-foreground-subtle`,children:[w(e),` · `,i.get(e.calendarId)??e.calendarId]}),e.location!==void 0&&e.location.length>0?o(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:e.location}):null]})]},e.id))})}function N(){let t=u(),i=c({}),h=d(),[_,v]=a(`month`),[C,w]=a(()=>g(new Date)),T=r(()=>g(new Date),[]),E=t.isSuccess,k=i.isSuccess&&i.data!==void 0?i.data:void 0,N=r(()=>!E||t.data===void 0?[]:t.data.map(e=>S(e,k)),[E,t.data,k]),P=r(()=>N.filter(e=>e.visible&&e.enabled),[N]),F=r(()=>P.map(e=>e.id),[P]),I=r(()=>y(C,_),[C,_]),L=l({startMs:I.startMs,endMs:I.endMs,calendarIds:[...F]},{enabled:E&&F.length>0}),R=L.data??[],z=r(()=>{let e=new Map;for(let t of N)e.set(t.id,t.color);return e},[N]),B=r(()=>{let e=new Map;for(let t of N)e.set(t.id,t.name);return e},[N]),V=e((e,t)=>{h.mutateAsync({calendarId:e,visible:t}).then(()=>i.refetch())},[i,h]),H=e((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&h.mutateAsync({calendarId:e,color:t}).then(()=>i.refetch())},[i,h]),U=e(()=>w(g(new Date)),[]),W=e(()=>w(e=>x(e,_,-1)),[_]),G=e(()=>w(e=>x(e,_,1)),[_]),K=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,q;return q=t.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading calendars…`}):t.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list calendars: `,t.error.message]}):N.length===0?o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:`No calendar sources yet. Connect a calendar-source addon (for example Home Assistant) and wait for it to register calendars.`}):F.length===0?n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(O,{calendars:N,onToggleVisible:V,onColorChange:H,busy:h.isPending}),o(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:`All calendars are hidden. Turn one on in the legend to see events.`})]}):n(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[o(O,{calendars:N,onToggleVisible:V,onColorChange:H,busy:h.isPending}),n(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(D,{mode:_,onChange:v}),n(`div`,{className:`flex items-center gap-1`,children:[o(`button`,{type:`button`,className:K,onClick:W,"aria-label":`Previous`,"data-testid":`calendars-prev`,children:o(p,{className:`h-4 w-4`})}),o(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:U,"data-testid":`calendars-today`,children:`Today`}),o(`button`,{type:`button`,className:K,onClick:G,"aria-label":`Next`,"data-testid":`calendars-next`,children:o(s,{className:`h-4 w-4`})})]}),o(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:b(C,_)})]}),L.isPending?o(`p`,{className:`text-sm text-foreground-subtle`,children:`Loading events…`}):L.isError?n(`p`,{className:`text-sm text-destructive`,children:[`Could not list events: `,L.error.message]}):_===`month`?o(A,{anchor:C,events:R,colorById:z,today:T}):_===`week`?o(j,{anchor:C,events:R,colorById:z,today:T}):o(M,{anchor:C,events:R,colorById:z,calName:B})]})]}),o(m,{icon:f,title:`Calendars`,subtitle:`Calendars from connected sources. Used by Calendar events notification rules.`,children:q})}export{N as CalendarsPage,N as default};
|
|
@@ -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-BcO9fxNP.js";import{Il as c,ed as l,td as u,yn as d,yu as f}from"./src-C2nRzmKs.js";import{t as p}from"./AdminPage-CiKtOLQm.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(f,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[f,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return t(p,{icon:c,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(d,{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-27qhPy_v.js";import{Kl as c,dd as l,ku as u,ud as d,yn as f}from"./src-IJPkPeFt.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(u,{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(d,{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(),[u,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:u};return t(p,{icon:c,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(d,{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(f,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
|