@camstack/addon-admin-ui 1.2.18 → 1.2.21

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.
Files changed (86) hide show
  1. package/dist/assets/{AddLocationWizard-BowIG3iq.js → AddLocationWizard-D_PB3-bX.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DzUEOYUV.js → AddonCollectionPage-dSmADNMP.js} +1 -1
  3. package/dist/assets/{Addons-B5DucodR.js → Addons-DMgC9u5C.js} +1 -1
  4. package/dist/assets/{AdminTabs-C-SMNF-6.js → AdminTabs-BKzZGgJh.js} +1 -1
  5. package/dist/assets/{AiProfiles-D65CezzL.js → AiProfiles-B0jDK_vA.js} +1 -1
  6. package/dist/assets/{BrokerForm-ENHOk64X.js → BrokerForm-CNbozrHN.js} +1 -1
  7. package/dist/assets/{Capabilities-dtlaxRnV.js → Capabilities-B2gS0Rwu.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-QVudw7lC.js → CapabilityBadges-o7CZ6OPx.js} +1 -1
  9. package/dist/assets/{Cluster-9-Ysfuh5.js → Cluster-CaAqX44E.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-CvimJgTY.js → ClusterRecordingTab-CoghG4H4.js} +1 -1
  11. package/dist/assets/{Dashboard-CXFEM2IR.js → Dashboard-CORp5RgM.js} +1 -1
  12. package/dist/assets/{Data-DPmsq4Rb.js → Data-CFQyq6_m.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-CsY0BCKS.js → DetectionIntelligence-TFDDlrdH.js} +1 -1
  14. package/dist/assets/{DeviceAggregateSection-CzThj0Vt.js → DeviceAggregateSection-Bzn-6IHu.js} +1 -1
  15. package/dist/assets/{DeviceDetail-BWX7NeMm.js → DeviceDetail-1M0aTbT0.js} +2 -2
  16. package/dist/assets/{Devices-CdMd1Rxe.js → Devices-BBfN82Zj.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BPMSAjgX.js → EmbedPlayerPage-Dg1q2TgQ.js} +1 -1
  18. package/dist/assets/{Events-DlSc5xWS.js → Events-CxwUSAha.js} +1 -1
  19. package/dist/assets/{FormBuilder-BTBth7Mm.js → FormBuilder-DzsVc3t_.js} +1 -1
  20. package/dist/assets/{Identity-BkJfHHax.js → Identity-CY5dHQRV.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-DjcVm32z.js → IntegrationDetail-C8G40UJW.js} +1 -1
  22. package/dist/assets/{Integrations-BstWDI9y.js → Integrations-BDmrI5RY.js} +1 -1
  23. package/dist/assets/{Integrations-CCkqm_Su.js → Integrations-CcMeLmxP.js} +1 -1
  24. package/dist/assets/{Logs-BKvPV_wj.js → Logs-UsUTF6t8.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-C3F5tNrn.js → MotionZonesSettings-CB7gr8F6.js} +1 -1
  26. package/dist/assets/{MyAccess-D94hQDyr.js → MyAccess-l9miezxA.js} +1 -1
  27. package/dist/assets/{Network-DRjrjeQG.js → Network-DXUFkR9R.js} +1 -1
  28. package/dist/assets/{NodeAddonsSettingsPanel-CL75zTHK.js → NodeAddonsSettingsPanel-BmYlaSwd.js} +1 -1
  29. package/dist/assets/{NodeInferenceDevices-gVLIWG74.js → NodeInferenceDevices-CYZ5CYbi.js} +1 -1
  30. package/dist/assets/{Notifications-7spoN22j.js → Notifications-Qg7i9wiX.js} +1 -1
  31. package/dist/assets/Pipeline-5s0vvgIe.js +1 -0
  32. package/dist/assets/{Plates-0nXxdKJX.js → Plates-CPGPlu2R.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-BC6o9lqJ.js → PrivacyMaskSettings-CaSwDDde.js} +1 -1
  34. package/dist/assets/{ProviderIcon-tK6tKDtF.js → ProviderIcon-DMpgPBRn.js} +1 -1
  35. package/dist/assets/{Recordings-BtjWTugI.js → Recordings-D34q9wcX.js} +1 -1
  36. package/dist/assets/{ScanNetworkModal-CwPUWLnW.js → ScanNetworkModal-C6c0dfjo.js} +1 -1
  37. package/dist/assets/{Settings-CmklSlYL.js → Settings-CDGhqzHq.js} +1 -1
  38. package/dist/assets/{Showroom-fSzPo12F.js → Showroom-CQ38FQB-.js} +1 -1
  39. package/dist/assets/{Terminal-DLULQ5yw.js → Terminal-CmIa6Oya.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C8V797Ba.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DbFIfmYk.js} +1 -1
  41. package/dist/assets/{build-cluster-graph-DIGI0NJ3.js → build-cluster-graph-D_ECGcuu.js} +1 -1
  42. package/dist/assets/circle-check-big-D8RfPowm.js +1 -0
  43. package/dist/assets/clock-uqs9ftmV.js +1 -0
  44. package/dist/assets/{copy-D4StuZzs.js → copy-VNmCXPyR.js} +1 -1
  45. package/dist/assets/{debounced-invalidate-CXo5TVm0.js → debounced-invalidate-pIqbOQJw.js} +1 -1
  46. package/dist/assets/{dist-B1ZcDDOx.js → dist-CRhdFszz.js} +1 -1
  47. package/dist/assets/dist-C_8TUMdk.js +7 -0
  48. package/dist/assets/{download-Dq6V-5xf.js → download-C0kOZZ-t.js} +1 -1
  49. package/dist/assets/{face-bbox-CnD55hf6.js → face-bbox-DAp7haB0.js} +1 -1
  50. package/dist/assets/{hostInit-DyHdo8Gk.js → hostInit-CP8mlANm.js} +1 -1
  51. package/dist/assets/{index-BsmimqzB.js → index-Oa9WZQrG.js} +3 -3
  52. package/dist/assets/{key-round-BC8uv06u.js → key-round-DBmUUaAQ.js} +1 -1
  53. package/dist/assets/{mf-entry-bootstrap-0-278ef480.js → mf-entry-bootstrap-0-3d968750.js} +2 -2
  54. package/dist/assets/{pencil-BuY8CueB.js → pencil-DhNh3tJt.js} +1 -1
  55. package/dist/assets/{player-overlays-CNHQKrHd.js → player-overlays-JTC60qWR.js} +1 -1
  56. package/dist/assets/plus-BGvFAYGp.js +1 -0
  57. package/dist/assets/{radio-CQ2Qddgd.js → radio-DO2Xi8xU.js} +1 -1
  58. package/dist/assets/{refresh-cw-BwbLLVV6.js → refresh-cw-BkT1Lcrs.js} +1 -1
  59. package/dist/assets/remoteEntry-BwWg0n8I.js +1 -0
  60. package/dist/assets/{rotate-ccw-D9ag3NNh.js → rotate-ccw-BDk431kn.js} +1 -1
  61. package/dist/assets/rotate-cw-D2Vz1VVs.js +1 -0
  62. package/dist/assets/search-ZKoT1VCm.js +1 -0
  63. package/dist/assets/{send-CrQGjBpn.js → send-DIPTfOM-.js} +1 -1
  64. package/dist/assets/{server-C-ApRIN8.js → server-57sVw14w.js} +1 -1
  65. package/dist/assets/square-BVSyqpTo.js +1 -0
  66. package/dist/assets/{square-check-big-D0Ns-qwF.js → square-check-big-BM6N6ia-.js} +1 -1
  67. package/dist/assets/{src-BDNLbHXL.js → src-0b5IR223.js} +4 -4
  68. package/dist/assets/src-CzRzcy_1.js +7 -0
  69. package/dist/assets/{upload-OKC5mQ8W.js → upload-MDtwKjzv.js} +1 -1
  70. package/dist/assets/{useEventInvalidation-BHTo3YFv.js → useEventInvalidation-D1XjovJZ.js} +1 -1
  71. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CkMK9IKI.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DYBYsHJM.js} +2 -2
  72. package/dist/assets/{wifi-xQgrxKer.js → wifi-B7bqZV0a.js} +1 -1
  73. package/dist/assets/{zap-B6f_Rmgy.js → zap-CWXvqdT_.js} +1 -1
  74. package/dist/index.html +5 -5
  75. package/dist/server/addon.js +1 -1
  76. package/package.json +2 -2
  77. package/dist/assets/Pipeline-Dmgt7OdK.js +0 -1
  78. package/dist/assets/circle-check-big-DifLR11P.js +0 -1
  79. package/dist/assets/clock-BXw5TTp6.js +0 -1
  80. package/dist/assets/dist-BqHHqLgd.js +0 -7
  81. package/dist/assets/plus-DyBHOfPx.js +0 -1
  82. package/dist/assets/remoteEntry-BQiHtOSG.js +0 -1
  83. package/dist/assets/rotate-cw-J5QBXynE.js +0 -1
  84. package/dist/assets/search-BLl1nrAm.js +0 -1
  85. package/dist/assets/square-D5oi0WlG.js +0 -1
  86. package/dist/assets/src-SFNx0Juf.js +0 -7
