@camstack/addon-admin-ui 1.1.12 → 1.1.14
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-DlR9gTk2.js → AddLocationWizard-CawJjq9O.js} +1 -1
- package/dist/assets/{AddonCollectionPage-Datt1QjM.js → AddonCollectionPage-DiF5AYnC.js} +1 -1
- package/dist/assets/Addons-C-8NeDO5.js +1 -0
- package/dist/assets/{AdminTabs-D7kzyXLz.js → AdminTabs-CrqkErQQ.js} +1 -1
- package/dist/assets/{BrokerForm-Dw9_9N5P.js → BrokerForm-0rKBuF8p.js} +1 -1
- package/dist/assets/{Capabilities-CLy9ICEh.js → Capabilities-DiiLGuTM.js} +1 -1
- package/dist/assets/{CapabilityBadges-BPfyv6vE.js → CapabilityBadges-DaHIljLG.js} +1 -1
- package/dist/assets/Cluster-B9bFGSK9.js +1 -0
- package/dist/assets/{Dashboard-BykmUF3R.js → Dashboard-EqPA4yT9.js} +1 -1
- package/dist/assets/{Data-DEJVq4Tn.js → Data-DgDHYoOn.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BxkEbvUW.js → DetectionIntelligence-BPOTI09n.js} +1 -1
- package/dist/assets/DeviceDetail-DnraMbRL.js +2 -0
- package/dist/assets/{Devices-DKvJqGNq.js → Devices-DZ_X4x6p.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-PG84aI9p.js → EmbedPlayerPage-DQo0RoN9.js} +1 -1
- package/dist/assets/{FormBuilder-DxflfkYi.js → FormBuilder-D-QNA2lK.js} +1 -1
- package/dist/assets/Identity-DCDezYKs.js +1 -0
- package/dist/assets/IntegrationDetail-DQ6HTyZW.js +1 -0
- package/dist/assets/Integrations-CoP8_M1e.js +1 -0
- package/dist/assets/{Integrations-DFzJOv99.js → Integrations-DgauthZ8.js} +1 -1
- package/dist/assets/{Logs-B_i6zUCC.js → Logs-Djo9uCRt.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CfD6FLpk.js → MotionZonesSettings-CI63uXWD.js} +1 -1
- package/dist/assets/{MyAccess-h2VOw8pX.js → MyAccess-C_bnUKhw.js} +1 -1
- package/dist/assets/{Network-DjbRbVT4.js → Network-CiNbhtus.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DwQvoGUf.js → NodeAddonsSettingsPanel-B4e-lRqr.js} +1 -1
- package/dist/assets/Pipeline-CcMk2ES1.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-pQazgIRJ.js → PrivacyMaskSettings-BummqklU.js} +1 -1
- package/dist/assets/{ProviderIcon-C0HnZBxx.js → ProviderIcon-BDFPkYDE.js} +1 -1
- package/dist/assets/ScanNetworkModal-vWYuMGDb.js +1 -0
- package/dist/assets/{Settings-VLw2oCwY.js → Settings-D73YFlEQ.js} +1 -1
- package/dist/assets/{Showroom-DwMkhg2M.js → Showroom-pqboQmke.js} +1 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C137oRgY.js +1 -0
- package/dist/assets/{bell-kKIifPdi.js → bell-CmeRVW62.js} +1 -1
- package/dist/assets/circle-check-big-Cv97W--S.js +1 -0
- package/dist/assets/{copy-CYPlIId0.js → copy-BK8sHe5Q.js} +1 -1
- package/dist/assets/{dist-Dq9dSqES.js → dist-CLT8PHlH.js} +1 -1
- package/dist/assets/dist-DepshcCH.js +2 -0
- package/dist/assets/{download-D3dyD303.js → download-iByzeG05.js} +1 -1
- package/dist/assets/{esm-D1aSlve1.js → esm-dN9syO45.js} +1 -1
- package/dist/assets/hostInit-C_whfpPE.js +1 -0
- package/dist/assets/index-CGhDR20N.css +2 -0
- package/dist/assets/index-D47Lr61N.js +4 -0
- package/dist/assets/{key-round-D9IA_YAT.js → key-round-BFzr1tXy.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-39b8eb5c.js → mf-entry-bootstrap-0-6ba630bb.js} +2 -2
- package/dist/assets/{pencil-kf9oWwQP.js → pencil-Bgmtz9nd.js} +1 -1
- package/dist/assets/{player-overlays-DY_CVt4U.js → player-overlays-CaqPpxmJ.js} +1 -1
- package/dist/assets/plus-1bnq-fpe.js +1 -0
- package/dist/assets/{radio-C4fS-iZ9.js → radio-CmNxZ34S.js} +1 -1
- package/dist/assets/{refresh-cw-SRDkmGt6.js → refresh-cw-C-HJCHCI.js} +1 -1
- package/dist/assets/remoteEntry-DR1-Sccw.js +1 -0
- package/dist/assets/{rotate-ccw-ov-aP4t5.js → rotate-ccw-Dl8LWFxz.js} +1 -1
- package/dist/assets/rotate-cw-BKVInbi8.js +1 -0
- package/dist/assets/search-DCU6LZ4q.js +1 -0
- package/dist/assets/{server-7BEVQ_1Q.js → server-CEgOqJh9.js} +1 -1
- package/dist/assets/{sparkles-BWCqk2kM.js → sparkles-D_w0SFvB.js} +1 -1
- package/dist/assets/square-C13IT6rC.js +1 -0
- package/dist/assets/{square-check-big-Czqt9V_V.js → square-check-big-CJH2zXcT.js} +1 -1
- package/dist/assets/src-CYTczZ73.js +2 -0
- package/dist/assets/src-D8t1tQm_.js +61 -0
- package/dist/assets/{upload-BusXXXDJ.js → upload-Cx2deF-8.js} +1 -1
- package/dist/assets/{useDevice-BxrbLlpH.js → useDevice-BIHpZ5m0.js} +1 -1
- package/dist/assets/{useEventInvalidation-CDlHOYGm.js → useEventInvalidation-Dnalcbum.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BCE6ubhD.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Csf3LiKD.js} +2 -2
- package/dist/assets/{wifi-BW-fVi7Z.js → wifi-zLl1cg2Y.js} +1 -1
- package/dist/assets/{zap-BOID3t2y.js → zap-nIYYJryw.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +91 -6
- package/package.json +1 -1
- package/dist/assets/Addons-D45c0-Md.js +0 -1
- package/dist/assets/BrokerStep-4yPt7WFf.js +0 -1
- package/dist/assets/Cluster-MaIh586X.js +0 -1
- package/dist/assets/DeviceDetail-CiHpdVia.js +0 -2
- package/dist/assets/Identity-DUrN0E9w.js +0 -1
- package/dist/assets/IntegrationDetail-Ht8B0DrX.js +0 -1
- package/dist/assets/Integrations-Cs6CJEVv.js +0 -1
- package/dist/assets/Pipeline-USFm9EMm.js +0 -1
- package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CqW10QJD.js +0 -1
- package/dist/assets/circle-check-big-CHV6BcRn.js +0 -1
- package/dist/assets/dist-DMayYqlf.js +0 -2
- package/dist/assets/hostInit-C7S14vqi.js +0 -1
- package/dist/assets/index-DH4Y-X3G.css +0 -2
- package/dist/assets/index-KGQreUXd.js +0 -4
- package/dist/assets/plus-B-sSvurw.js +0 -1
- package/dist/assets/remoteEntry-CQBXY6RK.js +0 -1
- package/dist/assets/rotate-cw-FopI4hrl.js +0 -1
- package/dist/assets/search-CJ28-QpX.js +0 -1
- package/dist/assets/square-Bcw-OQRd.js +0 -1
- package/dist/assets/src-DL7iSgmy.js +0 -2
- package/dist/assets/src-DVSeapHz.js +0 -34
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,Ii as t,Q as n,_r as r,_t as i,at as a,ct as o,dr as s,et as c,ft as l,g as u,gt as d,it as ee,lt as f,m as p,mt as m,nt as te,pt as h,rt as g,st as _,tt as v,ut as y,v as ne,vt as re,yt as b,zi as x}from"./src-DVSeapHz.js";import{G as S,I as C,K as w,R as T,S as E,W as D,Z as O,b as k,o 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-CCjPq1YD.js";import{p as N}from"./player-overlays-DY_CVt4U.js";import{t as P}from"./download-D3dyD303.js";import{t as ie}from"./plus-B-sSvurw.js";import{t as F}from"./refresh-cw-SRDkmGt6.js";import{t as ae}from"./search-CJ28-QpX.js";import{t as I}from"./upload-BusXXXDJ.js";import{A as L,B as R,F as oe,H as z,P as se,W as B,f as V,h as H,i as U,o as W,p as ce,s as le,x as G}from"./index-KGQreUXd.js";import{t as K}from"./AdminPage-vtcsGqRq.js";import{t as ue}from"./NodeAddonsSettingsPanel-DwQvoGUf.js";var de=R(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),q=R(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),J=R(`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`}]]),fe=R(`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`}]]);O();function pe({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i}){let a=n===`upload`||n===`local`,{data:o,isLoading:s}=g({name:e});return E(`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:[E(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),j(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:j(U,{className:`h-3 w-3`})})]}),a&&E(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[j(I,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),E(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[E(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,j(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),s&&E(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[j(G,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),o&&j(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:o.map(e=>{let n=e.version===t,i=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version);return E(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[j(`span`,{className:`font-mono flex-1 ${n?`text-primary font-semibold`:i?`text-amber-400`:`text-foreground`}`,children:e.version}),e.distTags.map(e=>j(`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&&j(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),j(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()}),n&&!a?j(oe,{className:`h-3 w-3 text-primary shrink-0`}):j(`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:j(P,{className:`h-3 w-3`})})]},e.version)})}),o&&o.length===0&&j(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Y={queued:{icon:q,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:G,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:F,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:oe,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:J,bg:`bg-danger/10 text-danger`,label:`failed`}};function me({item:e}){let t=Y[e.status],n=t.icon;return E(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[j(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}var X=`device-export`;function he(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===X)}function ge({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=w(!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 E(`div`,{className:`relative flex-shrink-0`,children:[j(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?j(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):j(e?fe:H,{className:`h-4 w-4`})}),t===`local`&&j(`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`&&j(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:j(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:j(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&j(`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:j(I,{className:`h-2.5 w-2.5 text-white`})})]})}function _e({version:e,availableUpdate:t,isUpdating:n,installSource:r,disabled:i,onActivate:a,onOpenPicker:o,children:s}){return n?E(`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:[j(G,{className:`h-3 w-3 animate-spin`}),`Updating…`]}):E(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:i,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`,r===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:t?`border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:t?`Update available (${t}) — tap to update. Current ${e}.`:`Version ${e} — tap to view all versions`,children:[t&&j(P,{className:`h-3 w-3`}),e,!t&&j(se,{className:`h-3 w-3 opacity-50`})]}),t&&j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:i,className:`hidden sm:inline-flex items-center rounded-md px-1 py-1 text-foreground-subtle border border-border hover:bg-surface-hover disabled:opacity-50`,title:`View all versions`,"aria-label":`View all versions`,children:j(se,{className:`h-3 w-3`})}),s]})}function ve({addonId:e}){let t=A(),{data:n=`inherit`}=c({addonId:e}),r=m({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return j(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>j(`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 ye({addon:e,agents:n=[],clusterStatus:r,hideVersion:a,availableUpdate:o,onUpdate:s,isUpdating:c,bundle:d,bulkItem:f,disabledByBulk:m,isSystem:te}){let[h,g]=w(!1),[_,v]=w(!1),[re,b]=w(!1),[x,S]=w(!1),[C,T]=w(!1),[D,O]=w(`logs`),M=A(),P=N(),ae=z(),I=t(),{manifest:L}=e,R=e.installedOn??[],oe=!d&&!L.protected&&L.removable!==!1,B=!!d,H=d?.displayName??L.name,W=d?.packageName??L.packageName,G=d?.version??L.packageVersion??L.version,K=d?.installSource??e.installSource,q=d?d.bundle?.description??d.addons[0]?.manifest.description:L.description,Y=i({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=y({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]})}}),be=ee({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]}),M.invalidateQueries({queryKey:[[`integrations`]]})}}),xe=l({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=e.health,Se=Z?.phase===`failed`&&!Z.inGracePeriod,Ce=Se&&Z?.nextRetryAt&&!Z.retrying;return E(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Se?`border-red-500/50`:`border-border`}`,children:[Se&&Z&&E(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[j(J,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),E(`div`,{className:`flex-1 min-w-0`,children:[E(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),j(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),Ce&&Z.nextRetryAt&&E(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),E(`button`,{type:`button`,disabled:xe.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),xe.mutate({packageName:W})},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:[j(F,{className:`h-3 w-3 ${xe.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),E(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[j(ge,{isBundle:B||!!L.components&&L.components.length>1,installSource:K,addonId:B?d.addons[0]?.manifest.id:L.id,iconPath:B?d.bundle?.icon??d.addons[0]?.manifest.icon:L.icon,color:B?d.addons[0]?.manifest.color:L.color}),E(`div`,{className:`flex-1 min-w-0`,children:[E(`div`,{className:`flex items-start justify-between gap-2`,children:[j(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:H}),!a&&j(_e,{version:G,availableUpdate:o,isUpdating:c,installSource:K,disabled:m,onActivate:()=>{o&&s?s():b(e=>!e)},onOpenPicker:()=>b(e=>!e),children:re&&j(pe,{packageName:W,currentVersion:G,...K?{installSource:K}:{},onInstall:e=>{b(!1),be.mutate({packageName:W,version:e})},onClose:()=>b(!1)})})]}),E(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[W!==H&&j(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:W}),B&&E(`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:[j(fe,{className:`h-3 w-3`}),d.addons.length]}),te&&E(`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:[j(F,{className:`h-3 w-3`}),`System`]}),f!=null&&j(me,{item:f})]}),q&&j(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:q}),!B&&e.process&&E(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[j(`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&&E(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),j(`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})]})]})]}),!B&&E(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:L.id})},disabled:X.isPending||m,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:[j(F,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${x?`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:[j(ce,{className:`h-3 w-3`}),`Logs`]}),!B&&E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${C?`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:[j(V,{className:`h-3 w-3`}),`Settings`]}),j(`div`,{className:`flex-1`}),oe&&E(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await I({title:`Uninstall ${L.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&Y.mutate({packageName:L.packageName})},disabled:Y.isPending||m,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:[j(le,{className:`h-3 w-3`}),Y.isPending?`Removing...`:`Uninstall`]})]}),r&&r.nodes.length>1&&!B&&E(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),j(`div`,{className:`space-y-1`,children:r.nodes.map(e=>E(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[j(`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`}`}),j(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),j(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&j(`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`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&j(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),x&&!B&&E(`div`,{className:`border-t border-border`,children:[E(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[E(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[j(`button`,{type:`button`,onClick:()=>O(`logs`),className:`px-2 py-0.5 transition-colors ${D===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),j(`button`,{type:`button`,onClick:()=>O(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${D===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),j(`div`,{className:`flex-1`}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(!1)},className:`text-foreground-subtle hover:text-foreground`,children:j(U,{className:`h-3.5 w-3.5`})})]}),D===`logs`&&j(u,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),D===`events`&&j(p,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),B&&E(k,{children:[j(`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:j(h?de:se,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),h&&j(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:d.addons.map(e=>j(ye,{addon:e,agents:n,hideVersion:!0},e.manifest.id))})]}),C&&!B&&j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>T(!1),children:E(`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:[E(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(V,{className:`h-4 w-4 text-primary`}),E(`h2`,{className:`text-sm font-semibold text-foreground`,children:[H,` Settings`]})]}),j(`button`,{onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:j(U,{className:`h-4 w-4`})})]}),E(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[j(ue,{nodeId:`hub`,addonIds:[L.id],level:`global`}),he(L)&&E(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),j(ne,{addonId:L.id,trpc:P.trpcClient,onOpenDevice:e=>ae(`/devices/${e}`)})]}),K===`npm`&&E(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),j(ve,{addonId:L.id})]}),L.components&&L.components.length>0&&E(`div`,{children:[E(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,L.components.length,`)`]}),j(`div`,{className:`flex flex-wrap gap-1`,children:L.components.map(e=>j(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),n.length>=2&&E(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),E(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.length===0&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),R.map(e=>j(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),E(`div`,{className:`relative`,children:[E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(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:[j(ie,{className:`h-3 w-3`}),`Add agent`]}),_&&E(`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:[n.filter(e=>!e.isHub&&!R.includes(e.name)).map(e=>j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(!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)),n.filter(e=>!e.isHub&&!R.includes(e.name)).length===0&&j(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),j(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:j(`button`,{type:`button`,onClick:()=>T(!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`})})]})})]})}O();var be=`.tgz,.tar.gz,.zip`;function xe({onUploadSuccess:e}){let[t,n]=w(!1),r=S(null),i=C(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 E(k,{children:[j(`input`,{ref:r,type:`file`,accept:be,onChange:C(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),E(`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?j(G,{className:`w-3.5 h-3.5 animate-spin`}):j(I,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}function Z({pending:e,onCancel:t,onConfirm:n,isPending:r,error:i}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:E(`div`,{className:`bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(W,{className:`w-4 h-4 text-amber-700`}),j(`h3`,{className:`text-sm font-medium text-foreground`,children:`Update system package?`})]}),E(`div`,{className:`space-y-2 text-[11px] text-foreground-subtle`,children:[E(`div`,{children:[j(`span`,{className:`font-mono text-foreground`,children:e.packageName}),j(`span`,{className:`mx-1`,children:`·`}),E(`span`,{className:`font-mono`,children:[`v`,e.fromVersion]}),j(`span`,{className:`mx-1`,children:`→`}),E(`span`,{className:`font-mono text-amber-700`,children:[`v`,e.toVersion]})]}),j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800`,children:`The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds.`}),i!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-2 text-danger`,children:i})]}),E(`div`,{className:`flex justify-end gap-2 pt-1`,children:[j(`button`,{type:`button`,onClick:t,disabled:r,className:`px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50`,children:`Cancel`}),E(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50`,children:[r?j(G,{className:`w-3 h-3 animate-spin`}):j(P,{className:`w-3 h-3`}),`Update & restart`]})]})]})})}O();function Se(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ce(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 we(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 Q(e){return`bundle`in e}function Te({addons:e,clusterStatus:r,selectedNode:i,onRefresh:a,isRefreshing:s}){let c=A(),[l,u]=w(``),f=T(l),[p,m]=w(!1),g=S(null);M(()=>{if(!p)return;let e=e=>{g.current&&!g.current.contains(e.target)&&m(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]);let{data:y}=o({nodeId:i.id}),ne=D(()=>{let e=new Map;for(let t of y??[])e.set(t.name,t.latestVersion);return e},[y]),[x,O]=w(null),[k,N]=w(null),ie=b({onMutate:e=>{O(e.name),N(null)},onSuccess:(e,t)=>{O(null);let n=e;if(n&&n.success===!1){N({name:t.name,message:n.error??`Update failed (no error message returned by server)`});return}c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{O(null),N({name:t.name,message:e instanceof Error?e.message:String(e)})}}),{data:I}=v(void 0),R=n({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:z,isFetching:se}=h({query:f||void 0},{enabled:p}),V=d(),{data:H}=te(void 0),U=H?.requestedAt,[W,ce]=w(null),[le,K]=w(!1);M(()=>{if(H?.kind===`framework-bulk-update`&&H.requestedAt!==W){ce(H.requestedAt),K(!0);let e=window.setTimeout(()=>K(!1),6e3);return()=>window.clearTimeout(e)}},[U,W,H]);let{data:ue}=_(void 0),de=D(()=>new Map((ue??[]).map(e=>[e.packageName,e])),[ue]),[q,J]=w(null),[fe,pe]=w(null),Y=re({onSuccess:()=>{J(null),c.invalidateQueries({queryKey:[[`addons`]]})},onError:e=>{pe(e instanceof Error?e.message:String(e))}}),me=t(),X=C(async()=>{let e=y??[];e.length!==0&&(e.some(e=>e.isSystem)&&!await me({title:`Update all — includes a system package`,message:`This batch updates a system package (@camstack/system). The hub will restart automatically once the framework update completes. In-flight requests are dropped; reconnect typically takes ~10 seconds.`,confirmLabel:`Update all & restart`,variant:`warning`})||await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[i.id]}))},[y,i.id,V,me]),he=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`integrations`]]})}}),[ge,_e]=w(`type`),[ve,be]=w(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Ce=e=>{be(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[Te,Ee]=B(),$=Te.get(`capability`),De=D(()=>{let t=i.isHub?e:e.filter(e=>Se(e.placement,i.isHub));return $&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===$))),t},[e,i.isHub,$]),Oe=()=>{let e=new URLSearchParams(Te);e.delete(`capability`),Ee(e,{replace:!0})},ke=ve===`flat`?De:we(De),Ae=D(()=>{let e=[...ke];switch(ge){case`type`:e.sort((e,t)=>{let n=+!Q(e),r=+!Q(t);if(n!==r)return n-r;let i=Q(e)?e.bundle.displayName:e.manifest.name,a=Q(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=Q(e)?e.bundle.displayName:e.manifest.name,r=Q(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=Q(e)?e.bundle.installSource??``:e.installSource??``,r=Q(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[ke,ge]);return E(`div`,{className:`space-y-4`,children:[k&&j(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:E(`div`,{className:`flex items-start justify-between gap-3`,children:[E(`div`,{className:`space-y-0.5`,children:[E(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,k.name]}),j(`div`,{className:`text-foreground-subtle font-mono`,children:k.message})]}),j(`button`,{type:`button`,onClick:()=>N(null),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})}),E(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),E(`select`,{value:ge,onChange:e=>_e(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:[j(`option`,{value:`type`,children:`Bundles first`}),j(`option`,{value:`name`,children:`Name`}),j(`option`,{value:`source`,children:`Install source`})]})]}),E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>j(`button`,{type:`button`,onClick:()=>Ce(e),className:`px-2.5 py-1.5 transition-colors capitalize ${ve===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&&E(`div`,{className:`flex items-center gap-1.5`,children:[j(F,{className:`h-3 w-3 text-foreground-subtle`}),j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>j(`button`,{type:`button`,onClick:()=>R.mutate({channel:e}),disabled:R.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${I?.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))})]}),(y?.length??0)>0&&E(`button`,{type:`button`,onClick:()=>void X(),disabled:V.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:[V.isPending?j(G,{className:`w-3 h-3 animate-spin`}):j(P,{className:`w-3 h-3`}),V.isPending?`Updating…`:`Update All (${y.length})`]}),E(`button`,{type:`button`,onClick:a,disabled:s||V.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:[j(F,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),E(`div`,{className:`flex items-center gap-3`,children:[E(`div`,{className:`relative flex-1 min-w-[200px]`,ref:g,children:[j(ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),j(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),m(!0)},onFocus:()=>m(!0),placeholder:`Search addons on npm...`,disabled:V.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`}),se&&j(G,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),p&&z&&z.length>0&&E(`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:[z.length>0&&E(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,z.length,`)`]}),z&&z.length>0&&j(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:z.map(e=>E(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[j(`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()}),E(`div`,{className:`flex-1 min-w-0`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-[11px] font-semibold truncate`,children:e.name}),E(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`v`,e.version]})]}),e.description&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?E(`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:[j(oe,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):E(`button`,{type:`button`,onClick:()=>he.mutate({packageName:e.name}),disabled:he.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:[he.isPending?j(G,{className:`h-3 w-3 animate-spin`}):j(P,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),j(xe,{onUploadSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),a()}})]}),$&&E(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),j(`span`,{className:`font-mono text-primary font-semibold`,children:$}),j(`button`,{type:`button`,onClick:Oe,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),le&&E(`div`,{className:`fixed top-4 right-4 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:[j(L,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),E(`div`,{children:[j(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),j(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),De.length===0&&j(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:$?`No installed addons declare the "${$}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${i.name} (placement filter active)`}),j(`div`,{className:`space-y-2`,children:Ae.map(e=>{let t=Q(e)?e.bundle.packageName:e.manifest.packageName,n=ne.get(t),a=Q(e)?e.representative:e,o=de.has(t),s=n?o?()=>J({packageName:t,fromVersion:de.get(t)?.currentVersion??a.manifest.packageVersion??a.manifest.version,toVersion:n}):()=>ie.mutate({name:t,version:n,nodeId:i.id}):void 0;return j(ye,{addon:a,clusterStatus:r?.[a.manifest.id],bundle:Q(e)?e.bundle:void 0,availableUpdate:n,isUpdating:x===t,onUpdate:s,isSystem:o,disabledByBulk:V.isPending},Q(e)?t:e.manifest.id)})}),q!==null&&j(Z,{pending:q,onCancel:()=>{J(null),pe(null)},onConfirm:()=>{pe(null),Y.mutate({packageName:q.packageName,version:q.toVersion})},isPending:Y.isPending,error:fe})]})}function Ee(){let t=A(),{data:n,isLoading:i,isError:o}=a(),{data:c}=s(void 0),{data:l}=r(void 0,{refetchInterval:1e4}),u=D(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of l??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[l]),[d,ee]=w(`hub`),p=u.find(e=>e.id===d)??u[0],m=e(),te=f(),h=m.isPending||te.isPending,g=async()=>{await m.mutateAsync({nodeId:d}),await te.mutateAsync(),t.invalidateQueries({queryKey:[[`addons`]]})},_=S(m);_.current=m,M(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(n??[]).map(Ce).filter(e=>e!==null);return E(K,{children:[E(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(x,{selectedNodeId:d,onSelect:ee}),E(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!i&&!o&&E(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),E(`button`,{type:`button`,onClick:()=>void g(),disabled:h,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:[j(F,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!p.isHub&&E(`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`,` `,j(`span`,{className:`font-medium text-foreground`,children:p.name}),` — agents only run`,` `,j(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,j(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),i&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),o&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!i&&!o&&j(Te,{addons:v,clusterStatus:c,selectedNode:p,onRefresh:()=>void g(),isRefreshing:h})]})}export{Ee as AddonsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Bt as e,It as t,Vt as n}from"./src-DVSeapHz.js";import{G as r,I as i,K as a,S as o,W as s,Z as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as d}from"./refresh-cw-SRDkmGt6.js";import{D as f,N as p,o as m,x as h}from"./index-KGQreUXd.js";import{t as g}from"./BrokerForm-Dw9_9N5P.js";c();var _=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],v=`/addon/import-alexa`,y=2e3;function b(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function x(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function S(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function C(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function w(e,t,n){let r=await fetch(`${v}${e}`,{method:`POST`,headers:C(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function T(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${v}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!x(i))throw Error(`Unexpected status response from server`);return i}async function E(e){try{await fetch(`${v}/login/cancel`,{method:`POST`,headers:C(),body:JSON.stringify({sessionId:e})})}catch{}}function D({brokerId:e,onResolved:t,onCancel:n}){let[s,c]=a(`amazon.it`),[p,g]=a(`Alexa account`),[v,x]=a({kind:`idle`}),C=r(!0);u(()=>(C.current=!0,()=>{C.current=!1}),[]);let D=r(null),O=r(null),k=i(()=>{O.current!==null&&(clearInterval(O.current),O.current=null)},[]),A=i(async n=>{k(),C.current&&x({kind:`committing`,sessionId:n});try{let r=await w(`/login/commit`,{sessionId:n,name:p.trim().length>0?p.trim():`Alexa account`,...e===void 0?{}:{brokerId:e}},S);D.current=null,t(r.brokerId)}catch(e){let t=e instanceof Error?e.message:String(e);C.current&&x({kind:`error`,message:t,sessionId:n})}},[e,p,t,k]),j=i((e,t)=>{k();let n=async()=>{try{let n=await T(e);if(n.phase===`captured`){k(),A(e);return}if(n.phase===`error`){k(),C.current&&x({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){k(),C.current&&x({kind:`idle`});return}C.current&&x({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);C.current&&x(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};O.current=setInterval(()=>{n()},y)},[k,A]);u(()=>()=>{k(),D.current!==null&&E(D.current)},[k]);let M=async()=>{k(),D.current!==null&&(E(D.current),D.current=null),x({kind:`starting`});try{let e=await w(`/login/start`,{amazonDomain:s},b);D.current=e.sessionId,x({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),j(e.sessionId,e.loginUrl)}catch(e){x({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},N=()=>{k(),D.current!==null&&(E(D.current),D.current=null),x({kind:`idle`})},P=()=>{N()},F=v.kind===`idle`,I=v.kind===`starting`,L=v.kind===`polling`,R=v.kind===`committing`,z=v.kind===`error`,B=I||L||R,V=v.kind===`polling`?v.phase:null,H=v.kind===`polling`?v.loginUrl:null,U=L&&V===`awaiting-login`,W=L&&(V===`starting`||V===null);return o(`div`,{className:`space-y-4`,children:[(F||z)&&o(`div`,{className:`space-y-3`,children:[e===void 0&&o(`div`,{className:`space-y-1`,children:[l(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),l(`input`,{id:`alexa-account-name`,type:`text`,value:p,onChange:e=>g(e.target.value),placeholder:`Alexa account`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),o(`div`,{className:`space-y-1`,children:[l(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),l(`select`,{id:`alexa-amazon-region`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:_.map(e=>l(`option`,{value:e,children:e},e))})]})]}),z&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[l(m,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),l(`span`,{children:v.message})]}),I&&o(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[l(h,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&o(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[l(h,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),R&&o(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[l(h,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&o(`div`,{className:`space-y-3`,children:[o(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[l(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),o(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[l(f,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),o(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[10px] text-amber-700 dark:text-amber-300`,children:[l(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,l(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),o(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[l(h,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),o(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[l(`button`,{type:`button`,onClick:B?N:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:B?`Cancel login`:`Back`}),o(`div`,{className:`flex items-center gap-2`,children:[z&&o(`button`,{type:`button`,onClick:P,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[l(d,{className:`h-3.5 w-3.5`}),`Retry`]}),F&&l(`button`,{type:`button`,onClick:()=>{M()},disabled:e===void 0&&p.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}c();var O=`alexa`;function k(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function A(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var j={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function M({kind:r,onResolved:i,onBack:c}){let[u,d]=a(r===O?`alexa-login`:`existing`),f=e({kind:r}),m=s(()=>k(f.data).filter(e=>e.kind===r),[f.data,r]),_=n(),v=s(()=>{for(let e of A(_.data))if(e.kinds.some(e=>e.kind===r))return e.addonId},[_.data,r]),[y,b]=a(null),[x,S]=a(``),C=t({}),w=()=>{y&&i(y)},T=async e=>{x.trim().length!==0&&i((await C.mutateAsync({kind:r,name:x.trim(),settings:e,...v===void 0?{}:{addonId:v}})).id)},E=e=>{e===`new`?b(null):C.reset(),d(e)};return o(`div`,{className:`space-y-4`,children:[o(`button`,{type:`button`,onClick:c,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[l(p,{className:`h-3.5 w-3.5`}),` Back`]}),o(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[r===O&&l(`button`,{type:`button`,onClick:()=>E(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${u===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),l(`button`,{type:`button`,onClick:()=>E(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${u===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),l(`button`,{type:`button`,onClick:()=>E(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${u===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:r===O?`Paste cookie`:`Create new`})]}),u===`alexa-login`&&l(D,{onResolved:i,onCancel:c}),u===`existing`&&o(`div`,{className:`space-y-3`,children:[f.isLoading&&o(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(h,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),f.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,f.error instanceof Error?f.error.message:`Unknown error`]}),!f.isLoading&&!f.isError&&m.length===0&&o(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,l(`span`,{className:`font-medium text-foreground`,children:r===O?`Login interactively`:`Create new`}),` `,`to register one.`]}),l(`div`,{className:`space-y-2`,children:m.map(e=>o(`button`,{type:`button`,onClick:()=>b(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${y===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[l(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),l(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${j[e.status]}`,children:e.status})]},e.id))}),m.length>0&&l(`div`,{className:`flex justify-end pt-1`,children:l(`button`,{type:`button`,onClick:w,disabled:!y,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),u===`new`&&o(`div`,{className:`space-y-3`,children:[o(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),l(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),C.isError&&l(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:C.error instanceof Error?C.error.message:String(C.error)}),l(g,{kind:r,...v===void 0?{}:{addonId:v},onSubmit:e=>{T(e).catch(()=>{})},onCancel:c,submitLabel:C.isPending?`Creating…`:`Create broker`,disabled:C.isPending||x.trim().length===0}),x.trim().length===0&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}export{M as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Gr as e,Hr as t,Ii as n,Qr as r,Rr as i,Ui as a,Vi as o,_r as s,ar as c,fr as l,g as u,gr as d,h as f,hr as p,ia as m,m as h,mr as g,na as _,or as v,pr as y,ra as b,ta as x,vr as S}from"./src-DVSeapHz.js";import{G as C,I as w,K as T,S as E,W as D,Z as O,b as k,o 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-CCjPq1YD.js";import{t as N}from"./pencil-kf9oWwQP.js";import{t as P}from"./radio-C4fS-iZ9.js";import{t as ee}from"./refresh-cw-SRDkmGt6.js";import{t as F}from"./rotate-cw-FopI4hrl.js";import{t as I}from"./server-7BEVQ_1Q.js";import{t as L}from"./upload-BusXXXDJ.js";import{B as R,F as te,L as z,M as B,P as V,i as ne,k as re,o as ie,p as H,s as U,x as W}from"./index-KGQreUXd.js";import{t as G}from"./format-size-CO9d3C3-.js";import{t as K}from"./NodeAddonsSettingsPanel-DwQvoGUf.js";import{a as q,i as J,n as Y,r as X,t as ae}from"./esm-D1aSlve1.js";var Z=R(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),oe=R(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=R(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=R(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=R(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);O();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:e,addons:t,isHub:r}){let i=A(),a=n(),[o,s]=T(null),[c,u]=T(null),[d,f]=T(!1),[p,m]=T(null),[h,_]=T(0),v=C(null),y=g(),b=S(),x=l({nodeId:e}),w=x.data??[],D=new Map(t.map(e=>[e.id,e.capabilities])),O=w.length>0?w.map(e=>({id:e.id,status:e.status,capabilities:D.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),k=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),x.refetch()},M=async t=>{s(t);try{await y.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to restart addon:`,e)}finally{s(null)}},N=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){u(t);try{await b.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{u(null)}}},P=E(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,m(null),f(!0),_(0);try{await le({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),k()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1),_(0)}}}}),E(`button`,{onClick:()=>v.current?.click(),disabled:d,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?j(W,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),d?`Uploading… ${h}%`:`Upload addon (.tgz)`]}),d&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${h}%`}})}),p&&j(`span`,{className:`text-[10px] text-destructive`,children:p})]});return O.length===0?E(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:x.isLoading?`Loading addons…`:`No addons on this node`})]}):E(`div`,{children:[P,E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:O.map(e=>E(`tr`,{className:`border-t border-border/50`,children:[E(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:E(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||c===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(F,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||c===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:c===e.id?j(W,{className:`h-3 w-3 animate-spin`}):j(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}O();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:i}){let a=e.services??[],o=a.length===1,[s,c]=T(o||n),[l,f]=T(null),[v,y]=T(`info`),S=e.name.includes(`(core)`),C=g(),w=p(),D=d(),O=async e=>{f(e);try{await C.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{f(null)}},k=async()=>{f(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{f(null)}},A=async n=>{let r=`${t}/${e.name}`;try{await D.mutateAsync({nodeId:r,level:n}),y(n)}catch(e){console.error(`Failed to set log level:`,e)}};return E(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[E(`div`,{role:o?void 0:`button`,tabIndex:o?void 0:0,onClick:o?void 0:()=>c(!s),onKeyDown:o?void 0:e=>{(e.key===`Enter`||e.key===` `)&&c(!s)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${o?``:`hover:bg-muted/40 cursor-pointer`}`,children:[o?j(`span`,{className:`h-3 w-3 shrink-0`}):j(s?V:B,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(I,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(z,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(fe,{state:e.state}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:G(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(e.uptimeSeconds)}),!S&&E(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[E(x,{children:[j(m,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:v}),j(_,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>j(b,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===v?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:k,disabled:l===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(F,{className:`h-3 w-3 ${l===e.name?`animate-spin`:``}`})})]})]}),s&&a.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:a.map(e=>E(`div`,{children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&E(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&E(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),E(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>i(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>i(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(P,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>O(e.addonId),disabled:l===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(F,{className:`h-3 w-3 ${l===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(u,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>i(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(h,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>i(e.addonId,`events`)})})]},e.addonId))}),s&&a.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=T(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}O();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let t=A(),r=n(),[i,a]=T(`all`),s=o(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:l}=v({nodeId:e}),u=s?.processes??l,d=D(()=>u?[...u]:[],[u]),f=D(()=>i===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,i]),p=D(()=>{let e=d.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[d]),m=c({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=D(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),g=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},_=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async n=>{let i=h.get(n.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${n.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${n.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${n.children.length} child(ren)?`,message:`SIGKILL parent pid ${n.ppid} and SIGTERM ${n.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(n.ppid,!0),...n.children.map(e=>_(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let n=d.filter(e=>e.classification===`ghost`);n.length!==0&&await r({title:`Kill all ${n.length} ghost process(es)?`,message:`SIGKILL ${n.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(n.map(e=>_(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,C=d.filter(e=>e.classification===`root`).length,w=d.filter(e=>e.classification===`system`).length;return E(`div`,{className:`space-y-4`,children:[E(`div`,{className:`flex items-start justify-between gap-4`,children:[E(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),E(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(ee,{className:`h-3 w-3`}),` Refresh`]})]}),E(`div`,{className:`grid grid-cols-4 gap-3`,children:[E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),E(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&j(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&E(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[E(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(ie,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:p.map(e=>E(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),E(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),E(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,d.length,`)`]}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:E(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),E(`tbody`,{children:[f.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>E(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),E(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:G(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:E(`div`,{className:`inline-flex gap-1`,children:[E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(U,{className:`h-3 w-3`}),` Term`]}),E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&E(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(K,{nodeId:e,addonIds:t,level:`global`})})}O();function be({nodeId:e,addons:t}){let n=A(),{data:a,isLoading:o}=i({nodeId:e}),s=D(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),c=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return s.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:s.map(({capName:t,providers:n})=>{let r=a?.[t]??n[0]??``,i=n.length===1;return E(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:r,onChange:n=>c.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:i||c.isPending||o,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:i?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}O();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=T(!1),[r,i]=T(e.name),a=A(),o=y({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?E(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(te,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ne,{className:`h-3.5 w-3.5`})})]}):E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(N,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,E(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,E(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>E(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}O();function Ce({node:e}){let[t,n]=T(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?E(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),E(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[E(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),E(`span`,{className:`flex items-center gap-1`,children:[j(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),E(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(he,{nodeId:e.id,processes:r}),t===`processes`&&j(ve,{nodeId:e.id}),t===`settings`&&j(ye,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(be,{nodeId:e.id,addons:e.addons})]})]}):E(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),E(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}O();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=C(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ce,{node:e})},e.id))})}O();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[a,o]=T(!1),s=g();function c(){s.mutateAsync({nodeId:t,addonId:e.addonId})}function l(){o(e=>!e)}return E(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[E(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),j(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),E(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),j(`span`,{className:`shrink-0 text-muted-foreground`,children:G(e.mem)}),E(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[j(n?V:B,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),E(`span`,{children:[`caps: `,e.caps.length]})]}),j(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:c,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(F,{className:`h-3 w-3`})}),j(`button`,{type:`button`,"aria-label":`Logs`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&j(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>E(`li`,{className:`text-muted-foreground`,children:[j(`span`,{className:`text-foreground`,children:e.name}),` · `,j(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),a&&j(f,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>o(!1)})]})}O();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=T(new Set),r=w(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return M(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]),E(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${e.isOnline?``:` opacity-50`}`,children:[j(X,{type:`target`,position:q.Left}),j(X,{type:`source`,position:q.Right}),E(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),j(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),j(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),j(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),j(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),E(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>j(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:r,pid:n.pid},n.pid)),e.runners.length===0&&j(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}O();var Oe={nodeBox:$};function ke(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function Ae(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function je({graph:e,onOpenNodeDetail:t}){let[n,r]=T(``),[i,a]=T(!1),[o,s]=T(0),c=w(()=>{a(!0),s(e=>e+1)},[]),l=w(()=>{a(!1),s(e=>e+1)},[]),u=w(e=>{t?.(e)},[t]),d=D(()=>ke(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),f=D(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!Ae(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o]),p=D(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return E(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[j(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),j(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),j(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`})]}),j(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:E(J,{nodes:f,edges:p,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[j(ae,{gap:20,size:1}),j(Y,{showInteractive:!1})]})})]})}function Me(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Ne(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Me(t)}}function Pe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Ne)}}function Fe(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Pe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}O();function Ie({onlineNodeIds:r}){let i=A(),a=n(),{data:o,isLoading:s}=t(),c=e({onSuccess:()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]})}}),l=D(()=>{if(!o)return[];let e=new Set(r);return e.add(`hub`),o.filter(t=>!e.has(t.nodeId))},[o,r]);if(s)return j(`section`,{className:`rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse`,children:`Loading persisted agent settings…`});let u=async e=>{await a({title:`Remove offline agent?`,message:`Drop the persisted orchestrator settings for "${e}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:`Remove`,cancelLabel:`Keep`,variant:`danger`})&&c.mutate({agentNodeId:e})};return l.length===0?j(`section`,{className:`rounded-lg border border-border bg-surface p-6`,children:E(`div`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[j(Z,{className:`h-6 w-6 opacity-40`}),j(`p`,{className:`text-xs`,children:`No stale agent entries.`}),j(`p`,{className:`text-[11px] opacity-60`,children:`Every persisted nodeId matches a node currently online in the cluster.`})]})}):E(`section`,{className:`rounded-lg border border-border bg-surface`,children:[E(`header`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border`,children:[j(Z,{className:`h-4 w-4 text-muted-foreground`}),j(`h2`,{className:`text-sm font-semibold`,children:`Offline agents`}),E(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[l.length,` stale `,l.length===1?`entry`:`entries`]})]}),j(`p`,{className:`px-4 pt-3 text-[11px] text-muted-foreground`,children:`Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts.`}),j(`ul`,{className:`divide-y divide-border`,children:l.map(e=>{let t=Object.keys(e.settings.addonDefaults??{}).length,n=Object.values(e.settings.addonDefaults??{}).filter(e=>e?.enabled).length;return E(`li`,{className:`flex items-center gap-3 px-4 py-2 text-xs`,children:[j(`span`,{className:`font-mono text-foreground`,children:e.nodeId}),E(`span`,{className:`text-muted-foreground`,children:[t,` addons configured`,t>0&&E(k,{children:[` · `,n,` enabled`]})]}),E(`button`,{type:`button`,onClick:()=>{u(e.nodeId)},disabled:c.isPending,className:`ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[j(U,{className:`h-3 w-3`}),`Remove`]})]},e.nodeId)})})]})}O();function Le(e){let[t,n]=T(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:e,isLoading:t}=s(void 0,{staleTime:1/0}),[n,r]=T(null);return a(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:D(()=>n??e??[],[n,e]),isLoading:t&&!n}}function ze(){let[e,n]=T(`table`),[r,i]=T(void 0),[a,o]=T(0),s=Le(`(max-width: 767px)`),c=s&&e===`graph`?`table`:e,{nodes:l,isLoading:u}=Re(),d=D(()=>Fe(l),[l]),f=l.filter(e=>e.isOnline).length,p=l.filter(e=>!e.isOnline).length,m=D(()=>l.map(e=>e.id??``).filter(Boolean),[l]),{data:h}=t(),g=D(()=>{if(!h)return 0;let e=new Set(m);return e.add(`hub`),h.filter(t=>!e.has(t.nodeId)).length},[h,m]),_=w(e=>{n(`table`),i(e),o(e=>e+1)},[]),v=(t,r,i,a)=>E(`button`,{onClick:()=>n(t),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===t?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),r,a!==void 0&&a>0&&j(`span`,{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===t?`bg-primary-foreground/20 text-primary-foreground`:`bg-destructive/15 text-destructive`}`,children:a})]});return E(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[E(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-2`,children:[f>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[f,` online`]}),p>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[p,` offline`]})]}),E(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[v(`table`,`Table`,ce),!s&&v(`graph`,`Graph`,oe),v(`offline-agents`,`Offline agents`,Z,g)]})]}),u?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):c===`graph`?j(je,{graph:d,onOpenNodeDetail:_}):c===`table`?j(`div`,{className:`flex-1 overflow-auto`,children:j(we,{nodes:l,focusNodeId:r,focusNonce:a})}):j(`div`,{className:`flex-1 overflow-auto`,children:j(Ie,{onlineNodeIds:m})})]})}export{ze as ClusterPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{A as e,Ai as t,Bn as n,Br as r,Cn as i,E as a,Et as o,Fr as s,G as c,H as l,Hr as u,I as d,Ii as f,Ji as p,Jn as m,Jt as h,K as g,Ki as _,Kn as v,L as y,Mi as b,R as x,Sn as S,Sr as C,T as w,U as T,V as E,W as D,Xi as ee,Xr as O,Yt as k,Zi as te,_n as A,a as j,ai as ne,an as re,ba as M,bn as ie,di as N,dn as ae,ea as oe,f as P,fi as F,fn as se,g as ce,gn as le,hn as ue,i as de,j as fe,ji as pe,jr as me,k as he,l as ge,ln as I,m as _e,mn as ve,n as L,o as ye,on as be,p as xe,pn as Se,q as Ce,qi as we,qn as Te,r as Ee,ri as De,rn as Oe,tn as ke,u as Ae,un as je,ur as R,ut as Me,vn as Ne,w as Pe,xa as Fe,xn as Ie,y as Le,yn as Re}from"./src-DVSeapHz.js";import{G as z,I as B,K as V,S as H,W as U,Z as W,b as ze,o as G,t as Be,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{c as Ve,k as He,p as J,r as Ue,t as We,u as Ge}from"./player-overlays-DY_CVt4U.js";import{C as Ke,E as qe,b as Y,g as Je,v as Ye}from"./src-DL7iSgmy.js";import{t as Xe}from"./CapabilityBadges-BPfyv6vE.js";import{t as Ze}from"./bell-kKIifPdi.js";import{n as Qe,t as $e}from"./rotate-ccw-ov-aP4t5.js";import{t as et}from"./ProviderIcon-C0HnZBxx.js";import{t as tt}from"./pencil-kf9oWwQP.js";import{t as nt}from"./plus-B-sSvurw.js";import{t as rt}from"./refresh-cw-SRDkmGt6.js";import{t as it}from"./rotate-cw-FopI4hrl.js";import{t as at}from"./server-7BEVQ_1Q.js";import{t as ot}from"./wifi-BW-fVi7Z.js";import{B as X,F as st,H as ct,I as lt,O as ut,U as dt,W as ft,_ as pt,a as mt,c as ht,i as gt,k as _t,p as vt,r as yt,s as bt,t as xt,v as St,x as Ct,z as wt}from"./index-KGQreUXd.js";import{t as Tt}from"./StatusBadge-BSsUNFG6.js";import{n as Et,t as Dt}from"./useDevice-BxrbLlpH.js";import{n as Ot,r as kt,t as At}from"./SchemaTabBar-DRo5sGP1.js";import{t as jt}from"./FormBuilder-DxflfkYi.js";import{t as Mt}from"./useEventInvalidation-CDlHOYGm.js";var Nt=X(`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`}]]),Pt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Ft=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),It=X(`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`}]]),Lt=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),Rt=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),zt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Bt=X(`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`}]]);W();var Vt=`device-export`,Ht=`export`,Ut=`Export`;function Wt(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Wt):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Wt)):e.writerCapName===Vt}function Gt(e){return e.fields.some(Wt)}function Kt(e){return j(J().trpcClient,e)}function qt(e){let[t,n]=V(`idle`),[r,i]=V(null),a=z(null),o=z(null),s=z(null),c=z(!0),l=Te(),u=v(),d=m(),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]),h=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 q(()=>(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:h,stop:p,isTalking:t===`talking`}}W();var Jt=0;function Z(){return++Jt}function Yt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Xt(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 Zt(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 Qt(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 $t({scope:e,greeting:t,className:n}){let r=J(),[i,a]=V(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${Yt(e)} — type help or context for available commands`}),n}),[o,s]=V(``),[c,l]=V([]),[u,d]=V(-1),f=z(null),p=z(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=Be({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:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Z(),kind:`info`,text:`scope: ${Yt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Qt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Zt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Z(),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:Z(),kind:`info`,text:`scope: ${Yt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`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 en({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),o=Kt(i?e:null),{streams:s,pipelineMetrics:l,createSession:u,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_}=de(n.trpcClient,i?e:null),v=c(n.trpcClient,i?e:null),y=qt(i&&t?e:null),b=y.state===`requesting-mic`||y.state===`starting`||y.state===`connecting`||y.state===`stopping`,x=y.isTalking||b,S=()=>{y.state===`idle`||y.state===`error`?y.start():y.state!==`stopping`&&y.stop()},C=Ue(),w=a(),T=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=C.length>0?K(ze,{children:C.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Le,{serverUrl:r,createSession:u,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,...w.request?{playbackUrl:w.request.url,playbackAuthToken:T,...w.request.label?{playbackLabel:w.request.label}:{},onExitPlayback:()=>w.clear()}:{},streams:s,pipelineMetrics:l,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:v.src,...v.src?{posterUrl:v.src}:{},snapshotLoading:v.loading,onRefreshSnapshot:v.refresh,intercomAvailable:t,intercomShown:x,onIntercomToggle:S,extraOverlay:E,chromeless:!0,className:`h-full`})}function tn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(ce,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function nn({deviceId:e}){if(!Number.isFinite(e))return H(`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 K($t,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function rn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(_e,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function an({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(P,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function on({parentDeviceId:e}){let{t}=xt(),n=ct(),r=J(),{data:i,isLoading:a,isError:o}=Et(e),{data:s}=I({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let u=l(s?.stableId??``,c,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=e=>{let t=`${p} `;return p.length>0&&e.startsWith(t)?e.slice(t.length):e},h=(e,t)=>K(E,{trpc:r.trpcClient,device:{...t,name:m(t.name)},variant:`minimal`,onNavigate:f},e),g=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),K(`div`,{className:`space-y-1`,children:d.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:K(T,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>K(T,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),y,b]})}function Q({label:e,value:t}){return H(`div`,{className:`${He} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function sn({deviceId:e,initialName:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t),[s,c]=V(!1),l=z(null);q(()=>{r||o(t)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let u=Re({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?K(Q,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`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`}),K(`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:K(st,{className:`h-3 w-3`})}),K(`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:K(gt,{className:`h-3 w-3`})})]})}):K(Q,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:K(tt,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function cn({deviceId:e,initialLocation:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t??``),[s,c]=V(!1),l=z(null),{data:u}=ve(void 0,{enabled:r}),d=u??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let f=Ne({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?K(Q,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,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`}),K(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(st,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(gt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&H(`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:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[K(Lt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),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:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K(Q,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:K(tt,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function ln({deviceId:e}){let t=G(),{data:n}=Dt(e),{data:r}=Et(e),[i,a]=V(null),o=ie({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=b(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(ze,{children:[K(Q,{label:`Primary child`,value:K(d,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}W();var un=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function dn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function fn(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function pn(){let t=e(),n=fe(),{data:r}=I({deviceId:t??0},{enabled:t!==null}),{data:i}=be({deviceId:t??0},{enabled:t!==null}),a=r??n??null,[o,s]=V(`identity`);if(t===null||!a)return null;let c=String(a.stableId??``),l=String(a.name??``),u=String(a.type??``),d=String(a.addonId??``),f=a.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(i?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=a.location??null,_=a.metadata??null,v=_!==null&&Object.keys(_).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(mn,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),K(mn,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!v||o===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K(Q,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),K(sn,{deviceId:t,initialName:l}),K(cn,{deviceId:t,initialLocation:g}),K(ln,{deviceId:t}),K(Q,{label:`Type`,value:u}),K(Q,{label:`Provider`,value:K(et,{type:d,size:`sm`,showLabel:!0})}),K(Q,{label:`Capabilities`,value:h.length>0?K(Xe,{capabilities:h,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&o===`hardware`&&K(hn,{metadata:_})]})}function mn({active:e,onClick:t,label:n}){return K(`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 hn({metadata:e}){let t=un.filter(t=>t in e),n=Object.keys(e).filter(e=>!un.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`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.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K(Q,{label:dn(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:fn(e[t])})},t))})]})}W();function gn({deviceId:e}){let[t,n]=V(null),r=ke({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 H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`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:[K(rt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function _n(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function vn({device:e}){let t=ct(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(Ye.Resyncable),{data:c}=R({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Ye.DoorbellButton),f=Ee(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(xe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&K(gn,{deviceId:n}),i&&n!==null&&K(Pe,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&K(Ae,{history:f.history,latestIsFresh:p}),i&&n!==null&&K(Pe,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(ot,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K(yn,{label:`Nominal`,value:_n(t.nominalBitrateKbps??0)}),K(yn,{label:`Observed`,value:_n(t.observedBitrateKbps??0)}),K(yn,{label:`Peak`,value:_n(t.peakBitrateKbps??0)}),K(yn,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(pn,{})]})}function yn({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function bn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[h,g]=V(m),_=l!==void 0,v=new Set(p.map(e=>e.id)),y=_?c&&v.has(c)?c:m:v.has(h)?h:m,b=e=>{_?l(e):g(e)},x=d.get(y)??[],S={sections:x.length<=1?x.length===1?[{...x[0],title:``}]:x:x.every(e=>!e.title)?[{...x[0],title:``,fields:x.flatMap(e=>e.fields)}]:x},C=K(Ot,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[K(jt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),C]});let w=new Map,T=new Map;for(let[e,t]of d){w.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&T.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[K(At,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:y,onChange:b,countByTab:w,pendingByTab:T}),K(jt,{schema:S,values:t,onChange:r,onAction:i,disabled:s}),C]})}W();function xn(e,t){return t&&t===`admin`?e:!0}function Sn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Gt(e)&&Gt(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Cn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function wn(e){return e.key}function Tn(e){if(!Cn(e))return e.value}function En(e){return Cn(e)?null:e}function Dn(e,t){for(let n of e)if(t(n),n.type===`group`)Dn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Dn(e.fields,t)}function On(e){if(!e)return{};let t={};for(let n of e.sections)Dn(n.fields,e=>{let n=wn(e);n!==null&&(t[n]=Tn(e))});return t}function kn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Dn(r.fields,e=>{if(n!==null||wn(e)!==t)return;let r=En(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function An(e){return{...e,fields:e.fields.map(jn)}}function jn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Mn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=En(e);return n?xn(t,n.minRole)?e:jn(e):e})}))}}function Nn({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let a=G(),{user:o}=yt(),s=o?.isAdmin===!0,c=z(!1),{data:l,isLoading:u}=je({deviceId:e},{refetchInterval:()=>c.current?!1:2500,enabled:Number.isFinite(e)}),{data:d}=I({deviceId:e},{enabled:Number.isFinite(e)}),f=l?.settings??null,p=l?.live??null,m=U(()=>{if(!f&&!p)return null;let e=f?.sections??[],n=(p?.sections??[]).map(An),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Gt(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...f?.tabs??[],...(p?.tabs??[]).filter(e=>!(f?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[f,p,t]),h=U(()=>Sn(m),[m]),g=U(()=>Mn(h,s),[h,s]),_=U(()=>On(g),[g]),v=F(),y=N(),b=S(),x=le(),C=i({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=kt({schema:g,serverValues:_,onImmediateSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=kn(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w]),onDeferredSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=kn(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w])}),{values:E,pendingKeys:D,handleChange:ee,handleSave:O,handleDiscard:k}=T;if(c.current=T.editingPaused,u)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[K(Ct,{className:`h-4 w-4 animate-spin mr-2`}),K(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!g||g.sections.length===0)return K(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=Ke(e,r);await v.mutateAsync({brokerId:i}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!d)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:d.addonId,type:d.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=Ke(e,t),i=await y.mutateAsync({brokerId:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return K(bn,{schema:g,values:E,pendingKeys:D,onChange:ee,onAction:te,onSave:O,onDiscard:k,disabled:w.isPending,activeSubTab:n,onSubTabChange:r})}function Pn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(Nn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}function Fn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`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:[K(et,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Tt,{status:r?`online`:`offline`}),i.length>0&&K(Xe,{capabilities:i})]}),K(`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.`})]})}W();function In({deviceId:e}){let t=G(),n=h({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Ln(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(Rn,{label:`Discovered`,value:i.total,icon:K(pt,{className:`h-3.5 w-3.5`})}),K(Rn,{label:`Adopted`,value:i.adopted,accent:`success`}),K(Rn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`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?K(Ct,{className:`h-3.5 w-3.5 animate-spin`}):K(rt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`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:[K(zn,{icon:K(ot,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(zn,{icon:K(St,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(zn,{icon:K(mt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(zn,{icon:K(Nt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Ln(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 Rn({label:e,value:t,icon:n,accent:r}){return H(`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:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function zn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}function Bn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(pe,{trpc:J().trpcClient,deviceId:e,features:t})})}function Vn({deviceId:e,features:n}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(t,{trpc:J().trpcClient,deviceId:e,features:n})})}function $({deviceId:e,deviceType:n,features:r}){let i=J(),a=Ce(n)?.HeroCard??t,o=Ge(Ve(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?K(`div`,{className:`flex justify-center`,children:K(x,{lastChangedAt:c})}):null,K(a,{trpc:i.trpcClient,deviceId:e,features:r})]})}function Hn({deviceId:e}){let t=J(),{data:n,isLoading:r}=Dt(e),{data:i,isLoading:a}=Et(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?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(y,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var Un={[Y.Switch]:$,[Y.Siren]:$,[Y.Light]:$,[Y.Sensor]:$,[Y.Button]:$,[Y.Hub]:In,[Y.Cover]:Bn,[Y.Valve]:$,[Y.Humidifier]:$,[Y.WaterHeater]:$,[Y.Container]:Hn,[Y.Lock]:$,[Y.Fan]:$,[Y.Thermostat]:$,[Y.MediaPlayer]:$,[Y.Control]:$,[Y.AlarmPanel]:Vn,[Y.EventEmitter]:Vn,[Y.Notifier]:Vn,[Y.Script]:Vn,[Y.Automation]:Vn,[Y.Presence]:$,[Y.Update]:$,[Y.Vacuum]:$,[Y.LawnMower]:$,[Y.Weather]:$,[Y.Image]:$};function Wn(e){return K(Un[e.deviceType]??Fn,{...e})}function Gn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=I({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Mt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=be({deviceId:e},{enabled:n}),{data:l}=Se({deviceType:i},{enabled:!!i}),u=Ie({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`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 H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(Qe,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`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 H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(ee,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(Kn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(qn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(Jn,{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 Kn({kind:e}){return e===`native`?H(`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:[K(at,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`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:[K(Pt,{className:`h-3 w-3`}),`wrapped`]}):H(`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:[K(Rt,{className:`h-3 w-3`}),`unbound`]})}function qn({nodeId:e}){return K(`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 Jn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`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:[K(i?st:$e,{className:`h-3 w-3`}),e]},e)})})}W();function Yn(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 Xn(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function Zn({agents:e,currentAgent:t,onPick:n}){let[r,i]=V(!1);return H(`div`,{className:`relative`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&K(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>K(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Qn({deviceId:e,refreshToken:t}){let n=G(),[i,a]=V(null),[o,c]=V(null),[l,d]=V(null),[f,m]=V(null),h=s({deviceId:e}),g=u(),v=r({deviceId:e}),y=me(),b=U(()=>v.data?.agentNodeId||y.data?.find(e=>e.online)?.nodeId||`hub`,[v.data?.agentNodeId,y.data]),x=o??b,S=C({nodeId:x??``},{enabled:!!x}),w=O({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),d(null)}}),T=U(()=>S.data?p(S.data):[],[S.data]),E=U(()=>{let e=h.data??null,t={};for(let n of g.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:Xn(e,n.nodeId,r)}),t[r]=i}return t},[h.data,g.data]),D=i?Yn(S.data??null,i):null,ee=x?g.data?.find(e=>e.nodeId===x)??null:null,k=i&&ee?ee.settings.addonDefaults[i]??null:null,te=i&&x?h.data?.stepOverridesByAgent?.[x]?.[i]??null:null,A=S.data?.selectedEngine.format??`coreml`,j=e=>{c(e),d(null),m(null)};return g.isLoading||S.isLoading?K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):S.data?K(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[K(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:K(we,{tree:T,selectedAddonId:i,onSelect:e=>{a(e),d(null),m(null)},agentDots:E})}),K(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!D?K(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),K(`div`,{className:`text-base font-semibold`,children:D.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),K(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(g.data??[]).map(e=>K(`button`,{type:`button`,onClick:()=>j(e.nodeId),className:`px-3 py-1 text-xs ${x===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),K(Zn,{agents:(g.data??[]).map(e=>e.nodeId),currentAgent:x,onPick:e=>{if(!x||!i||!S.data||!g.data)return;let t=g.data.find(t=>t.nodeId===e),n=g.data.find(e=>e.nodeId===x);if(!t||!n)return;let[r]=Fe({source:{nodeId:t.nodeId,engine:{format:A},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:A},defaults:n.settings.addonDefaults},catalog:S.data,addonIds:[i]});if(!r){m(`no mirror result`);return}if(r.outcome===`skip`){m(`skipped: ${r.reason??`no candidate`}`);return}d(r.patch),m(`${r.outcome} from ${e}`)}}),f&&K(`div`,{className:`text-[10px] text-foreground-subtle`,children:f})]}),k&&K(_,{mode:`device`,addon:D,agentDefault:k,agentNodeId:x??``,currentPatch:l??te,engineFormat:A,onChangePatch:d}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!te||w.isPending,onClick:()=>{!x||!i||w.mutate({deviceId:e,agentNodeId:x,addonId:i,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>d(null),children:`Reset draft`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!x||!i||w.isPending,onClick:()=>{!x||!i||w.mutate({deviceId:e,agentNodeId:x,addonId:i,patch:l})},children:w.isPending?`Saving…`:`Save`})]})]})]})})]})}):K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}W();function $n(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function er(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=$n(r.value,t));return n}function tr(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function nr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function rr(e){return e==null?`identity`:e.kind}function ir({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=V(()=>rr(e)),[o,s]=V(()=>tr(e,n)),[c,l]=V(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=V(()=>nr(e));q(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),q(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=er(o,r),n=c===``?void 0:$n(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(tr(void 0,n)),e===`linear`&&d(nr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[K(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),K(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[K(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),K(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[K(`option`,{value:``,children:`—`}),K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]}):K(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[K(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),K(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),K(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),K(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),K(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),K(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),K(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}W();function ar(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function or(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function sr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=se({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=ae({deviceId:e}),d=u?.caps??[],f=r==null?null:or(r.source.sourceKey,c,s),[p,m]=V(r?.target.cap??``),[h,g]=V(r?.target.fieldPath??``),[_,v]=V(f),[y,b]=V(r?.source.cap??``),[x,S]=V(r?.source.fieldPath??``),[C,w]=V(r?.transform);q(()=>{if(r!=null&&_===null&&s.length>0){let e=or(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=ae({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],D=d.find(e=>e.cap===p)?.fields??[],ee=D.find(e=>e.path===h),O=E.find(e=>e.cap===y)?.fields??[],k=O.find(e=>e.path===x),te=e=>{m(e),g(``)},A=e=>{v(e===``?null:Number(e)),b(``),S(``)},j=e=>{b(e),S(``)},ne=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,re=()=>{if(!ne)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??ar(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},M=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:p,onChange:e=>te(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a cap —`}),d.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a field —`}),D.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),H(`select`,{id:`link-source-device`,value:_??``,onChange:e=>A(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a device —`}),l.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),H(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>j(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a cap —`}),E.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),H(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a field —`}),O.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),K(ir,{value:C,onChange:w,sourceField:k,targetKind:ee?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[K(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),K(`button`,{type:`button`,disabled:!ne,onClick:re,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}W();function cr({deviceId:e}){let t=J(),n=G(),{data:r,isLoading:i}=I({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=V(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[K(nt,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[K(Ft,{className:`h-8 w-8 opacity-30`}),K(`p`,{className:`text-xs`,children:`No links yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):K(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>K(lr,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[K(`div`,{className:`flex items-center justify-between`,children:K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),K(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:K(sr,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function lr({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=L(n,e,t.target.cap),s=o===void 0?void 0:Je(o,t.target.fieldPath),c=s==null?`—`:String(s);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[K(It,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[K(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),K(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),K(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[K(`span`,{children:`←`}),K(`span`,{className:`font-mono`,children:t.source.sourceKey}),K(`span`,{className:`opacity-60`,children:`/`}),K(`span`,{className:`font-mono`,children:t.source.cap}),K(`span`,{className:`opacity-60`,children:`.`}),K(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&K(ur,{kind:t.transform.kind}),K(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),K(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),K(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function ur({kind:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}W();var dr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function fr(e){let t=e===Y.Camera;return dr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var pr=[{id:`logs`,icon:vt,label:`Logs`},{id:`repl`,icon:ht,label:`REPL`},{id:`events`,icon:Ze,label:`Events`},{id:`state`,icon:ut,label:`State`}];function mr(){let e=dt(),t=Number(e.deviceId),i=Number.isFinite(t),a=ct(),s=G(),c=f(),l=J(),[u,d]=ft(),p=u.get(`tab`)??`overview`,m=u.get(`sub`),[h,_]=V(`logs`),v=`device-detail.left-col-width-px`,[y,x]=V(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(v),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=z(y);S.current=y;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??y??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(v,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:T,isLoading:E,isError:ee}=I({deviceId:t},{enabled:i,refetchInterval:5e3,retry:1}),{data:O}=je({deviceId:t},{enabled:i}),k=U(()=>{let e=O?.settings?.sections??[],t=O?.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(Ht),[...r].map(e=>e===`export`?{id:e,label:Ut,isAddonContrib:!0}:{id:e,label:qe[e]?.label??e,isAddonContrib:!0})},[O]),A=T,j=String(A?.name??e.deviceId??`Device`),M=A?.online===!0,ie=M?`online`:`offline`,N=String(A?.addonId??`rtsp`),P=A?.features??[],F=A?.type,se=F===Y.Camera,{data:ce}=Et(i?t:0),le=F===Y.Container,de=U(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),fe=U(()=>le?b(de,typeof A?.linkDeviceId==`number`?A.linkDeviceId:null,typeof A?.primaryChildEntityId==`string`?A.primaryChildEntityId:null)?.id??null:null,[le,de,A?.linkDeviceId,A?.primaryChildEntityId]),{data:pe}=je({deviceId:fe??0},{enabled:fe!==null}),me=U(()=>{if(fe===null)return[];let e=pe?.settings?.sections??[],t=pe?.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:qe[e]?.label??e,isAddonContrib:!0,childDeviceId:fe}))},[fe,pe]),_e=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:ve}=I({deviceId:_e??0},{enabled:_e!==null}),L=oe(),be=A?.disabled!==!0,{data:xe}=ae({deviceId:t},{enabled:i}),Se=(xe?.caps.length??0)>0,Ce=U(()=>{let e=new Set,t=[];for(let n of[...fr(F),...k,...me])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Se)&&t.push(n));return t},[F,k,me,Se]),we=U(()=>Ce.some(e=>e.id===p)?p:`overview`,[Ce,p]),Te=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]),Ee=B(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),ke=(ce??[]).length>0,Ae=U(()=>pr.filter(({featureGate:e})=>!e||P.includes(e)),[P]),{data:R}=n({addonId:N},{enabled:!!N&&N!==`rtsp`}),Ne=ue({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]}),a(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Pe=re({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Oe({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=ne(),Le=Me({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=P.includes(Ye.Rebootable),W=P.includes(Ye.BatteryOperated),ze=g(l.trpcClient,W&&i?t:null),[Be,q]=V(!1),He=Ve(l.trpcClient,i?t:null),Ue=async()=>{if(!(Be||!He)){q(!0);try{await He.snapshot?.invalidateCache({});let e=await He.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.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{q(!1)}}},Ge=Pe.isPending||Fe.isPending,{data:Ke}=r({deviceId:t},{enabled:i,refetchInterval:1e4}),Je=Ke?.agentNodeId??null,Ze=typeof Je==`string`&&Je.length>0&&!Je.startsWith(`addon:`)?Je:void 0,{data:Qe}=De({deviceId:t,...Ze?{nodeId:Ze}:{}},{enabled:i,refetchInterval:3e3,retry:!1}),{data:$e}=o({deviceId:t},{enabled:i,refetchInterval:3e3,retry:!1}),tt=$e?.level?.dbfs??null;function nt(){if(!i)return null;switch(we){case`overview`:return K(vn,{device:A??{}});case`config`:return K(Pn,{deviceId:t,activeSubTab:m,onSubTabChange:Ee});case`pipeline`:return K(Qn,{deviceId:t,refreshToken:0});case`bindings`:return K(Gn,{deviceId:t});case`wiring`:return K(cr,{deviceId:t});default:{let e=we,n=k.some(t=>t.id===e),r=me.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return K(Nn,{deviceId:t,sectionFilter:Gt,activeSubTab:m,onSubTabChange:Ee});let a=K(Nn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:m,onSubTabChange:Ee});return r!==void 0&&i!==t?K(he,{deviceId:i,children:a}):a}}}return i?E?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ee||!T?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),K(`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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(te,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:R?.name??N,onClick:()=>R?.id&&a(`/integrations/${R.id}`)},{label:j}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K(et,{type:N,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),K(Tt,{status:ie}),W&&K(D,{status:ze,variant:`full`})]}),_e!==null&&ve&&H(`button`,{type:`button`,onClick:()=>a(`/devices/${_e}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ve.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(ve.name??`Device #${_e}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:P.length>0&&K(Xe,{capabilities:P})})]}),Qe&&K(`div`,{className:`hidden lg:flex`,children:K(hr,{metrics:Qe,dbfs:tt})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{be?await c({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Fe.mutate({deviceId:t}):Pe.mutate({deviceId:t})},disabled:Ge,title:be?`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 ${be?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(zt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:be?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(ge,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:lt,disabled:Be,onClick:()=>{Ue()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:it,hidden:!Re,disabled:Ie.isPending,danger:!0,onClick:async()=>{await c({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ie.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??N}.`,icon:rt,disabled:Le.isPending,danger:!0,onClick:async()=>{await c({title:`Restart "${R?.name??N}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Le.mutate({addonId:N})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:bt,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await c({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ne.mutate({deviceId:t})}}]})]})]})]}),K(he,{deviceId:t,device:A??void 0,children:K(w,{children:K(We,{children:K(ye,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${y===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&y!==null?{width:`${String(y)}px`}:void 0,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${se?`bg-black`:`bg-surface`}`,children:se?K(en,{deviceId:t,intercomAvailable:P.includes(Ye.TwoWayAudio)}):K(Wn,{deviceId:t,deviceName:j,deviceType:F??`unknown`,provider:N,isOnline:M,features:P})}),H(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ae.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>_(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${h===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[h===`logs`&&K(tn,{deviceId:t,containerDeviceId:F===`container`?t:void 0}),h===`repl`&&K(nn,{deviceId:t}),h===`events`&&K(rn,{deviceId:t}),h===`state`&&K(an,{deviceId:t})]})]})]}),!L&&K(`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:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-wrap items-center gap-0`,children:Ce.map(e=>{let t=we===e.id;return H(`button`,{onClick:()=>Te(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&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`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:[we===`overview`&&ke&&K(on,{parentDeviceId:t}),nt()]})]})]})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),K(`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 hr({metrics:e,dbfs:t}){let n=M(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(wt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(_t,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(Bt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{mr as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ci as e,Di as t,Ei as n,Ii as r,Oi as i,Si as a,Ti as o,Xi as s,_i as c,at as l,bi as u,c as d,gi as f,ha as p,hi as m,ki as h,ot as g,s as _,vi as v,wi as y,xi as b,yi as x}from"./src-DVSeapHz.js";import{K as S,S as C,W as w,Z as T,b as E,o as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as k}from"./circle-check-big-CHV6BcRn.js";import{t as A}from"./copy-CYPlIId0.js";import{t as j}from"./key-round-D9IA_YAT.js";import{t as M}from"./AddonCollectionPage-Datt1QjM.js";import{t as ee}from"./plus-B-sSvurw.js";import{B as N,C as P,F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-KGQreUXd.js";import{t as U}from"./AdminPage-vtcsGqRq.js";import{t as W}from"./AdminTabs-D7kzyXLz.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),ne=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);T();function re({userId:e,username:t,onClose:n}){let i=D(),a=r(),o=x({userId:e}),s=o.data,c=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),l=v({onSuccess:()=>{c(),n()}}),u=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(R,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[u===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),u===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),u===`enrolled`&&s&&C(E,{children:[C(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(p,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e})},disabled:l.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[l.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function J(){let t=D(),{user:n}=z(),[a,o]=S(!1),[l,u]=S(``),[d,p]=S(``),[m,g]=S(!1),[_,v]=S(null),{data:b,isLoading:x,isError:w}=e(),T=r(),E=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=f({onSuccess:()=>{E(),o(!1),u(``),p(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=c({onSuccess:E}),j=h({onSuccess:E}),M=y({onSuccess:E}),N=i({onSuccess:()=>{E(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await T({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await T({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function ne(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function J(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>o(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),a&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>o(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:d,onChange:e=>p(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&O(`p`,{className:`text-[10px] text-danger`,children:_}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>o(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:l,password:d,isAdmin:m}),disabled:k.isPending||!l||!d,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),w&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!w&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(s,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>ne(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:J(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let r=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==n?.id&&t.totpEnabled&&C(`button`,{onClick:()=>W(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[O(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>q(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[O(te,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>K(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(re,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(ie,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function ie(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ae,{...e,callerScopes:n?null:t?.scopes??[]})}function ae({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(_,{value:a,onChange:o,clampToParent:i,emptyHint:C(E,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}T();var oe=`bg-primary/10 text-primary`,se=`bg-foreground-subtle/10 text-foreground-subtle`;function Y(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ce(e){return e?e===`*`?`*`:e.join(`, `):``}function le(){let n=D(),i=r(),{data:a,isLoading:s}=u(),{data:c}=e(),l=w(()=>a??[],[a]),d=w(()=>c??[],[c]),f=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),p=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=S(!1),[_,v]=S(null),y=o({onSuccess:f}),b=m({onSuccess:({token:e,record:t})=>{p(),g(!1),v({token:e,label:t.name})}}),x=t({onSuccess:p}),T=async(e,t)=>{await i({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},E=async(e,t)=>{await i({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),C(`button`,{onClick:()=>g(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[O(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(X,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&O(de,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),l.length>0&&O(X,{title:`Legacy API keys`,subtitle:`${l.length} pre-existing — revoke only`,children:O(Z,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:l.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?oe:se}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ce(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{T(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),s&&O(ue,{}),h&&O(pe,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),_&&O(me,{token:_.token,label:_.label,onClose:()=>v(null)})]})}function X({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function ue(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function de({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Z({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:o,isLoading:s}=a({userId:e}),c=o??[];return s||c.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(Z,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:c.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,l]=S(``),[u,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=d(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Q,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(_,{value:u,onChange:f,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(he,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(ge,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?O(F,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}T();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function xe(){let e=D(),t=r(),{data:i,isLoading:a}=b(),o=w(()=>i??[],[i]),s=n({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),c=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&s.mutate({id:e})};return C(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[a&&O(ve,{}),!a&&o.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!a&&o.length>0&&O(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:o.map(e=>{let t=e.revokedAt!==null,n=(s.isPending?s.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{c(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}T();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=g({capName:`auth-provider`},{refetchInterval:Se}),t=l(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(G,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:ne,content:O(J,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(le,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$t as e,B as t,Gn as n,Ln as r,Ni as i,Pi as a,Qt as o,Rn as s,Sn as c,Un as l,Vn as u,Y as d,Zi as f,an as p,cn as m,d as h,da as g,en as _,fn as v,g as y,hn as b,nn as x,qt as S,rn as C,ut as w,x as ee,z as te,zn as ne}from"./src-DVSeapHz.js";import{G as T,I as E,K as D,S as O,W as k,Z as A,b as j,o as M,x as N,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as P}from"./player-overlays-DY_CVt4U.js";import{b as F}from"./src-DL7iSgmy.js";import{t as I}from"./ProviderIcon-C0HnZBxx.js";import{t as L}from"./plus-B-sSvurw.js";import{t as R}from"./refresh-cw-SRDkmGt6.js";import{t as z}from"./rotate-cw-FopI4hrl.js";import{t as B}from"./wifi-BW-fVi7Z.js";import{B as V,E as H,F as ie,H as ae,M as oe,P as U,R as se,T as W,U as ce,f as G,i as K,o as q,p as le,s as ue,t as de,x as J}from"./index-KGQreUXd.js";import{t as Y}from"./FormBuilder-DxflfkYi.js";import{t as X}from"./BrokerStep-4yPt7WFf.js";var fe=V(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);A();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function pe(e,t,n){let[r,i]=D(`idle`),[a,o]=D({}),s=k(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=E(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:E(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}A();function me(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...me(n.fields));return t}function he(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ge(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ge(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Q(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function _e({open:e,integrationId:t,addonId:n,onClose:r}){let{t:i}=de(),a=M(),[o,s]=D({}),[l,u]=D(!1),[d,f]=D(null),[p,h]=D(Q),g=m({addonId:n,type:F.Camera},{enabled:e}),_=g.data??null;re(()=>{e&&(s(_?ge(_.sections.flatMap(e=>e.fields)):{}),h(Q()),u(!1),f(null))},[e,t,_]);let v=k(()=>({...o,_probeRequestId:p}),[o,p]),b=x({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),S=c(),C=E(async(e,t)=>{u(!0);let r=await S.mutateAsync({addonId:n,type:F.Camera,key:e,value:t,formValues:v});return r.status===`ok`&&r.suggestedValues&&s(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))he(e[i])&&!he(a)&&(n[i]=a,t=!0);return t?n:e}),r},[S,n,v]),{testAllStatus:w,hasProbeFields:ee,probeResults:te,handleTestAll:ne,clearProbeResult:T}=pe(_??{sections:[]},o,C);async function A(e){f(null);try{await b.mutateAsync({addonId:n,type:F.Camera,config:o,integrationId:t}),e?s(_?ge(_.sections.flatMap(e=>e.fields)):{}):r()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let j=me((_?.sections??[]).flatMap(e=>e.fields)).filter(e=>he(o[e])),P=j.length===0,I=!g.isLoading&&(g.isError||_===null);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),O(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),N(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:N(K,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:g.isLoading?N(`div`,{className:`flex items-center justify-center py-8`,children:N(J,{className:`h-5 w-5 animate-spin text-primary`})}):I?O(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[N(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`space-y-1`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),O(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,N(`span`,{className:`font-mono`,children:n}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):N(Y,{schema:_,values:o,onChange:s,onTestField:C,probeResults:te,onClearProbe:T})}),!I&&!g.isLoading&&O(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[O(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[O(`span`,{className:`flex items-center gap-2`,children:[N(le,{className:`h-3.5 w-3.5`}),`Test logs`,N(`span`,{className:`font-mono text-[9px] opacity-60`,children:p.slice(0,14)})]}),N(U,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&N(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:N(y,{addonId:n,requestId:p,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!I&&!g.isLoading&&(d||j.length>0)&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${j.join(`, `)}`})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`)}),!I&&ee&&O(`button`,{type:`button`,onClick:ne,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 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 disabled:opacity-50`,children:[w===`testing`?N(J,{className:`h-3.5 w-3.5 animate-spin`}):N(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:()=>A(!0),disabled:I||!P||b.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:i(`integrations.saveAndNew`)}),N(`button`,{onClick:()=>A(!1),disabled:I||!P||b.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:b.isPending?i(`integrations.saving`):i(`integrations.save`)})]})]})]})]})}function ve(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}A();var $=`devices`,ye={id:$,label:`Devices`,isDefault:!0},be=2e4,xe=100;function Se({addonId:t,integrationId:n,onClose:r}){let{t:s}=de(),[c,l]=D(new Set),[u,d]=D(new Set),[f,p]=D(new Map),[m,h]=D(null),{data:g}=ne(),v=(g??[]).find(e=>e.addonId===t)?.supportsLocationImport??!1,[y,b]=D(!0),x=S({integrationId:n}).data?.filters,C=x&&x.length>0?x:[ye],[w,ee]=D(C.find(e=>e.isDefault)?.id??(C.some(e=>e.id===$)?$:C[0].id)),k=w!==$,A=_(),j=e({addonId:t,integrationId:n,page:1,pageSize:be,filter:w}),M=j.refetch,P=A.mutate,F=E(()=>{P({addonId:t,integrationId:n},{onSettled:()=>{M()}})},[P,t,n,M]),I=T(null);re(()=>{let e=`${t}::${n}`;I.current===e||j.isLoading||(I.current=e,(j.data?.candidates.length??0)===0&&F())},[t,n,j.isLoading,j.data,F]);let L=A.isPending,R=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,B=j.data?.candidates??[],V=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,H=o(),ae=E(e=>{e.alreadyAdopted||l(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=E(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),U=E((e,t)=>{p(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),se=E(e=>{let t={};for(let n of e){let e=f.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[f]),W=E(async()=>{h(null);let e=[...c];if(e.length!==0)try{let i=se(e);await H.mutateAsync({addonId:t,integrationId:n,filter:w,childNativeIds:e,...i?{perCandidate:i}:{},...v?{importLocations:y}:{}}),l(new Set),p(new Map),await M(),r()}catch(e){h(e instanceof Error?e.message:String(e))}},[c,se,H,t,n,w,M,v,y]),ce=E(e=>{ee(e),l(new Set),d(new Set),p(new Map),h(null)},[]),G=c.size;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),O(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:s(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),N(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:s(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),O(`div`,{className:`flex items-center gap-3 shrink-0`,children:[v&&O(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[N(`input`,{type:`checkbox`,checked:y,onChange:e=>b(e.target.checked),className:`accent-primary`}),s(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),N(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:N(K,{className:`h-4 w-4`})})]})]}),O(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??V)&&B.length===0&&N(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`min-w-0`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:s(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),N(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??V})]})]})}),C.length>1&&N(Ce,{filters:C,activeFilter:w,onSelect:ce}),N(`div`,{className:`flex-1 min-h-0`,children:N(te,{mode:`generic`,items:B,pageSize:xe,getKey:e=>e.childNativeId,getSearchText:ve,getFilterType:e=>e.type,filterOptions:i(),filterLabel:s(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||L&&B.length===0,searchPlaceholder:s(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??V)&&B.length===0?``:s(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:O(`button`,{type:`button`,onClick:F,disabled:L,title:s(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[N(z,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),s(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:s(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>N(we,{candidate:e,expandable:!k,expanded:u.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:s(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:s(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=a(e.type),n=t.icon;return O(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[N(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>N(`div`,{className:`flex items-center justify-end`,children:N(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":c.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${c.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:c.has(e.childNativeId)&&N(ie,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&u.has(e.childNativeId),renderExpanded:k?void 0:e=>N(Te,{candidate:e,hiddenChildIds:f.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>U(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:c.has(e.childNativeId)?`bg-primary/5`:``})})]}),m&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:m})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[N(`div`,{}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.cancel`,{defaultValue:`Cancel`})}),O(`button`,{onClick:W,disabled:G===0||H.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[H.isPending&&N(J,{className:`h-3.5 w-3.5 animate-spin`}),s(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function Ce({filters:e,activeFilter:t,onSelect:n}){return N(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return N(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function we({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return O(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?O(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[N(n?U:oe,{className:`h-3.5 w-3.5`}),a]}):N(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),N(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&N(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Te({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:N(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return O(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[N(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&N(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),N(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:N(r?H:W,{className:`h-3 w-3`})})]},e.childNativeId)})})}A();function Ee({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=de(),c=M(),d=r===`device-adoption`,{data:f}=u({id:e},{enabled:d}),p=k(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=l();return N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:O(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`mb-3 flex items-center justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),N(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:N(K,{className:`h-4 w-4`})})]}),d?i?O(`div`,{className:`space-y-3`,children:[N(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&O(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,N(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?O(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[N(J,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):N(X,{kind:i,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),m.isError&&N(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):N(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):N(ee,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}A();function De(){let{t:e}=de(),{integrationId:i}=ce(),a=M(),o=ae(),c=P(),[l,u]=D(!1),[m,_]=D(!1),[x,S]=D(!1),[ee,T]=D(!1),{data:A,isLoading:re}=s({id:i??``},{enabled:!!i}),{data:F}=d({addonId:A?.addonId??``,nodeId:`hub`},{enabled:!!A?.addonId}),{data:z,isSuccess:B}=ne(),V=k(()=>{let e=A?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[z,A?.addonId,B]),H=V!==null,ie=H?V===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),oe=k(()=>{let e=A?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.brokerKind??null},[z,A?.addonId,B]),U=F!=null&&Array.isArray(F.sections)&&F.sections.some(e=>e.fields.length>0),{data:W}=v({},{refetchInterval:5e3}),Y=[[`integrations`,`get`],{input:{id:i??``},type:`query`}],X=n({onMutate:async e=>{await a.cancelQueries({queryKey:Y});let t=a.getQueryData(Y);return t!=null&&a.setQueryData(Y,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&a.setQueryData(Y,r.previous)},onSettled:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=r({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]}),S(!1),o(`/integrations`)}}),pe=w({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),me=b({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),he=C({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ge=p({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=k(()=>W??[],[W]),ve=k(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),$=E(e=>ve.get(e)??null,[ve]),ye=E(e=>N(I,{type:e,size:`sm`}),[]),be=E(e=>o(`/devices/${String(e)}`),[o]),xe=k(()=>{let e=A?.addonId;return e?Q.filter(t=>t.addonId===e):[]},[Q,A?.addonId]),Ce=k(()=>t(xe).length,[xe]);return re?O(`div`,{className:`p-4`,children:[N(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),N(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):A?O(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[N(f,{items:[{label:`Integrations`,onClick:()=>o(`/integrations`)},{label:A.name}]}),O(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[O(`div`,{className:`flex items-center gap-3 min-w-0`,children:[N(`img`,{src:`/api/addon-assets/${A.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),O(`div`,{className:`min-w-0`,children:[N(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:A.name}),O(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[A.addonId,` · `,Ce,` `,e(`integrations.devices`)]})]})]}),O(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[O(`button`,{onClick:()=>u(!0),disabled:!H,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ie,children:[N(L,{className:`h-3.5 w-3.5`}),ie]}),O(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${X.isPending?`opacity-60`:``} ${A.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[N(g,{checked:A.enabled,onCheckedChange:e=>X.mutate({id:i,enabled:e}),disabled:X.isPending,"aria-label":A.enabled?`Disable integration`:`Enable integration`}),N(`span`,{className:`text-[11px] font-medium ${A.enabled?`text-success`:`text-foreground-subtle`}`,children:A.enabled?`Enabled`:`Disabled`}),X.isPending&&N(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(U||V===`device-adoption`)&&O(`button`,{onClick:()=>_(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(G,{className:`h-3 w-3`}),e(`integrations.config`)]}),O(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[N(le,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),N(h,{label:`Restart`,icon:R,title:`Restart "${A.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ce} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:pe.isPending,action:()=>pe.mutateAsync({addonId:A.addonId})}),O(`button`,{onClick:()=>S(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[N(ue,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),N(te,{context:`integration-detail`,devices:Q,trpc:c.trpcClient,defaultView:`cards`,forceAddon:A.addonId,urlScope:`root`,lsKey:`integration-detail:${A.addonId}`,resolveIntegrationIcon:ye,resolveParent:$,onNavigate:be,batchActions:{remove:me.mutate,disable:he.mutate,enable:ge.mutate},onDeleteDevice:e=>me.mutate({deviceId:e.id})}),l&&i&&V===`device-adoption`&&N(Se,{addonId:A.addonId,integrationId:i,onClose:()=>u(!1)}),l&&i&&V===`device-provider`&&N(_e,{open:l,integrationId:i,addonId:A.addonId,onClose:()=>u(!1)}),m&&i&&V!==null&&N(Ee,{integrationId:i,addonId:A.addonId,name:A.name,kind:V,brokerKind:oe,trpc:c.trpcClient,onClose:()=>_(!1)}),ee&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>T(!1),children:O(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[O(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N(le,{className:`h-4 w-4 text-primary shrink-0`}),N(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:A.name}),O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[A.addonId,i?` · ${i}`:``]})]}),N(`button`,{onClick:()=>T(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:N(K,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:N(y,{addonId:A.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),x&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&S(!1),children:O(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`flex items-start gap-3`,children:[N(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:N(q,{className:`h-4 w-4 text-danger`})}),O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),N(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:A.name,count:Ce})})]})]}),Z.error&&N(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),O(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[N(`button`,{onClick:()=>S(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),N(`button`,{onClick:()=>Z.mutate({id:i}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?O(j,{children:[N(J,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):O(j,{children:[N(ue,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):O(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[N(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:N(fe,{className:`h-6 w-6 text-foreground-subtle`})}),O(`div`,{className:`space-y-1 max-w-sm`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),N(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:i??``})})]}),O(`button`,{onClick:()=>o(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[N(se,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{De as IntegrationDetailPage};
|