@camstack/addon-admin-ui 1.2.47 → 1.2.49
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/{AddLocationWizard-D8Izx1gh.js → AddLocationWizard-BJu3mtSw.js} +1 -1
- package/dist/assets/{AddonCollectionPage-DqaifWMB.js → AddonCollectionPage-CK4v9jSU.js} +1 -1
- package/dist/assets/Addons-Dnx44V_o.js +1 -0
- package/dist/assets/{AdminTabs-qMC1WN7t.js → AdminTabs-BjQnY4OV.js} +1 -1
- package/dist/assets/{AiProfiles-CkaDb5G-.js → AiProfiles-Tiz5n9gM.js} +1 -1
- package/dist/assets/{BrokerForm-nGOoPwcx.js → BrokerForm-CUTNnLfC.js} +1 -1
- package/dist/assets/Build-BRIKYrPw.js +32 -0
- package/dist/assets/{Capabilities-BvTJQt-3.js → Capabilities-DmsUSTXd.js} +1 -1
- package/dist/assets/{CapabilityBadges-74hb8M82.js → CapabilityBadges-Da9_ag1O.js} +1 -1
- package/dist/assets/{Cluster-BdYYMi89.js → Cluster-BmsvZJvy.js} +1 -1
- package/dist/assets/{Data-D8MGzmyj.js → Data-H8wE3b6C.js} +1 -1
- package/dist/assets/DetectionIntelligence-I9-ie1ja.js +1 -0
- package/dist/assets/{DeviceAggregateSection-Tq3TjsO-.js → DeviceAggregateSection-D1VtHpJo.js} +1 -1
- package/dist/assets/DeviceDetail-DV8r8vC8.js +2 -0
- package/dist/assets/{Devices-DQeFVfTP.js → Devices-rXat7KjL.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B2geI7HH.js → EmbedPlayerPage-DNvt-aaI.js} +1 -1
- package/dist/assets/Events-FgGu0qQ0.js +1 -0
- package/dist/assets/{FormBuilder-_oFQtE7x.js → FormBuilder-D4TCK09f.js} +1 -1
- package/dist/assets/{Identity-B9xM3PPQ.js → Identity-C7zrPYT4.js} +1 -1
- package/dist/assets/{IntegrationDetail-D6srOD52.js → IntegrationDetail-Blpd6T8m.js} +1 -1
- package/dist/assets/{Integrations-D5GsA0v6.js → Integrations-C21FuAge.js} +1 -1
- package/dist/assets/{Integrations-BMDYnEUm.js → Integrations-CWOM_mMA.js} +1 -1
- package/dist/assets/{Logs-Cr3usRtb.js → Logs-CNmLN2Va.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BgF0ipHJ.js → MotionZonesSettings-Dok-N0KG.js} +1 -1
- package/dist/assets/{MyAccess-COg9lyIf.js → MyAccess-DyujbjpW.js} +1 -1
- package/dist/assets/{Network-DzuA8p3Z.js → Network-Ct57a8tW.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BAVG1LEY.js → NodeAddonsSettingsPanel-BVpPQh6Y.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CcxOtvMd.js → NodeInferenceDevices-DciF7oLw.js} +1 -1
- package/dist/assets/Notifications-OJ3PnTPK.js +1 -0
- package/dist/assets/Pipeline-eSN-kICU.js +1 -0
- package/dist/assets/Plates-DWVIZ4YS.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-yOIEXwrU.js → PrivacyMaskSettings-CUaRx10f.js} +1 -1
- package/dist/assets/{ProviderIcon-Ck_2pUvf.js → ProviderIcon-nTPdMviY.js} +1 -1
- package/dist/assets/Recordings-BkZiVZTc.js +1 -0
- package/dist/assets/{ScanNetworkModal-D2dbax7J.js → ScanNetworkModal-DBfj4Bdm.js} +1 -1
- package/dist/assets/{Settings-n3YjyvD9.js → Settings-BxZlSYcW.js} +1 -1
- package/dist/assets/{Showroom-kb37ihHy.js → Showroom-BwtVPGmm.js} +1 -1
- package/dist/assets/{Terminal-DPgh1LOa.js → Terminal-D-FupEae.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DD9SArM5.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DOJdLj_I.js} +1 -1
- package/dist/assets/{boxes-0BrwpGRK.js → boxes-DvSDRyF7.js} +1 -1
- package/dist/assets/{build-cluster-graph-CNmW9-To.js → build-cluster-graph-DyYa_05V.js} +1 -1
- package/dist/assets/circle-check-big-FWiOlzic.js +1 -0
- package/dist/assets/{circle-x-CeSEyt9j.js → circle-x-DtQPDgsE.js} +1 -1
- package/dist/assets/clock-DHnCdO7L.js +1 -0
- package/dist/assets/{copy-CLkoN4vv.js → copy-BfSZhaqH.js} +1 -1
- package/dist/assets/{debounced-invalidate-CjozCZrp.js → debounced-invalidate-6ffK2Oyp.js} +1 -1
- package/dist/assets/{dist-5MqZUHpg.js → dist-35X66BEr.js} +1 -1
- package/dist/assets/dist-IhEsNjtp.js +345 -0
- package/dist/assets/{download-D2kk10ws.js → download-BYiYWbFt.js} +1 -1
- package/dist/assets/{face-bbox-Dd_CKaP5.js → face-bbox-CnPEtuY2.js} +1 -1
- package/dist/assets/{hard-drive-YgwGO7Iy.js → hard-drive-DrH4p5NE.js} +1 -1
- package/dist/assets/{hostInit-DQHnlGm4.js → hostInit-CyX7yag6.js} +1 -1
- package/dist/assets/{index-qYnug9Qs.js → index-BQrlv_je.js} +3 -3
- package/dist/assets/{key-round-58wJWtml.js → key-round-dZ1BFcdp.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-d57082e0.js → mf-entry-bootstrap-0-9f224a8e.js} +2 -2
- package/dist/assets/{pencil-DDNEW9Yb.js → pencil-Bz_ZrJOa.js} +1 -1
- package/dist/assets/play-BlvH1l2D.js +1 -0
- package/dist/assets/{player-overlays-BzwYRH08.js → player-overlays-COkjFkib.js} +1 -1
- package/dist/assets/plus-C5i2pOFJ.js +1 -0
- package/dist/assets/power-w9jdL6aH.js +1 -0
- package/dist/assets/{radio-M8jdl_tl.js → radio-Db7gl-zS.js} +1 -1
- package/dist/assets/{refresh-cw-CYEUy6Ve.js → refresh-cw-CGyy1yV7.js} +1 -1
- package/dist/assets/remoteEntry-C6r9GH5z.js +1 -0
- package/dist/assets/rotate-ccw-DC6Yovo0.js +1 -0
- package/dist/assets/rotate-cw-DLAOZ01F.js +1 -0
- package/dist/assets/search-BFiLJvvR.js +1 -0
- package/dist/assets/{send-DeNrNMe8.js → send-BRkSGin7.js} +1 -1
- package/dist/assets/{server-C3tpWUwZ.js → server-BQv2rJCm.js} +1 -1
- package/dist/assets/square-DVLwx5hK.js +1 -0
- package/dist/assets/{square-check-big-DEqd8dem.js → square-check-big-Ga52OEfa.js} +1 -1
- package/dist/assets/src-Di5BmOTg.js +345 -0
- package/dist/assets/src-bB3TQU8X.js +67 -0
- package/dist/assets/{undo-2-BnRU8pkW.js → undo-2-J1RIT6Px.js} +1 -1
- package/dist/assets/{upload--4mqPfVH.js → upload-BvwaLd2o.js} +1 -1
- package/dist/assets/{useEventInvalidation-XgGxFYwt.js → useEventInvalidation-BsKdSBfH.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cl2xnNlc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BJpuTutd.js} +2 -2
- package/dist/assets/{wifi-C8Oz0yjQ.js → wifi-DQcK0Biw.js} +1 -1
- package/dist/assets/{zap-BQjibRA6.js → zap-B_NogjfF.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +109 -7
- package/package.json +1 -1
- package/dist/assets/Addons-Cbum2Ue7.js +0 -1
- package/dist/assets/Build-D4A-vNUJ.js +0 -32
- package/dist/assets/DetectionIntelligence-E410sfaW.js +0 -1
- package/dist/assets/DeviceDetail-Cyp63o9e.js +0 -2
- package/dist/assets/Events-tUp70vOo.js +0 -1
- package/dist/assets/Notifications-mGunk-af.js +0 -1
- package/dist/assets/Pipeline-YdFX0pzB.js +0 -1
- package/dist/assets/Plates-BZ8XXBRF.js +0 -1
- package/dist/assets/Recordings-DN2qpsF8.js +0 -1
- package/dist/assets/circle-check-big-CX86TDQ3.js +0 -1
- package/dist/assets/clock-dbqOPTlc.js +0 -1
- package/dist/assets/dist-Bayrm69X.js +0 -345
- package/dist/assets/play-rmom08n0.js +0 -1
- package/dist/assets/plus-DW_KHfhe.js +0 -1
- package/dist/assets/power-DV05ZWPi.js +0 -1
- package/dist/assets/remoteEntry-BAJ0ezfD.js +0 -1
- package/dist/assets/rotate-ccw-DTUvT-HV.js +0 -1
- package/dist/assets/rotate-cw-DWJibY6w.js +0 -1
- package/dist/assets/search-BVDP_pJD.js +0 -1
- package/dist/assets/square-C5l0pveB.js +0 -1
- package/dist/assets/src-BoczRE1G.js +0 -67
- package/dist/assets/src-Bok3PEiz.js +0 -345
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{At as e,Co as t,Ct as n,Dt as r,Et as i,Lr as a,Mt as o,Ot as s,St as c,Ur as l,_o as u,_t as d,bo as f,ft as p,g as m,gt as h,ht as g,jt as _,m as v,mt as y,pt as b,v as ee,vt as te,wt as ne,xt as re,yt as x}from"./src-BoczRE1G.js";import{I as S,K as C,Q as w,R as ie,S as T,W as E,b as D,o as ae,q as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as j}from"./src-Bok3PEiz.js";import{p as oe}from"./player-overlays-BzwYRH08.js";import{t as M}from"./clock-dbqOPTlc.js";import{t as N}from"./download-D2kk10ws.js";import{t as se}from"./plus-DW_KHfhe.js";import{t as P}from"./refresh-cw-CYEUy6Ve.js";import{t as ce}from"./search-BVDP_pJD.js";import{t as F}from"./upload--4mqPfVH.js";import{I,J as le,K as ue,L,M as de,S as R,W as z,g as B,i as V,m as fe,p as H,s as U}from"./index-qYnug9Qs.js";import{t as W}from"./AdminPage-Dq33XE9j.js";import{t as pe}from"./NodeAddonsSettingsPanel-BAVG1LEY.js";var me=z(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),G=z(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),he=z(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),K=z(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);w();var q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),J=new Set([`done`,`failed`,`skipped`]);function Y(e){return!J.has(e.phase)&&!q.has(e.jobState)}function ge(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=q.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function _e(){let{data:e}=re({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:n}=t(j.AddonsJobProgress,e=>e.job.jobId);return E(()=>{let t=new Map;for(let n of e??[])t.set(n.jobId,n);for(let[e,r]of n)t.set(e,r.job);return ge([...t.values()],Date.now())},[e,n])}var X={queued:{icon:M,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:R,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:R,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:R,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:R,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:R,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:R,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:L,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:G,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:K,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ve({progress:e}){let t=X[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return T(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,T(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function ye({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=d({name:e});return T(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[T(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[k(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),k(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:k(V,{className:`h-3 w-3`})})]}),s&&T(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[k(F,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),T(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[T(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,k(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&T(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[k(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&k(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=T(D,{children:[k(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&k(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),k(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?T(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`span`,{className:`w-3 shrink-0`})]},e.version):T(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!s?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:k(N,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&k(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var be={queued:{icon:M,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:R,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:P,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:L,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:G,bg:`bg-danger/10 text-danger`,label:`failed`}};function xe({item:e}){let t=be[e.status],n=t.icon;return T(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}w();var Z=`device-export`;function Se(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Z)}function Ce({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=O(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return T(`div`,{className:`relative flex-shrink-0`,children:[k(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?k(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):k(e?he:B,{className:`h-4 w-4`})}),t===`local`&&k(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&k(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:k(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:k(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&k(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:k(F,{className:`h-2.5 w-2.5 text-white`})})]})}function we({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return T(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[k(R,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return T(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[k(N,{className:`h-3 w-3`}),`Update`]}),T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[k(`span`,{className:`font-normal opacity-70`,children:e}),k(`span`,{className:`font-normal opacity-70`,children:`→`}),r,k(I,{className:`h-3 w-3`})]}),c]})}return T(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,i===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,k(I,{className:`h-3 w-3 opacity-50`})]}),c]})}function Te({addonId:e}){let t=ae(),{data:n=`inherit`}=y({addonId:e}),r=s({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return k(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>k(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function Ee({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:o,isUpdating:s,jobProgress:c,bundle:l,bulkItem:d,disabledByBulk:f,isSystem:p}){let[h,g]=O(!1),[y,b]=O(!1),[re,x]=O(!1),[S,C]=O(null);A(()=>{C(null)},[a]);let w=S??a,[ie,E]=O(!1),[j,M]=O(!1),[N,ce]=O(`logs`),F=ae(),le=oe(),L=ue(),de=u(),{manifest:R}=e,z=e.installedOn??[],B=!l&&!R.protected&&R.removable!==!1,W=!!l,K=l?.displayName??R.name,q=l?.packageName??R.packageName,J=l?.version??R.packageVersion??R.version,Y=l?.installSource??e.installSource,ge=l?l.bundle?.description??l.addons[0]?.manifest.description:R.description,_e=_({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=ne({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]})}}),be=te({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]}),F.invalidateQueries({queryKey:[[`integrations`]]})}}),Z=i({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`alerts`]]})}}),Q=e.health,De=Q?.phase===`failed`&&!Q.inGracePeriod,Oe=De&&Q?.nextRetryAt&&!Q.retrying;return T(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${De?`border-red-500/50`:`border-border`}`,children:[De&&Q&&T(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[k(G,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Q.retryCount,`)`]}),k(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Q.lastError?.message??`Unknown error`}),Oe&&Q.nextRetryAt&&T(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),T(`button`,{type:`button`,disabled:Z.isPending||Q.retrying,onClick:e=>{e.stopPropagation(),Z.mutate({packageName:q})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[k(P,{className:`h-3 w-3 ${Z.isPending||Q.retrying?`animate-spin`:``}`}),`Retry now`]})]}),T(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[k(Ce,{isBundle:W||!!R.components&&R.components.length>1,installSource:Y,addonId:W?l.addons[0]?.manifest.id:R.id,iconPath:W?l.bundle?.icon??l.addons[0]?.manifest.icon:R.icon,color:W?l.addons[0]?.manifest.color:R.color}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`flex items-start justify-between gap-2`,children:[k(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:K}),!r&&k(we,{version:J,availableUpdate:a,...w===void 0?{}:{selectedVersion:w},isUpdating:s,installSource:Y,disabled:f,...o&&w!==void 0?{onUpdate:()=>o(w)}:{},onOpenPicker:()=>x(e=>!e),children:re&&k(ye,{packageName:q,currentVersion:J,...Y?{installSource:Y}:{},...a!==void 0&&w!==void 0?{selectedVersion:w,onSelect:e=>{C(e),x(!1)}}:{},onInstall:e=>{x(!1),be.mutate({packageName:q,version:e})},onClose:()=>x(!1)})})]}),T(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[q!==K&&k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:q}),W&&T(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[k(he,{className:`h-3 w-3`}),l.addons.length]}),p&&T(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[k(P,{className:`h-3 w-3`}),`System`]}),d!=null&&k(xe,{item:d}),c!=null&&k(ve,{progress:c})]}),ge&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ge}),!W&&e.process&&T(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&T(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!W&&T(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:R.id})},disabled:X.isPending||f,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[k(P,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),E(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${ie?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[k(fe,{className:`h-3 w-3`}),`Logs`]}),!W&&T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),M(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${j?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[k(H,{className:`h-3 w-3`}),`Settings`]}),k(`div`,{className:`flex-1`}),B&&T(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await de({title:`Uninstall ${R.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&_e.mutate({packageName:R.packageName})},disabled:_e.isPending||f,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[k(U,{className:`h-3 w-3`}),_e.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!W&&T(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),k(`div`,{className:`space-y-1`,children:n.nodes.map(e=>T(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[k(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),k(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),k(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&k(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ie&&!W&&T(`div`,{className:`border-t border-border`,children:[T(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[T(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[k(`button`,{type:`button`,onClick:()=>ce(`logs`),className:`px-2 py-0.5 transition-colors ${N===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),k(`button`,{type:`button`,onClick:()=>ce(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${N===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),k(`div`,{className:`flex-1`}),k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),E(!1)},className:`text-foreground-subtle hover:text-foreground`,children:k(V,{className:`h-3.5 w-3.5`})})]}),N===`logs`&&k(m,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),N===`events`&&k(v,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),W&&T(D,{children:[k(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:k(h?me:I,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),h&&k(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:l.addons.map(e=>k(Ee,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),j&&!W&&k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>M(!1),children:T(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[T(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[T(`div`,{className:`flex items-center gap-2`,children:[k(H,{className:`h-4 w-4 text-primary`}),T(`h2`,{className:`text-sm font-semibold text-foreground`,children:[K,` Settings`]})]}),k(`button`,{onClick:()=>M(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:k(V,{className:`h-4 w-4`})})]}),T(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[k(pe,{nodeId:`hub`,addonIds:[R.id],level:`global`}),Se(R)&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),k(ee,{addonId:R.id,trpc:le.trpcClient,onOpenDevice:e=>L(`/devices/${e}`)})]}),Y===`npm`&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),k(Te,{addonId:R.id})]}),R.components&&R.components.length>0&&T(`div`,{children:[T(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),k(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>k(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),T(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>k(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),T(`div`,{className:`relative`,children:[T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[k(se,{className:`h-3 w-3`}),`Add agent`]}),y&&T(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&k(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),k(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:k(`button`,{type:`button`,onClick:()=>M(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}w();var Q=`.tgz,.tar.gz,.zip`;function De({onUploadSuccess:e}){let[t,n]=O(!1),r=C(null),i=S(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return T(D,{children:[k(`input`,{ref:r,type:`file`,accept:Q,onChange:S(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),T(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[t?k(R,{className:`w-3.5 h-3.5 animate-spin`}):k(F,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}w();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Me(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Ne({addons:t,clusterStatus:n,selectedNode:i,onRefresh:a,isRefreshing:s}){let l=ae(),[d,f]=O(``),m=ie(d),[_,v]=O(!1),y=C(null);A(()=>{if(!_)return;let e=e=>{y.current&&!y.current.contains(e.target)&&v(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[_]);let{data:b}=c({nodeId:i.id}),ee=E(()=>{let e=new Map;for(let t of b??[])e.set(t.name,t.latestVersion);return e},[b]),ne=E(()=>(b??[]).filter(e=>!e.isSystem).length,[b]),[re,x]=O(()=>new Set),[w,D]=O(()=>new Map),j=S(e=>{x(t=>new Set(t).add(e))},[]),oe=S(e=>{x(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),M=S((e,t)=>{D(n=>new Map(n).set(e,t))},[]),se=S(e=>{D(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),F=o({onMutate:e=>{j(e.name),se(e.name)},onSuccess:(e,t)=>{oe(t.name);let n=e;if(n&&n.success===!1){M(t.name,n.error??`Update failed (no error message returned by server)`);return}l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{oe(t.name),M(t.name,e instanceof Error?e.message:String(e))}}),I=_e(),ue=C(new Set);A(()=>{let e=new Set;for(let[t,n]of I)Y(n)&&e.add(t);let t=[...ue.current].some(t=>!e.has(t));ue.current=e,t&&(l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[I,l]);let{data:z}=g(void 0),B=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:V,isFetching:fe}=r({query:m||void 0},{enabled:_}),H=e(),{data:U}=h(void 0),W=U?.requestedAt,[pe,me]=O(null),[G,he]=O(!1);A(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==pe){me(U.requestedAt),he(!0);let e=window.setTimeout(()=>he(!1),6e3);return()=>window.clearTimeout(e)}},[W,pe,U]),u();let K=S(async()=>{let e=(b??[]).filter(e=>!e.isSystem);e.length!==0&&await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[i.id]})},[b,i.id,H]),q=te({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addonPages`]]}),l.invalidateQueries({queryKey:[[`capabilities`]]}),l.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ge]=O(`type`),[X,ve]=O(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),ye=e=>{ve(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[be,xe]=le(),Z=be.get(`capability`),Se=E(()=>{let e=t.filter(e=>!ke(e.manifest.packageName));return i.isHub||(e=e.filter(e=>Ae(e.placement,i.isHub))),Z&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),e},[t,i.isHub,Z]),Ce=()=>{let e=new URLSearchParams(be);e.delete(`capability`),xe(e,{replace:!0})},we=X===`flat`?Se:Me(Se),Te=E(()=>{let e=[...we];switch(J){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[we,J]);return T(`div`,{className:`space-y-4`,children:[[...w.entries()].map(([e,t])=>k(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:T(`div`,{className:`flex items-start justify-between gap-3`,children:[T(`div`,{className:`space-y-0.5`,children:[T(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),k(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),k(`button`,{type:`button`,onClick:()=>se(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),T(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),T(`select`,{value:J,onChange:e=>ge(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[k(`option`,{value:`type`,children:`Bundles first`}),k(`option`,{value:`name`,children:`Name`}),k(`option`,{value:`source`,children:`Install source`})]})]}),T(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>k(`button`,{type:`button`,onClick:()=>ye(e),className:`px-2.5 py-1.5 transition-colors capitalize ${X===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),i.isHub&&T(`div`,{className:`flex items-center gap-1.5`,children:[k(P,{className:`h-3 w-3 text-foreground-subtle`}),k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>k(`button`,{type:`button`,onClick:()=>B.mutate({channel:e}),disabled:B.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${z?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),ne>0&&T(`button`,{type:`button`,onClick:()=>void K(),disabled:H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[H.isPending?k(R,{className:`w-3 h-3 animate-spin`}):k(N,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${ne})`]}),T(`button`,{type:`button`,onClick:a,disabled:s||H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[k(P,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),T(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[T(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:y,children:[k(ce,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),k(`input`,{type:`text`,value:d,onChange:e=>{f(e.target.value),v(!0)},onFocus:()=>v(!0),placeholder:`Search addons on npm...`,disabled:H.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),fe&&k(R,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),_&&V&&V.length>0&&T(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[V.length>0&&T(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,V.length,`)`]}),V&&V.length>0&&k(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:V.map(e=>T(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[k(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[k(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),k(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&k(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?T(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[k(L,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):T(`button`,{type:`button`,onClick:()=>q.mutate({packageName:e.name}),disabled:q.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[q.isPending?k(R,{className:`h-3 w-3 animate-spin`}):k(N,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),k(De,{onUploadSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),a()}})]}),Z&&T(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[k(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),k(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),k(`button`,{type:`button`,onClick:Ce,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),G&&T(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[k(de,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),T(`div`,{children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),k(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Se.length===0&&k(`div`,{className:`text-xs text-foreground-subtle`,children:t.length===0?`No addons installed`:Z?`No installed addons declare the "${Z}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${i.name} (placement filter active)`}),k(`div`,{className:`space-y-2`,children:Te.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,r=ee.get(t),a=$(e)?e.representative:e,o=r?e=>F.mutate({name:t,version:e,nodeId:i.id}):void 0,s=I.get(t)??null,c=s!==null&&Y(s);return k(Ee,{addon:a,clusterStatus:n?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:r,isUpdating:re.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:H.isPending},$(e)?t:e.manifest.id)})})]})}function Pe(){let e=ae(),{data:t,isLoading:r,isError:i}=x(),{data:o}=a(void 0),{data:s}=l(void 0,{refetchInterval:1e4}),c=E(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of s??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[s]),[u,d]=O(`hub`),p=c.find(e=>e.id===u)??c[0],m=b(),h=n(),g=m.isPending||h.isPending,_=async()=>{await m.mutateAsync({nodeId:u}),await h.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},v=C(m);v.current=m,A(()=>{v.current.mutate({nodeId:`hub`})},[]);let y=(t??[]).map(je).filter(e=>e!==null);return T(W,{children:[T(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[k(f,{selectedNodeId:u,onSelect:d}),T(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!i&&T(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[y.length,` installed`]}),T(`button`,{type:`button`,onClick:()=>void _(),disabled:g,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[k(P,{className:`w-3 h-3 ${g?`animate-spin`:``}`}),`Check for updates`]})]})]}),!p.isHub&&T(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,k(`span`,{className:`font-medium text-foreground`,children:p.name}),` — agents only run`,` `,k(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,k(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&k(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),i&&k(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!i&&k(Ne,{addons:y,clusterStatus:o,selectedNode:p,onRefresh:()=>void _(),isRefreshing:g})]})}export{Pe as AddonsPage};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import{Bo as e,Fo as t,Ho as n,Io as r,Lo as i,Po as a,Vo as o,_o as s,_s as c,as as l,bo as u,es as d,g as f,ho as p,hs as m,is as h,ns as g,rs as _,ts as v,vo as y}from"./src-BoczRE1G.js";import{I as b,K as x,M as S,Q as C,S as w,T,W as E,a as D,b as O,q as k,t as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as N,A as P,F,I,L as ee,R as L,f as R,z as te}from"./src-Bok3PEiz.js";import{p as z}from"./player-overlays-BzwYRH08.js";import{t as ne}from"./boxes-0BrwpGRK.js";import{t as re}from"./pencil-DDNEW9Yb.js";import{t as ie}from"./play-rmom08n0.js";import{t as B}from"./plus-DW_KHfhe.js";import{t as ae}from"./rotate-cw-DWJibY6w.js";import{I as oe,J as se,M as ce,P as le,S as ue,W as de,b as fe,m as pe,o as me,s as V,w as he}from"./index-qYnug9Qs.js";import{t as ge}from"./AdminPage-Dq33XE9j.js";var _e=de(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ve=de(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ye=de(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),be=de(`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`}]]);C();var xe=6e4;function Se(){let e=z();return D({queryKey:[`automation`,`devices`],staleTime:xe,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).sort((e,t)=>e.name.localeCompare(t.name))})}function Ce(e){let t=z();return D({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:xe,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function we(e){let t=z();return D({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:xe,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Te(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ee(){let e=new Set;for(let t of Object.values(R))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function De(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(R)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return j(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Oe(e){let t=we(e.deviceId);if(t.data!==void 0)return Te(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ke({value:e,devices:t,onChange:n}){let r=we(e.deviceId),i=r.data??[],a=Te(i,e.cap);return w(O,{children:[w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Device`}),j(v,{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}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Capability`}),j(v,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Ae(e.deviceId,i.length,r.isLoading)},...i.map(e=>({value:e.cap,label:e.cap}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Field`}),j(v,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:a.length===0?`No readable fields`:`Select a field…`},...a.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Ae(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 je=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Me(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 je}}function Ne(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 Pe(e){return Me(e).map(e=>({value:e,label:Ne(e)}))}function Fe(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 Ie={triggers:[],actions:[]};function Le(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 Re(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
2
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Be(){return{kind:`expression`,expr:``,bindings:{}}}function Ve(e,t,n){return e.map((e,r)=>r===t?n:e)}function He(e,t){return e.filter((e,n)=>n!==t)}function Ue(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=He(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function We(e,t){return{...e,triggers:[...t]}}function Ge(e,t){return{...e,actions:[...t]}}var Ke=`deviceId`,qe=`$trigger`,Je=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ye({actions:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,i)=>w(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(h,{variant:`default`,children:i+1}),w(`label`,{className:`w-40`,children:[j(H,{children:`Step`}),j(v,{value:r.kind,onChange:t=>n(Ve(e,i,Re(Xe(t.target.value)))),options:Je.map(e=>({value:e.value,label:e.label}))})]}),w(`div`,{className:`ml-auto flex items-center gap-1`,children:[j(l,{variant:`ghost`,disabled:i===0,onClick:()=>n(Ue(e,i,i-1)),title:`Run this step earlier`,children:j(ve,{className:`h-3.5 w-3.5`})}),j(l,{variant:`ghost`,disabled:i===e.length-1,onClick:()=>n(Ue(e,i,i+1)),title:`Run this step later`,children:j(_e,{className:`h-3.5 w-3.5`})}),j(l,{variant:`ghost`,onClick:()=>n(He(e,i)),title:`Remove this step`,children:j(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&w(`label`,{className:`block w-32`,children:[j(H,{children:`Seconds`}),j(g,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ve(e,i,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&w(`label`,{className:`block`,children:[j(H,{children:`Code`}),j(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ve(e,i,{kind:`code`,code:t.target.value}))}),w(`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. `,j(`code`,{children:`ctx`}),` and `,j(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&j(Ze,{action:r,devices:t,onChange:t=>n(Ve(e,i,t))})]},`${r.kind}-${String(i)}`)),w(`div`,{className:`flex items-center gap-2`,children:[w(l,{variant:`outline`,onClick:()=>n([...e,Re(`cap`)]),children:[j(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&j(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Xe(e){return Je.find(t=>t.value===e)?.value??`cap`}function Ze({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,i=typeof e.deviceId==`number`?e.deviceId:0,a=Ce(i),o=r?Ee():a.data??[],s=De(e.cap);return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Device`}),j(v,{value:r?qe:String(i),onChange:t=>n({...e,deviceId:t.target.value===qe?{$var:Ke}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:qe,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Capability`}),j(v,{value:e.cap,disabled:o.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:o.length===0?`Pick a device first`:`Select a capability…`},...o.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Method`}),j(v,{value:e.method,disabled:s.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:s.length===0?`Pick a capability first`:`Select a method…`},...s.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Arguments (JSON)`}),j(g,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(Qe(e,t.target.value))})]})]})}function Qe(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function $e({value:e,field:t,onChange:n}){return t?.kind===`boolean`?j(v,{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?j(v,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?j(g,{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)}}):j(g,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function et({value:e,field:t,onChange:n}){return j(g,{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 tt(e){return typeof e==`object`}function nt(e){return tt(e)?e[0]??``:e}function rt(e){return tt(e)?e:typeof e==`boolean`?[]:[e]}function it({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a=Pe(i?.kind),o=e.operator===`in`,s=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},c=t=>{let r=at(t,a);n({...e,operator:r,value:r===`in`?rt(e.value):nt(e.value)})};return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(ke,{value:r,devices:t,onChange:s}),w(`label`,{className:`min-w-[8rem]`,children:[j(H,{children:`Comparison`}),j(v,{value:e.operator,onChange:e=>c(e.target.value),options:a.map(e=>({value:e.value,label:e.label}))})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Value`}),o?j(et,{value:rt(e.value),field:i,onChange:t=>n({...e,value:t})}):j($e,{value:nt(e.value),field:i,onChange:t=>n({...e,value:t})})]})]})}function at(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function st({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),i=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return w(`div`,{className:`space-y-2`,children:[w(`label`,{className:`block`,children:[j(H,{children:`Expression`}),j(g,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),j(`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.`})]}),w(`div`,{className:`space-y-1.5`,children:[r.length===0&&j(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>j(ct,{alias:n,source:r,devices:t,onRename:t=>i(mt(e.bindings,n,t)),onChange:t=>i({...e.bindings,[n]:t}),onRemove:()=>i(ht(e.bindings,n))},n)),w(l,{variant:`ghost`,onClick:()=>i({...e.bindings,[pt(e.bindings)]:ot}),children:[j(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ct({alias:e,source:t,devices:n,onRename:r,onChange:i,onRemove:a}){let o=t.kind===`literal`,s=o?{deviceId:0,cap:``,fieldPath:``}:{deviceId:dt(n,ut(t)),cap:t.cap,fieldPath:t.fieldPath};return w(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[w(`label`,{className:`w-32`,children:[j(H,{children:`Name`}),j(g,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),w(`label`,{className:`w-36`,children:[j(H,{children:`Reads`}),j(v,{value:o?`literal`:`global`,onChange:e=>i(e.target.value===`literal`?{kind:`literal`,value:``}:ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),o?w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Constant`}),j(g,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>i({kind:`literal`,value:lt(e.target.value)})})]}):j(ke,{value:s,devices:n,onChange:e=>i({kind:`global`,sourceStableId:ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),j(l,{variant:`ghost`,onClick:a,title:`Remove this name`,children:j(V,{className:`h-3.5 w-3.5`})})]})}function lt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ut(e){return e.kind===`global`?e.sourceStableId:``}function dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function pt(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 mt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function ht(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function gt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function _t(e){return gt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function vt(e){return e===null?null:te({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function yt(e){let t=W(e);return{depth:t.children.length===0?0:ee(t),leaves:t.children.length===0?0:L(t),depthLimit:3,leafLimit:32}}function bt(e,t){let n=vt(t);return n===null?{ok:!0,recipe:gt(e,t)}:{ok:!1,reason:n}}function xt(e,t){let n=W(e);return bt(e,{kind:n.kind,children:[...n.children,t]})}function St(e,t,n){return gt(e,K(W(e),t,()=>n))}function Ct(e,t){return gt(e,K(W(e),t,()=>null))}function wt(e,t,n){return gt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Tt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:bt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Et(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 Dt(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=Et(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return bt(e,K(i,r.path,()=>d))}function Ot(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return bt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Et(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return bt(e,K(n,i.path,()=>o))}var kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function At(e){return e.join(`/`)}function jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Mt({recipe:e,devices:t,onChange:n}){let[r,i]=k([]),[a,o]=k(null),s=W(e),c=yt(e),u=E(()=>r.map(jt),[r]),d=e=>{if(!e.ok){o(e.reason);return}o(null),i([]),n(e.recipe)},f=Dt(e,u,`all`),p=Dt(e,u,`any`),m=u.length===1?Tt(e,u[0]??[]):{ok:!1,reason:`select exactly one row to negate`},g={devices:t,selected:new Set(r),onToggleSelect:e=>i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(St(e,t,r)),onRemove:t=>{i([]),n(Ct(e,t))},onSetKind:(t,r)=>n(wt(e,t,r)),onUngroup:t=>d(Ot(e,t))};return w(`div`,{className:`space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(h,{variant:`default`,children:`And only if`}),j(`div`,{className:`w-32`,children:j(v,{value:s.kind,onChange:t=>n(wt(e,[],Nt(t.target.value))),options:kt})}),w(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,c.depth,`/`,c.depthLimit,` · `,c.leaves,`/`,c.leafLimit,` conditions`]})]}),s.children.length===0?j(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):j(Pt,{container:s,path:[],handlers:g}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(l,{variant:`outline`,onClick:()=>d(xt(e,ze())),title:`Compare one device field to a value`,children:[j(B,{className:`h-4 w-4`}),` Condition`]}),w(l,{variant:`outline`,onClick:()=>d(xt(e,Be())),title:`Arithmetic across device fields — the bounded expression engine`,children:[j(ye,{className:`h-4 w-4`}),` Expression`]}),j(`span`,{className:`mx-1 h-5 w-px bg-border`}),j(l,{variant:`ghost`,disabled:!f.ok,onClick:()=>d(f),title:f.ok?`All selected rows must be true`:f.reason,children:`Group as ALL`}),j(l,{variant:`ghost`,disabled:!p.ok,onClick:()=>d(p),title:p.ok?`Any one of the selected rows is enough`:p.reason,children:`Group as ANY`}),j(l,{variant:`ghost`,disabled:!m.ok,onClick:()=>d(m),title:m.ok?`Invert the selected row`:m.reason,children:`NOT`}),r.length>0&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),a!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:a})]})}function Nt(e){return e===`any`?`any`:`all`}function Pt({container:e,path:t,handlers:n}){return j(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>j(Ft,{node:e,path:[...t,r],handlers:n},At([...t,r])))})}function Ft({node:e,path:t,handlers:n}){let r=At(t),i=j(d,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?w(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(`div`,{className:`w-32`,children:j(v,{value:e.kind,onChange:e=>n.onSetKind(t,Nt(e.target.value)),options:kt})}),w(l,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[j(be,{className:`h-3.5 w-3.5`}),` Ungroup`]}),j(l,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:j(V,{className:`h-3.5 w-3.5`})})]}),j(`div`,{className:`pl-4`,children:j(Pt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?w(`div`,{className:`rounded border border-border p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(h,{variant:`warning`,children:`NOT`}),w(l,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[j(be,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),j(`div`,{className:`pl-4`,children:j(Ft,{node:e.child,path:[...t,0],handlers:n})})]}):w(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[j(`div`,{className:`pt-6`,children:i}),j(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?j(it,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):j(st,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),j(l,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:j(V,{className:`h-3.5 w-3.5`})})]})}C();function It({code:e,error:t,canEject:n,ejecting:r,onEject:i}){let[a,o]=k(!1),c=s(),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`})&&i()};return w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[w(l,{variant:`ghost`,onClick:()=>o(!a),children:[j(a?oe:le,{className:`h-4 w-4`}),`Generated code`]}),j(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),w(l,{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:[j(fe,{className:`h-4 w-4`}),` Eject to code`]})]}),a&&j(`div`,{className:`border-t border-border p-3`,children:e===null?j(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):j(p,{maxHeight:420,children:e})})]})}var Lt=[`device-state`,`device-event`,`schedule`,`manual`],Rt=Object.values(N).sort((e,t)=>e.localeCompare(t));function zt({triggers:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`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)=>j(Bt,{trigger:r,devices:t,position:i,onChange:t=>n(Ve(e,i,t)),onRemove:()=>n(He(e,i))},`${r.kind}-${String(i)}`)),w(l,{variant:`outline`,onClick:()=>n([...e,Le(`device-state`)]),title:`Add another way this automation can start`,children:[j(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Bt({trigger:e,devices:t,position:n,onChange:r,onRemove:i}){return w(`div`,{className:`rounded border border-border p-3`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(h,{variant:`default`,children:n===0?`When`:`or when`}),w(`label`,{className:`min-w-[13rem] flex-1`,children:[j(H,{children:`Trigger`}),j(v,{value:e.kind,onChange:e=>r(Le(Vt(e.target.value))),options:Lt.map(e=>({value:e,label:Fe(e)}))})]}),j(l,{variant:`ghost`,onClick:i,title:`Remove this trigger`,children:j(V,{className:`h-4 w-4`})})]}),w(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&j(Ht,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&j(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&w(`label`,{className:`min-w-[14rem] flex-1`,children:[j(H,{children:`Cron expression`}),j(g,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),w(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,j(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&w(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,j(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Vt(e){return Lt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ht({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a={...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 w(O,{children:[j(ke,{value:r,devices:t,onChange:e=>n(q(e,a))}),w(`div`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Becomes`}),w(`div`,{className:`flex items-center gap-2`,children:[w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(d,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...a,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&j($e,{value:e.becomes,field:i,onChange:e=>n(q(r,{...a,becomes:e}))})]})]}),w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(d,{checked:e.edge===!0,onChange:e=>n(q(r,{...a,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Held for (s)`}),j(g,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,forMs:Ut(e.target.value)}))})]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Debounce (s)`}),j(g,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,debounceMs:Ut(e.target.value)}))})]})]})}function Ut(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Wt({trigger:e,devices:t,onChange:n}){return w(O,{children:[w(`label`,{className:`min-w-[15rem] flex-1`,children:[j(H,{children:`Event category`}),j(v,{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…`},...Rt.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`From device`}),j(v,{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}))]})]})]})}C();var Gt=`hub`;function Kt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:i,onSave:a,onEject:o,onCancel:s}){let[c,u]=k(e?.name??``),[d,p]=k(()=>_t(t)),[m,v]=k(!1),y=Se().data??[],b=te(d),x=E(()=>Jt(d),[d]),S=E(()=>Yt(c.trim()===``?`Untitled automation`:c.trim(),d),[c,d]),C=c.trim()===``,T=C||b!==null||x!==null||S.code===null;return j(_,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),j(h,{variant:`info`,children:`runs on the hub`})]}),w(`label`,{className:`block max-w-md text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(g,{className:`mt-1`,value:c,onChange:e=>u(e.target.value),placeholder:`What this automation does`})]}),j(qt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:j(zt,{triggers:d.triggers,devices:y,onChange:e=>p(We(d,e))})}),j(qt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:j(Mt,{recipe:d,devices:y,onChange:p})}),j(qt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:j(Ye,{actions:d.actions,devices:y,onChange:e=>p(Ge(d,e))})}),j(It,{code:S.code,error:S.error,canEject:e!==null,ejecting:i,onEject:o}),m&&e!==null&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(f,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&j(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(l,{onClick:()=>{S.code!==null&&a({name:c.trim(),code:S.code,enabled:e?.enabled??!0,placement:Gt})},disabled:n||T,children:[n&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(l,{variant:`ghost`,onClick:()=>v(!m),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs`]}),j(l,{variant:`ghost`,onClick:s,disabled:n,children:`Close`}),C&&j(h,{variant:`warning`,children:`Name required`})]})]})})}function qt({step:e,title:t,subtitle:n,children:r}){return w(`section`,{className:`border-l-2 border-border pl-4`,children:[w(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[j(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),j(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),j(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Jt(e){let t=I.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 Yt(e,t){try{return{code:F({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Xt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Zt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Qt(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function $t(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function en({block:t,busy:r,confirming:i,logsOpen:a,unreadable:s,onEdit:c,onToggle:u,onToggleLogs:d,onAskDelete:p,onCancelDelete:g,onConfirmDelete:_}){let v=J(t),y=m(t.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:t.name}),j(h,{variant:Xt(v.tone),children:v.label}),y!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,y]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:v.detail}),s!==null&&w(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,s,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),i?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),j(l,{variant:`danger`,onClick:_,disabled:r,children:`Delete`}),j(l,{variant:`ghost`,onClick:g,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(l,{variant:`ghost`,onClick:c,disabled:s!==null,title:s===null?`Edit`:`This block cannot be opened visually`,children:j(re,{className:`h-4 w-4`})}),w(e,{children:[j(n,{children:j(l,{variant:`ghost`,disabled:!0,title:`Run actions`,children:j(ie,{className:`h-4 w-4`})})}),j(o,{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.`})]}),j(l,{variant:`ghost`,onClick:d,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(l,{variant:`ghost`,onClick:()=>u(!t.enabled),disabled:r,title:t.enabled?`Disable`:`Enable`,children:t.enabled?`Disable`:`Enable`}),j(l,{variant:`ghost`,onClick:p,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),a&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(t.id)})]}),j(f,{addonId:P(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function tn({onCreate:e}){return j(_,{children:w(`div`,{className:`space-y-2 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),j(`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.`}),j(l,{onClick:e,children:`New automation`})]})})}var nn=`const AUTOMATION_RECIPE =`,rn=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
3
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
4
|
-
// here the editor could re-open this block and overwrite everything below.`;function an(e){return e.includes(nn)}function on(e){let t=e.indexOf(nn);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 sn(e){let t=on(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=I.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 cn(e){let t=on(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)}${rn}${e.slice(i)}`}C();var ln=[`coreBlocks`,`list`],un=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function dn({onOpenScripts:e}){let t=z(),[n,r]=k({mode:`closed`}),[i,a]=k(null),[o,s]=k(null),c=D({queryKey:ln,refetchInterval:un,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),u=()=>{c.refetch()},d=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),u()}}),f=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),u()}}),p=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{a(null),u()}}),m=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:u}),h=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:cn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),u(),e(t.block.id)}}),g=c.data,v=Qt((g??[]).filter(e=>an(e.code))),b=g!==void 0&&v.length===0,x=n.mode===`edit`&&n.block!==null?Zt(v,n.block):null,S=x===null?null:sn(x.code),C=d.error===null?f.error===null?h.error===null?null:Y(h.error):Y(f.error):Y(d.error);return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:g===void 0?``:$t(v)}),w(l,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New automation`]})]}),c.error!=null&&j(y,{title:`Could not read the automations`,message:Y(c.error),onRetry:u}),n.mode===`edit`&&j(Kt,{existing:x,initialRecipe:S!==null&&S.ok?S.recipe:Ie,saving:d.isPending||f.isPending,saveError:C,ejecting:h.isPending,onSave:e=>{x===null?d.mutate(e):f.mutate({blockId:x.id,block:e})},onEject:()=>{x!==null&&h.mutate(x)},onCancel:()=>{d.reset(),f.reset(),h.reset(),r({mode:`closed`})}},x?.id??`new`),b&&j(tn,{onCreate:()=>r({mode:`edit`,block:null})}),v.length>0&&j(_,{children:j(`ul`,{className:`divide-y divide-border`,children:v.map(e=>{let t=sn(e.code);return j(en,{block:e,busy:m.isPending||p.isPending,confirming:i===e.id,logsOpen:o===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>m.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>s(o===e.id?null:e.id),onAskDelete:()=>a(e.id),onCancelDelete:()=>a(null),onConfirmDelete:()=>p.mutate(e.id)},e.id)})})}),p.error!=null&&j(y,{message:Y(p.error)}),m.error!=null&&j(y,{message:Y(m.error)})]})}function fn({onOpenScripts:e}){return j(_,{children:w(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[w(`div`,{className:`flex items-center gap-2`,children:[j(ne,{className:`h-5 w-5 text-foreground-subtle`}),j(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,j(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,j(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),j(l,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function pn(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 mn(e){if(Array.isArray(e))return e}function hn(e,t,n){return(t=wn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gn(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 _n(){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 vn(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 yn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?vn(Object(n),!0).forEach(function(t){hn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function bn(e,t){if(e==null)return{};var n,r,i=xn(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 xn(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 Sn(e,t){return mn(e)||gn(e,t)||Tn(e,t)||_n()}function Cn(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 wn(e){var t=Cn(e,`string`);return typeof t==`symbol`?t:t+``}function Tn(e,t){if(e){if(typeof e==`string`)return pn(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)?pn(e,t):void 0}}function En(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Dn(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 On(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Dn(Object(n),!0).forEach(function(t){En(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function kn(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function An(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 jn(e){return{}.toString.call(e).includes(`Object`)}function Mn(e){return!Object.keys(e).length}function Nn(e){return typeof e==`function`}function Pn(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fn(e,t){return jn(t)||X(`changeType`),Object.keys(t).some(function(t){return!Pn(e,t)})&&X(`changeField`),t}function In(e){Nn(e)||X(`selectorType`)}function Ln(e){Nn(e)||jn(e)||X(`handlerType`),jn(e)&&Object.values(e).some(function(e){return!Nn(e)})&&X(`handlersType`)}function Rn(e){e||X(`initialIsRequired`),jn(e)||X(`initialType`),Mn(e)&&X(`initialContent`)}function zn(e,t){throw Error(e[t]||e.default)}var X=An(zn)({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"}),Bn={changes:Fn,selector:In,handler:Ln,initial:Rn};function Vn(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Bn.initial(e),Bn.handler(t);var n={current:e},r=An(Wn)(n,t),i=An(Un)(n),a=An(Bn.changes)(e),o=An(Hn)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Bn.selector(e),e(n.current)}function c(e){kn(r,i,a,o)(e)}return[s,c]}function Hn(e,t){return Nn(t)?t(e.current):t}function Un(e,t){return e.current=On(On({},e.current),t),t}function Wn(e,t,n){return Nn(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Gn={create:Vn},Kn={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function qn(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 Jn(e){return{}.toString.call(e).includes(`Object`)}function Yn(e){return e||$n(`configIsRequired`),Jn(e)||$n(`configType`),e.urls?(Xn(),{paths:{vs:e.urls.monacoBase}}):e}function Xn(){console.warn(Qn.deprecation)}function Zn(e,t){throw Error(e[t]||e.default)}var Qn={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
|
-
`},$n=qn(Zn)(Qn),er={config:Yn},tr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function nr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],nr(e[n],t[n]))}),yn(yn({},e),t)}var rr={type:`cancelation`,msg:`operation is manually canceled`};function ir(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(rr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var ar=[`monaco`],or=Sn(Gn.create({config:Kn,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),sr=or[0],cr=or[1];function lr(e){var t=er.config(e),n=t.monaco,r=bn(t,ar);cr(function(e){return{config:nr(e.config,r),monaco:n}})}function ur(){var e=sr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(cr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ir(_r);if(window.monaco&&window.monaco.editor)return hr(window.monaco),e.resolve(window.monaco),ir(_r);tr(dr,pr)(mr)}return ir(_r)}function dr(e){return document.body.appendChild(e)}function fr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function pr(e){var t=sr(function(e){return{config:e.config,reject:e.reject}}),n=fr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function mr(){var e=sr(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;hr(n),e.resolve(n)},function(t){e.reject(t)})}function hr(e){sr().monaco||cr({monaco:e})}function gr(){return sr(function(e){return e.monaco})}var _r=new Promise(function(e,t){return cr({resolve:e,reject:t})}),vr={config:lr,init:ur,__getMonacoInstance:gr};C();var yr={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},br={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function xr({children:e}){return T.createElement(`div`,{style:br.container},e)}var Sr=xr;function Cr({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return T.createElement(`section`,{style:{...yr.wrapper,width:e,height:t},...o},!n&&T.createElement(Sr,null,r),T.createElement(`div`,{ref:i,style:{...yr.fullWidth,...!n&&yr.hide},className:a}))}var wr=S(Cr);function Tr(e){M(e,[])}var Er=Tr;function Dr(e,t,n=!0){let r=x(!0);M(r.current||!n?()=>{r.current=!1}:e,t)}var Z=Dr;function Or(){}function Q(e,t,n,r){return kr(e,r)||Ar(e,t,n,r)}function kr(e,t){return e.editor.getModel(jr(e,t))}function Ar(e,t,n,r){return e.editor.createModel(t,n,r?jr(e,r):void 0)}function jr(e,t){return e.Uri.parse(t)}function Mr({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:i,originalModelPath:a,modifiedModelPath:o,keepCurrentOriginalModel:s=!1,keepCurrentModifiedModel:c=!1,theme:l=`light`,loading:u=`Loading...`,options:d={},height:f=`100%`,width:p=`100%`,className:m,wrapperProps:h={},beforeMount:g=Or,onMount:_=Or}){let[v,y]=k(!1),[S,C]=k(!0),w=x(null),E=x(null),D=x(null),O=x(_),A=x(g),j=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(E.current=e)&&C(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>w.current?F():e.cancel()}),Z(()=>{if(w.current&&E.current){let t=w.current.getOriginalEditor(),i=Q(E.current,e||``,r||n||`text`,a||``);i!==t.getModel()&&t.setModel(i)}},[a],v),Z(()=>{if(w.current&&E.current){let e=w.current.getModifiedEditor(),r=Q(E.current,t||``,i||n||`text`,o||``);r!==e.getModel()&&e.setModel(r)}},[o],v),Z(()=>{let e=w.current.getModifiedEditor();e.getOption(E.current.editor.EditorOption.readOnly)?e.setValue(t||``):t!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:t||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[t],v),Z(()=>{w.current?.getModel()?.original.setValue(e||``)},[e],v),Z(()=>{let{original:e,modified:t}=w.current.getModel();E.current.editor.setModelLanguage(e,r||n||`text`),E.current.editor.setModelLanguage(t,i||n||`text`)},[n,r,i],v),Z(()=>{E.current?.editor.setTheme(l)},[l],v),Z(()=>{w.current?.updateOptions(d)},[d],v);let N=b(()=>{if(!E.current)return;A.current(E.current);let s=Q(E.current,e||``,r||n||`text`,a||``),c=Q(E.current,t||``,i||n||`text`,o||``);w.current?.setModel({original:s,modified:c})},[n,t,i,e,r,a,o]),P=b(()=>{!j.current&&D.current&&(w.current=E.current.editor.createDiffEditor(D.current,{automaticLayout:!0,...d}),N(),E.current?.editor.setTheme(l),y(!0),j.current=!0)},[d,l,N]);M(()=>{v&&O.current(w.current,E.current)},[v]),M(()=>{!S&&!v&&P()},[S,v,P]);function F(){let e=w.current?.getModel();s||e?.original?.dispose(),c||e?.modified?.dispose(),w.current?.dispose()}return T.createElement(wr,{width:p,height:f,isEditorReady:v,loading:u,_ref:D,className:m,wrapperProps:h})}S(Mr);function Nr(e){let t=x();return M(()=>{t.current=e},[e]),t.current}var Pr=Nr,Fr=new Map;function Ir({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:i,path:a,theme:o=`light`,line:s,loading:c=`Loading...`,options:l={},overrideServices:u={},saveViewState:d=!0,keepCurrentModel:f=!1,width:p=`100%`,height:m=`100%`,className:h,wrapperProps:g={},beforeMount:_=Or,onMount:v=Or,onChange:y,onValidate:S=Or}){let[C,w]=k(!1),[E,D]=k(!0),O=x(null),A=x(null),j=x(null),N=x(v),P=x(_),F=x(),I=x(r),ee=Pr(a),L=x(!1),R=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(O.current=e)&&D(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>A.current?z():e.cancel()}),Z(()=>{let o=Q(O.current,e||r||``,t||i||``,a||n||``);o!==A.current?.getModel()&&(d&&Fr.set(ee,A.current?.saveViewState()),A.current?.setModel(o),d&&A.current?.restoreViewState(Fr.get(a)))},[a],C),Z(()=>{A.current?.updateOptions(l)},[l],C),Z(()=>{!A.current||r===void 0||(A.current.getOption(O.current.editor.EditorOption.readOnly)?A.current.setValue(r):r!==A.current.getValue()&&(R.current=!0,A.current.executeEdits(``,[{range:A.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),A.current.pushUndoStop(),R.current=!1))},[r],C),Z(()=>{let e=A.current?.getModel();e&&i&&O.current?.editor.setModelLanguage(e,i)},[i],C),Z(()=>{s!==void 0&&A.current?.revealLine(s)},[s],C),Z(()=>{O.current?.editor.setTheme(o)},[o],C);let te=b(()=>{if(!(!j.current||!O.current)&&!L.current){P.current(O.current);let c=a||n,f=Q(O.current,r||e||``,t||i||``,c||``);A.current=O.current?.editor.create(j.current,{model:f,automaticLayout:!0,...l},u),d&&A.current.restoreViewState(Fr.get(c)),O.current.editor.setTheme(o),s!==void 0&&A.current.revealLine(s),w(!0),L.current=!0}},[e,t,n,r,i,a,l,u,d,o,s]);M(()=>{C&&N.current(A.current,O.current)},[C]),M(()=>{!E&&!C&&te()},[E,C,te]),I.current=r,M(()=>{C&&y&&(F.current?.dispose(),F.current=A.current?.onDidChangeModelContent(e=>{R.current||y(A.current.getValue(),e)}))},[C,y]),M(()=>{if(C){let e=O.current.editor.onDidChangeMarkers(e=>{let t=A.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=O.current.editor.getModelMarkers({resource:t});S?.(e)}});return()=>{e?.dispose()}}return()=>{}},[C,S]);function z(){F.current?.dispose(),f?d&&Fr.set(a,A.current.saveViewState()):A.current.getModel()?.dispose(),A.current.dispose()}return T.createElement(wr,{width:p,height:m,isEditorReady:C,loading:c,_ref:j,className:h,wrapperProps:g})}var Lr=S(Ir);C();var Rr={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function zr(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Rr}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Br({value:e,onChange:t,extraLibs:n=[],onDiagnostics:r,readOnly:i=!1,heightPx:a=420,dark:o=!0}){let s=x(null),c=b((e,t)=>{if(s.current=t,zr(t,n),r===void 0)return;let i=e.getModel();if(i===null)return;let a=()=>{r(t.editor.getModelMarkers({resource:i.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(a),a()},[n,r]);return j(Lr,{height:a,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:o?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:c,options:{readOnly:i,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Vr(e){return e.some(e=>e.severity>=8)}var Hr=`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
|
-
* it is awaited on shutdown.
|
|
20
|
-
*/
|
|
21
|
-
export default function block(ctx: AddonContext) {
|
|
22
|
-
ctx.logger.info('hello from a core block')
|
|
23
|
-
|
|
24
|
-
const timer = setInterval(() => {
|
|
25
|
-
ctx.logger.info('tick')
|
|
26
|
-
}, 60_000)
|
|
27
|
-
|
|
28
|
-
return () => {
|
|
29
|
-
clearInterval(timer)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
`;function Ur({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.`}C();var Wr=`hub`;function Gr({existing:e,typeDefs:t,typeDefsLoading:n,saving:r,saveError:i,restarting:a,restartError:o,onRestart:s,onSave:d,onCancel:p}){let m=z(),{resolvedMode:v}=c(),[y,b]=k(e?.name??``),[x,S]=k(e?.code??Hr),[C,T]=k(e?.placement??Wr),[D,M]=k(e?.integrationId??``),[N,F]=k([]),[I,ee]=k(!1),L=A({mutationFn:e=>m.trpcClient.coreBlocks.compile.mutate({code:e})}),R=E(()=>N.filter(e=>e.severity>=8),[N]),te=Vr(N),ne=y.trim()===``,re=e===null||x!==e.code||y.trim()!==e.name||C!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ie=()=>{L.reset(),d({name:y.trim(),code:x,enabled:e?.enabled??!0,placement:C,...D.trim()===``?{}:{integrationId:D.trim()}})},B=e===null?null:J(e),oe=Ur({existing:e,dirty:re,saving:r,restarting:a});return j(_,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),B!==null&&j(h,{variant:Xt(B.tone),children:B.label})]}),w(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(g,{className:`mt-1`,value:y,onChange:e=>b(e.target.value),placeholder:`What this script does`})]}),w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),j(g,{className:`mt-1`,value:D,onChange:e=>M(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),w(`div`,{children:[j(u,{selectedNodeId:C,onSelect:T,label:`Runs on`,alwaysShow:!0}),C!==Wr&&w(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[j(me,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),w(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,j(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),w(`div`,{className:I?`grid gap-3 lg:grid-cols-2`:``,children:[j(`div`,{className:`rounded border border-border`,children:n?j(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):j(Br,{value:x,onChange:S,extraLibs:t?.libs??[],onDiagnostics:F,dark:v===`dark`,heightPx:420})}),I&&w(`div`,{className:`rounded border border-border`,children:[j(`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.`:w(O,{children:[`Logs — `,j(`code`,{children:P(e.id)})]})}),e!==null&&j(f,{addonId:P(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&j(`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.`}),R.length>0&&w(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[w(`p`,{className:`font-medium text-danger`,children:[R.length,` error`,R.length===1?``:`s`,` — the block cannot be saved.`]}),R.slice(0,5).map(e=>w(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),R.length>5&&w(`p`,{className:`text-foreground-subtle`,children:[`…and `,R.length-5,` more.`]})]}),L.data!==void 0&&(L.data.ok?w(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[j(ce,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[L.data.line===void 0?``:`line ${String(L.data.line)}: `,L.data.error??`the code does not compile`]})),L.error!==null&&w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Kr(L.error)]}),i!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:i}),o!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:o}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(l,{variant:`outline`,onClick:()=>L.mutate(x),disabled:L.isPending||r,title:`Type-check on the node without saving`,children:[L.isPending&&j(ue,{className:`h-4 w-4 animate-spin`}),` Compile`]}),w(l,{onClick:ie,disabled:r||te||ne,children:[r&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(l,{variant:`outline`,onClick:()=>s?.(),disabled:oe!==null||s===void 0,title:oe??`Stop the process and let the supervisor bring it back`,children:[a?j(ae,{className:`h-4 w-4 animate-spin`}):j(ae,{className:`h-4 w-4`}),` `,`Restart`]}),w(l,{variant:`ghost`,onClick:()=>ee(!I),title:`Show this script's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs `,I?`⇤`:`⇄`]}),j(l,{variant:`ghost`,onClick:p,disabled:r,children:`Close`}),w(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,R.length,re&&e!==null?` · unsaved changes`:``]}),ne&&j(h,{variant:`warning`,children:`Name required`})]})]})})}function Kr(e){return e instanceof Error?e.message:String(e)}C();var qr=[`coreBlocks`,`list`],Jr=[`coreBlocks`,`getTypeDefs`],Yr=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xr({initialBlockId:e}={}){let t=z(),[n,r]=k({mode:`closed`}),[i,a]=k(null),[o,s]=k(null),c=D({queryKey:qr,refetchInterval:Yr,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),u=D({queryKey:Jr,enabled:n.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>t.trpcClient.coreBlocks.getTypeDefs.query({})}),d=()=>{c.refetch()},f=x(null),p=c.data;M(()=>{if(e===void 0||f.current===e)return;let t=p?.find(t=>t.id===e);t!==void 0&&(f.current=e,r({mode:`edit`,block:t}))},[e,p]);let m=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),h=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),g=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{a(null),d()}}),v=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:d}),b=A({mutationFn:e=>t.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:d}),S=Qt(c.data??[]),C=c.data!==void 0&&S.length===0,T=m.isPending||h.isPending,E=m.error===null?h.error===null?null:$(h.error):$(m.error),O=n.mode===`edit`&&n.block!==null?Zt(S,n.block):null;return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:c.data===void 0?``:$t(S)}),w(l,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New script`]})]}),c.error!=null&&j(y,{title:`Could not read the scripts`,message:$(c.error),onRetry:d}),n.mode===`edit`&&j(Gr,{existing:O,typeDefs:u.data,typeDefsLoading:u.isLoading,saving:T,saveError:E,restarting:b.isPending,restartError:b.error===null?null:$(b.error),onRestart:O===null?void 0:()=>b.mutate(O.id),onSave:e=>{let t=O;t===null?m.mutate(e):h.mutate({blockId:t.id,block:e})},onCancel:()=>{m.reset(),h.reset(),b.reset(),r({mode:`closed`})}}),C&&j(_,{children:w(`div`,{className:`space-y-1 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),j(`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.`})]})}),S.length>0&&j(_,{children:j(`ul`,{className:`divide-y divide-border`,children:S.map(e=>j(Zr,{block:e,busy:v.isPending||g.isPending,restarting:b.isPending&&b.variables===e.id,confirming:i===e.id,logsOpen:o===e.id,onToggle:t=>v.mutate({blockId:e.id,enabled:t}),onRestart:()=>b.mutate(e.id),onToggleLogs:()=>s(o===e.id?null:e.id),onEdit:()=>r({mode:`edit`,block:e}),onAskDelete:()=>a(e.id),onCancelDelete:()=>a(null),onConfirmDelete:()=>g.mutate(e.id)},e.id))})}),g.error!=null&&j(y,{message:$(g.error)}),v.error!=null&&j(y,{message:$(v.error)}),b.error!=null&&j(y,{message:$(b.error)})]})}function Zr({block:e,busy:t,restarting:n,confirming:r,logsOpen:i,onToggle:a,onRestart:o,onToggleLogs:s,onEdit:c,onAskDelete:u,onCancelDelete:d,onConfirmDelete:p}){let g=J(e),_=m(e.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:e.name}),j(h,{variant:Xt(g.tone),children:g.label}),j(h,{variant:`info`,children:e.placement}),_!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,_]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:g.detail})]}),r?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),j(l,{variant:`danger`,onClick:p,disabled:t,children:`Delete`}),j(l,{variant:`ghost`,onClick:d,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(l,{variant:`ghost`,onClick:c,title:`Edit`,children:j(re,{className:`h-4 w-4`})}),j(l,{variant:`ghost`,onClick:o,disabled:t||n||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:j(ae,{className:`h-4 w-4${n?` animate-spin`:``}`})}),j(l,{variant:`ghost`,onClick:s,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(l,{variant:`ghost`,onClick:()=>a(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),j(l,{variant:`ghost`,onClick:u,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),i&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(f,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qr=[`automations`,`scripts`,`custom-device`];function $r(e){return e!==null&&Qr.some(t=>t===e)}function ei(){let[e,n]=se(),o=e.get(`tab`),s=$r(o)?o:`automations`,c=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})};return j(ge,{icon:he,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:w(a,{value:s,onValueChange:c,children:[w(r,{children:[j(i,{value:`automations`,children:`Automations`}),j(i,{value:`scripts`,children:`Scripts`}),j(i,{value:`custom-device`,children:`Custom Device`})]}),j(t,{value:`automations`,children:j(dn,{onOpenScripts:e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),j(t,{value:`scripts`,children:j(Xr,{initialBlockId:e.get(`block`)??void 0})}),j(t,{value:`custom-device`,children:j(fn,{onOpenScripts:()=>c(`scripts`)})})]})})}export{ei as BuildPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$n as e,Jn as t,Jo as n,Mn as r,Qn as i,Qo as a,Xn as o,Xo as s,Yn as c,Yo as l,Zn as u,Zo as d,_o as f,ar as p,as as m,er as h,ir as g,is as _,nr as v,ns as y,qn as b,qo as x,rr as S,tr as C,wo as w}from"./src-BoczRE1G.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as P}from"./src-Bok3PEiz.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-Dd_CKaP5.js";import{a as z,c as te,f as B,i as ne,l as re,m as V,n as H,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-CjozCZrp.js";import{t as W}from"./pencil-DDNEW9Yb.js";import{t as G}from"./plus-DW_KHfhe.js";import{t as le}from"./refresh-cw-CYEUy6Ve.js";import{t as ue}from"./square-check-big-DEqd8dem.js";import{t as de}from"./square-C5l0pveB.js";import{t as K}from"./undo-2-BnRU8pkW.js";import{I as q,L as fe,P as pe,S as J,W as me,h as Y,i as X,l as he,s as Z}from"./index-qYnug9Qs.js";import{t as Q}from"./AdminPage-Dq33XE9j.js";import{r as ge,t as _e}from"./authed-media-B8T1dsFh.js";var ve=me(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:t}){let n=A(),{data:r,isLoading:i}=e({identityId:t}),a=C();function o(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:$})}})}return i?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>o(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:M(X,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:e,expanded:t,onToggle:r}){let i=A(),[c,u]=j(``),[f,p]=j(!1),[h,g]=j(!1),b=v(),S=o();function C(){u(e.name),p(!0)}function w(){p(!1),u(``)}function T(){let t=c.trim();if(!t||t===e.name){w();return}b.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:$}),w()}})}function E(){S.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:$}),g(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?D(k,{children:[M(y,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:b.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(fe,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(X,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),M(_,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!f&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(W,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>g(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(Z,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:M(t?q:pe,{className:`h-3.5 w-3.5`})})]}),t&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:e.id})}),M(x,{open:h,onOpenChange:e=>!e&&g(!1),children:D(n,{children:[D(d,{children:[M(a,{children:`Delete person`}),D(l,{children:[`Delete `,M(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),D(s,{children:[M(m,{variant:`secondary`,onClick:()=>g(!1),children:`Cancel`}),D(m,{variant:`danger`,onClick:E,disabled:S.isPending,children:[S.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[n,r]=j(``),i=t();function a(){let t=n.trim();t&&i.mutate({name:t},{onSettled:()=>{e.invalidateQueries({queryKey:$}),r(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(y,{placeholder:`New person name…`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),D(m,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!n.trim(),children:[i.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=i(),[n,r]=j(null);function a(e){r(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>a(e.id)},e.id)),M(xe,{})]})}function Ce(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}function Ee(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}E();var De=[[`faceGallery`]];function Oe({faceIds:e,identities:r,onDone:i}){let o=A(),c=b(),u=t(),[f,p]=j(``),[h,g]=j(!1),[_,v]=j(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){g(!1),p(``),v(null)}function T(){w(),i()}function E(t){!e||e.length===0||c.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{o.invalidateQueries({queryKey:De}),T()}})}function O(){!e||!f.trim()||u.mutate({name:f.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{o.invalidateQueries({queryKey:De}),T()}})}let k=c.isPending||u.isPending;return M(x,{open:S,onOpenChange:e=>!e&&T(),children:D(n,{children:[D(d,{children:[M(a,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),M(l,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:r.map(e=>D(`button`,{type:`button`,onClick:()=>v(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${_===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(y,{placeholder:`New person name…`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{v(null),g(!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…`}),D(s,{children:[M(m,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),h?D(m,{variant:`primary`,onClick:O,disabled:k||!f.trim(),children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(m,{variant:`primary`,onClick:()=>_&&E(_),disabled:k||!_,children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}E();function ke(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await ge(`${_e}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{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 Ae(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function je({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Me({box:e}){return M(`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:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ne({face:e,cameraName:t,onClose:r,onAssign:i,onUnassign:a,onDelete:o,actionsPending:s}){let{data:c,isFetching:l}=u({faceId:e?.faceId??``},{enabled:e!==null}),[d,f]=j(`frame`),{frameSrc:p,naturalWidth:h,naturalHeight:g,failed:_}=ke(e?.keyFrameMediaKey),v=O(()=>{let t=Ae(c??[]);return t?`data:image/jpeg;base64,${t.base64}`:Ee(e)},[c,e]),y=O(()=>!e?.faceBbox||h===null||g===null?null:R(e.faceBbox,h,g),[e?.faceBbox,h,g]);if(e===null)return null;let b=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!_,S=b&&d===`frame`,C=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(x,{open:!0,onOpenChange:e=>!e&&r(),children:D(n,{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:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(X,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[b&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>f(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>f(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),S&&p?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(H,{src:p,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:y?M(Me,{box:y}):void 0})}):v?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(H,{src:v,alt:`Detected face`,className:`h-full w-full`}),l&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`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:[M(V,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`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.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(je,{label:`Camera`,value:t}),M(je,{label:`Captured`,value:U(e.timestamp)}),M(je,{label:`Track`,value:e.trackId}),M(je,{label:`Identity`,value:C})]})]}),D(`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?D(m,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:s,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(m,{variant:`primary`,onClick:()=>i(e.faceId),disabled:s,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(m,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:s,children:[M(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Pe(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Fe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Ie(e,t){return e.faceIds.filter(e=>t(e))}E();var Le=[[`faceGallery`]],Re=20,ze=.3,Be=.9,Ve=.05,He=.5,Ue=2,We=10,Ge=2;function Ke({cluster:e,face:t,active:n,onSelect:r}){let i=Ee(t);return D(`button`,{type:`button`,onClick:r,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:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:i===null?M(V,{className:`h-24 w-24 p-6 text-foreground-subtle`}):M(`img`,{src:i,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),D(`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 qe({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){let s=Ee(e);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[s===null?D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(V,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):M(H,{src:s,alt:`Face from ${t}`,className:`h-full w-full`}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?K:X,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,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:o?M(J,{className:`h-4 w-4 animate-spin`}):M(Z,{className:`h-4 w-4`})})})]})}function Je({open:e,onClose:t,byId:r,cameraName:i,nowMs:a,identities:o,selectMany:s}){let l=A(),u=f(),d=c(),[p,h]=j(He),[g,_]=j(Ge),[v,y]=j(null),[b,C]=j({}),[w,T]=j(null),{data:E,isFetching:P,refetch:F}=S({threshold:p,minClusterSize:g,limit:Re},{enabled:e}),I=E??[];N(()=>{C({})},[p,g]),N(()=>{if(I.length===0){y(null);return}I.some(e=>e.representativeFaceId===v)||y(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===v)??null,[I,v]),R=L?b[L.representativeFaceId]??new Set:new Set,z=O(()=>L?Ie(L,e=>r.has(e)):[],[L,r]),te=L?L.faceIds.length-z.length:0,B=L?Fe({...L,faceIds:z},R):[];function ne(e){if(!L)return;let t=L.representativeFaceId;C(n=>({...n,[t]:Pe(n[t]??new Set,e)}))}function re(){l.invalidateQueries({queryKey:Le})}async function V(e){await u({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({faceId:e},{onSettled:re})}function H(){T(null),t()}function ie(){B.length!==0&&(s(B),H())}return D(x,{open:e,onOpenChange:e=>!e&&H(),children:[D(n,{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:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:H,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(X,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:ze,max:Be,step:Ve,value:p,onChange:e=>h(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:Ue,max:We,step:1,value:g,onChange:e=>_(Math.min(We,Math.max(Ue,Number(e.target.value)||Ue))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(m,{variant:`secondary`,onClick:()=>{C({}),F()},disabled:P,children:[P?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`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?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ke,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===v,onSelect:()=>y(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ke,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===v,onSelect:()=>y(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[te>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[te,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=r.get(e);return t?M(qe,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:R.has(e),onToggleExclude:()=>ne(e),onDelete:()=>void V(e),deletePending:d.isPending&&d.variables?.faceId===e},e):null})})]})})]})}),D(`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:[M(m,{variant:`secondary`,onClick:ie,disabled:B.length===0,children:`Select in gallery`}),D(m,{variant:`primary`,onClick:()=>T(B),disabled:B.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),M(Oe,{faceIds:w,identities:o,onDone:()=>T(null)})]})}E();var Ye=[[`faceGallery`]],Xe=500,Ze=120;function Qe({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:o}){let s=A(),l=g(),u=c(),d=()=>{s.invalidateQueries({queryKey:Ye})},f=()=>o(e.faceId),p=Ee(e);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[p===null?D(`button`,{type:`button`,onClick:f,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:[M(V,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):M(`img`,{src:p,alt:`Face from ${t}`,onClick:f,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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":r?`Deselect`:`Select`,children:r?M(ue,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},disabled:l.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:l.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(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:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({faceId:e.faceId},{onSettled:d})},disabled:u.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:u.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(Z,{className:`h-4 w-4`})})]})]})}var $e=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function et(){let e=A(),[t,n]=j(`all`),[a,o]=j(oe),[s,l]=j(new Set),[u,d]=j(new Set),[f,_]=j(null),[v,y]=j(!1),[x,S]=j(null),{data:C,isLoading:w}=h({limit:Xe,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=i(),{data:E}=r({}),N=b(),P=g(),F=p(),I=c(),R=Date.now(),B=C??[],H=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),U=e=>H.get(e)??`Camera #${String(e)}`,se=O(()=>te(B).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,H]),W=O(()=>re(ce(B,a),s),[B,a,s]),G=ie(W,Ze,O(()=>JSON.stringify([t,a.fromMs,a.toMs,[...s].sort((e,t)=>e-t)]),[t,a.fromMs,a.toMs,s])),le=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),ue=O(()=>Te(W),[W]),de=x===null?null:le.get(x)??null,K=()=>{e.invalidateQueries({queryKey:Ye})},q=()=>d(new Set);function fe(e){d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){d(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Y=[...u],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Y.length!==0&&F.mutate({faceIds:Y},{onSettled:()=>{K(),q()}})}function ve(){Y.length!==0&&Promise.allSettled(Y.map(e=>I.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){S(null),_([e])}function ye(e){P.mutate({faceId:e},{onSettled:K}),S(null)}function be(e){I.mutate({faceId:e},{onSettled:K}),S(null)}let xe=W.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:$e.map(e=>M(`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))}),M(ae,{onChange:o}),M(ne,{cameras:se,selected:s,onChange:l}),D(`button`,{type:`button`,onClick:()=>y(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${v?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!w&&ue>0&&D(`button`,{type:`button`,onClick:me,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:[M(V,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!w&&M(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(B.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),u.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[u.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(m,{variant:`primary`,onClick:()=>_(Y),disabled:Q,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(m,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(m,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),M(m,{variant:`ghost`,onClick:q,disabled:Q,children:M(X,{className:`h-3.5 w-3.5`})})]})]}),w&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!w&&W.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!w&&W.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>M(Qe,{face:e,cameraName:U(e.deviceId),nowMs:R,selected:u.has(e.faceId),onToggleSelect:fe,onAssign:e=>_([e]),onOpenDetail:S},e.faceId))}),M(z,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),M(Ne,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>S(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Oe,{faceIds:f,identities:T,onDone:()=>{_(null),q()}}),M(Je,{open:v,onClose:()=>y(!1),byId:le,cameraName:U,nowMs:R,identities:T,selectMany:pe})]})}E();var tt=[[`faceGallery`]],nt=2e3;function rt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=se({delayMs:nt,invalidate:()=>{t.current.invalidateQueries({queryKey:tt})}}),N(()=>()=>n.current?.cancel(),[]),w(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function it(){return rt(),M(Q,{icon:Y,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`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.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`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.`}),M(et,{})]})]})})}export{it as DetectionIntelligencePage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,Ai as t,Ao as n,Bn as r,D as i,Di as a,Do as o,E as s,Ei as c,Eo as l,Fo as u,Gi as d,H as f,Hn as p,Io as m,Ir as h,J as g,Ln as _,Lo as v,M as y,Mo as b,N as x,Ni as S,Nn as C,O as w,On as T,P as ee,Pn as te,Po as E,Q as ne,T as D,Tn as O,U as k,Ui as re,Un as ie,Ur as A,V as j,Vn as M,Wi as ae,Wn as N,X as oe,Y as se,Z as ce,Zi as le,_o as P,_r as F,a as ue,at as de,cn as I,ds as fe,et as L,f as pe,fa as me,fs as he,g as ge,gn as _e,gr as ve,hi as ye,i as be,it as xe,jn as R,jo as Se,kn as Ce,ko as we,l as Te,m as Ee,mo as De,n as Oe,nt as ke,o as Ae,ot as je,p as Me,po as Ne,ps as Pe,q as Fe,r as Ie,sn as Le,u as Re,ur as ze,us as z,vr as Be,wi as Ve,wn as He,wt as Ue,y as We,yn as Ge,zn as Ke,zo as qe,zt as Je}from"./src-BoczRE1G.js";import{I as B,K as V,Q as H,S as U,W,a as Ye,b as Xe,o as G,q as K,t as Ze,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{M as Qe,P as Y,Z as $e,a as et,i as tt}from"./src-Bok3PEiz.js";import{c as nt,k as rt,p as X,r as it,t as at,u as ot}from"./player-overlays-BzwYRH08.js";import{t as st}from"./CapabilityBadges-74hb8M82.js";import{t as ct}from"./boxes-0BrwpGRK.js";import{t as lt}from"./ProviderIcon-Ck_2pUvf.js";import{a as ut,c as dt,l as ft,n as pt,o as mt}from"./NodeInferenceDevices-CcxOtvMd.js";import{n as ht}from"./FormBuilder-_oFQtE7x.js";import{t as gt}from"./pencil-DDNEW9Yb.js";import{t as _t}from"./power-DV05ZWPi.js";import{t as vt}from"./refresh-cw-CYEUy6Ve.js";import{t as yt}from"./rotate-ccw-DTUvT-HV.js";import{t as bt}from"./rotate-cw-DWJibY6w.js";import{t as xt}from"./server-C3tpWUwZ.js";import{t as St}from"./wifi-C8Oz0yjQ.js";import{A as Ct,J as wt,K as Tt,L as Et,S as Dt,U as Ot,V as kt,W as At,a as jt,c as Mt,i as Nt,j as Pt,m as Ft,o as It,q as Lt,s as Rt,t as zt,v as Bt,y as Vt,z as Ht}from"./index-qYnug9Qs.js";import{t as Ut}from"./StatusBadge-Dcr2bw58.js";import{t as Wt}from"./useEventInvalidation-XgGxFYwt.js";import{i as Gt,n as Kt,r as qt,t as Jt}from"./DeviceAggregateSection-Tq3TjsO-.js";var Yt=At(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Xt=At(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),Zt=At(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Qt=At(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),$t=At(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);H();function en({parentDeviceId:t}){let{t:n}=zt(),r=Tt(),i=X(),{data:a,isLoading:o,isError:s}=mt(t),{data:c}=T({deviceId:t},{enabled:Number.isFinite(t)});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`common.loading`,{defaultValue:`Loading…`})})});if(s)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=se(c?.stableId??``,l,c?.childLayout),d=u.ungrouped,f=e=>r(`/devices/${String(e)}`),p=c?.name??``,m=(t,n)=>q(Fe,{trpc:i.trpcClient,device:{...n,name:e(n,p)},variant:`minimal`,onNavigate:f},t),h=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=h&&!_?n(`device.accessories`,{defaultValue:`Accessories`}):!h&&_?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`device.children`,{defaultValue:`Children`}),y=d.length>0?U(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),q(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:q(g,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:U(`div`,{className:`space-y-2`,children:[y,b]}):U(`div`,{className:`space-y-2`,children:[u.sections.map(e=>q(g,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function tn({deviceId:e}){let t=X(),{data:n,isLoading:r}=ut(e),{data:i,isLoading:a}=mt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(f,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}function nn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=ot(e?.state.motionTrigger),[a,o]=K(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return U(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[q(Ot,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}H();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=de(t)?.HeroCard??Ne,a=nt(r.trpcClient,e),o=ot(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return U(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?q(`div`,{className:`flex justify-center`,children:q(k,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(nn,{dev:a,busy:s,setBusy:c})})]})}function rn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(De,{trpc:X().trpcClient,deviceId:e,features:t})})}function an({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(Ne,{trpc:X().trpcClient,deviceId:e,features:t})})}function on(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function sn(e){if(!e)return null;let t=on(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var cn=1e3,ln=60*cn,un=60*ln,dn=24*un;function fn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<cn?`just now`:n<ln?`${String(Math.floor(n/cn))}s ago`:n<un?`${String(Math.floor(n/ln))}m ago`:n<dn?`${String(Math.floor(n/un))}h ago`:`${String(Math.floor(n/dn))}d ago`}H();var pn=1500,mn=15e3,hn=1e3;function gn({deviceId:e}){let t=nt(X().trpcClient,e)?.state.eventEmitter,n=ot(t);J(()=>{if(!t)return;t.refresh();let e=setInterval(()=>{t.refresh()},mn);return()=>{clearInterval(e)}},[t]);let r=n?.lastEvent??null,i=r?.seq??null,a=V(null),[o,s]=K(!1);J(()=>{if(i===null)return;let e=a.current;if(a.current=i,e===null||e===i)return;s(!0);let t=setTimeout(()=>{s(!1)},pn);return()=>{clearTimeout(t)}},[i]);let[c,l]=K(()=>Date.now());J(()=>{let e=setInterval(()=>{l(Date.now())},hn);return()=>{clearInterval(e)}},[]);let u=sn(r),d=n?.eventTypes??[],f=n?.eventCountSinceStart??0,p=n!==void 0,m=on(r?.data);return U(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[q(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(o),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${o?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:u??`No press recorded`,children:q(o?Qt:Xt,{className:`h-10 w-10`})}),U(`div`,{className:`text-center`,children:[m!==null&&q(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(m)}`}),q(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${u?`text-foreground`:`text-foreground-subtle`}`,children:u??(p?`No press recorded`:`Awaiting state…`)}),q(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r?fn(r.timestamp,c):`Waiting for the first event`})]}),d.length>0&&q(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:d.map(e=>q(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===r?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),q(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(f)} ${f===1?`event`:`events`} since start`})]})}function _n({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return U(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[q(lt,{type:n,size:`lg`}),U(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),U(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(Ut,{status:r?`online`:`offline`}),i.length>0&&q(st,{capabilities:i})]}),q(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}H();function vn({deviceId:e}){let t=G(),n=Le({deviceId:e},{refetchInterval:1e4,retry:!1}),r=I({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=W(()=>yn(n.data??[]),[n.data]);return U(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[U(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(bn,{label:`Discovered`,value:i.total,icon:q(Bt,{className:`h-3.5 w-3.5`})}),q(bn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(bn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),U(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?q(Dt,{className:`h-3.5 w-3.5 animate-spin`}):q(vt,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),U(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[q(xn,{icon:q(St,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(xn,{icon:q(Vt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(xn,{icon:q(jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(xn,{icon:q(Yt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function yn(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function bn({label:e,value:t,icon:n,accent:r}){return U(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[U(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function xn({icon:e,label:t}){return U(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}var Sn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:vn,[Y.Cover]:rn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:tn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:gn,[Y.Notifier]:an,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Cn(e){return Sn[e]??_n}function wn(e){return q(Cn(e.deviceType),{...e})}function Tn(e){return ue(X().trpcClient,e)}H();function En(e){let[t,n]=K(`idle`),[r,i]=K(null),a=V(null),o=V(null),s=V(null),c=V(!0),l=F(),u=ve(),d=Be(),f=B(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=B(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=B(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}H();var Dn=0;function Q(){return++Dn}function On(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function kn(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function An(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function jn(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Mn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${On(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=V(null),p=V(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=Ze({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...jn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return U(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[U(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),U(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Nn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Tn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=be(n.trpcClient,i?e:null),g=ce(i?e:null,{width:Rn}),_=En(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=it(),S=w(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(Xe,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(We,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:T,chromeless:!0,className:`h-full`})}function Pn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ge,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Fn({deviceId:e}){if(!Number.isFinite(e))return U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return q(Mn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function In({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ee,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ln({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(pe,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Rn=960,zn={"no-provider":`Not available — nothing in this installation provides it.`,"source-unreachable":`Unknown — the service that owns this did not answer.`,"not-configured":`Nothing set up yet — configure it first (Image → Privacy Mask).`};function Bn({deviceId:e}){let t=G(),{data:n,isLoading:r,error:i}=a({deviceId:e},{enabled:Number.isFinite(e)});Wt([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let o=[[`pipelineOrchestrator`,`getCameraSwitches`],{input:{deviceId:e}}],s=d({onMutate:async e=>{await t.cancelQueries({queryKey:o});let n=t.getQueryData(o);return n!==void 0&&t.setQueryData(o,{...n,switches:n.switches.map(t=>t.id===e.switchId&&t.available?{...t,enabled:e.enabled}:t)}),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(o,r.previous)},onSuccess:e=>{t.setQueryData(o,e),t.invalidateQueries({queryKey:[[`deviceManager`]]}),t.invalidateQueries({queryKey:[[`recording`]]})}});return r?U(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[q(Dt,{className:`h-3 w-3 animate-spin`}),` Loading camera functions…`]}):i||!n?U(`div`,{className:`flex items-start gap-2 rounded-lg border border-border p-3 text-xs text-muted`,children:[q(It,{className:`mt-0.5 h-3 w-3 shrink-0`}),q(`span`,{children:`Camera functions could not be read. Nothing has changed — the switches are not shown rather than shown with a guessed state.`})]}):q(`div`,{className:`flex flex-col gap-2`,children:n.switches.map(t=>q(Vn,{row:t,busy:s.isPending&&s.variables?.switchId===t.id,onToggle:n=>s.mutate({deviceId:e,switchId:t.id,enabled:n})},t.id))})}function Vn({row:e,busy:t,onToggle:n}){let r=e.available&&!e.enabled;return U(`div`,{className:`rounded-lg border p-3 ${r?`border-warning/50 bg-warning/5`:`border-border`}`,children:[U(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[U(`div`,{className:`flex items-center gap-2`,children:[q(`span`,{className:`text-sm font-medium`,children:e.label}),r?q(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-warning`,children:`Off`}):null]}),e.available?q(`button`,{type:`button`,disabled:t,onClick:()=>n(!e.enabled),className:`shrink-0 rounded border border-border px-2 py-1 text-xs disabled:opacity-50`,children:e.enabled?`Turn off`:`Turn on`}):q(`span`,{className:`shrink-0 text-[11px] text-muted`,children:e.unavailableReason?zn[e.unavailableReason]:`Not available.`})]}),q(`p`,{className:`mt-1.5 text-xs leading-snug text-muted`,children:e.costWhenOff})]})}function Hn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=T({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Wt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=O({deviceId:e},{enabled:n}),{data:l}=C({deviceType:i},{enabled:!!i}),u=N({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return U(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return U(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(ct,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return U(`div`,{className:`flex flex-col gap-3 p-1`,children:[i===`camera`?U(`section`,{className:`flex flex-col gap-2`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Camera functions`}),q(Bn,{deviceId:e})]}):null,U(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(Se,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Un,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(Wn,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(Gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function Un({kind:e}){return e===`native`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(xt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(ft,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Zt,{className:`h-3 w-3`}),`linked`]}):U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(dt,{className:`h-3 w-3`}),`unbound`]})}function Wn({nodeId:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return U(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(i?Et:yt,{className:`h-3 w-3`}),e]},e)})})}function Kn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Jt,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}H();var qn=new Set([`package-detection`]);function Jn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Yn(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Xn({deviceId:e,refreshToken:t}){let r=G(),i=X().trpcClient,[a,s]=K(null),[u,d]=K(null),[f,p]=K(null),m=Ve({deviceId:e},{refetchOnMount:`always`}),h=c({deviceId:e},{refetchOnMount:`always`}),g=S(void 0,{refetchOnMount:`always`});Wt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let _=A(void 0,{refetchOnMount:`always`}),v=W(()=>{let e=new Set;for(let t of _.data??[])t.isOnline&&e.add(t.id);return e},[_.data]),y=W(()=>(g.data??[]).filter(e=>v.has(e.nodeId)).map(e=>e.nodeId),[g.data,v]),b=y[0]??``,x=ye({nodeId:b},{enabled:b!==``,refetchOnMount:`always`}),C=Ye({enabled:y.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,y.join(`,`),t],queryFn:async()=>{let e={};for(let t of y)try{e[t]=(await i.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),w=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},T=re({onSuccess:w}),ee=ae({onSuccess:w}),te=W(()=>x.data?we(x.data):[],[x.data]),E=W(()=>{let e=g.data??[],t=v.size===0?[]:e.filter(e=>v.has(e.nodeId)),n=[];for(let e of t){let t=(C.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:pt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[g.data,C.data,v]),ne=(e,t)=>C.data?.[e]?.find(e=>e.key===t)??null,D=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=C.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},O=(e,t,n)=>h.data?.[e]?.[t]?.[n]??null,k=e=>{if(qn.has(e))return{kind:`zone-driven`};let t=Jn(x.data??null,e)?.enabledByDefault??!0,n=m.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ie=(e,t)=>{let n=Jn(x.data??null,e);if(n)return fe(n,t)},j=(e,t)=>{let n=k(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Jn(x.data??null,e),a=D(t),o=a===null?null:ne(t.agentNodeId,a);if(!Pe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:O(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?he({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Yn(s)}},M=a&&x.data?Jn(x.data,a.addonId):null,N=a?ne(a.agentNodeId,a.deviceKey):null,oe=N?.format??`coreml`,se=a?Yn(O(a.agentNodeId,a.deviceKey,a.addonId)):!1,ce=a?ie(a.addonId,N):void 0,le=W(()=>{if(!a||!N)return null;let e=N.steps?.[a.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[a,N]),P=()=>{s(null),d(null)},F=(e,t)=>{let n=D(t);n!==null&&(s({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),d(O(t.agentNodeId,n,e)))},ue=(t,n)=>{ee.mutate({deviceId:e,addonId:t,enabled:n})},de=()=>{a&&T.mutate({deviceId:e,agentNodeId:a.agentNodeId,deviceKey:a.deviceKey,addonId:a.addonId,patch:u},{onSuccess:P})},I=()=>{a&&T.mutate({deviceId:e,agentNodeId:a.agentNodeId,deviceKey:a.deviceKey,addonId:a.addonId,patch:null},{onSuccess:P})};if(g.isLoading||b!==``&&x.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(E.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!x.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let L=a!==null&&M!==null&&N!==null;return U(`div`,{className:`relative h-full w-full space-y-3`,children:[U(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,q(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),U(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),q(`div`,{className:L?`md:pr-[360px]`:``,children:te.length>0?q(l,{tree:te,agents:E,gateFor:k,getCellState:j,onCellClick:F,selectedCell:a,onSetGate:ue,gateBusy:ee.isPending,fallbackNodeId:f,onFallbackNodeChange:p}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(n,{open:L,onClose:P,title:M?.name??``,subtitle:a&&N?`${a.agentNodeId} · ${pt(N).label} · ${N.format}`:``,footer:U(Xe,{children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!se||T.isPending,onClick:I,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),q(`button`,{type:`button`,disabled:!a||!le||T.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:de,children:T.isPending?`Saving…`:`Save`})]}),children:M&&a&&le?q(o,{mode:`device`,addon:M,agentDefault:le,agentNodeId:a.agentNodeId,currentPatch:u,engineFormat:oe,effectiveModelId:ce,onChangePatch:d}):q(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var Zn=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Qn={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function $n(e){return Qn[e]??`object-detection`}H();var er=`steps`,tr=`settings`,nr=new Set([er,tr]);function rr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function ir({deviceId:e,activeSubTab:t,onSubTabChange:n}){return U(E,{value:t&&nr.has(t)?t:er,onValueChange:B(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[U(m,{className:`flex-shrink-0`,children:[q(v,{value:er,children:`Steps`}),q(v,{value:tr,children:`Settings`})]}),q(u,{value:er,children:q(Xn,{deviceId:e,refreshToken:0})}),q(u,{value:tr,children:q(Jt,{deviceId:e,sectionFilter:rr,subTabGrouping:{groupOf:e=>$n(e.id),tabs:Zn}})})]})}function $({label:e,value:t}){return U(`div`,{className:`${rt} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}H();function ar({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=V(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=M({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Et,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Nt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(gt,{className:`h-3.5 w-3.5`})})]})})}H();function or({deviceId:e,initialLocation:t}){let n=G(),[i,a]=K(!1),[o,s]=K(t??``),[c,l]=K(!1),u=V(null),{data:d}=te(void 0,{enabled:i}),f=d??[];J(()=>{i||s(t??``)},[t,i]),J(()=>{i&&u.current?.focus()},[i]);let p=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=W(()=>{let e=o.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,o]),h=o.trim().length>0&&!f.some(e=>e.toLowerCase()===o.trim().toLowerCase()),g=async n=>{let r=(n??o).trim(),i=r.length===0?null:r;if(i===(t??null)){a(!1);return}l(!0);try{await p.mutateAsync({deviceId:e,location:i}),a(!1)}catch{}finally{l(!1)}},_=()=>{s(t??``),a(!1)};return i?q($,{label:`Location`,value:U(`div`,{className:`relative`,children:[U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:u,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:c,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void g(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Et,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Nt,{className:`h-3 w-3`})})]}),(m.length>0||h)&&U(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[m.map(e=>U(`button`,{type:`button`,onClick:()=>{s(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(ht,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&U(`button`,{type:`button`,onClick:()=>void g(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),U(`span`,{className:`font-medium truncate`,children:[`"`,o.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>a(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(gt,{className:`h-3.5 w-3.5`})})]})})}H();function sr({deviceId:e}){let t=G(),{data:n}=ut(e),{data:r}=mt(e),[i,a]=K(null),o=p({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=xe(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return U(Xe,{children:[q($,{label:`Primary child`,value:q(j,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}H();var cr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function lr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ur(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dr(){let e=x(),t=ee(),{data:n}=T({deviceId:e??0},{enabled:e!==null}),{data:r}=O({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[U(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&U(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(fr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(fr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&U(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:U(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,U(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),q(ar,{deviceId:e,initialName:c}),q(or,{deviceId:e,initialLocation:h}),q(sr,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(lt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:m.length>0?q(st,{capabilities:m,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&q(pr,{metadata:g})]})}function fr({active:e,onClick:t,label:n}){return q(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function pr({metadata:e}){let t=cr.filter(t=>t in e),n=Object.keys(e).filter(e=>!cr.includes(e)).toSorted(),r=[...t,...n];return U(`div`,{children:[q(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:lr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ur(e[t])})},t))})]})}H();function mr({deviceId:e}){let[t,n]=K(null),r=_e({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return U(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[U(`div`,{className:`flex items-center justify-between gap-3`,children:[U(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),U(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[q(vt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}H();var hr={icon:``,label:``,unit:``,precision:``,hidden:!1};function gr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _r(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function yr({deviceId:e}){let t=X(),n=G(),{data:r}=T({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:je[i],o=a?.kind===`numeric`,s=Oe(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=_r(s)??c,u=l===void 0?void 0:tt(l),d=W(()=>u===void 0?[]:et(u),[u]),[f,p]=K(null),m=f??gr(r?.display),h=Ke({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:g}=R({},{staleTime:6e4}),_=ie({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let v=e=>{p({...m,...e})},y=()=>{h.mutate({deviceId:e,display:vr(m)})},b=()=>{p(hr),h.mutate({deviceId:e,display:null})},x=()=>{let e={...m.icon===``?{}:{icon:m.icon},...m.unit===``?{}:{unit:m.unit},...m.precision.trim()!==``&&Number.isFinite(Number.parseInt(m.precision,10))?{precision:Number.parseInt(m.precision,10)}:{}},t={...g?.defaults??{},[i]:e};_.mutate({defaults:t})},S=ke(i).label,C=Object.keys(L);return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),U(`div`,{className:`p-4 space-y-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.icon,onChange:e=>v({icon:e.target.value}),children:[U(`option`,{value:``,children:[`Default (`,S,`)`]}),C.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:S,value:m.label,onChange:e=>v({label:e.target.value})})]}),o&&U(`div`,{className:`grid grid-cols-2 gap-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.unit,onChange:e=>v({unit:e.target.value}),disabled:d.length===0,children:[U(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),d.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:m.precision,onChange:e=>v({precision:e.target.value})})]})]}),U(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:m.hidden,onChange:e=>v({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),U(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:y,disabled:h.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:b,disabled:h.isPending,children:`Reset`}),U(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:_.isPending,title:`Apply this unit / precision / icon as the default for every ${S} sensor`,children:[`Set as default for all `,S,` sensors`]})]})]})]})}function br(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function xr({device:e}){let t=Tt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(Qe.Resyncable),{data:l}=h({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(Qe.DoorbellButton),p=Ie(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return U(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Me,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(mr,{deviceId:n}),i&&n!==null&&q(D,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Re,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(D,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&U(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>U(`div`,{className:`px-4 py-2.5`,children:[U(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(St,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),U(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(Sr,{label:`Nominal`,value:br(t.nominalBitrateKbps??0)}),q(Sr,{label:`Observed`,value:br(t.observedBitrateKbps??0)}),q(Sr,{label:`Peak`,value:br(t.peakBitrateKbps??0)}),q(Sr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(dr,{}),o&&n!==null&&q(yr,{deviceId:n})]})}function Sr({label:e,value:t,warning:n}){return U(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}H();var Cr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0}];function wr(e){let t=e===Y.Camera;return Cr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var Tr=[{id:`logs`,icon:Ft,label:`Logs`},{id:`repl`,icon:Mt,label:`REPL`},{id:`events`,icon:kt,label:`Events`},{id:`state`,icon:Ct,label:`State`}];function Er(){let e=Lt(),n=Number(e.deviceId),r=Number.isFinite(n),a=Tt(),o=G(),c=P(),l=X(),[u,d]=wt(),f=u.get(`tab`)??`overview`,p=u.get(`sub`),[m,h]=K(`logs`),g=`device-detail.left-col-width-px`,[v,x]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(g),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=V(v);S.current=v;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??v??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{x(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(g,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:w,isLoading:ee,isError:te}=T({deviceId:n},{enabled:r,refetchInterval:5e3,retry:1}),{data:E}=Ce({deviceId:n},{enabled:r}),D=W(()=>{let e=E?.settings?.sections??[],t=E?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Gt)&&r.add(Kt),[...r].map(e=>e===`export`?{id:e,label:qt,isAddonContrib:!0}:{id:e,label:$e[e]?.label??e,isAddonContrib:!0})},[E]),O=w,k=String(O?.name??e.deviceId??`Device`),re=O?.online===!0,ie=re?`online`:`offline`,A=String(O?.addonId??`rtsp`),j=O?.features??[],M=O?.type,ae=M===Y.Camera,{data:N}=mt(r?n:0),se=M===Y.Container,ce=W(()=>(N??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[N]),F=W(()=>se?xe(ce,typeof O?.linkDeviceId==`number`?O.linkDeviceId:null,typeof O?.primaryChildEntityId==`string`?O.primaryChildEntityId:null)?.id??null:null,[se,ce,O?.linkDeviceId,O?.primaryChildEntityId]),{data:ue}=Ce({deviceId:F??0},{enabled:F!==null}),de=W(()=>{if(F===null)return[];let e=ue?.settings?.sections??[],t=ue?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:$e[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,ue]),I=typeof O?.parentDeviceId==`number`?O.parentDeviceId:null,{data:fe}=T({deviceId:I??0},{enabled:I!==null}),L=qe(),pe=O?.disabled!==!0,he=W(()=>{let e=new Set,t=[];for(let n of[...wr(M),...D,...de])e.has(n.id)||(e.add(n.id),t.push(n));return t},[M,D,de]),ge=W(()=>he.some(e=>e.id===f)?f:`overview`,[he,f]),_e=B(e=>{d(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[d]),ve=B(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),ye=(N??[]).length>0,be=W(()=>Tr.filter(({featureGate:e})=>!e||j.includes(e)),[j]),{data:R}=ze({addonId:A},{enabled:!!A&&A!==`rtsp`}),Se=_({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]}),a(R?.id?`/integrations/${R.id}`:`/integrations`)}}),we=He({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=Ge({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=me(),Oe=Ue({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=j.includes(Qe.Rebootable),je=j.includes(Qe.BatteryOperated),Me=ne(l.trpcClient,je&&r?n:null),[Ne,Pe]=K(!1),Fe=nt(l.trpcClient,r?n:null),Ie=async()=>{if(!(Ne||!Fe)){Pe(!0);try{await Fe.snapshot?.invalidateCache({});let e=await Fe.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=k.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Pe(!1)}}},Le=we.isPending||Ee.isPending,{data:Re}=t({deviceId:n},{enabled:r,refetchInterval:1e4}),z=Re?.agentNodeId??null,Be=typeof z==`string`&&z.length>0&&!z.startsWith(`addon:`)?z:void 0,{data:Ve}=le({deviceId:n,...Be?{nodeId:Be}:{}},{enabled:r,refetchInterval:3e3,retry:!1}),{data:We}=Je({deviceId:n},{enabled:r,refetchInterval:3e3,retry:!1}),Ke=We?.level?.dbfs??null;function H(){if(!r)return null;switch(ge){case`overview`:return q(xr,{device:O??{}});case`config`:return q(Kn,{deviceId:n,activeSubTab:p,onSubTabChange:ve});case`detection-pipeline`:return q(ir,{deviceId:n,activeSubTab:p,onSubTabChange:ve});case`bindings`:return q(Hn,{deviceId:n});default:{let e=ge,t=D.some(t=>t.id===e),r=de.find(t=>t.id===e);if(!t&&r===void 0)return null;let i=r?.childDeviceId??n;if(e===`export`)return q(Jt,{deviceId:n,sectionFilter:Gt,activeSubTab:p,onSubTabChange:ve});let a=q(Jt,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:p,onSubTabChange:ve});return r!==void 0&&i!==n?q(y,{deviceId:i,children:a}):a}}}return r?ee?U(`div`,{className:`flex flex-col h-full`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):te||!w?U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),U(`p`,{className:`text-xs`,children:[`No device with ID`,` `,U(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n]})]}),q(`button`,{onClick:()=>a(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):U(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(b,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:R?.name??A,onClick:()=>R?.id&&a(`/integrations/${R.id}`)},{label:k}]})}),U(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(lt,{type:A,size:`lg`}),U(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:k}),q(Ut,{status:ie}),je&&q(oe,{status:Me,variant:`full`})]}),I!==null&&fe&&U(`button`,{type:`button`,onClick:()=>a(`/devices/${I}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${fe.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(fe.name??`Device #${I}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:j.length>0&&q(st,{capabilities:j})})]}),Ve&&q(`div`,{className:`hidden lg:flex`,children:q(Dr,{metrics:Ve,dbfs:Ke})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:[U(`button`,{onClick:async()=>{pe?await c({title:`Disable "${k}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ee.mutate({deviceId:n}):we.mutate({deviceId:n})},disabled:Le,title:pe?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${pe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(_t,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:pe?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(Te,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Ht,disabled:Ne,onClick:()=>{Ie()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:bt,hidden:!ke,disabled:De.isPending,danger:!0,onClick:async()=>{await c({title:`Reboot "${k}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&De.mutate({deviceId:n})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??A}.`,icon:vt,disabled:Oe.isPending,danger:!0,onClick:async()=>{await c({title:`Restart "${R?.name??A}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${k}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Oe.mutate({addonId:A})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Rt,separatorBefore:!0,disabled:Se.isPending,danger:!0,onClick:async()=>{await c({title:`Delete "${k}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Se.mutate({deviceId:n})}}]})]})]})]}),q(y,{deviceId:n,device:O??void 0,children:q(i,{children:q(s,{children:q(at,{children:q(Ae,{children:U(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[U(`div`,{className:L?`flex flex-col bg-surface`:`${v===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&v!==null?{width:`${String(v)}px`}:void 0,children:[q(`div`,{className:ae?`flex-shrink-0 border-b border-border-subtle bg-black`:L?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ae?q(Nn,{deviceId:n,intercomAvailable:j.includes(Qe.TwoWayAudio)}):q(wn,{deviceId:n,deviceName:k,deviceType:M??`unknown`,provider:A,isOnline:re,features:j})}),U(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:be.map(({id:e,label:t,icon:n})=>U(`button`,{onClick:()=>h(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${m===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),U(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[m===`logs`&&q(Pn,{deviceId:n,containerDeviceId:M===`container`?n:void 0}),m===`repl`&&q(Fn,{deviceId:n}),m===`events`&&q(In,{deviceId:n}),m===`state`&&q(Ln,{deviceId:n})]})]})]}),!L&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),U(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:he.map(e=>{let t=ge===e.id;return U(`button`,{onClick:()=>_e(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),U(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ge===`overview`&&ye&&q(en,{parentDeviceId:n}),H()]})]})]})})})})})})]}):U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),U(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>a(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function Dr({metrics:e,dbfs:t}){let n=z(e.phase??`idle`);return U(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[U(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Ot,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Pt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q($t,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&U(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Er as DeviceDetailPage};
|