@camstack/addon-admin-ui 1.2.342 → 1.2.343
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-DMer3W7x.js → AddonCollectionPage-tKFP5Lwa.js} +1 -1
- package/dist/assets/Addons-CGbLyp8a.js +1 -0
- package/dist/assets/{AdminTabs-8K5IGAB8.js → AdminTabs-D49DFF7T.js} +1 -1
- package/dist/assets/AiProfiles-ByvyVf4S.js +3 -0
- package/dist/assets/{BrokerForm-B7pu8gw6.js → BrokerForm-DE4STkG6.js} +1 -1
- package/dist/assets/Build-CcAMfH-X.js +40 -0
- package/dist/assets/{Calendars-DeYzry19.js → Calendars-lHwkwn_Q.js} +1 -1
- package/dist/assets/{Capabilities-BlzqjCkv.js → Capabilities-C3a6ifyd.js} +1 -1
- package/dist/assets/{Cluster-BO4_UGaX.js → Cluster-DXTRgQzx.js} +2 -2
- package/dist/assets/{CompositionEditor-B6fgYvbE.js → CompositionEditor-CWYvMou1.js} +1 -1
- package/dist/assets/{CompositionEditorPage-NxiR7QQh.js → CompositionEditorPage-BHOuMbtu.js} +1 -1
- package/dist/assets/Data-DJP48qWx.js +1 -0
- package/dist/assets/DetectionIntelligence-BbWnsTU0.js +1 -0
- package/dist/assets/DeviceDetail-CcqKE_PI.js +2 -0
- package/dist/assets/{DeviceDoActionFields-BTGvB-rE.js → DeviceDoActionFields-BZAxfdmk.js} +1 -1
- package/dist/assets/{Devices-DzqN9BfL.js → Devices-H-xH_fOc.js} +1 -1
- package/dist/assets/{EmbedPlayerPage--gPnf__x.js → EmbedPlayerPage-rd7j1pI_.js} +1 -1
- package/dist/assets/Events-D_v5uKvS.js +1 -0
- package/dist/assets/Identity-QTqu661c.js +1 -0
- package/dist/assets/IntegrationDetail-teGC9uQ3.js +1 -0
- package/dist/assets/Integrations-B_b1MZeg.js +1 -0
- package/dist/assets/{Integrations-CPNmXnNZ.js → Integrations-D2owF0PE.js} +1 -1
- package/dist/assets/Locations-Nnkdufnb.js +3 -0
- package/dist/assets/{Logs-lxtWEkCP.js → Logs-Cu1x3xDP.js} +1 -1
- package/dist/assets/{MotionZonesSettings-PK_RhzUS.js → MotionZonesSettings-BI_ML-IA.js} +1 -1
- package/dist/assets/{MyAccess-ByVOiLoY.js → MyAccess-BMOMwFN6.js} +1 -1
- package/dist/assets/Network-g8u56vjt.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-D604xGht.js → NodeAddonsSettingsPanel-CCzjSPCH.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DSHgXUIY.js → NodeInferenceDevices-BA75g0Jb.js} +1 -1
- package/dist/assets/Notifications-CBpqUyAM.js +1 -0
- package/dist/assets/Pipeline-jYp-0uE9.js +1 -0
- package/dist/assets/Plates-eS6TvGN2.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-BnjtiPUD.js → PrivacyMaskSettings-DsUfWvYn.js} +1 -1
- package/dist/assets/Recordings-C7ZkqUCP.js +1 -0
- package/dist/assets/{ScanNetworkModal-CbBwJI-2.js → ScanNetworkModal-2aKeFiXH.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-C35-Indg.js → SceneMonitorEditor-nXoXaKpY.js} +1 -1
- package/dist/assets/{Scenes-u29K3L8z.js → Scenes-omiebXrA.js} +1 -1
- package/dist/assets/{Settings-B_TdmhVB.js → Settings-B0eYhaSp.js} +1 -1
- package/dist/assets/{Showroom-CmZzpo6R.js → Showroom-B3quOoSI.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-BubFNpD_.js → StorageLocationsPanel-D6Ig0BwB.js} +1 -1
- package/dist/assets/{Terminal-CgmMWRwh.js → Terminal-yD7p878O.js} +3 -3
- package/dist/assets/{Viewer-BpYyXG64.js → Viewer-C7Iutjs_.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DYaeQRfF.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CzYdLxy-.js} +1 -1
- package/dist/assets/{archive-Cr-BIlNA.js → archive-CwIHc_Ww.js} +1 -1
- package/dist/assets/{authed-media-Dsq6dhVf.js → authed-media-DMMEqds_.js} +1 -1
- package/dist/assets/{boxes-C54oMdA_.js → boxes-BTpyboKa.js} +1 -1
- package/dist/assets/circle-slash-D8H2cOhG.js +1 -0
- package/dist/assets/client-CO0rTXhq.js +357 -0
- package/dist/assets/{debounced-invalidate-BJmaQT-4.js → debounced-invalidate-C8AHMwDh.js} +1 -1
- package/dist/assets/{device-integration-icon-DWs_AbRL.js → device-integration-icon-D1bjIPIV.js} +1 -1
- package/dist/assets/device-picker-model-chIcly0V.js +1 -0
- package/dist/assets/{dist-cztQPA_y.js → dist-D1cRlg3k.js} +1 -1
- package/dist/assets/dist-D6gIHviK.js +357 -0
- package/dist/assets/{face-bbox-G6Z1voG1.js → face-bbox-BFnrsYn8.js} +1 -1
- package/dist/assets/{hard-drive-download-C-k_wqAM.js → hard-drive-download-D2tdSqRj.js} +1 -1
- package/dist/assets/{hostInit-B_WZ2Gy8.js → hostInit-D_wBT4ni.js} +1 -1
- package/dist/assets/index-EsRvr_Ii.css +2 -0
- package/dist/assets/index-JHVJQCLQ.js +4 -0
- package/dist/assets/{layers-CW939zq1.js → layers-D1zKyXV5.js} +1 -1
- package/dist/assets/{location-owned-usage-Cn8KruJL.js → location-owned-usage-H3GZTDrd.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a707d600.js → mf-entry-bootstrap-0-5fe03ef0.js} +2 -2
- package/dist/assets/mount-chIcly0V.js +1 -0
- package/dist/assets/{notification-schedule-field-Bp8DTlPQ.js → notification-schedule-field-DWf74Obl.js} +1 -1
- package/dist/assets/{player-overlays-BzWBMmxi.js → player-overlays-BElx6KR1.js} +1 -1
- package/dist/assets/remoteEntry-6T0NU91Z.js +1 -0
- package/dist/assets/{send-DkNVOtAO.js → send-B6nyL8aN.js} +1 -1
- package/dist/assets/{settings-2-C2Xnx-LO.js → settings-2-B1zaQVrp.js} +1 -1
- package/dist/assets/{square-check-big-Cye5KH4u.js → square-check-big-xzhGc_rP.js} +1 -1
- package/dist/assets/{src-DryjbkTc.js → src-CUxCUGne.js} +17 -17
- package/dist/assets/{use-scenes-feed-BjyTyZVh.js → use-scenes-feed-pv0_KeWI.js} +1 -1
- package/dist/assets/{use-stationary-objects-bFk21PMu.js → use-stationary-objects-CjF8p_p7.js} +1 -1
- package/dist/assets/useEventInvalidation-chIcly0V.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CivR-_O-.js → useNodeUrlSelection-C32KGJ5p.js} +1 -1
- package/dist/assets/user-round-CsSrwOpd.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CK6jZXGF.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B3KPRT_5.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +280 -9
- package/package.json +1 -1
- package/dist/assets/Addons-CCB5Mhf0.js +0 -1
- package/dist/assets/AiProfiles-CSSe_12X.js +0 -3
- package/dist/assets/Build-BLoEyldh.js +0 -40
- package/dist/assets/Data-CoObUhmn.js +0 -1
- package/dist/assets/DetectionIntelligence-Dmz6stFp.js +0 -1
- package/dist/assets/DeviceDetail-BsBDq47F.js +0 -2
- package/dist/assets/Events-EaZ3wtPc.js +0 -1
- package/dist/assets/Identity-Bc98FIpW.js +0 -1
- package/dist/assets/IntegrationDetail-DaRzcvf1.js +0 -1
- package/dist/assets/Integrations-r_lIevSO.js +0 -1
- package/dist/assets/Locations-BP5dY9EA.js +0 -3
- package/dist/assets/Network-wF6b24iS.js +0 -1
- package/dist/assets/Notifications-CVlNXgoo.js +0 -1
- package/dist/assets/Pipeline-DePIr3MD.js +0 -1
- package/dist/assets/Plates-B-dp-vdZ.js +0 -1
- package/dist/assets/Recordings-CaUwVjZS.js +0 -1
- package/dist/assets/circle-slash-iHyT1430.js +0 -1
- package/dist/assets/client-USvucJT_.js +0 -357
- package/dist/assets/device-picker-model-C7bibG8k.js +0 -1
- package/dist/assets/dist-DAPUZI5S.js +0 -357
- package/dist/assets/index-7VTcgfLR.css +0 -2
- package/dist/assets/index-CV0bhG27.js +0 -4
- package/dist/assets/mount-C7bibG8k.js +0 -1
- package/dist/assets/remoteEntry-Bp8bsjuG.js +0 -1
- package/dist/assets/useEventInvalidation-C7bibG8k.js +0 -1
- package/dist/assets/user-round-BjVxqy86.js +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as p,gt as m,ht as h,st as g,vt as _}from"./player-overlays-BzWBMmxi.js";import{Bd as v,Cn as y,Fn as b,Ft as x,Gt as S,Gu as C,It as w,Ki as T,Ld as E,Lt as D,Ot as O,Pt as k,Pu as A,Rl as j,Su as M,Tt as N,Un as P,Ut as F,Wt as ee,_t as te,ai as I,bu as L,ct as R,cu as ne,di as re,en as ie,fi as ae,gd as oe,ht as se,k as ce,oi as le,pi as ue,pu as de,tn as z,ui as fe,vn as B,wn as V,wt as pe,xn as H,xu as me}from"./src-DryjbkTc.js";import{Gn as he,Gr as ge,Hn as U,Pt as _e,Qn as ve,Wn as W,dr as G,fr as ye,ir as be,lr as xe,pr as Se,rr as K,ur as Ce}from"./client-USvucJT_.js";import{E as we,F as Te,M as Ee,a as De,b as Oe,c as ke,o as Ae,z as je}from"./index-CV0bhG27.js";import{t as Me}from"./AdminPage-CiKtOLQm.js";import{t as Ne}from"./DeviceDoActionFields-BTGvB-rE.js";var Pe=_(`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`}]]),Fe=_(`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`}]]),Ie=`const AUTOMATION_RECIPE =`,Le=`// 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 Re(e){return e.includes(Ie)}function ze(e){let t=e.indexOf(Ie);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 Be(e){let t=ze(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 Ve(e){let t=ze(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)}${Le}${e.slice(i)}`}r();var He=6e4;function Ue(){let e=T({projection:`slim`});return o(()=>(e.data??[]).filter(e=>_e(String(e.type))).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 We(e){let t=p();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:He,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ge(e,t){return e.find(e=>e.cap===t)?.fields??[]}function q({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Ke(e){let t=We(e.deviceId);if(t.data!==void 0)return Ge(t.data,e.cap).find(t=>t.path===e.fieldPath)}function qe({value:e,devices:t,onChange:n}){let r=We(e.deviceId),a=r.data??[],o=Ge(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(q,{children:`Device`}),d(y,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Capability`}),d(y,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Je(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Field`}),d(y,{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 Je(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 Ye=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Xe(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 Ye}}function Ze(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 Qe(e){return Xe(e).map(e=>({value:e,label:Ze(e)}))}function $e(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 et={triggers:[],actions:[]};function tt(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 nt(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 rt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function it(){return{kind:`expression`,expr:``,bindings:{}}}function at(e,t,n){return e.map((e,r)=>r===t?n:e)}function ot(e,t){return e.filter((e,n)=>n!==t)}function st(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=ot(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function ct(e,t){return{...e,triggers:[...t]}}function lt(e,t){return{...e,actions:[...t]}}var ut=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function dt({actions:e,devices:t,devicesState:n=`answered`,onChange:r}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((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:[d(P,{variant:`default`,children:o+1}),i(`label`,{className:`w-40`,children:[d(q,{children:`Step`}),d(y,{value:a.kind,onChange:t=>r(at(e,o,nt(ft(t.target.value)))),options:ut.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(V,{variant:`ghost`,disabled:o===0,onClick:()=>r(st(e,o,o-1)),title:`Run this step earlier`,children:d(E,{className:`h-3.5 w-3.5`})}),d(V,{variant:`ghost`,disabled:o===e.length-1,onClick:()=>r(st(e,o,o+1)),title:`Run this step later`,children:d(v,{className:`h-3.5 w-3.5`})}),d(V,{variant:`ghost`,onClick:()=>r(ot(e,o)),title:`Remove this step`,children:d(g,{className:`h-3.5 w-3.5`})})]})]}),a.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(q,{children:`Seconds`}),d(z,{type:`number`,min:0,max:300,value:String(a.seconds),onChange:t=>r(at(e,o,{kind:`wait`,seconds:Number(t.target.value)}))})]}),a.kind===`code`&&i(`label`,{className:`block`,children:[d(q,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:a.code,spellCheck:!1,onChange:t=>r(at(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. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),a.kind===`cap`&&d(mt,{action:a,devices:t,devicesState:n,onChange:t=>r(at(e,o,t))})]},`${a.kind}-${String(o)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(V,{variant:`outline`,onClick:()=>r([...e,nt(`cap`)]),children:[d(L,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function ft(e){return ut.find(t=>t.value===e)?.value??`cap`}function pt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function mt({action:e,devices:t,devicesState:n,onChange:r}){return d(Ne,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:pt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function ht({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(y,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(y,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(z,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(z,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function gt({value:e,field:t,onChange:n}){return d(z,{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 _t(e){return typeof e==`object`}function vt(e){return _t(e)?e[0]??``:e}function yt(e){return _t(e)?e:typeof e==`boolean`?[]:[e]}function bt({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o=Qe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=xt(t,o);n({...e,operator:r,value:r===`in`?yt(e.value):vt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(qe,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(q,{children:`Comparison`}),d(y,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Value`}),s?d(gt,{value:yt(e.value),field:a,onChange:t=>n({...e,value:t})}):d(ht,{value:vt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function xt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var St={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Ct({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(q,{children:`Expression`}),d(z,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(wt,{alias:n,source:r,devices:t,onRename:t=>a(At(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(jt(e.bindings,n))},n)),i(V,{variant:`ghost`,onClick:()=>a({...e.bindings,[kt(e.bindings)]:St}),children:[d(L,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function wt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Dt(n,Et(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(q,{children:`Name`}),d(z,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(q,{children:`Reads`}),d(y,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:St),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(q,{children:`Constant`}),d(z,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Tt(e.target.value)})})]}):d(qe,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:Ot(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(V,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(g,{className:`h-3.5 w-3.5`})})]})}function Tt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Et(e){return e.kind===`global`?e.sourceStableId:``}function Dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ot(e,t){return e.find(e=>e.id===t)?.stableId??``}function kt(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 At(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function jt(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 Mt(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 Nt(e){return Mt(e,Y(e))}function Pt(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?Pt(e.child,r):null;if(!J(e))return null;let i=e.children[n];return i===void 0?null:Pt(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 Ft(e){return e===null?null:Se({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function It(e){let t=Y(e);return{depth:t.children.length===0?0:G(t),leaves:t.children.length===0?0:ye(t),depthLimit:3,leafLimit:32}}function Lt(e,t){let n=Ft(t);return n===null?{ok:!0,recipe:Mt(e,t)}:{ok:!1,reason:n}}function Rt(e,t){let n=Y(e);return Lt(e,{kind:n.kind,children:[...n.children,t]})}function zt(e,t,n){return Mt(e,X(Y(e),t,()=>n))}function Bt(e,t){return Mt(e,X(Y(e),t,()=>null))}function Vt(e,t,n){return Mt(e,X(Y(e),t,e=>J(e)?{kind:n,children:e.children}:e))}function Ht(e,t){return Pt(Y(e),t)===null?{ok:!1,reason:`that row is no longer there`}:Lt(e,X(Y(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Ut(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 Wt(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=Ut(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=Y(e),a=Pt(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 Lt(e,X(i,r.path,()=>d))}function Gt(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=Pt(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return Lt(e,X(n,t,()=>r.child));if(!J(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Ut(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=Pt(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 Lt(e,X(n,i.path,()=>o))}r();var Kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function qt(e){return e.join(`/`)}function Jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Yt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=Y(e),f=It(e),p=o(()=>r.map(Jt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Wt(e,p,`all`),g=Wt(e,p,`any`),_=p.length===1?Ht(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(zt(e,t,r)),onRemove:t=>{a([]),n(Bt(e,t))},onSetKind:(t,r)=>n(Vt(e,t,r)),onUngroup:t=>m(Gt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(P,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(y,{value:u.kind,onChange:t=>n(Vt(e,[],Xt(t.target.value))),options:Kt})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Zt,{container:u,path:[],handlers:v}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(V,{variant:`outline`,onClick:()=>m(Rt(e,rt())),title:`Compare one device field to a value`,children:[d(L,{className:`h-4 w-4`}),` Condition`]}),i(V,{variant:`outline`,onClick:()=>m(Rt(e,it())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(Pe,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(V,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(V,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(V,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Xt(e){return e===`any`?`any`:`all`}function Zt({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(Qt,{node:e,path:[...t,r],handlers:n},qt([...t,r])))})}function Qt({node:e,path:t,handlers:n}){let r=qt(t),a=d(ie,{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,d(`div`,{className:`w-32`,children:d(y,{value:e.kind,onChange:e=>n.onSetKind(t,Xt(e.target.value)),options:Kt})}),i(V,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(V,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(g,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Zt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(P,{variant:`warning`,children:`NOT`}),i(V,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(Fe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(Qt,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(bt,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(Ct,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(V,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(g,{className:`h-3.5 w-3.5`})})]})}r();function $t({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=b(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(V,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?m:h,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(V,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(je,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(O,{maxHeight:420,children:e})})]})}var en=[`device-state`,`device-event`,`schedule`,`manual`],tn=Object.values(ge).sort((e,t)=>e.localeCompare(t));function nn({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(rn,{trigger:r,devices:t,position:i,onChange:t=>n(at(e,i,t)),onRemove:()=>n(ot(e,i))},`${r.kind}-${String(i)}`)),i(V,{variant:`outline`,onClick:()=>n([...e,tt(`device-state`)]),title:`Add another way this automation can start`,children:[d(L,{className:`h-4 w-4`}),` Trigger`]})]})}function rn({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(P,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(q,{children:`Trigger`}),d(y,{value:e.kind,onChange:e=>r(tt(an(e.target.value))),options:en.map(e=>({value:e,label:$e(e)}))})]}),d(V,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(sn,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(ln,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(q,{children:`Cron expression`}),d(z,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function an(e){return en.find(t=>t===e)??`manual`}function on(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 sn({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=Ke(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(qe,{value:r,devices:t,onChange:e=>n(on(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(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:[d(ie,{checked:e.becomes===void 0,onChange:e=>n(on(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(ht,{value:e.becomes,field:a,onChange:e=>n(on(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(ie,{checked:e.edge===!0,onChange:e=>n(on(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Held for (s)`}),d(z,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,forMs:cn(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(q,{children:`Debounce (s)`}),d(z,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(on(r,{...o,debounceMs:cn(e.target.value)}))})]})]})}function cn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function ln({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(q,{children:`Event category`}),d(y,{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…`},...tn.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(q,{children:`From device`}),d(y,{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 un=`hub`;function dn({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[m,h]=l(()=>Nt(t)),[g,_]=l(!1),v=Ue(),y=Se(m),b=o(()=>pn(m),[m]),x=o(()=>mn(f.trim()===``?`Untitled automation`:f.trim(),m),[f,m]),S=f.trim()===``,C=S||y!==null||b!==null||x.code===null;return d(B,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(P,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(fn,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(nn,{triggers:m.triggers,devices:v,onChange:e=>h(ct(m,e))})}),d(fn,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Yt,{recipe:m,devices:v,onChange:h})}),d(fn,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(dt,{actions:m.actions,devices:v,onChange:e=>h(lt(m,e))})}),d($t,{code:x.code,error:x.error,canEject:e!==null,ejecting:a,onEject:c}),y!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:y}),y===null&&b!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(V,{onClick:()=>{x.code!==null&&s({name:f.trim(),code:x.code,enabled:e?.enabled??!0,placement:un})},disabled:n||C,children:[n&&d(A,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(V,{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`,"data-testid":`automation-logs-toggle`,children:[d(ne,{className:`h-4 w-4`}),` Logs `,g?`▾`:`▸`]}),d(V,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),S&&d(P,{variant:`warning`,children:`Name required`})]}),g&&e!==null&&i(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:U(e.id)})]}),d(se,{addonId:U(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})})}function fn({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function pn(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 mn(e,t){try{return{code:xe({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function hn(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 gn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _n(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function vn(e){let t=e=>{let t=hn(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 yn(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>hn(e).tone===`error`).length,n=e.filter(e=>hn(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 bn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=hn(e),m=R(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(P,{variant:gn(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(V,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(V,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(V,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(M,{className:`h-4 w-4`})}),i(F,{children:[d(S,{children:d(V,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(me,{className:`h-4 w-4`})})}),d(ee,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(V,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(V,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(V,{variant:`ghost`,onClick:l,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:U(e.id)})]}),d(se,{addonId:U(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xn({onCreate:e}){return d(B,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(V,{onClick:e,children:`New automation`})]})})}r();var Sn=[`coreBlocks`,`list`],Cn=5e3;function wn(e){return e instanceof Error?e.message:String(e)}function Tn({onOpenScripts:e,initialBlockId:n,onBlockIdChange:r,createRequested:a=!1,onCreateConsumed:o}){let c=p(),[m,h]=l({mode:`closed`}),[g,_]=l(null),[v,y]=l(null),b=t(null);f(()=>{a&&(h({mode:`edit`,block:null}),r?.(null),o?.())},[a,o,r]);let x=s({queryKey:Sn,refetchInterval:Cn,queryFn:async()=>(await c.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{x.refetch()},C=x.data;f(()=>{if(n===void 0||b.current===n)return;let e=C?.find(e=>e.id===n&&Re(e.code));e!==void 0&&(b.current=n,h({mode:`edit`,block:e}))},[n,C]);let w=u({mutationFn:e=>c.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),T=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{h({mode:`edit`,block:e.block}),r?.(e.block.id),S()}}),E=u({mutationFn:e=>c.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{_(null),S()}}),D=u({mutationFn:e=>c.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),O=u({mutationFn:e=>c.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Ve(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{h({mode:`closed`}),S(),e(t.block.id)}}),k=x.data,A=vn((k??[]).filter(e=>Re(e.code))),j=k!==void 0&&A.length===0,M=m.mode===`edit`&&m.block!==null?_n(A,m.block):null,N=M===null?null:Be(M.code),P=w.error===null?T.error===null?O.error===null?null:wn(O.error):wn(T.error):wn(w.error),F=m.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!F&&d(`p`,{className:`text-xs text-foreground-subtle`,children:k===void 0?``:yn(A)}),x.error!=null&&d(H,{title:`Could not read the automations`,message:wn(x.error),onRetry:S}),F&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`automation-editor-panel`,children:d(dn,{existing:M,initialRecipe:N!==null&&N.ok?N.recipe:et,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(),h({mode:`closed`}),r?.(null)}},M?.id??`new`)}),!F&&j&&d(xn,{onCreate:()=>{h({mode:`edit`,block:null}),r?.(null)}}),!F&&A.length>0&&d(B,{children:d(`ul`,{className:`divide-y divide-border`,children:A.map(e=>{let t=Be(e.code);return d(bn,{block:e,busy:D.isPending||E.isPending,confirming:g===e.id,logsOpen:v===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{h({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&&d(H,{message:wn(E.error)}),D.error!=null&&d(H,{message:wn(D.error)})]})}function En(e){return{state:`answered`,byRef:new Map(e.map(e=>[K(e),e]))}}function Dn(e,t){if(e.state!==`unanswered`)return e.byRef.get(K(t))??null}function On(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function kn(e){return be(e).map(e=>e.source)}function An(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(...kn(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...kn(e))}let r=new Set;return n.filter(e=>{let t=K(e);return r.has(t)?!1:(r.add(t),!0)})}function jn(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function Mn(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?[`${jn(t.length,`field`)} unavailable`]:[],...n.length>0?[`${jn(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 Nn(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Mn(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 Pn(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}`}).`}:Nn(n.state,t.lastError):{tone:`idle`,label:`Off`,reason:null}}function Fn(e){return K(e)}function In(e,t){let n=Dn(t,e);return{key:K(e),label:n?n.name:Fn(e),presence:On(n),deviceId:n?n.id:null}}function Ln(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Rn(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:ve(e.block.id),a=K(i),o=An(e).filter(e=>K(e)!==a).map(e=>In(e,t)),s=n.features.map(e=>e.enabled===!1?`${e.cap} (off)`:e.cap),c=Dn(t,i),l=Ln(e),u=Pn(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=On(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Fn(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function zn(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Bn(e,t){return zn(e)-zn(t)||e.name.localeCompare(t.name)}function Vn(e,t){let n=e.flatMap(e=>{let n=Rn(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Bn),customizations:n.filter(e=>e.kind===`customization`).toSorted(Bn)}}var Hn=1e4;function Un(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Wn(){let e=we();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 (${Un(e.error)})`}:En(e.data)}function Gn(){let e=fe({},{refetchInterval:Hn}),t=Wn(),n=e.data;if(e.error!=null&&n===void 0)return d(H,{title:`Could not read the compositions`,message:Un(e.error),onRetry:()=>void e.refetch()});if(n===void 0)return d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading compositions…`});if(n.state===`not-loaded`)return d(B,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-warning`,children:`The composition store has not been read yet.`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`This is not the same as having none — the list appears once the hub has read it (`,n.reason,`).`]})]})});let r=e.error==null?null:Un(e.error);return d(Kn,{lists:Vn(n.views,t),fleet:t,refreshError:r})}function Kn({lists:e,fleet:t,refreshError:n}){return i(`div`,{className:`space-y-4`,children:[n!==null&&i(`p`,{className:`text-xs text-warning`,children:[`Showing the last answer — the latest refresh failed: `,n]}),t.state===`unanswered`&&i(`p`,{className:`text-xs text-warning`,children:[`Device names are shown as references: `,t.reason,`. No source is marked missing until it has.`]}),d(qn,{title:`Composed devices`,hint:`A new device whose state is derived from other devices.`,rows:e.composed,nameHeader:`Name`,emptyMessage:`No composed devices.`,action:d(Ee,{to:De,className:`text-xs text-primary hover:underline`,children:`+ New composed device`})}),d(qn,{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 qn({title:e,hint:t,rows:n,nameHeader:r,emptyMessage:a,action:o}){return i(`section`,{className:`space-y-2`,"aria-label":e,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`div`,{children:[d(`h3`,{className:`font-medium`,children:e}),d(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),o!==void 0&&o]}),d(B,{variant:`flat`,className:`p-0`,children:d(pe,{columns:Jn(r),rows:n,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:N,emptyMessage:a})})]})}function Jn(e){return[{key:`name`,header:e,sortValue:e=>e.name.toLowerCase(),render:e=>d(Yn,{row:e})},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>d(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??`unknown`})},{key:`state`,header:`State`,nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:e=>i(`div`,{className:`space-y-0.5`,children:[d(P,{variant:gn(e.state.tone),children:e.state.label}),e.state.reason!==null&&d(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:e.state.reason})]})},{key:`sources`,header:`Sources`,nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>d(Zn,{sources:e.sources})}]}function Yn({row:e}){return i(`div`,{className:`space-y-0.5`,children:[d(Xn,{row:e}),e.namePresence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`device missing`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.features.join(`, `)})]})}function Xn({row:e}){return e.kind===`composed`?d(Ee,{to:Ae(e.blockId),className:`text-xs text-foreground hover:underline`,children:e.name}):e.reportedDeviceId===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:[e.name,` — device not reported yet`]}):d(Ee,{to:ke(e.reportedDeviceId),className:`text-xs text-foreground hover:underline`,children:e.name})}function Zn({sources:e}){return e.length===0?d(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):d(`ul`,{className:`space-y-0.5`,children:e.map(e=>i(`li`,{className:`text-xs`,children:[e.deviceId===null?d(`span`,{className:e.presence===`missing`?`text-danger`:`text-foreground`,children:e.label}):d(Ee,{to:`/devices/${String(e.deviceId)}`,className:`hover:underline`,children:e.label}),e.presence===`missing`&&d(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:`missing`})]},e.key))})}function Qn(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 $n(e){if(Array.isArray(e))return e}function er(e,t,n){return(t=lr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function tr(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 nr(){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 rr(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 ir(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?rr(Object(n),!0).forEach(function(t){er(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):rr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ar(e,t){if(e==null)return{};var n,r,i=or(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 or(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 sr(e,t){return $n(e)||tr(e,t)||ur(e,t)||nr()}function cr(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 lr(e){var t=cr(e,`string`);return typeof t==`symbol`?t:t+``}function ur(e,t){if(e){if(typeof e==`string`)return Qn(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)?Qn(e,t):void 0}}function dr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function fr(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 pr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?fr(Object(n),!0).forEach(function(t){dr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function mr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function hr(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 gr(e){return{}.toString.call(e).includes(`Object`)}function _r(e){return!Object.keys(e).length}function vr(e){return typeof e==`function`}function yr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function br(e,t){return gr(t)||Z(`changeType`),Object.keys(t).some(function(t){return!yr(e,t)})&&Z(`changeField`),t}function xr(e){vr(e)||Z(`selectorType`)}function Sr(e){vr(e)||gr(e)||Z(`handlerType`),gr(e)&&Object.values(e).some(function(e){return!vr(e)})&&Z(`handlersType`)}function Cr(e){e||Z(`initialIsRequired`),gr(e)||Z(`initialType`),_r(e)&&Z(`initialContent`)}function wr(e,t){throw Error(e[t]||e.default)}var Z=hr(wr)({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"}),Tr={changes:br,selector:xr,handler:Sr,initial:Cr};function Er(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Tr.initial(e),Tr.handler(t);var n={current:e},r=hr(kr)(n,t),i=hr(Or)(n),a=hr(Tr.changes)(e),o=hr(Dr)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Tr.selector(e),e(n.current)}function c(e){mr(r,i,a,o)(e)}return[s,c]}function Dr(e,t){return vr(t)?t(e.current):t}function Or(e,t){return e.current=pr(pr({},e.current),t),t}function kr(e,t,n){return vr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Ar={create:Er},jr={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Mr(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 Nr(e){return{}.toString.call(e).includes(`Object`)}function Pr(e){return e||Rr(`configIsRequired`),Nr(e)||Rr(`configType`),e.urls?(Fr(),{paths:{vs:e.urls.monacoBase}}):e}function Fr(){console.warn(Lr.deprecation)}function Ir(e,t){throw Error(e[t]||e.default)}var Lr={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
|
-
`},Rr=Mr(Ir)(Lr),zr={config:Pr},Br=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Vr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Vr(e[n],t[n]))}),ir(ir({},e),t)}var Hr={type:`cancelation`,msg:`operation is manually canceled`};function Ur(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Hr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Wr=[`monaco`],Gr=sr(Ar.create({config:jr,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),Kr=Gr[0],qr=Gr[1];function Jr(e){var t=zr.config(e),n=t.monaco,r=ar(t,Wr);qr(function(e){return{config:Vr(e.config,r),monaco:n}})}function Yr(){var e=Kr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(qr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Ur(ni);if(window.monaco&&window.monaco.editor)return ei(window.monaco),e.resolve(window.monaco),Ur(ni);Br(Xr,Qr)($r)}return Ur(ni)}function Xr(e){return document.body.appendChild(e)}function Zr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Qr(e){var t=Kr(function(e){return{config:e.config,reject:e.reject}}),n=Zr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function $r(){var e=Kr(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;ei(n),e.resolve(n)},function(t){e.reject(t)})}function ei(e){Kr().monaco||qr({monaco:e})}function ti(){return Kr(function(e){return e.monaco})}var ni=new Promise(function(e,t){return qr({resolve:e,reject:t})}),ri={config:Jr,init:Yr,__getMonacoInstance:ti};r();var ii={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},ai={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function oi({children:e}){return a.createElement(`div`,{style:ai.container},e)}var si=oi;function ci({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:o,wrapperProps:s}){return a.createElement(`section`,{style:{...ii.wrapper,width:e,height:t},...s},!n&&a.createElement(si,null,r),a.createElement(`div`,{ref:i,style:{...ii.fullWidth,...!n&&ii.hide},className:o}))}var li=n(ci);function ui(e){f(e,[])}var di=ui;function fi(e,n,r=!0){let i=t(!0);f(i.current||!r?()=>{i.current=!1}:e,n)}var Q=fi;function pi(){}function mi(e,t,n,r){return hi(e,r)||gi(e,t,n,r)}function hi(e,t){return e.editor.getModel(_i(e,t))}function gi(e,t,n,r){return e.editor.createModel(t,n,r?_i(e,r):void 0)}function _i(e,t){return e.Uri.parse(t)}function vi({original:n,modified:r,language:i,originalLanguage:o,modifiedLanguage:s,originalModelPath:c,modifiedModelPath:u,keepCurrentOriginalModel:d=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=pi,onMount:S=pi}){let[C,w]=l(!1),[T,E]=l(!0),D=t(null),O=t(null),k=t(null),A=t(S),j=t(x),M=t(!1);di(()=>{let e=ri.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=mi(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=mi(O.current,r||``,s||i||`text`,u||``);t!==e.getModel()&&e.setModel(t)}},[u],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=mi(O.current,n||``,o||i||`text`,c||``),t=mi(O.current,r||``,s||i||`text`,u||``);D.current?.setModel({original:e,modified:t})},[i,r,s,n,o,c,u]),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]);f(()=>{C&&A.current(D.current,O.current)},[C]),f(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();d||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return a.createElement(li,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}n(vi);function yi(e){let n=t();return f(()=>{n.current=e},[e]),n.current}var bi=yi,xi=new Map;function Si({defaultValue:n,defaultLanguage:r,defaultPath:i,value:o,language:s,path:c,theme:u=`light`,line:d,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=pi,onMount:C=pi,onChange:w,onValidate:T=pi}){let[E,D]=l(!1),[O,k]=l(!0),A=t(null),j=t(null),M=t(null),N=t(C),P=t(S),F=t(),ee=t(o),te=bi(c),I=t(!1),L=t(!1);di(()=>{let e=ri.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?ne():e.cancel()}),Q(()=>{let e=mi(A.current,n||o||``,r||s||``,c||i||``);e!==j.current?.getModel()&&(g&&xi.set(te,j.current?.saveViewState()),j.current?.setModel(e),g&&j.current?.restoreViewState(xi.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()&&(L.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),L.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(u)},[u],E);let R=e(()=>{if(!(!M.current||!A.current)&&!I.current){P.current(A.current);let e=c||i,t=mi(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(xi.get(e)),A.current.editor.setTheme(u),d!==void 0&&j.current.revealLine(d),D(!0),I.current=!0}},[n,r,i,o,s,c,m,h,g,u,d]);f(()=>{E&&N.current(j.current,A.current)},[E]),f(()=>{!O&&!E&&R()},[O,E,R]),ee.current=o,f(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{L.current||w(j.current.getValue(),e)}))},[E,w]),f(()=>{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 ne(){F.current?.dispose(),_?g&&xi.set(c,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return a.createElement(li,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Ci=n(Si);r();function wi(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}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=[],path:a=`file:///block.ts`,onDiagnostics:o,readOnly:s=!1,heightPx:c=420,dark:l=!0}){let u=t(null),p=e((e,t)=>{if(u.current=t,Ei(t,i),o===void 0)return;let n=e.getModel();if(n===null)return;let r=()=>{o(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,o]);return f(()=>{let e=u.current;e!==null&&Ei(e,i)},[i]),d(Ci,{height:c,defaultLanguage:`typescript`,path:a,theme:l?`vs-dark`:`vs`,value:n,onChange:e=>r(e??``),onMount:p,options:{readOnly:s,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.
|
|
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
|
-
`}}];function Ai(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var ji=ki.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
-
|
|
36
|
-
export default function block(ctx: AddonContext) {
|
|
37
|
-
ctx.logger.info('hello from a core block')
|
|
38
|
-
return () => undefined
|
|
39
|
-
}
|
|
40
|
-
`;function Mi({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 Ni=5e3;function Pi(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 Fi({blockId:e}){let t=U(e),n=T({addonId:t,projection:`slim`},{refetchInterval:Ni}),r=o(()=>Pi(n.data),[n.data]);return n.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),` Loading devices owned by this script…`]}):n.isError?i(`p`,{className:`text-xs text-danger`,children:[`Could not list devices:`,` `,n.error instanceof Error?n.error.message:String(n.error)]}):i(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[i(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`div`,{children:[d(`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 (`,d(`code`,{className:`text-[11px]`,children:t}),`). Open a device for its export section.`]})]}),d(P,{variant:`default`,children:r.length})]}),r.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:[`No devices yet. Call `,d(`code`,{children:`reconcileBlockDevices(ctx, …)`}),` from the script (and Restart) to declare them.`]}):d(`ul`,{className:`space-y-3`,children:r.map(e=>d(`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:[d(Ee,{to:`/devices/${String(e.id)}`,className:`text-sm font-medium hover:underline`,title:`Open device detail`,children:e.name}),d(P,{variant:`info`,style:`outline`,children:e.type}),e.stableId!==void 0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,d(`code`,{children:e.stableId})]}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,e.id]})]})},e.id))})]})}r();function Ii(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function Li(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function Ri(e){switch(e){case`refresh-channel-catalog`:return`Script enabled so the channel catalog can scrape.`;case`send-tv-schedule-now`:return`Script enabled so the TV schedule can send.`;case`refresh-nordvpn-catalog`:return`Script enabled so the NordVPN catalog can refresh.`;case`probe-nordvpn-italy`:return`Script enabled so Italy stations can be probed.`;case`test-nordvpn-endpoint`:return`Script enabled so the VPN endpoint can be tested.`;case`refresh-unifi-catalog`:return`Script enabled so UniFi IDs can be fetched.`}}function zi(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Bi(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Vi(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=zi(e);n!==null&&(t[n]=Bi(e))}return t}function Hi(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Ui({blockId:t}){let n=p(),r=I({blockId:t},{retry:!1}),a=le({blockId:t},{refetchInterval:1e4,retry:!1}),s=ue({onSuccess:()=>{a.refetch()}}),c=re(),u=ae(),[f,m]=l(null),[h,g]=l(null),[_,v]=l(null),[y,b]=l(!1),x=Hi(a.data)?a.data:null,S=o(()=>x===null?{}:Vi(x),[x]),C=f??S,w=e(e=>{m(e)},[]),T=f!==null,E=e(()=>{f!==null&&(g(null),s.mutate({blockId:t,patch:f},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,f,s]),D=e(async(e,i)=>{if(Ii(e)){b(!0),g(null),v(null);try{f!==null&&(await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:f}),m(null)),await n.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:Li(e)}),r.data?.block?.enabled!==!0&&(await u.mutateAsync({blockId:t,enabled:!0}),v(Ri(e))),await c.mutateAsync({blockId:t}),await a.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[t,r.data?.block?.enabled,f,c,u,a,n.trpcClient.coreBlocks]);return a.isLoading?i(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),` Loading script settings…`]}):a.isError?i(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[`Could not load settings:`,` `,a.error instanceof Error?a.error.message:String(a.error)]}):x===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:[d(`h4`,{className:`text-sm font-medium`,children:`Settings`}),i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Declared by this script's `,d(`code`,{children:`settingsSchema`}),` export.`]})]}),i(V,{size:`sm`,variant:`primary`,onClick:E,disabled:!T||s.isPending||y,children:[s.isPending&&d(A,{className:`h-3.5 w-3.5 animate-spin`}),`Save settings`]})]}),d(Oe,{schema:x,values:C,onChange:w,onAction:D}),h===null?null:d(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:d(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}r();var Wi=`hub`;function Gi({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:a,restarting:s,restartError:f,onRestart:m,onSave:h,onCancel:g}){let _=p(),v=b(),{resolvedMode:y}=te(),x=he({code:e?.code??ji,files:e?.files,entry:e?.entry}),[S,C]=l(e?.name??``),[w,T]=l(x.files),[E,D]=l(x.entry),[O,k]=l(x.entry),[M,N]=l(e?.placement??Wi),[F,ee]=l(e?.integrationId??``),[I,L]=l([]),[R,re]=l(!1),[ie,ae]=l(`blank`),[le,ue]=l(null),[fe,pe]=l(``),H=w[O]??``,me=e=>{T(t=>({...t,[O]:e}))},ge=Object.keys(w).toSorted(),_e=ki.length>1,ve=o(()=>[...t?.libs??[],...wi(w,O)],[t?.libs,w,O]),W=u({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:w,entry:E})}),G=o(()=>I.filter(e=>e.severity>=8),[I]),ye=Oi(I),be=S.trim()===``,xe=e===null?null:he(e),Se=e===null||xe===null||JSON.stringify(w)!==JSON.stringify(xe.files)||E!==xe.entry||S.trim()!==e.name||M!==e.placement||(F.trim()===``?void 0:F.trim())!==e.integrationId,K=()=>{W.reset(),h({name:S.trim(),files:w,entry:E,enabled:e?.enabled??!0,placement:M,...F.trim()===``?{}:{integrationId:F.trim()}})},Ce=()=>{let e=Ai(Object.keys(w));T(t=>({...t,[e]:``})),k(e),ue(e),pe(e)},we=e=>{ue(e),pe(e)},Te=()=>{if(le===null)return;let e=le,t=fe.trim();if(ue(null),!(t===``||t===e)){if(w[t]!==void 0){k(t);return}T(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),E===e&&D(t),k(t)}},Ee=async 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(w)===JSON.stringify(n.files)&&E===n.entry)&&!await v({title:`Load example`,message:`Replace the current editor contents with this example?`,confirmLabel:`Replace`,variant:`warning`})||(ae(e),T({...t.files}),D(t.entry),k(t.entry),(S.trim()===``||ie===`blank`)&&C(t.id===`blank`?``:t.name))},De=e===null?null:hn(e),Oe=Mi({existing:e,dirty:Se,saving:r,restarting:s});return d(B,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),De!==null&&d(P,{variant:gn(De.tone),children:De.label})]}),i(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(z,{className:`mt-1`,value:S,onChange:e=>C(e.target.value),placeholder:`What this script does`})]}),i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),d(z,{className:`mt-1`,value:F,onChange:e=>ee(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),e===null&&_e&&i(`label`,{className:`block text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Start from`}),d(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:ie,onChange:e=>void Ee(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:[d(ce,{selectedNodeId:M,onSelect:N,label:`Runs on`,alwaysShow:!0}),M!==Wi&&i(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[d(j,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),i(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,d(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),i(`div`,{className:`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:[ge.map(e=>le===e?d(z,{value:fe,onChange:e=>pe(e.target.value),onBlur:()=>Te(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Te()),e.key===`Escape`&&(e.preventDefault(),ue(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":`Rename file`},e):i(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${e===O?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>k(e),onDoubleClick:()=>we(e),title:`Double-click to rename`,"data-testid":`script-file-tab-${e}`,children:[e,e===E?` · entry`:``]},e)),d(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:Ce,"data-testid":`script-file-add`,children:`+ file`}),O!==E&&d(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>D(O),title:`Use this file as the compile entry`,children:`Set as entry`})]}),n?d(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):d(Di,{value:H,onChange:me,path:`file:///${O}`,extraLibs:ve,onDiagnostics:L,dark:y===`dark`,heightPx:560})]}),t!==void 0&&t.libs.length===0&&d(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),G.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:[G.length,` error`,G.length===1?``:`s`,` — the block cannot be saved.`]}),G.slice(0,5).map(e=>i(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),G.length>5&&i(`p`,{className:`text-foreground-subtle`,children:[`…and `,G.length-5,` more.`]})]}),W.data!==void 0&&(W.data.ok?i(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[d(oe,{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:[W.data.line===void 0?``:`line ${String(W.data.line)}: `,W.data.error??`the code does not compile`]})),W.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: `,Ki(W.error)]}),a!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),f!==null&&d(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:f}),e!==null&&i(`div`,{className:`space-y-3`,children:[d(Ui,{blockId:e.id}),d(Fi,{blockId:e.id})]}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(V,{variant:`outline`,onClick:()=>W.mutate(),disabled:W.isPending||r,title:`Type-check on the node without saving`,children:[W.isPending&&d(A,{className:`h-4 w-4 animate-spin`}),` Compile`]}),i(V,{onClick:K,disabled:r||ye||be,children:[r&&d(A,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(V,{variant:`outline`,onClick:()=>m?.(),disabled:Oe!==null||m===void 0,title:Oe??`Stop the process and let the supervisor bring it back`,children:[s?d(de,{className:`h-4 w-4 animate-spin`}):d(de,{className:`h-4 w-4`}),` `,`Restart`]}),i(V,{variant:`ghost`,onClick:()=>re(!R),title:`Show this script's process logs`,"data-testid":`script-logs-toggle`,children:[d(ne,{className:`h-4 w-4`}),` Logs `,R?`▾`:`▸`]}),d(V,{variant:`ghost`,onClick:g,disabled:r,children:`Close`}),i(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,G.length,Se&&e!==null?` · unsaved changes`:``]}),be&&d(P,{variant:`warning`,children:`Name required`})]}),R&&i(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[d(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:i(c,{children:[`Logs — `,d(`code`,{children:U(e.id)})]})}),e!==null&&d(se,{addonId:U(e.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})})}function Ki(e){return e instanceof Error?e.message:String(e)}r();var qi=[`coreBlocks`,`list`],Ji=[`coreBlocks`,`getTypeDefs`],Yi=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xi({initialBlockId:e,onBlockIdChange:n,createRequested:r=!1,onCreateConsumed:a}={}){let o=p(),[c,m]=l({mode:`closed`}),[h,g]=l(null),[_,v]=l(null),y=s({queryKey:qi,refetchInterval:Yi,queryFn:async()=>(await o.trpcClient.coreBlocks.list.query({})).blocks}),b=s({queryKey:Ji,enabled:c.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>o.trpcClient.coreBlocks.getTypeDefs.query({})}),x=()=>{y.refetch()},S=t(null),C=y.data;f(()=>{if(e===void 0||S.current===e)return;let t=C?.find(t=>t.id===e&&W(t)===`code`);t!==void 0&&(S.current=e,m({mode:`edit`,block:t}))},[e,C]),f(()=>{r&&(m({mode:`edit`,block:null}),n?.(null),a?.())},[r,a,n]);let w=u({mutationFn:e=>o.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),T=u({mutationFn:e=>o.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{m({mode:`edit`,block:e.block}),n?.(e.block.id),x()}}),E=u({mutationFn:e=>o.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{g(null),x()}}),D=u({mutationFn:e=>o.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:x}),O=u({mutationFn:e=>o.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:x}),k=vn((y.data??[]).filter(e=>W(e)===`code`)),A=y.data!==void 0&&k.length===0,j=w.isPending||T.isPending,M=w.error===null?T.error===null?null:$(T.error):$(w.error),N=c.mode===`edit`&&c.block!==null?_n(k,c.block):null,P=c.mode===`edit`;return i(`div`,{className:`space-y-3`,children:[!P&&d(`p`,{className:`text-xs text-foreground-subtle`,children:y.data===void 0?``:yn(k)}),y.error!=null&&d(H,{title:`Could not read the scripts`,message:$(y.error),onRetry:x}),P&&d(`div`,{className:`min-h-[70vh]`,"data-testid":`script-editor-panel`,children:d(Gi,{existing:N,typeDefs:b.data,typeDefsLoading:b.isLoading,saving:j,saveError:M,restarting:O.isPending,restartError:O.error===null?null:$(O.error),onRestart:N===null?void 0:()=>O.mutate(N.id),onSave:e=>{let t=N;t===null?w.mutate(e):T.mutate({blockId:t.id,block:e})},onCancel:()=>{w.reset(),T.reset(),O.reset(),m({mode:`closed`}),n?.(null)}})}),!P&&A&&d(B,{children:i(`div`,{className:`space-y-1 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),!P&&k.length>0&&d(B,{children:d(`ul`,{className:`divide-y divide-border`,"data-testid":`scripts-list`,children:k.map(e=>d(Zi,{block:e,busy:D.isPending||E.isPending,restarting:O.isPending&&O.variables===e.id,confirming:h===e.id,logsOpen:_===e.id,onToggle:t=>D.mutate({blockId:e.id,enabled:t}),onRestart:()=>O.mutate(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onEdit:()=>{m({mode:`edit`,block:e}),n?.(e.id)},onAskDelete:()=>g(e.id),onCancelDelete:()=>g(null),onConfirmDelete:()=>E.mutate(e.id)},e.id))})}),E.error!=null&&d(H,{message:$(E.error)}),D.error!=null&&d(H,{message:$(D.error)}),O.error!=null&&d(H,{message:$(O.error)})]})}function Zi({block:e,busy:t,restarting:n,confirming:r,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:f,onConfirmDelete:p}){let m=hn(e),h=R(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(P,{variant:gn(m.tone),children:m.label}),d(P,{variant:`info`,children:e.placement}),h!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,h]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:m.detail})]}),r?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),d(V,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),d(V,{variant:`ghost`,onClick:f,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(V,{variant:`ghost`,onClick:l,title:`Edit`,children:d(M,{className:`h-4 w-4`})}),d(V,{variant:`ghost`,onClick:s,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:d(de,{className:`h-4 w-4${n?` animate-spin`:``}`})}),d(V,{variant:`ghost`,onClick:c,title:`Logs`,children:d(ne,{className:`h-4 w-4`})}),d(V,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(V,{variant:`ghost`,onClick:u,title:`Delete`,children:d(g,{className:`h-4 w-4`})})]})]}),a&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:U(e.id)})]}),d(se,{addonId:U(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qi=[`automations`,`scripts`,`custom-device`];function $i(e){return e!==null&&Qi.some(t=>t===e)}var ea=[`coreBlocks`,`list`,`build-counts`];function ta(e){return e.filter(e=>W(e)===`code`).length}function na(e){return e.filter(e=>Re(e.code)).length}function ra(){let e=p(),[t,n]=Te(),r=t.get(`tab`),a=$i(r)?r:`automations`,o=t.get(`create`)===`1`,c=s({queryKey:ea,refetchInterval:5e3,queryFn:async()=>(await e.trpcClient.coreBlocks.list.query({})).blocks}).data,l=c===void 0?null:ta(c),u=c===void 0?null:na(c),f=s({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>e.trpcClient.coreBlocks.listCompositions.query({})}),m=f.data?.state===`loaded`?f.data.views.length:null,h=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=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},y=()=>{n(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},b=()=>{n(e=>{let t=new URLSearchParams(e);return t.delete(`create`),t},{replace:!0})};return d(Me,{icon:C,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,actions:a===`custom-device`?void 0:i(V,{type:`button`,onClick:y,"data-testid":`build-new`,children:[d(L,{className:`h-4 w-4`}),` `,a===`automations`?`New automation`:a===`scripts`?`New script`:`New composition`]}),children:i(k,{value:a,onValueChange:h,children:[i(w,{children:[i(D,{value:`automations`,children:[`Automations`,u===null?``:` (${String(u)})`]}),i(D,{value:`scripts`,children:[`Scripts`,l===null?``:` (${String(l)})`]}),i(D,{value:`custom-device`,children:[`Custom Device`,m===null?``:` (${String(m)})`]})]}),d(x,{value:`automations`,children:d(Tn,{onOpenScripts:g,initialBlockId:a===`automations`?t.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:a===`automations`&&o,onCreateConsumed:b})}),d(x,{value:`scripts`,children:d(Xi,{initialBlockId:a===`scripts`?t.get(`block`)??void 0:void 0,onBlockIdChange:v,createRequested:a===`scripts`&&o,onCreateConsumed:b})}),d(x,{value:`custom-device`,children:d(Gn,{})})]})})}export{ra as BuildPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l,gt as u,ht as d,st as f,vt as p}from"./player-overlays-BzWBMmxi.js";import{Br as m,Cl as h,Fn as g,Fr as _,Hr as v,Id as y,Ir as b,Lr as x,Mr as S,Nr as C,Oc as w,Pr as T,Pu as E,Rd as D,Rr as O,Su as k,Uu as A,Vr as j,bu as M,dd as N,fc as P,fd as F,gd as I,hc as L,hr as R,jr as ee,mc as te,pc as ne,pu as z,rd as re,tc as ie,xu as ae,zd as oe,zr as se}from"./src-DryjbkTc.js";import{t as ce}from"./archive-Cr-BIlNA.js";import{t as B}from"./circle-slash-iHyT1430.js";import{a as V,c as H,l as U,n as W,o as G,s as le,t as ue,u as de}from"./location-owned-usage-Cn8KruJL.js";import{t as fe}from"./hard-drive-download-C-k_wqAM.js";import"./mount-C7bibG8k.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{n as pe}from"./authed-media-Dsq6dhVf.js";import{t as me}from"./AdminTabs-8K5IGAB8.js";import{t as q}from"./format-size-DIxKXxtj.js";var he=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ge=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function _e(){let e=a(),t=g(),{data:i,isLoading:c,isError:l}=L({}),u=te(),d=r(()=>u.data??[],[u.data]),{data:f}=ie({},{refetchOnWindowFocus:!1}),p=r(()=>ue(i??[],f?.locations),[i,f?.locations]),{data:m}=ne({},{refetchOnWindowFocus:!1}),h=r(()=>V(m),[m]),[_,v]=o(null),[y,b]=o(null),x=P({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=w({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),C=async(e,n)=>{U(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${H(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||S.mutate(le(e,{mode:n}))},T=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await x.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&x.mutate({id:e.id,force:!0})}},E=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(K,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(W,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>v(e),onEdit:e=>b(e),onDelete:e=>{T(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{C(e,t)}},e.id))]}),_!==null&&s(de,{initialType:_,onClose:()=>v(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),v(null)}}),y!==null&&s(G,{location:y,onClose:()=>b(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),b(null)}})]})}t();var ve=[[`backup`,`listDestinations`]],ye=[`backup`,`listArchives`];function be({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=g(),{data:d,isLoading:p,isError:m}=_({destinationId:t}),h=d??[],v=S({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ye]]}),l.invalidateQueries({queryKey:ve})}}),y=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({destinationId:t,backupId:e.id})},[u,t,v]),[b,x]=o(null),C=e(async e=>{x(e.id);try{let n=await pe(xe(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[t]),w=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):w.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:w.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Se(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:q(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{C(e)},disabled:b===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[b===e.id?s(E,{className:`h-3 w-3 animate-spin`}):s(re,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(z,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{y(e)},disabled:v.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:v.isPending?s(E,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function xe(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Se(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function Ce({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=O(),l=i??[],u=b().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(we,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function we({row:t,destById:l,isOpen:p,onToggle:m,onEdit:h,onOpenRestoreWizard:_}){let y=a(),b=g(),x=v({onSuccess:()=>{y.invalidateQueries({queryKey:J})}}),S=C({onSuccess:()=>{y.invalidateQueries({queryKey:J})}}),w=j({onMutate:()=>{y.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{y.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),y.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),y.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[T,D]=o(String(t.retentionCount));c(()=>{D(String(t.retentionCount))},[t.retentionCount]);let O=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),A=e(e=>{x.mutate({...O,enabled:e})},[x,O]),M=e(()=>{let e=Number.parseInt(T,10);if(Number.isNaN(e)||e<1){D(String(t.retentionCount));return}e!==t.retentionCount&&x.mutate({...O,enabled:t.enabled,retentionCount:e})},[x,O,T,t.retentionCount,t.enabled]),N=e(()=>{t.locationIds.length!==0&&w.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[w,t]),P=e(async()=>{await b({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&S.mutate({id:t.id})},[b,S,t.id,t.label]),F=t.cron.trim().length>0,I=x.isPending||S.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:m,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:p?`Hide archives`:`Show archives`,children:s(p?u:d,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:h,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:I,onChange:e=>A(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:T,disabled:I,onChange:e=>D(e.target.value),onBlur:M,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&D(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:h,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(he,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:F?t.cron:`Manual`})]}),F&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:N,disabled:w.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[w.isPending?s(E,{className:`h-3 w-3 animate-spin`}):s(ae,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:h,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(k,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{P()},disabled:I,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(f,{className:`h-3 w-3`})})]})})]}),p&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(be,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,..._?{onOpenRestoreWizard:_}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Te(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Ee({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Te(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=ke(e,250),f=se({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(De,{cron:d,preview:p,loading:f.isFetching})]})}function De({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(E,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Oe(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function Oe(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ke(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ae=[[`backup`,`listSchedules`]];function je({entry:e,onClose:t,onSaved:i}){let c=a(),l=b(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[g,_]=o(e?.enabled??!0),[y,x]=o(String(e?.retentionCount??7)),[S,C]=o(new Set(e?.locationIds??[])),w=v({onSuccess:()=>{c.invalidateQueries({queryKey:Ae}),i()}}),T=e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(y,10),O=r(()=>d.trim().length>0&&S.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[d,S,D]),k=()=>{O&&w.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:g,locationIds:Array.from(S),retentionCount:D})},A=w.error instanceof Error?w.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(h,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,S.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(E,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:S.has(e.id),onChange:()=>T(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:y,onChange:e=>x(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(Ee,{value:p,onChange:m,disabled:w.isPending})]}),A&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:A})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:k,disabled:!O||w.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[w.isPending&&s(E,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Me=2e3,Ne=5e3;function X(e){return e.state===`queued`||e.state===`running`}function Pe(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Fe(){let t=g(),[n,r]=o(null),i=x(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Me:Ne}),a=ee({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pe(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Ie,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Ie({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Le,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Le({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(Re,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(ze,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Be,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ve,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(E,{className:`h-3 w-3 animate-spin`}):s(y,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Re({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(N,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(E,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(I,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(F,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(B,{className:`h-3 w-3`}),`Stopped`]})}}function ze({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:He(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(fe,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(ge,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),t===void 0?``:` / ${q(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[q(t),` archive`]})}function Be({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Ve({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function He(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ue=[[`backup`,`list`]];function We({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,g]=o(e),[v,y]=o(t),[x,S]=o(new Set),{data:C}=b(),w=C??[],{data:O,isLoading:k}=_({destinationId:p??``},{enabled:!!p}),A=O??[];c(()=>{if(p!==void 0)return;let e=w.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[p,w]);let{data:j}=T({destinationId:p??``,backupId:v??``},{enabled:!!p&&!!v}),M=r(()=>j?.locations??[],[j]);c(()=>{M.length!==0&&S(e=>e.size===0?new Set(M):e)},[M]);let N=m({onSuccess:()=>{u.invalidateQueries({queryKey:Ue}),l(),i()}}),P=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=!!p&&!!v,I=x.size>0,L=F&&I&&!N.isPending,R=()=>{!p||!v||N.mutate({destinationId:p,backupId:v,locations:[...x]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(h,{className:`h-4 w-4`})})]}),d===1&&s(Ge,{destinations:w,destinationId:p,onPickDestination:e=>{g(e),y(void 0),S(new Set)},archives:A,archivesLoading:k,archiveId:v,onPickArchive:y}),d===2&&s(Ke,{locations:M,picked:x,onToggle:P}),d===3&&s(qe,{destinationName:w.find(e=>e.id===p)?.displayName??p??``,archive:A.find(e=>e.id===v),picked:[...x]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(oe,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!F||d===2&&!I,onClick:()=>f(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(D,{className:`h-3 w-3`})]}):n(`button`,{onClick:R,disabled:!L,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[N.isPending?s(E,{className:`h-3.5 w-3.5 animate-spin`}):s(z,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Ge({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Ke({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ye(e)})]},e))})]})]})}function qe({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Je={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ye(e){return Je[e]??``}t();function Xe(){let e=g(),t=R(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(K,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(z,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(M,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(z,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(E,{className:`h-3.5 w-3.5 animate-spin`}):s(z,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Fe,{}),s(Ce,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(je,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(We,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}function Ze(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`storage`,label:`Storage`,icon:A,content:s(_e,{})},{id:`backup`,label:`Backup`,icon:ce,content:s(Xe,{})}]})})}export{Ze as DataPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}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 u,ct as d,ft as f,gt as p,ht as m,st as h,vt as g}from"./player-overlays-BzWBMmxi.js";import{Aa as _,Ca as v,Cl as y,Cn as b,Da as x,Ea as S,Fn as C,Il as w,Jt as T,Ki as E,Kt as D,Ma as O,Na as k,Oa as A,Pa as ee,Pl as j,Pu as M,Qt as N,Rl as P,Sa as F,Su as I,Ta as L,Un as R,Xt as z,Yt as B,Zt as V,bl as H,bu as U,ja as W,ka as G,lu as K,mu as q,pu as te,ql as ne,tn as J,wa as re,wn as Y,xd as ie}from"./src-DryjbkTc.js";import{i as ae,n as oe,r as se,t as ce}from"./face-bbox-G6Z1voG1.js";import{t as X}from"./square-check-big-Cye5KH4u.js";import{t as Z}from"./user-round-BjVxqy86.js";import{Gr as le}from"./client-USvucJT_.js";import{L as ue}from"./index-CV0bhG27.js";import{t as de}from"./AdminPage-CiKtOLQm.js";import{n as fe,r as pe}from"./authed-media-Dsq6dhVf.js";import{a as me,c as he,f as ge,i as _e,l as ve,n as ye,o as be,p as xe,r as Se,s as Ce,t as we,u as Te}from"./debounced-invalidate-BJmaQT-4.js";var Ee=g(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]);n();var De=`pipeline-analytics`,Oe=`photo.analyze`,ke=`photo.enroll`,Ae=`photo.discard`,je=18*1024*1024;function Me(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ne(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pe(e){if(!Me(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Fe(e){if(!Me(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ie(e){if(!Me(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Ne(e,`enrollable`),i=Pe(e.bbox),a=Fe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Le(e){if(!Me(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ie(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Re(e){if(!Me(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ze(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Be(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ve(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function He(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function Ue(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function We(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Ge(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ke(e,t){return`${e}:${t}`}function qe(e,t,n,r){let i=ze(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Je(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Be(r.analysis.faces,t[r.photoIndex]??{}));return n}var Ye=`__new__`;function Xe(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Ke(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Ze(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Ke(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Qe(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ve(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function $e(e){return/expired/i.test(e)}function et(e){return e instanceof Error?e.message:String(e)}async function tt(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Qe(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=et(t);if(!$e(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${et(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${et(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var nt=[[`faceGallery`]],rt=``;function it(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function at(e){return e instanceof Error?e.message:String(e)}function ot({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:rt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Ye,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Z,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(b,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(R,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:He(e.refusedReason)})]})]})}function st({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(M,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(Y,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(te,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(P,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(ot,{face:e,identities:t,value:d[e.faceIndex]??rt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Ye).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ke(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function ct({open:n,onOpenChange:a}){let l=u(),d=o(),f=t(null),{data:p}=x(),m=v(),[h,g]=s([]),[_,y]=s(!1),[b,S]=s(null),[C,w]=s({}),[E,O]=s({}),[k,A]=s(null),ee=i(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),j=h.some(e=>e.status===`queued`||e.status===`analyzing`),F=j||_,I=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:De,action:Ae,input:{sessionId:e}}).catch(()=>void 0)}},[l]),L=e(()=>{g([]),w({}),O({}),S(null),A(null),f.current&&(f.current.value=``)},[]),R=e(()=>{I(h),L(),a(!1)},[I,a,h,L]),H=e(async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:De,action:Oe,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{g(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);g(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[H]),W=e(async e=>{if(e.length===0)return;I(h),L();let t=Ue(e,{maxCount:12,maxBytes:je}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(je/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&S(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await it(e),status:`queued`})))}catch(e){S(at(e));return}g(r),await We(r,2,e=>U(e))},[I,h,L,U]),G=Je(h,C),K=e(async()=>{y(!0),S(null),A(null);try{let e=Xe(h,C,E);if(e.kind===`error`){S(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await tt(h,Ze(C,E,t),{enroll:async e=>{let t=Re(await l.trpcClient.addons.custom.mutate({addonId:De,action:ke,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:nt}),n.failures.length>0&&S(n.failures.join(` · `)),A(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){S(at(e))}finally{y(!1)}},[H,m,C,E,h,d,l]),q=h.filter(e=>e.status===`analyzed`).length;return c(D,{open:n,onOpenChange:e=>e?a(!0):R(),children:r(T,{className:`max-w-3xl`,children:[r(V,{children:[c(N,{children:`Enrol from photos`}),c(B,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void W(Array.from(e.target.files??[]))}),r(Y,{variant:`secondary`,size:`sm`,disabled:F,onClick:()=>f.current?.click(),children:[j?c(M,{className:`h-3.5 w-3.5 animate-spin`}):c(Ee,{className:`h-3.5 w-3.5`}),`Choose photos`]}),h.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[q,`/`,h.length,` photo`,h.length===1?``:`s`,` analysed`]})]}),b!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(P,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:b})]}),k!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:k}),h.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>c(st,{photo:e,identities:ee,draft:C,newNames:E,disabled:F,onAssign:(t,n)=>w(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>O(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(z,{children:[c(Y,{variant:`secondary`,onClick:R,disabled:_,children:`Close`}),r(Y,{variant:`primary`,onClick:()=>void K(),disabled:F||G===0,children:[_?c(M,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,G,` face`,G===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=A({identityId:e}),a=_();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:lt})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(M,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Z,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(Ee,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:c(y,{className:`h-4 w-4 text-white`})})]},e.id))})}function dt({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[d,f]=s(!1),[g,_]=s(!1),v=W(),b=L();function x(){u(e.name),f(!0)}function S(){f(!1),u(``)}function C(){let t=l.trim();if(!t||t===e.name){S();return}v.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),S()}})}function w(){b.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),_(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:c(oe,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Z,{className:`h-4 w-4 text-foreground-subtle`})})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(a,{children:[c(J,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&S()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:C,disabled:v.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(ie,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:S,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(y,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(R,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:x,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(I,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>_(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(h,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?p:m,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(ut,{identityId:e.id})}),c(D,{open:g,onOpenChange:e=>!e&&_(!1),children:r(T,{children:[r(V,{children:[c(N,{children:`Delete person`}),r(B,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(z,{children:[c(Y,{variant:`secondary`,onClick:()=>_(!1),children:`Cancel`}),r(Y,{variant:`danger`,onClick:w,disabled:b.isPending,children:[b.isPending?c(M,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=v();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:lt}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(J,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(Y,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(M,{className:`h-3.5 w-3.5 animate-spin`}):c(U,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=x(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(M,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(dt,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(ft,{}),c(`div`,{className:`pt-1`,children:r(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(Ee,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(ct,{open:a,onOpenChange:o})]})}function mt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function ht(e){return e.filter(mt).map(e=>e.faceId)}function gt(e){let t=0;for(let n of e)mt(n)&&(t+=1);return t}function _t(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var vt=[[`faceGallery`]];function yt({faceIds:e,identities:t,onDone:n}){let i=o(),a=F(),l=v(),[u,d]=s(``),[f,p]=s(!1),[m,h]=s(null),g=e!==null&&e.length>0,_=e?.length??0;function y(){p(!1),d(``),h(null)}function b(){y(),n()}function x(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),b()}})}function S(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),b()}})}let C=a.isPending||l.isPending;return c(D,{open:g,onOpenChange:e=>!e&&b(),children:r(T,{children:[r(V,{children:[c(N,{children:_>1?`Assign ${String(_)} faces to person`:`Assign face to person`}),c(B,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),f?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(J,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{h(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),r(z,{children:[c(Y,{variant:`secondary`,onClick:b,disabled:C,children:`Cancel`}),f?r(Y,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&c(M,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(Y,{variant:`primary`,onClick:()=>m&&x(m),disabled:C||!m,children:[C&&c(M,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}n();function bt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await fe(pe(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function xt(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function St({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Ct({box:e}){return c(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function wt({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:p}=S({faceId:e?.faceId??``},{enabled:e!==null}),[m,g]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:b,failed:x}=bt(e?.keyFrameMediaId),C=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),w=i(()=>!e?.faceBbox||v===null||b===null?null:ce(e.faceBbox,v,b),[e?.faceBbox,v,b]);if(e===null)return null;let E=e.keyFrameMediaId!==void 0&&!x,O=E&&m===`frame`,k=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(D,{open:!0,onOpenChange:e=>!e&&n(),children:r(T,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(y,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[E&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(K,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ae,{className:`h-3.5 w-3.5`}),` Crop`]})]}),O&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(ye,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:w?c(Ct,{box:w}):void 0})}):C?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(ye,{src:C,alt:`Detected face`,className:`h-full w-full`}),p&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(M,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[c(f,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(St,{label:`Camera`,value:t}),c(St,{label:`Captured`,value:xe(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:k})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(Y,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(se,{className:`h-3.5 w-3.5`}),` Detach`]}):r(Y,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(j,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Tt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Et(e,t){return e.faceIds.filter(e=>!t.has(e))}function Dt(e,t){return e.faceIds.filter(e=>t(e))}n();var Ot=[[`faceGallery`]],kt=20,At=.3,jt=.9,Mt=.05,Nt=.5,Pt=2,Ft=10,It=2;function Lt({cluster:e,face:t,active:n,onSelect:i}){let a=_t(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(f,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Rt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(f,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(ye,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?w:y,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ge(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?c(M,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})})]})}function zt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let m=o(),h=C(),g=re(),[_,v]=s(Nt),[b,x]=s(It),[S,w]=s(null),[E,k]=s({}),[A,ee]=s(null),{data:N,isFetching:P,refetch:F}=O({threshold:_,minClusterSize:b,limit:kt},{enabled:e}),I=N??[];l(()=>{k({})},[_,b]),l(()=>{if(I.length===0){w(null);return}I.some(e=>e.representativeFaceId===S)||w(I[0]?.representativeFaceId??null)},[I]);let L=i(()=>I.find(e=>e.representativeFaceId===S)??null,[I,S]),R=L?E[L.representativeFaceId]??new Set:new Set,z=i(()=>L?Dt(L,e=>n.has(e)):[],[L,n]),B=L?L.faceIds.length-z.length:0,V=L?Et({...L,faceIds:z},R):[];function H(e){if(!L)return;let t=L.representativeFaceId;k(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function U(){m.invalidateQueries({queryKey:Ot})}async function W(e){await h({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({faceId:e},{onSettled:U})}function G(){ee(null),t()}function K(){V.length!==0&&(p(V),G())}return r(D,{open:e,onOpenChange:e=>!e&&G(),children:[r(T,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(ne,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(y,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:At,max:jt,step:Mt,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:_.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Pt,max:Ft,step:1,value:b,onChange:e=>x(Math.min(Ft,Math.max(Pt,Number(e.target.value)||Pt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(Y,{variant:`secondary`,onClick:()=>{k({}),F()},disabled:P,children:[P?c(M,{className:`h-3.5 w-3.5 animate-spin`}):c(q,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(M,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[B>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[B,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>H(e),onDelete:()=>void W(e),deletePending:g.isPending&&g.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[c(Y,{variant:`secondary`,onClick:K,disabled:V.length===0,children:`Select in gallery`}),r(Y,{variant:`primary`,onClick:()=>ee(V),disabled:V.length===0,children:[c(j,{className:`h-3.5 w-3.5`}),` Adopt (`,V.length,`)`]})]})]}),c(yt,{faceIds:A,identities:f,onDone:()=>ee(null)})]})}n();var Bt=[[`faceGallery`]],Vt=500,Ht=120;function Ut({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),p=k(),m=re(),g=()=>{u.invalidateQueries({queryKey:Bt})},_=()=>l(e.faceId),v=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[v===null?r(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[c(f,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:v,alt:`Face from ${t}`,onClick:_,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?c(X,{className:`h-4 w-4 text-primary`}):c(d,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ge(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:g})},disabled:p.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:p.isPending?c(M,{className:`h-4 w-4 animate-spin`}):c(se,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:c(j,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),m.mutate({faceId:e.faceId},{onSettled:g})},disabled:m.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:m.isPending?c(M,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})]})]})}var Wt=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Gt(){let e=o(),[t,n]=s(`all`),[l,u]=s(Ce),[d,p]=s(new Set),[m,g]=s(new Set),[_,v]=s(null),[b,S]=s(!1),[C,w]=s(null),{data:T,isLoading:D}=G({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:O=[]}=x(),{data:A}=E({isCamera:!0,projection:`slim`}),N=F(),P=k(),I=ee(),L=re(),R=Date.now(),z=T??[],B=i(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),V=e=>B.get(e)??`Camera #${String(e)}`,H=i(()=>he(z).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,B]),U=i(()=>ve(Te(z,l),d),[z,l,d]),W=be(U,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),K=i(()=>new Map(z.map(e=>[e.faceId,e])),[z]),q=i(()=>gt(U),[U]),te=C===null?null:K.get(C)??null,J=()=>{e.invalidateQueries({queryKey:Bt})},ie=()=>g(new Set);function ae(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ce(){oe(ht(U))}let X=[...m],Z=N.isPending||I.isPending||L.isPending,le=P.isPending||L.isPending;function ue(){X.length!==0&&I.mutate({faceIds:X},{onSettled:()=>{J(),ie()}})}function de(){X.length!==0&&Promise.allSettled(X.map(e=>L.mutateAsync({faceId:e}))).then(()=>{J(),ie()})}function fe(e){w(null),v([e])}function pe(e){P.mutate({faceId:e},{onSettled:J}),w(null)}function ge(e){L.mutate({faceId:e},{onSettled:J}),w(null)}let ye=U.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Wt.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(Se,{onChange:u}),c(_e,{cameras:H,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ne,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!D&&q>0&&r(`button`,{type:`button`,onClick:ce,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[c(f,{className:`h-3.5 w-3.5`}),` Select `,q,` crop-less`]}),!D&&c(`span`,{className:`text-[10px] text-foreground-subtle ${q>0?`ml-2`:`ml-auto`}`,children:ye?`${String(U.length)} of ${String(z.length)} faces`:`${String(U.length)} face${U.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(Y,{variant:`primary`,onClick:()=>v(X),disabled:Z,children:[c(j,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:ue,disabled:Z,children:[I.isPending?c(M,{className:`h-3.5 w-3.5 animate-spin`}):c(se,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(Y,{variant:`secondary`,onClick:de,disabled:Z,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]}),c(Y,{variant:`ghost`,onClick:ie,disabled:Z,children:c(y,{className:`h-3.5 w-3.5`})})]})]}),D&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(M,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!D&&U.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:z.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!D&&U.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:W.pageItems.map(e=>c(Ut,{face:e,cameraName:V(e.deviceId),nowMs:R,selected:m.has(e.faceId),onToggleSelect:ae,onAssign:e=>v([e]),onOpenDetail:w},e.faceId))}),c(me,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`faces`})]}),c(wt,{face:te,cameraName:te?V(te.deviceId):``,onClose:()=>w(null),onAssign:fe,onUnassign:pe,onDelete:ge,actionsPending:le}),c(yt,{faceIds:_,identities:O,onDone:()=>{v(null),ie()}}),c(zt,{open:b,onClose:()=>S(!1),byId:K,cameraName:V,nowMs:R,identities:O,selectMany:oe})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=we({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),H(le.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(de,{icon:ue,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(pt,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Gt,{})]})]})})}export{Yt as DetectionIntelligencePage};
|