@@ -1 +1 @@
1
- import{Ga as e,Qt as t,Zt as n,an as r,bt as i,en as a,in as o,nn as s,rn as c,tn as l,un as u,v as d}from"./src-BDNLbHXL.js";import{Q as f,S as p,W as m,b as h,o as g,q as _,x as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c as y,n as b,u as x}from"./src-SFNx0Juf.js";import{p as S}from"./player-overlays-CNHQKrHd.js";import{t as C}from"./pencil-BuY8CueB.js";import{t as w}from"./AddonCollectionPage-DzUEOYUV.js";import{t as T}from"./plus-DyBHOfPx.js";import{t as ee}from"./radio-CQ2Qddgd.js";import{t as E}from"./wifi-xQgrxKer.js";import{K as D,S as O,W as k,_ as A,i as j,s as M}from"./index-BsmimqzB.js";import{t as N}from"./AdminPage-Dq33XE9j.js";import{t as P}from"./BrokerForm-ENHOk64X.js";import{t as F}from"./useBodyScrollLock-B_rtaBV1.js";import{t as I}from"./AdminTabs-C-SMNF-6.js";var L=k(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),R=k(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);f();var z={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function B(e){return z[e]??e}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var te={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 H({status:e}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${te[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:t,onClose:n,children:r}){return F(),v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:p(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[p(`div`,{className:`space-y-0.5`,children:[v(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&v(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),v(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:v(j,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:r})]})})}function G({kinds:e,onClose:t,onDone:r}){let i=g(),a=e=>`${e.addonId??``}::${e.kind}`,[o,s]=_(e[0]?a(e[0]):``),[c,l]=_(``),u=e.find(e=>a(e)===o)??e[0],d=u?.kind??``,f=u?.addonId,m=n({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),r()}}),h=e=>{!d||c.trim().length===0||m.mutate({kind:d,name:c.trim(),settings:e,...f===void 0?{}:{addonId:f}})};return v(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:m.isPending?()=>{}:t,children:p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),v(`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 text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>v(`option`,{value:a(e),children:e.label},a(e)))})]}),p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),v(`input`,{type:`text`,value:c,onChange:e=>l(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`})]}),m.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:m.error instanceof Error?m.error.message:String(m.error)}),d&&v(P,{kind:d,...f===void 0?{}:{addonId:f},onSubmit:h,onCancel:t,submitLabel:m.isPending?`Adding…`:`Add broker`,disabled:m.isPending}),c.trim().length===0&&v(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function K({broker:e,onClose:n,onDone:r}){let i=g(),a=t({id:e.id,addonId:e.addonId}),s=o({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),i.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),r()}}),c=m(()=>{let e=a.data;return e&&typeof e==`object`?{...e}:{}},[a.data]);return v(W,{title:`Edit ${e.name}`,subtitle:`${B(e.kind)} · ${e.id}`,onClose:s.isPending?()=>{}:n,children:a.isLoading?p(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[v(O,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):a.isError?p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,a.error instanceof Error?a.error.message:`Unknown error`]}),v(`div`,{className:`flex justify-end`,children:v(`button`,{type:`button`,onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):p(`div`,{className:`space-y-3`,children:[s.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:s.error instanceof Error?s.error.message:String(s.error)}),v(P,{kind:e.kind,addonId:e.addonId,initialValues:c,onSubmit:t=>{s.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:n,submitLabel:s.isPending?`Saving…`:`Save`,disabled:s.isPending})]})})}function q({broker:t,onEdit:n}){let i=g(),a=e(),[o,s]=_(null),l=r({onSuccess:e=>s(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>s({ok:!1,error:e instanceof Error?e.message:String(e)})}),u=c({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),d=async()=>{await a({title:`Delete broker`,message:`Delete broker "${t.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({id:t.id,addonId:t.addonId})};return p(`tr`,{className:`border-b border-border last:border-0`,children:[v(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:t.name}),v(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:B(t.kind)}),p(`td`,{className:`px-3 py-2`,children:[v(H,{status:t.status}),o&&v(`span`,{className:`ml-2 text-[10px] ${o.ok?`text-success`:`text-danger`}`,children:o.ok?`OK`:o.error??`failed`})]}),v(`td`,{className:`px-3 py-2`,children:p(`div`,{className:`flex items-center justify-end gap-1.5`,children:[p(`button`,{type:`button`,onClick:()=>l.mutate({id:t.id,addonId:t.addonId}),disabled:l.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[l.isPending?v(O,{className:`h-3 w-3 animate-spin`}):v(E,{className:`h-3 w-3`}),`Test`]}),p(`button`,{type:`button`,onClick:()=>n(t),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[v(C,{className:`h-3 w-3`}),` Edit`]}),p(`button`,{type:`button`,onClick:()=>{d()},disabled:u.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?v(O,{className:`h-3 w-3 animate-spin`}):v(M,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=l({}),t=s(),n=m(()=>U(e.data),[e.data]),[r,i]=_(!1),[a,o]=_(null),c=m(()=>{let e=new Map;for(let n of V(t.data))for(let t of n.kinds)e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label});for(let t of n)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:B(t.kind)});return[...e.values()]},[n,t.data]);return p(`div`,{className:`space-y-3`,children:[v(`div`,{className:`flex items-center justify-end`,children:p(`button`,{type:`button`,onClick:()=>i(!0),disabled:c.length===0,title:c.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[v(T,{className:`h-3.5 w-3.5`}),` Add broker`]})}),v(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:p(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[v(`thead`,{children:p(`tr`,{className:`border-b border-border bg-background/50`,children:[v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),v(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),p(`tbody`,{children:[e.isLoading&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[v(O,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&n.length===0&&v(`tr`,{children:v(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),n.map(e=>v(q,{broker:e,onEdit:o},e.id))]})]})}),r&&v(G,{kinds:c,onClose:()=>i(!1),onDone:()=>i(!1)}),a&&v(K,{broker:a,onClose:()=>o(null),onDone:()=>o(null)})]})}var Y=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:R,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:L,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:ee,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function X(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(b))if(n===e)return t;return null}function re(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=a({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data;return v($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=u({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=y.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return v($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?v(ie,{addonId:t}):e===`device-export`?v(ae,{addonId:t}):null}function se({descriptor:e,rows:t,isLoading:n}){let r=ne(e.kind),i=e.kind===`device-export`,a=S(),o=D();return v(w,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=re(t.processState);return p(h,{children:[v($,{label:n.label,className:n.className}),v(oe,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>v(d,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=i(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return v(N,{icon:A,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:v(I,{tabs:Y.map(n=>{let r=Object.entries(b).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?v(J,{}):v(se,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
1
+ import{Ga as e,Qt as t,Zt as n,an as r,bt as i,en as a,in as o,nn as s,rn as c,tn as l,un as u,v as d}from"./src-0b5IR223.js";import{Q as f,S as p,W as m,b as h,o as g,q as _,x as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c as y,n as b,u as x}from"./src-CzRzcy_1.js";import{p as S}from"./player-overlays-JTC60qWR.js";import{t as C}from"./pencil-DhNh3tJt.js";import{t as w}from"./AddonCollectionPage-dSmADNMP.js";import{t as T}from"./plus-BGvFAYGp.js";import{t as ee}from"./radio-DO2Xi8xU.js";import{t as E}from"./wifi-B7bqZV0a.js";import{K as D,S as O,W as k,_ as A,i as j,s as M}from"./index-Oa9WZQrG.js";import{t as N}from"./AdminPage-Dq33XE9j.js";import{t as P}from"./BrokerForm-CNbozrHN.js";import{t as F}from"./useBodyScrollLock-B_rtaBV1.js";import{t as I}from"./AdminTabs-BKzZGgJh.js";var L=k(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),R=k(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);f();var z={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function B(e){return z[e]??e}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var te={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 H({status:e}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${te[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:t,onClose:n,children:r}){return F(),v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:p(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[p(`div`,{className:`space-y-0.5`,children:[v(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&v(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),v(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:v(j,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:r})]})})}function G({kinds:e,onClose:t,onDone:r}){let i=g(),a=e=>`${e.addonId??``}::${e.kind}`,[o,s]=_(e[0]?a(e[0]):``),[c,l]=_(``),u=e.find(e=>a(e)===o)??e[0],d=u?.kind??``,f=u?.addonId,m=n({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),r()}}),h=e=>{!d||c.trim().length===0||m.mutate({kind:d,name:c.trim(),settings:e,...f===void 0?{}:{addonId:f}})};return v(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:m.isPending?()=>{}:t,children:p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),v(`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 text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>v(`option`,{value:a(e),children:e.label},a(e)))})]}),p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),v(`input`,{type:`text`,value:c,onChange:e=>l(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`})]}),m.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:m.error instanceof Error?m.error.message:String(m.error)}),d&&v(P,{kind:d,...f===void 0?{}:{addonId:f},onSubmit:h,onCancel:t,submitLabel:m.isPending?`Adding…`:`Add broker`,disabled:m.isPending}),c.trim().length===0&&v(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function K({broker:e,onClose:n,onDone:r}){let i=g(),a=t({id:e.id,addonId:e.addonId}),s=o({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),i.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),r()}}),c=m(()=>{let e=a.data;return e&&typeof e==`object`?{...e}:{}},[a.data]);return v(W,{title:`Edit ${e.name}`,subtitle:`${B(e.kind)} · ${e.id}`,onClose:s.isPending?()=>{}:n,children:a.isLoading?p(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[v(O,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):a.isError?p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,a.error instanceof Error?a.error.message:`Unknown error`]}),v(`div`,{className:`flex justify-end`,children:v(`button`,{type:`button`,onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):p(`div`,{className:`space-y-3`,children:[s.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:s.error instanceof Error?s.error.message:String(s.error)}),v(P,{kind:e.kind,addonId:e.addonId,initialValues:c,onSubmit:t=>{s.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:n,submitLabel:s.isPending?`Saving…`:`Save`,disabled:s.isPending})]})})}function q({broker:t,onEdit:n}){let i=g(),a=e(),[o,s]=_(null),l=r({onSuccess:e=>s(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>s({ok:!1,error:e instanceof Error?e.message:String(e)})}),u=c({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),d=async()=>{await a({title:`Delete broker`,message:`Delete broker "${t.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({id:t.id,addonId:t.addonId})};return p(`tr`,{className:`border-b border-border last:border-0`,children:[v(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:t.name}),v(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:B(t.kind)}),p(`td`,{className:`px-3 py-2`,children:[v(H,{status:t.status}),o&&v(`span`,{className:`ml-2 text-[10px] ${o.ok?`text-success`:`text-danger`}`,children:o.ok?`OK`:o.error??`failed`})]}),v(`td`,{className:`px-3 py-2`,children:p(`div`,{className:`flex items-center justify-end gap-1.5`,children:[p(`button`,{type:`button`,onClick:()=>l.mutate({id:t.id,addonId:t.addonId}),disabled:l.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[l.isPending?v(O,{className:`h-3 w-3 animate-spin`}):v(E,{className:`h-3 w-3`}),`Test`]}),p(`button`,{type:`button`,onClick:()=>n(t),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[v(C,{className:`h-3 w-3`}),` Edit`]}),p(`button`,{type:`button`,onClick:()=>{d()},disabled:u.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?v(O,{className:`h-3 w-3 animate-spin`}):v(M,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=l({}),t=s(),n=m(()=>U(e.data),[e.data]),[r,i]=_(!1),[a,o]=_(null),c=m(()=>{let e=new Map;for(let n of V(t.data))for(let t of n.kinds)e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label});for(let t of n)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:B(t.kind)});return[...e.values()]},[n,t.data]);return p(`div`,{className:`space-y-3`,children:[v(`div`,{className:`flex items-center justify-end`,children:p(`button`,{type:`button`,onClick:()=>i(!0),disabled:c.length===0,title:c.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[v(T,{className:`h-3.5 w-3.5`}),` Add broker`]})}),v(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:p(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[v(`thead`,{children:p(`tr`,{className:`border-b border-border bg-background/50`,children:[v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),v(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),p(`tbody`,{children:[e.isLoading&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[v(O,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&n.length===0&&v(`tr`,{children:v(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),n.map(e=>v(q,{broker:e,onEdit:o},e.id))]})]})}),r&&v(G,{kinds:c,onClose:()=>i(!1),onDone:()=>i(!1)}),a&&v(K,{broker:a,onClose:()=>o(null),onDone:()=>o(null)})]})}var Y=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:R,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:L,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:ee,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function X(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(b))if(n===e)return t;return null}function re(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=a({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data;return v($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=u({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=y.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return v($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?v(ie,{addonId:t}):e===`device-export`?v(ae,{addonId:t}):null}function se({descriptor:e,rows:t,isLoading:n}){let r=ne(e.kind),i=e.kind===`device-export`,a=S(),o=D();return v(w,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=re(t.processState);return p(h,{children:[v($,{label:n.label,className:n.className}),v(oe,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>v(d,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=i(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return v(N,{icon:A,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:v(I,{tabs:Y.map(n=>{let r=Object.entries(b).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?v(J,{}):v(se,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
@@ -1 +1 @@
1
- import{G as e,K as t,Lo as n,Mn as r,bn as i,dn as a,hr as o,pr as s,sr as c,ur as l,ut as u}from"./src-BDNLbHXL.js";import{I as d,Q as f,S as p,W as m,b as h,o as ee,q as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as y}from"./player-overlays-CNHQKrHd.js";import{t as b}from"./ProviderIcon-tK6tKDtF.js";import{t as x}from"./FormBuilder-BTBth7Mm.js";import{t as S}from"./plus-DyBHOfPx.js";import{n as te,r as C,t as w}from"./ScanNetworkModal-CwPUWLnW.js";import{t as ne}from"./refresh-cw-BwbLLVV6.js";import{I as T,J as E,K as D,L as O,P as k,S as A,_ as j,i as M,p as N,t as P,z as F}from"./index-BsmimqzB.js";import{t as I}from"./AdminPage-Dq33XE9j.js";import{t as L}from"./StatusBadge-Dcr2bw58.js";import{t as R}from"./useEventInvalidation-BHTo3YFv.js";import{t as z}from"./useBodyScrollLock-B_rtaBV1.js";f();function B(e,t){let[n,r]=g(!1);return v(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}function V({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=P(),i=D(),{data:a,isLoading:o}=l();if(o)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return p(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind,a.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?_(A,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(N,{className:`h-3 w-3`}),r(`integrations.manage`)]}):_(k,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}f();function re({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=P(),[a,s]=g(``),[c,l]=g({}),[u,d]=g(null),f=o({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),_(`input`,{type:`text`,value:a,onChange:e=>s(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(x,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`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.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.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:f.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:a,config:c}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}f();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=P(),[a,o]=g(new Set),s=i(),c=s.data,l=s.isPending||!s.data&&!s.isError;v(()=>{e&&(s.isPending||s.data||s.mutate({addonId:e}))},[e,s]);function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=a.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(O,{className:`h-3 w-3 text-primary-foreground`})}),_(F,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}f();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ie=2e4;function ae({open:e,onClose:t}){let{t:n}=P(),r=D(),o=ee(),[s,l]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,S]=g(`manual`),[C,w]=g(null),[ne,T]=g(``),[E,O]=g(null),[k,j]=g(null),{data:N}=u({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),F=m(()=>N?U(N):null,[N]),I=c({onSuccess:()=>o.invalidateQueries({queryKey:[[`integrations`]]})}),L=i(),R=L.data;v(()=>{s!==`discovery`||!y||!d||L.isPending||L.data||L.mutate({addonId:d})},[s,y,d,L]);let ae=a({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o){if(!I.isPending){if(f(e),S(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}w(a),l(`broker`);return}if(o===`account`){l(`config`);return}oe(e,r)}}async function oe(e,n){try{let i=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),r(`/integrations/${i.id}?add=1`)}catch{}}async function se(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?l(`discovery`):q(t.id)}catch{}}async function G(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:ne,settings:{brokerId:e}});O(t.id),b(t.id),q(t.id)}catch{}}async function K(e){if(d){for(let t of e){let e=R?.find(e=>e.stableId===t);e&&await ae.mutateAsync({addonId:d,candidate:e,...E===null?{}:{integrationId:E}})}q()}}function q(e){let n=e??y??d;t(),J(),n&&r(`/integrations/${n}`)}function J(){l(`picker`),f(null),b(null),S(`manual`),w(null),T(``),O(null),j(null)}function Y(){t(),J()}z(e);let X=I.isPending,Z=B(X,ie);if(!e)return null;let ce={picker:n(`integrations.newIntegration`),config:n(`integrations.configureIntegration`),discovery:n(`integrations.importDevices`),broker:n(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},le=X?d:null,Q=I.error,$=X&&!Z;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:$?void 0:Y}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ce[s]}),_(`button`,{onClick:Y,disabled:$,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(M,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!X&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),s===`picker`&&p(h,{children:[k&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),_(V,{onSelect:W,onClose:Y,pendingAddonId:le})]}),s===`config`&&d&&_(re,{addonId:d,configSchema:F??null,onSave:se,onBack:()=>l(`picker`)}),s===`broker`&&C&&_(te,{kind:C,onResolved:e=>{G(e)},onBack:()=>l(`picker`)}),s===`discovery`&&y&&_(H,{providerId:y,onImport:K,onSkip:q})]}),X&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[_(A,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:n(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&p(h,{children:[_(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:n(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),_(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:n(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?T:k,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function oe(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(L,{status:e.status})}]}f();function se(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t:i}=P(),a=D(),o=y(),[c]=E(),[l,u]=g(!1),f=d(()=>u(!0),[]),ee=d(()=>u(!1),[]),[v,x]=g(!1),te=d(()=>x(!0),[]),T=d(()=>x(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:O,isLoading:k,refetch:A}=s(void 0),{data:M,isLoading:N,refetch:F}=r({}),L=m(()=>M??[],[M]),z=m(()=>O??[],[O]),B=m(()=>{let e=new Map;for(let t of L)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[L]),V=m(()=>{let e=new Map;for(let n of t(L)){let t=n.addonId??``;t&&e.set(t,(e.get(t)??0)+1)}return e},[L]),re=m(()=>z.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:se(e),deviceCount:V.get(e.addonId)??0})),[z,V]),H=c.get(G),U=d(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),ie=d(e=>a(`/integrations/${e.id}`),[a]),W=d(e=>B.get(e)??null,[B]),K=d(e=>_(b,{type:e,size:`sm`}),[]),q=d(e=>a(`/devices/${String(e)}`),[a]),J=d(t=>_(e,{context:`integration-detail`,devices:L,trpc:o.trpcClient,forceAddon:t.addonId,urlScope:`nested`,lsKey:`integrations:nested:${t.addonId}`,resolveIntegrationIcon:K,resolveParent:W,onNavigate:q}),[L,o.trpcClient,K,W,q]),Y=d(e=>H===e.addonId,[H]),X=m(()=>oe({isExpanded:Y,onToggleExpand:U}),[Y,U]),Z=d(e=>`${e.name} ${e.addonId}`,[]),ce=d(e=>e.addonId,[]),le=d(()=>{A(),F()},[A,F]),Q=k||N,$=z.length>0;return p(I,{icon:j,title:i(`nav.integrations`,`Integrations`),actions:p(h,{children:[_(`button`,{onClick:le,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(ne,{className:n(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),p(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,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`,children:[_(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&_(e,{mode:`generic`,items:re,getKey:ce,getSearchText:Z,columns:X,onRowClick:ie,isExpanded:Y,renderExpanded:J,searchPlaceholder:i(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:i(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ae,{open:l,onClose:ee}),_(w,{open:v,onClose:T})]})}export{K as IntegrationsPage};
1
+ import{G as e,K as t,Lo as n,Mn as r,bn as i,dn as a,hr as o,pr as s,sr as c,ur as l,ut as u}from"./src-0b5IR223.js";import{I as d,Q as f,S as p,W as m,b as h,o as ee,q as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as y}from"./player-overlays-JTC60qWR.js";import{t as b}from"./ProviderIcon-DMpgPBRn.js";import{t as x}from"./FormBuilder-DzsVc3t_.js";import{t as S}from"./plus-BGvFAYGp.js";import{n as te,r as C,t as w}from"./ScanNetworkModal-C6c0dfjo.js";import{t as ne}from"./refresh-cw-BkT1Lcrs.js";import{I as T,J as E,K as D,L as O,P as k,S as A,_ as j,i as M,p as N,t as P,z as F}from"./index-Oa9WZQrG.js";import{t as I}from"./AdminPage-Dq33XE9j.js";import{t as L}from"./StatusBadge-Dcr2bw58.js";import{t as R}from"./useEventInvalidation-D1XjovJZ.js";import{t as z}from"./useBodyScrollLock-B_rtaBV1.js";f();function B(e,t){let[n,r]=g(!1);return v(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}function V({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=P(),i=D(),{data:a,isLoading:o}=l();if(o)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return p(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind,a.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?_(A,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(N,{className:`h-3 w-3`}),r(`integrations.manage`)]}):_(k,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}f();function re({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=P(),[a,s]=g(``),[c,l]=g({}),[u,d]=g(null),f=o({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),_(`input`,{type:`text`,value:a,onChange:e=>s(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(x,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`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.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.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:f.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:a,config:c}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}f();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=P(),[a,o]=g(new Set),s=i(),c=s.data,l=s.isPending||!s.data&&!s.isError;v(()=>{e&&(s.isPending||s.data||s.mutate({addonId:e}))},[e,s]);function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=a.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(O,{className:`h-3 w-3 text-primary-foreground`})}),_(F,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}f();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ie=2e4;function ae({open:e,onClose:t}){let{t:n}=P(),r=D(),o=ee(),[s,l]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,S]=g(`manual`),[C,w]=g(null),[ne,T]=g(``),[E,O]=g(null),[k,j]=g(null),{data:N}=u({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),F=m(()=>N?U(N):null,[N]),I=c({onSuccess:()=>o.invalidateQueries({queryKey:[[`integrations`]]})}),L=i(),R=L.data;v(()=>{s!==`discovery`||!y||!d||L.isPending||L.data||L.mutate({addonId:d})},[s,y,d,L]);let ae=a({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o){if(!I.isPending){if(f(e),S(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}w(a),l(`broker`);return}if(o===`account`){l(`config`);return}oe(e,r)}}async function oe(e,n){try{let i=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),r(`/integrations/${i.id}?add=1`)}catch{}}async function se(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?l(`discovery`):q(t.id)}catch{}}async function G(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:ne,settings:{brokerId:e}});O(t.id),b(t.id),q(t.id)}catch{}}async function K(e){if(d){for(let t of e){let e=R?.find(e=>e.stableId===t);e&&await ae.mutateAsync({addonId:d,candidate:e,...E===null?{}:{integrationId:E}})}q()}}function q(e){let n=e??y??d;t(),J(),n&&r(`/integrations/${n}`)}function J(){l(`picker`),f(null),b(null),S(`manual`),w(null),T(``),O(null),j(null)}function Y(){t(),J()}z(e);let X=I.isPending,Z=B(X,ie);if(!e)return null;let ce={picker:n(`integrations.newIntegration`),config:n(`integrations.configureIntegration`),discovery:n(`integrations.importDevices`),broker:n(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},le=X?d:null,Q=I.error,$=X&&!Z;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:$?void 0:Y}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ce[s]}),_(`button`,{onClick:Y,disabled:$,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(M,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!X&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),s===`picker`&&p(h,{children:[k&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),_(V,{onSelect:W,onClose:Y,pendingAddonId:le})]}),s===`config`&&d&&_(re,{addonId:d,configSchema:F??null,onSave:se,onBack:()=>l(`picker`)}),s===`broker`&&C&&_(te,{kind:C,onResolved:e=>{G(e)},onBack:()=>l(`picker`)}),s===`discovery`&&y&&_(H,{providerId:y,onImport:K,onSkip:q})]}),X&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[_(A,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:n(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&p(h,{children:[_(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:n(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),_(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:n(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?T:k,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function oe(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(L,{status:e.status})}]}f();function se(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t:i}=P(),a=D(),o=y(),[c]=E(),[l,u]=g(!1),f=d(()=>u(!0),[]),ee=d(()=>u(!1),[]),[v,x]=g(!1),te=d(()=>x(!0),[]),T=d(()=>x(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:O,isLoading:k,refetch:A}=s(void 0),{data:M,isLoading:N,refetch:F}=r({}),L=m(()=>M??[],[M]),z=m(()=>O??[],[O]),B=m(()=>{let e=new Map;for(let t of L)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[L]),V=m(()=>{let e=new Map;for(let n of t(L)){let t=n.addonId??``;t&&e.set(t,(e.get(t)??0)+1)}return e},[L]),re=m(()=>z.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:se(e),deviceCount:V.get(e.addonId)??0})),[z,V]),H=c.get(G),U=d(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),ie=d(e=>a(`/integrations/${e.id}`),[a]),W=d(e=>B.get(e)??null,[B]),K=d(e=>_(b,{type:e,size:`sm`}),[]),q=d(e=>a(`/devices/${String(e)}`),[a]),J=d(t=>_(e,{context:`integration-detail`,devices:L,trpc:o.trpcClient,forceAddon:t.addonId,urlScope:`nested`,lsKey:`integrations:nested:${t.addonId}`,resolveIntegrationIcon:K,resolveParent:W,onNavigate:q}),[L,o.trpcClient,K,W,q]),Y=d(e=>H===e.addonId,[H]),X=m(()=>oe({isExpanded:Y,onToggleExpand:U}),[Y,U]),Z=d(e=>`${e.name} ${e.addonId}`,[]),ce=d(e=>e.addonId,[]),le=d(()=>{A(),F()},[A,F]),Q=k||N,$=z.length>0;return p(I,{icon:j,title:i(`nav.integrations`,`Integrations`),actions:p(h,{children:[_(`button`,{onClick:le,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(ne,{className:n(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),p(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,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`,children:[_(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&_(e,{mode:`generic`,items:re,getKey:ce,getSearchText:Z,columns:X,onRowClick:ie,isExpanded:Y,renderExpanded:J,searchPlaceholder:i(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:i(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ae,{open:l,onClose:ee}),_(w,{open:v,onClose:T})]})}export{K as IntegrationsPage};
@@ -1 +1 @@
1
- import{g as e}from"./src-BDNLbHXL.js";import{x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as n}from"./AdminPage-Dq33XE9j.js";function r(){return t(n,{children:t(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:t(e,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
1
+ import{g as e}from"./src-0b5IR223.js";import{x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as n}from"./AdminPage-Dq33XE9j.js";function r(){return t(n,{children:t(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:t(e,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
@@ -1 +1 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as l,V as u,c as ee,g as d,n as f,p,s as m}from"./player-overlays-CNHQKrHd.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-pGn6MKOi.js";var te=d(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let d=ee(p().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!d)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await d.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await d.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[d]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!d||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await d.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await d.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[d,A,w,P]);return f(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),d?s(m,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${l} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${l} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${l} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${l} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${l} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
1
+ import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as l,V as u,c as ee,g as d,n as f,p,s as m}from"./player-overlays-JTC60qWR.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-pGn6MKOi.js";var te=d(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let d=ee(p().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!d)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await d.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await d.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[d]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!d||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await d.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await d.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[d,A,w,P]);return f(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),d?s(m,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${l} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${l} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${l} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${l} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${l} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browser-BHo8W_uH.js","assets/rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import{M as n,T as r}from"./src-BDNLbHXL.js";import{Q as i,S as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p}from"./player-overlays-CNHQKrHd.js";import{t as m}from"./circle-check-big-DifLR11P.js";import{t as h}from"./copy-D4StuZzs.js";import{t as g}from"./key-round-BC8uv06u.js";import{t as _}from"./pencil-BuY8CueB.js";import{D as v,N as y,S as b,b as x,r as S,s as C,u as w,w as T,x as E}from"./index-BsmimqzB.js";import{t as D}from"./AdminPage-Dq33XE9j.js";i();function O({value:n,size:r=192}){let[i,o]=l(null),[s,c]=l(null);if(f(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){c(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||c(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{r||c(`qrcode library not installed`)}),()=>{r=!0}},[n]),s)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:r,height:r},children:`QR rendering unavailable — use the secret below.`});if(!i)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:r,height:r},children:`Generating…`});let u=i.modules.size,p=r/u,m=[];for(let e=0;e<u;e++)for(let t=0;t<u;t++)i.modules.data[e*u+t]&&m.push(d(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return a(`svg`,{width:r,height:r,viewBox:`0 0 ${r} ${r}`,className:`text-black`,children:[d(`rect`,{x:0,y:0,width:r,height:r,fill:`white`}),m]})}i();var k={view:{icon:v,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:_,cls:`bg-primary/15 text-primary`},delete:{icon:C,cls:`bg-danger/15 text-danger`}};function A(){let{user:e,logout:t}=S();if(!e)return d(D,{children:d(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return a(D,{children:[a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[d(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),a(`div`,{className:`flex-1 min-w-0`,children:[d(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),a(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,a(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&a(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[d(T,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),d(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),d(j,{}),d(N,{username:e.username}),d(P,{}),r.length>0&&a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2 border-b border-border`,children:[d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),a(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[d(`div`,{children:`Type`}),d(`div`,{children:`Target`}),d(`div`,{children:`Access`})]}),d(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>a(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[d(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),d(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),d(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=k[t];return a(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[d(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[d(x,{className:`h-3 w-3`}),`Sign out`]})})]})}function j(){let e=p(),[t,n]=l(``),[r,i]=l(``),[o,s]=l(``),[c,f]=l(null),h=u({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{f({kind:`success`,msg:`Password updated.`}),n(``),i(``),s(``)},onError:e=>{f({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=r.length>0&&o.length>0&&r!==o,v=r.length>0&&r.length<8,x=t.length>=1&&r.length>=8&&r===o;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),a(`div`,{className:`p-4 space-y-3`,children:[d(M,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),d(M,{label:`New password`,value:r,onChange:i,autoComplete:`new-password`,hint:`At least 8 characters.`}),d(M,{label:`Confirm new password`,value:o,onChange:s,autoComplete:`new-password`}),(_||v)&&d(`div`,{className:`text-[11px] text-danger`,children:_?`Passwords do not match.`:`New password must be at least 8 characters.`}),c&&a(`div`,{className:`text-[11px] flex items-center gap-1 ${c.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[c.kind===`success`?d(m,{className:`h-3 w-3`}):d(y,{className:`h-3 w-3`}),c.msg]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{f(null),h.mutate({currentPassword:t,newPassword:r})},disabled:!x||h.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[h.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(E,{className:`h-3 w-3`}),`Update password`]})})]})]})}function M({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return a(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,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`}),i&&d(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function N({username:e}){let t=p(),n=s({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[i,g]=l(null),[_,v]=l(``),[x,S]=l(null),[C,T]=l(!1),E=u({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=u({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=u({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});f(()=>{if(!C)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[C]);let A=o(()=>n.isLoading?`loading`:i?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,i]);return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),a(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(b,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&a(c,{children:[d(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{S(null),E.mutate()},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(w,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&i&&a(c,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,d(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),a(`div`,{className:`flex flex-col items-center gap-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:d(O,{value:i.otpauthUrl,size:180})}),a(`div`,{className:`w-full`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[d(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:i.secret}),a(`button`,{onClick:()=>{i&&navigator.clipboard.writeText(i.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[C?d(m,{className:`h-3 w-3 text-emerald-500`}):d(h,{className:`h-3 w-3`}),C?`Copied`:`Copy`]})]})]})]}),a(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),d(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&a(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(y,{className:`h-3 w-3`}),x]}),a(`div`,{className:`flex justify-end gap-2`,children:[d(`button`,{onClick:()=>{g(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a(`button`,{onClick:()=>{S(null),D.mutate({code:_})},disabled:D.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(m,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&r&&a(c,{children:[a(`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:[d(m,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:`2FA is active`}),a(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),x&&a(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(y,{className:`h-3 w-3`}),x]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{S(null),k.mutate()},disabled:k.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:[k.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(w,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function P(){return n(`auth-webauthn/passkey-enrollment`)?d(r,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{A as MyAccessPage};
2
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import{M as n,T as r}from"./src-0b5IR223.js";import{Q as i,S as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p}from"./player-overlays-JTC60qWR.js";import{t as m}from"./circle-check-big-D8RfPowm.js";import{t as h}from"./copy-VNmCXPyR.js";import{t as g}from"./key-round-DBmUUaAQ.js";import{t as _}from"./pencil-DhNh3tJt.js";import{D as v,N as y,S as b,b as x,r as S,s as C,u as w,w as T,x as E}from"./index-Oa9WZQrG.js";import{t as D}from"./AdminPage-Dq33XE9j.js";i();function O({value:n,size:r=192}){let[i,o]=l(null),[s,c]=l(null);if(f(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){c(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||c(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{r||c(`qrcode library not installed`)}),()=>{r=!0}},[n]),s)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:r,height:r},children:`QR rendering unavailable — use the secret below.`});if(!i)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:r,height:r},children:`Generating…`});let u=i.modules.size,p=r/u,m=[];for(let e=0;e<u;e++)for(let t=0;t<u;t++)i.modules.data[e*u+t]&&m.push(d(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return a(`svg`,{width:r,height:r,viewBox:`0 0 ${r} ${r}`,className:`text-black`,children:[d(`rect`,{x:0,y:0,width:r,height:r,fill:`white`}),m]})}i();var k={view:{icon:v,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:_,cls:`bg-primary/15 text-primary`},delete:{icon:C,cls:`bg-danger/15 text-danger`}};function A(){let{user:e,logout:t}=S();if(!e)return d(D,{children:d(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return a(D,{children:[a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[d(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),a(`div`,{className:`flex-1 min-w-0`,children:[d(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),a(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,a(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&a(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[d(T,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),d(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),d(j,{}),d(N,{username:e.username}),d(P,{}),r.length>0&&a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2 border-b border-border`,children:[d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),a(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[d(`div`,{children:`Type`}),d(`div`,{children:`Target`}),d(`div`,{children:`Access`})]}),d(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>a(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[d(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),d(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),d(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=k[t];return a(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[d(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[d(x,{className:`h-3 w-3`}),`Sign out`]})})]})}function j(){let e=p(),[t,n]=l(``),[r,i]=l(``),[o,s]=l(``),[c,f]=l(null),h=u({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{f({kind:`success`,msg:`Password updated.`}),n(``),i(``),s(``)},onError:e=>{f({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=r.length>0&&o.length>0&&r!==o,v=r.length>0&&r.length<8,x=t.length>=1&&r.length>=8&&r===o;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),a(`div`,{className:`p-4 space-y-3`,children:[d(M,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),d(M,{label:`New password`,value:r,onChange:i,autoComplete:`new-password`,hint:`At least 8 characters.`}),d(M,{label:`Confirm new password`,value:o,onChange:s,autoComplete:`new-password`}),(_||v)&&d(`div`,{className:`text-[11px] text-danger`,children:_?`Passwords do not match.`:`New password must be at least 8 characters.`}),c&&a(`div`,{className:`text-[11px] flex items-center gap-1 ${c.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[c.kind===`success`?d(m,{className:`h-3 w-3`}):d(y,{className:`h-3 w-3`}),c.msg]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{f(null),h.mutate({currentPassword:t,newPassword:r})},disabled:!x||h.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[h.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(E,{className:`h-3 w-3`}),`Update password`]})})]})]})}function M({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return a(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,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`}),i&&d(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function N({username:e}){let t=p(),n=s({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[i,g]=l(null),[_,v]=l(``),[x,S]=l(null),[C,T]=l(!1),E=u({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=u({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=u({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});f(()=>{if(!C)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[C]);let A=o(()=>n.isLoading?`loading`:i?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,i]);return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),a(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(b,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&a(c,{children:[d(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{S(null),E.mutate()},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(w,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&i&&a(c,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,d(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),a(`div`,{className:`flex flex-col items-center gap-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:d(O,{value:i.otpauthUrl,size:180})}),a(`div`,{className:`w-full`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[d(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:i.secret}),a(`button`,{onClick:()=>{i&&navigator.clipboard.writeText(i.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[C?d(m,{className:`h-3 w-3 text-emerald-500`}):d(h,{className:`h-3 w-3`}),C?`Copied`:`Copy`]})]})]})]}),a(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),d(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&a(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(y,{className:`h-3 w-3`}),x]}),a(`div`,{className:`flex justify-end gap-2`,children:[d(`button`,{onClick:()=>{g(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a(`button`,{onClick:()=>{S(null),D.mutate({code:_})},disabled:D.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(m,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&r&&a(c,{children:[a(`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:[d(m,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:`2FA is active`}),a(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),x&&a(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(y,{className:`h-3 w-3`}),x]}),d(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>{S(null),k.mutate()},disabled:k.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:[k.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(w,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function P(){return n(`auth-webauthn/passkey-enrollment`)?d(r,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{A as MyAccessPage};
@@ -1 +1 @@
1
- import{Ao as e,Ar as t,Cr as n,Dr as r,Er as i,Fr as a,Ir as o,Ka as s,Oo as c,Or as l,Pr as u,Sr as d,Ta as f,Tr as p,br as m,bt as h,jr as g,ko as _,kr as v,oo as y,wr as ee,xr as te,xt as b}from"./src-BDNLbHXL.js";import{I as x,Q as S,S as C,W as w,b as T,o as E,q as D,x as O,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as k,s as A}from"./src-SFNx0Juf.js";import{p as j}from"./player-overlays-CNHQKrHd.js";import{n as M,t as re}from"./rotate-ccw-D9ag3NNh.js";import{t as N}from"./copy-D4StuZzs.js";import{n as P,t as F}from"./AddonCollectionPage-DzUEOYUV.js";import{t as ie}from"./refresh-cw-BwbLLVV6.js";import{t as I}from"./server-C-ApRIN8.js";import{t as ae}from"./square-D5oi0WlG.js";import{t as oe}from"./wifi-xQgrxKer.js";import{L as se,S as L,T as R,V as ce,W as z,b as le,i as ue,k as B,l as de,o as V,v as H,x as fe}from"./index-BsmimqzB.js";import{t as pe}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-C-SMNF-6.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var he=z(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ge=z(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=z(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);S();var G=5e3,_e={connected:!1,endpoint:null};function ve(){let e=E(),t=b({capName:`network-access`},{refetchInterval:G}),n=h(void 0,{refetchInterval:G}),r=w(()=>U(n.data??[]),[n.data]),i=w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=D(null),[l,u]=D({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=a({onSuccess:d,onError:f}),m=o({onSuccess:d,onError:f});return O(F,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:R,itemIcon:R,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>O(ye,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>O(q,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),p.mutate({addonId:e})},onStop:e=>{c(e),m.mutate({addonId:e})}})})}function K(e){let{data:t}=u({addonId:e},{refetchInterval:G,retry:!1}),n=t?A.safeParse(t):null;return n?.success?n.data:_e}function ye({addonId:e}){let t=K(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&C(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[O(B,{className:`h-3 w-3`}),t.endpoint.url]})]})}function q({addonId:t,busyId:n,onStart:r,onStop:i}){let a=K(t),o=n===t;return a.connected?C(e,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(t),children:[o?O(L,{className:`h-3 w-3 animate-spin`}):O(ae,{className:`h-3 w-3`}),`Stop`]}):C(e,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(t),children:[o?O(L,{className:`h-3 w-3 animate-spin`}):O(P,{className:`h-3 w-3`}),`Start`]})}S();var J=3e4;function be(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function xe(){let t=b({capName:`turn-provider`},{refetchInterval:J}),n=h(void 0,{refetchInterval:J}),r=f(),i=r.data??[],a=w(()=>U(n.data??[]),[n.data]);return O(F,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:H,itemIcon:H,capability:`turn-provider`,installButtonLabel:`Add provider`,items:w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),isLoading:t.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>O(Se,{addonId:e.addonId,enabled:e.isActive}),trailing:C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),O(e,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),O(`div`,{className:`p-4`,children:i.length===0?O(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):O(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return C(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&C(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,O(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,O(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),O(`ul`,{className:`divide-y divide-border`,children:n.map(e=>O(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Se({addonId:e,enabled:t}){let n=f({addonId:e},{enabled:t,retry:!1}),r=w(()=>be(n.data??[]),[n.data]);return!t||r.length===0?null:C(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[C(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>O(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}S();var Ce={lan:H,wifi:oe,docker:M,vpn:fe,loopback:I,other:I},we={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Te=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ee(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=w(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=w(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Te.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):O(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>C(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[C(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[O(Ce[t]??I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),O(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:we[t]??t}),C(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),O(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return C(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[O(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&O(se,{className:`h-3 w-3`})}),C(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[O(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),C(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}S();var Y={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function De(){let t=E(),r=j(),a=n(void 0,{refetchInterval:3e4}),o=m(void 0),s=p({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=ee({onSuccess:e=>{g(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=w(()=>a.data?.interfaces??[],[a.data]),f=te({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[h,g]=D([]),[_,v]=D(!1);ne(()=>{!_&&o.data&&(g(o.data.addresses),v(!0))},[o.data,_]);let y=o.data?.addresses??[],b=w(()=>{if(h.length!==y.length)return!0;let e=[...h].toSorted(),t=[...y].toSorted();return e.some((e,n)=>e!==t[n])},[h,y]),x=()=>{s.mutate({addresses:[...h]})},S=()=>{g(y)},T=()=>{g([])},k=()=>{a.refetch(),f.refetch(),o.refetch()},A=async()=>{try{let e=await r.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},M=d(),N=i({onSuccess:()=>void M.refetch()}),P=f.data?.endpoints??[],F=M.data?.baseUrl??null,I=M.data?.resolved??null;return C(pe,{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:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),C(`div`,{className:`flex items-center gap-2 shrink-0`,children:[C(e,{size:`sm`,variant:`secondary`,onClick:k,disabled:a.isLoading,children:[O(ie,{className:`h-3 w-3 ${a.isLoading?`animate-spin`:``}`}),`Refresh`]}),O(e,{size:`sm`,variant:`secondary`,onClick:A,children:`Probe race`})]})]}),C(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:h.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${h.length} pinned`})]}),C(`div`,{className:`flex items-center gap-1`,children:[C(e,{size:`sm`,variant:`secondary`,onClick:()=>l.mutate(void 0),disabled:l.isPending||s.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[O(de,{className:`h-3 w-3`}),l.isPending?`Detecting…`:`Best match`]}),C(e,{size:`sm`,variant:`secondary`,onClick:T,disabled:h.length===0||s.isPending,children:[O(re,{className:`h-3 w-3`}),`Clear`]}),b&&O(e,{size:`sm`,variant:`secondary`,onClick:S,disabled:s.isPending,children:`Discard`}),C(e,{size:`sm`,variant:`primary`,onClick:x,disabled:!b||s.isPending,children:[O(ge,{className:`h-3 w-3`}),s.isPending?`Saving…`:`Save`]})]})]}),O(`div`,{className:`p-4`,children:O(Ee,{mode:`multiple`,interfaces:u,value:h,onChange:g,disabled:s.isPending,emptyMessage:a.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border`,children:[O(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),C(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),O(`span`,{className:`font-mono text-foreground`,children:F??`${I??`nothing reachable`} (auto)`}),F!==null&&O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),F===null&&I===null&&O(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),O(`div`,{className:`p-4`,children:P.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:f.isLoading?`Loading…`:`No endpoints available.`}):O(`ul`,{className:`space-y-1 text-xs`,children:P.map(e=>C(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[O(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[e.kind]??Y.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),O(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),C(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:F===e.baseUrl?C(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[O(ce,{className:`h-2.5 w-2.5`}),` notifications`]}):O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}S();var Oe={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,ke=3e4,Ae={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function je(){let e=b({capName:`mesh-network`},{refetchInterval:X}),t=h(void 0,{refetchInterval:X}),n=w(()=>U(t.data??[]),[t.data]);return O(F,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:M,itemIcon:H,capability:`mesh-network`,installButtonLabel:`Add mesh`,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 mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>O(Me,{addonId:e.addonId}),renderPrimaryAction:e=>O(Ne,{addonId:e.addonId}),renderExpandedPanel:e=>O(Pe,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=r({addonId:e},{refetchInterval:X,retry:!1}),i=t?k.safeParse(t):null;return{status:i?.success?i.data:Ae,isLoading:n}}function Me({addonId:e}){let{status:t}=Z(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ne({addonId:n}){let r=E(),[i,a]=D(!1),[o,s]=D(null),c=j(),{status:u}=Z(n),d=x(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),f=g(),p=l({onSuccess:d}),m=t({onSuccess:d}),h=x(async()=>{a(!0);let e={cancelled:!1};s(e);try{let t=await f.mutateAsync({addonId:n});if(e.cancelled)return;t.loginUrl&&window.open(t.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await ze(2e3),!e.cancelled);){let e=await c.trpcClient.meshNetwork.getStatus.query({addonId:n}).catch(()=>null),t=e?k.safeParse(e):null;if(t?.success&&t.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{a(!1),s(null)}},[n,d,f,c]),_=x(()=>{o&&(o.cancelled=!0),a(!1),s(null)},[o]);return O(T,{children:u.joined?C(T,{children:[C(e,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:n}),children:[p.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(le,{className:`h-3 w-3`}),`Disconnect`]}),C(e,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:n}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]}):i?C(e,{size:`sm`,variant:`ghost`,onClick:_,children:[O(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):C(T,{children:[C(e,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[O(he,{className:`h-3 w-3`}),`Connect`]}),C(e,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:n}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Pe({addonId:e}){let{status:t}=Z(e),n=v({addonId:e},{refetchInterval:ke,retry:!1});return C(`div`,{className:`rounded-lg border border-border bg-surface`,children:[C(`div`,{className:`p-4 space-y-4`,children:[t.error&&O(s,{message:t.error}),O(Fe,{status:t}),t.endpoints.length>0&&C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>C(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Oe[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?O(R,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),C(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[O(B,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),O(`div`,{className:`border-t border-border`,children:O(Le,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fe({status:e}){return O(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ie(e.keyExpiry):`—`}].map(e=>C(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[O(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),O(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ie(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Le({peers:e,loading:t}){let n=w(()=>e.map(e=>({...e,_id:e.id})),[e]),r=x(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=w(()=>[{key:`hostname`,header:`Hostname`,render:e=>C(`div`,{className:`flex flex-col`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&O(_,{variant:`info`,children:`self`}),e.exitNodeOption&&O(_,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),O(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs`,children:t}),O(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>C(`div`,{className:`flex items-center gap-1.5`,children:[O(_,{variant:Re(e.connection),children:e.connection}),e.relay&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?O(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>O(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?C(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[O(L,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?O(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):O(`div`,{className:`p-4`,children:O(y,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Re(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function ze(e){return new Promise(t=>setTimeout(t,e))}function Be(){return O(`div`,{className:`flex flex-col p-4`,children:O(me,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:I,content:O(De,{})},{id:`remote-access`,label:`Remote Access`,icon:R,content:O(ve,{})},{id:`mesh`,label:`Mesh Networks`,icon:M,content:O(je,{})},{id:`turn`,label:`TURN Servers`,icon:H,content:O(xe,{})}]})})}export{Be as NetworkPage};
1
+ import{Ao as e,Ar as t,Cr as n,Dr as r,Er as i,Fr as a,Ir as o,Ka as s,Oo as c,Or as l,Pr as u,Sr as d,Ta as f,Tr as p,br as m,bt as h,jr as g,ko as _,kr as v,oo as y,wr as ee,xr as te,xt as b}from"./src-0b5IR223.js";import{I as x,Q as S,S as C,W as w,b as T,o as E,q as D,x as O,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as k,s as A}from"./src-CzRzcy_1.js";import{p as j}from"./player-overlays-JTC60qWR.js";import{n as M,t as re}from"./rotate-ccw-BDk431kn.js";import{t as N}from"./copy-VNmCXPyR.js";import{n as P,t as F}from"./AddonCollectionPage-dSmADNMP.js";import{t as ie}from"./refresh-cw-BkT1Lcrs.js";import{t as I}from"./server-57sVw14w.js";import{t as ae}from"./square-BVSyqpTo.js";import{t as oe}from"./wifi-B7bqZV0a.js";import{L as se,S as L,T as R,V as ce,W as z,b as le,i as ue,k as B,l as de,o as V,v as H,x as fe}from"./index-Oa9WZQrG.js";import{t as pe}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-BKzZGgJh.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var he=z(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ge=z(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=z(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);S();var G=5e3,_e={connected:!1,endpoint:null};function ve(){let e=E(),t=b({capName:`network-access`},{refetchInterval:G}),n=h(void 0,{refetchInterval:G}),r=w(()=>U(n.data??[]),[n.data]),i=w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=D(null),[l,u]=D({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=a({onSuccess:d,onError:f}),m=o({onSuccess:d,onError:f});return O(F,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:R,itemIcon:R,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>O(ye,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>O(q,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),p.mutate({addonId:e})},onStop:e=>{c(e),m.mutate({addonId:e})}})})}function K(e){let{data:t}=u({addonId:e},{refetchInterval:G,retry:!1}),n=t?A.safeParse(t):null;return n?.success?n.data:_e}function ye({addonId:e}){let t=K(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&C(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[O(B,{className:`h-3 w-3`}),t.endpoint.url]})]})}function q({addonId:t,busyId:n,onStart:r,onStop:i}){let a=K(t),o=n===t;return a.connected?C(e,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(t),children:[o?O(L,{className:`h-3 w-3 animate-spin`}):O(ae,{className:`h-3 w-3`}),`Stop`]}):C(e,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(t),children:[o?O(L,{className:`h-3 w-3 animate-spin`}):O(P,{className:`h-3 w-3`}),`Start`]})}S();var J=3e4;function be(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function xe(){let t=b({capName:`turn-provider`},{refetchInterval:J}),n=h(void 0,{refetchInterval:J}),r=f(),i=r.data??[],a=w(()=>U(n.data??[]),[n.data]);return O(F,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:H,itemIcon:H,capability:`turn-provider`,installButtonLabel:`Add provider`,items:w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),isLoading:t.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>O(Se,{addonId:e.addonId,enabled:e.isActive}),trailing:C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),O(e,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),O(`div`,{className:`p-4`,children:i.length===0?O(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):O(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return C(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&C(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,O(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,O(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),O(`ul`,{className:`divide-y divide-border`,children:n.map(e=>O(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Se({addonId:e,enabled:t}){let n=f({addonId:e},{enabled:t,retry:!1}),r=w(()=>be(n.data??[]),[n.data]);return!t||r.length===0?null:C(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[C(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>O(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}S();var Ce={lan:H,wifi:oe,docker:M,vpn:fe,loopback:I,other:I},we={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Te=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ee(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=w(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=w(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Te.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):O(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>C(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[C(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[O(Ce[t]??I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),O(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:we[t]??t}),C(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),O(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return C(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[O(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&O(se,{className:`h-3 w-3`})}),C(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[O(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),C(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}S();var Y={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function De(){let t=E(),r=j(),a=n(void 0,{refetchInterval:3e4}),o=m(void 0),s=p({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=ee({onSuccess:e=>{g(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=w(()=>a.data?.interfaces??[],[a.data]),f=te({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[h,g]=D([]),[_,v]=D(!1);ne(()=>{!_&&o.data&&(g(o.data.addresses),v(!0))},[o.data,_]);let y=o.data?.addresses??[],b=w(()=>{if(h.length!==y.length)return!0;let e=[...h].toSorted(),t=[...y].toSorted();return e.some((e,n)=>e!==t[n])},[h,y]),x=()=>{s.mutate({addresses:[...h]})},S=()=>{g(y)},T=()=>{g([])},k=()=>{a.refetch(),f.refetch(),o.refetch()},A=async()=>{try{let e=await r.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},M=d(),N=i({onSuccess:()=>void M.refetch()}),P=f.data?.endpoints??[],F=M.data?.baseUrl??null,I=M.data?.resolved??null;return C(pe,{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:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),C(`div`,{className:`flex items-center gap-2 shrink-0`,children:[C(e,{size:`sm`,variant:`secondary`,onClick:k,disabled:a.isLoading,children:[O(ie,{className:`h-3 w-3 ${a.isLoading?`animate-spin`:``}`}),`Refresh`]}),O(e,{size:`sm`,variant:`secondary`,onClick:A,children:`Probe race`})]})]}),C(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:h.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${h.length} pinned`})]}),C(`div`,{className:`flex items-center gap-1`,children:[C(e,{size:`sm`,variant:`secondary`,onClick:()=>l.mutate(void 0),disabled:l.isPending||s.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[O(de,{className:`h-3 w-3`}),l.isPending?`Detecting…`:`Best match`]}),C(e,{size:`sm`,variant:`secondary`,onClick:T,disabled:h.length===0||s.isPending,children:[O(re,{className:`h-3 w-3`}),`Clear`]}),b&&O(e,{size:`sm`,variant:`secondary`,onClick:S,disabled:s.isPending,children:`Discard`}),C(e,{size:`sm`,variant:`primary`,onClick:x,disabled:!b||s.isPending,children:[O(ge,{className:`h-3 w-3`}),s.isPending?`Saving…`:`Save`]})]})]}),O(`div`,{className:`p-4`,children:O(Ee,{mode:`multiple`,interfaces:u,value:h,onChange:g,disabled:s.isPending,emptyMessage:a.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),C(c,{children:[C(`div`,{className:`px-4 py-3 border-b border-border`,children:[O(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),C(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),O(`span`,{className:`font-mono text-foreground`,children:F??`${I??`nothing reachable`} (auto)`}),F!==null&&O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),F===null&&I===null&&O(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),O(`div`,{className:`p-4`,children:P.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:f.isLoading?`Loading…`:`No endpoints available.`}):O(`ul`,{className:`space-y-1 text-xs`,children:P.map(e=>C(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[O(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[e.kind]??Y.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),O(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),C(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:F===e.baseUrl?C(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[O(ce,{className:`h-2.5 w-2.5`}),` notifications`]}):O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}S();var Oe={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,ke=3e4,Ae={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function je(){let e=b({capName:`mesh-network`},{refetchInterval:X}),t=h(void 0,{refetchInterval:X}),n=w(()=>U(t.data??[]),[t.data]);return O(F,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:M,itemIcon:H,capability:`mesh-network`,installButtonLabel:`Add mesh`,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 mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>O(Me,{addonId:e.addonId}),renderPrimaryAction:e=>O(Ne,{addonId:e.addonId}),renderExpandedPanel:e=>O(Pe,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=r({addonId:e},{refetchInterval:X,retry:!1}),i=t?k.safeParse(t):null;return{status:i?.success?i.data:Ae,isLoading:n}}function Me({addonId:e}){let{status:t}=Z(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ne({addonId:n}){let r=E(),[i,a]=D(!1),[o,s]=D(null),c=j(),{status:u}=Z(n),d=x(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),f=g(),p=l({onSuccess:d}),m=t({onSuccess:d}),h=x(async()=>{a(!0);let e={cancelled:!1};s(e);try{let t=await f.mutateAsync({addonId:n});if(e.cancelled)return;t.loginUrl&&window.open(t.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await ze(2e3),!e.cancelled);){let e=await c.trpcClient.meshNetwork.getStatus.query({addonId:n}).catch(()=>null),t=e?k.safeParse(e):null;if(t?.success&&t.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{a(!1),s(null)}},[n,d,f,c]),_=x(()=>{o&&(o.cancelled=!0),a(!1),s(null)},[o]);return O(T,{children:u.joined?C(T,{children:[C(e,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:n}),children:[p.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(le,{className:`h-3 w-3`}),`Disconnect`]}),C(e,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:n}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]}):i?C(e,{size:`sm`,variant:`ghost`,onClick:_,children:[O(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):C(T,{children:[C(e,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[O(he,{className:`h-3 w-3`}),`Connect`]}),C(e,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:n}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Pe({addonId:e}){let{status:t}=Z(e),n=v({addonId:e},{refetchInterval:ke,retry:!1});return C(`div`,{className:`rounded-lg border border-border bg-surface`,children:[C(`div`,{className:`p-4 space-y-4`,children:[t.error&&O(s,{message:t.error}),O(Fe,{status:t}),t.endpoints.length>0&&C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>C(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Oe[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?O(R,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),C(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[O(B,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),O(`div`,{className:`border-t border-border`,children:O(Le,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fe({status:e}){return O(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ie(e.keyExpiry):`—`}].map(e=>C(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[O(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),O(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ie(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Le({peers:e,loading:t}){let n=w(()=>e.map(e=>({...e,_id:e.id})),[e]),r=x(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=w(()=>[{key:`hostname`,header:`Hostname`,render:e=>C(`div`,{className:`flex flex-col`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&O(_,{variant:`info`,children:`self`}),e.exitNodeOption&&O(_,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),O(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs`,children:t}),O(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>C(`div`,{className:`flex items-center gap-1.5`,children:[O(_,{variant:Re(e.connection),children:e.connection}),e.relay&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?O(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>O(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?C(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[O(L,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?O(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):O(`div`,{className:`p-4`,children:O(y,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Re(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function ze(e){return new Promise(t=>setTimeout(t,e))}function Be(){return O(`div`,{className:`flex flex-col p-4`,children:O(me,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:I,content:O(De,{})},{id:`remote-access`,label:`Remote Access`,icon:R,content:O(ve,{})},{id:`mesh`,label:`Mesh Networks`,icon:M,content:O(je,{})},{id:`turn`,label:`TURN Servers`,icon:H,content:O(xe,{})}]})})}export{Be as NetworkPage};
@@ -1 +1 @@
1
- import{bt as e,dt as t,ft as n,sn as r,zt as i}from"./src-BDNLbHXL.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as y}from"./src-SFNx0Juf.js";import{p as ee}from"./player-overlays-CNHQKrHd.js";import{t as b}from"./FormBuilder-BTBth7Mm.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=e(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
1
+ import{bt as e,dt as t,ft as n,sn as r,zt as i}from"./src-0b5IR223.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as y}from"./src-CzRzcy_1.js";import{p as ee}from"./player-overlays-JTC60qWR.js";import{t as b}from"./FormBuilder-DzsVc3t_.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=e(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
@@ -1 +1 @@
1
- import{Dn as e,Mn as t,Oi as n,Tn as r,To as i,_i as a,ko as o}from"./src-BDNLbHXL.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as g}from"./zap-B6f_Rmgy.js";import{P as _,W as v,a as y,j as b,x}from"./index-BsmimqzB.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`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`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return t({addonId:e})}function k(t){return e({deviceId:t},{enabled:Number.isFinite(t)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),r({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=A?!1:j}})}c();function N(e,t,n){return Math.min(Math.max(e,t),n)}function P(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function F(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:N(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function I(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function L({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>P(e)),[c,u]=p(new Set);h(()=>{s(P(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>F(n,e,t,c,f))},v=()=>{let t=I(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function R(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var z={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function B({nodeId:e,nodeName:t,isOnline:r}){let s=f(),{data:c,isLoading:g}=a({nodeId:e},{refetchInterval:15e3}),v=n({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??r,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=t=>{let n={};for(let[e,r]of Object.entries(t)){if(!r.enabled)continue;let t=Object.keys(r.steps).length>0;n[e]={enabled:!0,weight:Math.max(1,r.weight),...r.maxSessions!=null&&r.maxSessions>0?{maxSessions:r.maxSessions}:{},...t?{steps:r.steps}:{}}}v.mutate({agentNodeId:e,inferenceDevices:n})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},N=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},P=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),F=u(()=>P.map(e=>({id:e.key,name:R(e).label,weight:S[e.key]?.weight??e.weight})),[P,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(e=>{let t=R(e),n=S[e.key]??j(e),r=n.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?r?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${z[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(o,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(o,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!r&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),r&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(i,{checked:r,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(V,{}),x&&P.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(L,{nodes:F,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function V(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{M as a,C as c,k as i,R as n,O as o,L as r,T as s,B as t};
1
+ import{Dn as e,Mn as t,Oi as n,Tn as r,To as i,_i as a,ko as o}from"./src-0b5IR223.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as g}from"./zap-CWXvqdT_.js";import{P as _,W as v,a as y,j as b,x}from"./index-Oa9WZQrG.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`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`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return t({addonId:e})}function k(t){return e({deviceId:t},{enabled:Number.isFinite(t)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),r({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=A?!1:j}})}function N(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}c();function P(e,t,n){return Math.min(Math.max(e,t),n)}function F(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function I(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:P(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function L(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function R({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>F(e)),[c,u]=p(new Set);h(()=>{s(F(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>I(n,e,t,c,f))},v=()=>{let t=L(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function z(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var B={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function V({nodeId:e,nodeName:t,isOnline:r}){let s=f(),{data:c,isLoading:g}=a({nodeId:e},{refetchInterval:15e3}),v=n({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??r,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=t=>{let n=b.map(e=>{let n=t[e.key]??j(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});v.mutate({agentNodeId:e,inferenceDevices:N(n)})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},P=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},F=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),I=u(()=>F.map(e=>({id:e.key,name:z(e).label,weight:S[e.key]?.weight??e.weight})),[F,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(e=>{let t=z(e),n=S[e.key]??j(e),r=n.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?r?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${B[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(o,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(o,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!r&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),r&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);P(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(i,{checked:r,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(H,{}),x&&F.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(R,{nodes:I,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function H(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{k as a,T as c,N as i,C as l,z as n,M as o,R as r,O as s,V as t};