@camstack/addon-admin-ui 1.2.99 → 1.2.100

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 (114) hide show
  1. package/dist/assets/{AddLocationWizard-BoMdcUqK.js → AddLocationWizard-ww2FaZ1E.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BeuyrbPU.js → AddonCollectionPage-2an6cPDR.js} +1 -1
  3. package/dist/assets/Addons-Dnc-RXgM.js +1 -0
  4. package/dist/assets/{AdminTabs-CX9dEC2O.js → AdminTabs-Bp6VWjqO.js} +1 -1
  5. package/dist/assets/AiProfiles-DpS2g7XY.js +3 -0
  6. package/dist/assets/{BrokerForm-B7hzX8rb.js → BrokerForm-MO0zLICQ.js} +1 -1
  7. package/dist/assets/{Build-tE4EhSaT.js → Build-C6grDXZj.js} +3 -3
  8. package/dist/assets/Capabilities-C1oKrOiJ.js +1 -0
  9. package/dist/assets/{CapabilityBadges-emVPX4I2.js → CapabilityBadges-CQ8iNKjJ.js} +1 -1
  10. package/dist/assets/{Cluster-JUwg2dkP.js → Cluster-BlBr9mrc.js} +1 -1
  11. package/dist/assets/{Data-Cxg1mPBE.js → Data-CbSER22j.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-CbKPyUop.js → DetectionIntelligence-CZyeSCJf.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-waoppD0W.js → DeviceAggregateSection-DJUAmzyp.js} +1 -1
  14. package/dist/assets/{DeviceDetail-Dci5cbpv.js → DeviceDetail-DmgBCV4a.js} +2 -2
  15. package/dist/assets/{Devices-D9II1LJb.js → Devices-BrElFvY3.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-BttmGIA6.js → EmbedPlayerPage-4Ay_8z3U.js} +1 -1
  17. package/dist/assets/Events-KnLsawMq.js +1 -0
  18. package/dist/assets/FormBuilder-CEw554z0.js +1 -0
  19. package/dist/assets/{Identity-BdTuPuKv.js → Identity-bGGI1QWE.js} +1 -1
  20. package/dist/assets/IntegrationDetail-eQjr_VZf.js +1 -0
  21. package/dist/assets/Integrations-CDOiRBS9.js +1 -0
  22. package/dist/assets/{Integrations-B5uZQ_hG.js → Integrations-R6vGB8m2.js} +1 -1
  23. package/dist/assets/{Logs-ClnZCjgz.js → Logs-It8Tm5s9.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-BcBzi-j4.js → MotionZonesSettings-DwzHsRPk.js} +1 -1
  25. package/dist/assets/MyAccess-Bo811JUn.js +2 -0
  26. package/dist/assets/Network-B6zVgaCe.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-ptvTM4Ri.js → NodeAddonsSettingsPanel-hGBeOFYH.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-BOyHlH5j.js → NodeInferenceDevices-BCmCXC5y.js} +1 -1
  29. package/dist/assets/Notifications-DSAFFXJr.js +1 -0
  30. package/dist/assets/{Pipeline-tifFVNvD.js → Pipeline-BbnF9Ozb.js} +1 -1
  31. package/dist/assets/{Plates-DS0aJWI5.js → Plates-Ck6zc0jT.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-CWQfl1TC.js → PrivacyMaskSettings-B_z0irSV.js} +1 -1
  33. package/dist/assets/{ProviderIcon-BYY3__KP.js → ProviderIcon-DupRG1e9.js} +1 -1
  34. package/dist/assets/Recordings-BmEupF3w.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-B8lG3NsX.js → ScanNetworkModal-D0r0hQ_h.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Bqwf_0qV.js → SceneMonitorEditor-CGXIUSVs.js} +1 -1
  37. package/dist/assets/{Scenes-Cwmh_GbN.js → Scenes-BNeqc2nK.js} +1 -1
  38. package/dist/assets/{Settings-D_2-xI9-.js → Settings-Bh1XKvEL.js} +1 -1
  39. package/dist/assets/{Showroom-Cl7eIhbG.js → Showroom-BzVgVZC7.js} +1 -1
  40. package/dist/assets/{Terminal-CFwukkqI.js → Terminal-B58p5WIp.js} +4 -4
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CI4I2cYP.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-TBqHL73f.js} +1 -1
  42. package/dist/assets/{bell-ring-CsQYceF5.js → bell-ring-DTczejZ4.js} +1 -1
  43. package/dist/assets/{boxes-6foKhsHw.js → boxes-C985Wrl0.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-Ccj9w__U.js → build-cluster-graph-CipaA_oB.js} +2 -2
  45. package/dist/assets/circle-check-big-Bj2tv0Uy.js +1 -0
  46. package/dist/assets/{circle-x-Bf5Kcelv.js → circle-x-CDQw-Oki.js} +1 -1
  47. package/dist/assets/clock-BcKuptwD.js +1 -0
  48. package/dist/assets/{copy-B4N78LE2.js → copy-CAOXjD5r.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-BvcuJvDz.js → debounced-invalidate-DpIEFwPp.js} +1 -1
  50. package/dist/assets/dist-BHaLZy2_.js +349 -0
  51. package/dist/assets/{dist-D-Jc8U0i.js → dist-CI4L7l-2.js} +1 -1
  52. package/dist/assets/{download-BsBZ8S8R.js → download-CAJNFrAB.js} +1 -1
  53. package/dist/assets/{face-bbox-CG7h6fE-.js → face-bbox-BFgt9EZy.js} +1 -1
  54. package/dist/assets/{hostInit-D01Z23QG.js → hostInit-CAD--nfI.js} +1 -1
  55. package/dist/assets/index-9YoL1cUW.css +2 -0
  56. package/dist/assets/index-KHEomj2t.js +4 -0
  57. package/dist/assets/{key-round-B46YLw7m.js → key-round-D_sH_q8V.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-063874c6.js → mf-entry-bootstrap-0-c4e36f72.js} +2 -2
  59. package/dist/assets/{pencil-BQJAwzya.js → pencil-CqqsHO49.js} +1 -1
  60. package/dist/assets/play-I3HZudQM.js +1 -0
  61. package/dist/assets/{player-overlays-BDZbxeCH.js → player-overlays-bbH94q-C.js} +1 -1
  62. package/dist/assets/plus-CJqabi49.js +1 -0
  63. package/dist/assets/power-txJcg2ZI.js +1 -0
  64. package/dist/assets/{radio-DpeKwLzo.js → radio-Cug4imoO.js} +1 -1
  65. package/dist/assets/{refresh-cw-DLQxYBTF.js → refresh-cw-BGCphjMn.js} +1 -1
  66. package/dist/assets/remoteEntry-BG1pNM_r.js +1 -0
  67. package/dist/assets/rotate-ccw-h1d3r46-.js +1 -0
  68. package/dist/assets/rotate-cw-Bfa_vcNi.js +1 -0
  69. package/dist/assets/{send-SvrrXT_D.js → send-C5aDTEjJ.js} +1 -1
  70. package/dist/assets/{server-ZhEvwONi.js → server-3wNyeBU4.js} +1 -1
  71. package/dist/assets/{shield-4rMaNiMB.js → shield-DplCqcL2.js} +1 -1
  72. package/dist/assets/square-BTe4gnO3.js +1 -0
  73. package/dist/assets/{square-check-big-B3-8gxk1.js → square-check-big-DH3-Pa_W.js} +1 -1
  74. package/dist/assets/src-CEeJOwlR.js +349 -0
  75. package/dist/assets/src-D7V1-vUs.js +67 -0
  76. package/dist/assets/{star-BwlNFxIs.js → star-Y4-10BmL.js} +1 -1
  77. package/dist/assets/{undo-2-DqcWKrwk.js → undo-2-DEYHOb0E.js} +1 -1
  78. package/dist/assets/{upload-C7vU_A2m.js → upload-BtP3VBCU.js} +1 -1
  79. package/dist/assets/{use-scenes-feed-8dvuhS6R.js → use-scenes-feed-BXzv1F4x.js} +1 -1
  80. package/dist/assets/useEventInvalidation-Bzw3MDRD.js +1 -0
  81. package/dist/assets/{video-CWHO5MEy.js → video-CXx7eETO.js} +1 -1
  82. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CBSniS6c.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DyH01HQs.js} +2 -2
  83. package/dist/assets/{wifi-BUxK1DpB.js → wifi-ClKydJp-.js} +1 -1
  84. package/dist/assets/{zap-C6IN4srQ.js → zap-Dnj7qxTO.js} +1 -1
  85. package/dist/index.html +6 -6
  86. package/dist/server/addon.js +192 -51
  87. package/package.json +1 -1
  88. package/dist/assets/Addons-BHwAi_Ds.js +0 -1
  89. package/dist/assets/AiProfiles-DlwniNcN.js +0 -3
  90. package/dist/assets/Capabilities-DxVvgAzD.js +0 -1
  91. package/dist/assets/Events-BjaKZpZf.js +0 -1
  92. package/dist/assets/FormBuilder-1r_2pkuu.js +0 -1
  93. package/dist/assets/IntegrationDetail-CvxZbTm2.js +0 -1
  94. package/dist/assets/Integrations-Dm_ug2n_.js +0 -1
  95. package/dist/assets/MyAccess-D27HsjNA.js +0 -2
  96. package/dist/assets/Network-BpaCiAzG.js +0 -1
  97. package/dist/assets/Notifications-BNZyRpU4.js +0 -1
  98. package/dist/assets/Recordings-DZSmzuAc.js +0 -1
  99. package/dist/assets/circle-check-big-B8rnDG8h.js +0 -1
  100. package/dist/assets/clock-DnzOV8EI.js +0 -1
  101. package/dist/assets/dist-CXnx4jTF.js +0 -349
  102. package/dist/assets/index-CUen2nrR.js +0 -4
  103. package/dist/assets/index-DM8saR4E.css +0 -2
  104. package/dist/assets/play-DoOoBM0P.js +0 -1
  105. package/dist/assets/plus-DDGOU54V.js +0 -1
  106. package/dist/assets/power-DmlMC-7S.js +0 -1
  107. package/dist/assets/remoteEntry-Dm-Wta47.js +0 -1
  108. package/dist/assets/rotate-ccw-wXYD6bC7.js +0 -1
  109. package/dist/assets/rotate-cw-ClC0Tfzf.js +0 -1
  110. package/dist/assets/search-C1UMvnoJ.js +0 -1
  111. package/dist/assets/square-ookqWTBx.js +0 -1
  112. package/dist/assets/src-BO2615nJ.js +0 -67
  113. package/dist/assets/src-BgxUlUk-.js +0 -349
  114. package/dist/assets/useEventInvalidation-BEgRNMRl.js +0 -1
@@ -1,3 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d,o as f}from"./player-overlays-BDZbxeCH.js";import{At as p,Et as m,Ft as h,Gt as g,It as _,Lt as v,Nt as y,Ot as b,Pt as x,Tt as S,Yt as C,et as w,g as T,jt as E,kt as D,tt as O,wt as k}from"./src-BO2615nJ.js";import{ot as A}from"./src-BgxUlUk-.js";import{t as j}from"./boxes-6foKhsHw.js";import{t as M}from"./download-BsBZ8S8R.js";import{n as ee,t as te}from"./send-SvrrXT_D.js";import{t as ne}from"./pencil-BQJAwzya.js";import{t as N}from"./plus-DDGOU54V.js";import{t as P}from"./search-C1UMvnoJ.js";import{t as F}from"./server-ZhEvwONi.js";import{t as re}from"./square-ookqWTBx.js";import{C as I,D as L,H as R,K as z,N as B,V,i as ie,l as H,s as ae,t as U,v as W}from"./index-CUen2nrR.js";import{t as G}from"./AdminPage-CCD07UMs.js";import{t as K}from"./AdminTabs-CX9dEC2O.js";var q=z(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),oe=z(`message-square-plus`,[[`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`,key:`1lielz`}],[`path`,{d:`M12 7v6`,key:`lw1j43`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}]]);n();var se=[`llm`,`listProfiles`],ce=[`llm`,`listProfileKinds`],le=[`llm`,`getDefaults`],J=[`llm`,`listRuntimeNodes`],ue=[`llm`,`listModelCatalog`],de=[`llm`,`getUsage`],fe=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],pe=new Map(Object.entries({openai:q,anthropic:q,google:q,"openai-compatible":W,"managed-local":B}));function me(e){return pe.get(e)??null}function Y(e){return typeof e==`string`&&e.length>0?e:void 0}function X(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Z(e){return e===!0}function he(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:ye(e.runtime?.extraArgs??[])}}var ge=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function _e(e){return typeof e==`string`&&ge.includes(e)?e:void 0}function ve(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function ye(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var be=[`--jinja`,`--cont-batching`];function xe(e,t,n){let r=X(e.threads),i=X(e.batchSize),a=X(e.ubatchSize),o=_e(e.cacheTypeK),s=_e(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...ve(Y(e.extraArgs)??``)],contextSize:X(e.contextSize)??4096,gpuLayers:X(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:X(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Z(e.flashAttention),mlock:Z(e.mlock),noMmap:Z(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Z(e.autoStart),idleStopMinutes:X(e.idleStopMinutes)??30}}function Se(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:Y(r.model)??n?.model??``,supportsVision:i?.supportsVision??Z(r.supportsVision),timeoutMs:X(r.timeoutMs)??A.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??A.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??A.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??A.idleMs,retry:{enabled:Z(r.retryEnabled),maxAttempts:X(r.retryMaxAttempts)??1},toolsEnabled:Z(r.toolsEnabled)},o=Y(r.baseUrl),s=Y(r.apiKey),c=X(r.temperature),l=X(r.topP),u=X(r.topK),d=X(r.maxTokens),f=X(r.contextLength),p=Y(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:xe(r,i.nodeId,i.model)}}}function Ce(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var we=2e3;function Q(e){return`${(e/1e9).toFixed(2)} GB`}function Te(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Ee({nodeId:e,value:t,onChange:n}){let{t:o}=U(),u=d(),[f,p]=s(``),[m,h]=s(null),[g,b]=s(!1),S=a({queryKey:ue,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),C=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),w=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),b(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),T=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{b(!0),C.refetch()}}),E=a({queryKey:J,enabled:T.isPending,refetchInterval:T.isPending?we:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,D=i(()=>{let t=(S.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(C.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:Q(t.sizeBytes),node:e})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[S.data,C.data,m,e,o]),O=e=>{if(e===``){n(null);return}if(e===`custom`){if(m?.ok!==!0)return;n({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=S.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=C.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},k=e=>{f.trim()!==``&&w.mutate({ref:f.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(y,{id:`ai-model`,value:Te(t),options:D,onChange:e=>O(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(x,{value:f,onChange:e=>p(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),k())}}),r(v,{size:`sm`,variant:`secondary`,type:`button`,disabled:f.trim()===``||w.isPending,onClick:()=>k(),children:[w.isPending?l(I,{className:`h-3.5 w-3.5 animate-spin`}):l(P,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),w.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:w.error instanceof Error?w.error.message:o(`common.error`,`Error`)}),m?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:m.message}),m.candidates!==void 0&&m.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:m.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${f.trim().split(`:`)[0]??``}:${e}`;p(t),w.mutate({ref:t})},children:e},e))}),m.requiredBytes!==void 0&&l(v,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>k(m.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]}),m?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),l(_,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),l(_,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(v,{size:`sm`,type:`button`,disabled:T.isPending||g,onClick:()=>T.mutate(m.model),children:[T.isPending?l(I,{className:`h-3.5 w-3.5 animate-spin`}):l(M,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),E!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:E.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:E.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:E.file,index:E.fileIndex,count:E.fileCount,done:Q(E.downloadedBytes),total:E.totalBytes===void 0?``:` / ${Q(E.totalBytes)}`})})]}),T.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:T.error instanceof Error?T.error.message:o(`common.error`,`Error`)})]})]})]})}n();function De({kind:e,className:t}){let n=me(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Oe({kinds:e,onPick:t,onCancel:n}){let{t:a}=U(),o=i(()=>Ce(e),[e]);return l(k,{open:!0,onOpenChange:e=>!e&&n(),children:r(m,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(D,{children:l(p,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(S,{className:`space-y-4 pr-1`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(De,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),l(b,{children:l(v,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:a(`common.cancel`,`Cancel`)})})]})})}function ke({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=U(),f=e.kind===`managed-local`,[h,y]=s(t?.name??e.label),[C,w]=s(()=>t===null?{}:he(t)),[E,O]=s(t?.runtime?.nodeId??`hub`),[A,j]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),M=i(()=>ve(Y(C.extraArgs)??``),[C.extraArgs]),ee=()=>{if(!f){n(Se(e.kind,h,t,C));return}A!==null&&n(Se(e.kind,h,t,C,{nodeId:E,model:A.model,modelId:A.modelId,supportsVision:A.supportsVision}))},te=c||h.trim()===``||f&&A===null;return l(k,{open:!0,onOpenChange:e=>!e&&a(),children:r(m,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(D,{children:r(p,{className:`flex items-center gap-2`,children:[l(De,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name})]})}),r(S,{className:`space-y-3 pr-1`,children:[u!==null&&l(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:u}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(x,{id:`ai-profile-name`,value:h,onChange:e=>y(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(T,{selectedNodeId:E,onSelect:O,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Ee,{nodeId:E,value:A,onChange:j}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(x,{id:`ai-extra-args`,value:Y(C.extraArgs)??``,onChange:e=>w({...C,extraArgs:e.target.value}),placeholder:be.join(` `)}),M.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:M.map((e,t)=>l(_,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),l(g,{schema:e.configSchema,values:C,onChange:w}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),r(b,{children:[f&&A===null&&l(_,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),l(v,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(v,{size:`sm`,type:`button`,disabled:te,onClick:ee,children:[c&&l(I,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]})]})})}n();function Ae(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(De,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(_,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(_,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(E,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(I,{className:`h-3.5 w-3.5 animate-spin`}):l(te,{className:`h-3.5 w-3.5`})}),l(v,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(ne,{className:`h-3.5 w-3.5`})}),l(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(ae,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function je(){let{t:e}=U(),t=d(),[n,o]=s({mode:`closed`}),[u,f]=s(null),[p,m]=s(null),g=a({queryKey:se,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),_=a({queryKey:ce,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),y=()=>{g.refetch()},b=c({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),m(null),y()},onError:t=>m(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),x=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:y}),S=c({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>f({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),T=g.data??[],E=i(()=>_.data??[],[_.data]),D=i(()=>{let e=new Map;for(let t of E)e.set(t.kind,t);return e},[E]);return r(G,{icon:H,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:r(v,{size:`sm`,type:`button`,onClick:()=>{m(null),o({mode:`pick-kind`})},children:[l(N,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[g.isError&&l(C,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:g.error instanceof Error?g.error.message:e(`common.error`,`Error`),onRetry:()=>void g.refetch()}),l(Me,{profiles:T}),g.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(I,{className:`h-6 w-6 animate-spin text-primary`})}),!g.isLoading&&T.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),T.length>0&&l(h,{children:l(w,{columns:Ae({kindByName:D,testResult:u,testingId:S.isPending?S.variables?.id??null:null,t:e,onToggle:e=>b.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>S.mutate(e),onEdit:e=>{let t=D.get(e.kind);t!==void 0&&(m(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>x.mutate(e)}),rows:T,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Oe,{kinds:E,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),n.mode===`form`&&l(ke,{kind:n.kind,existing:n.profile,saving:b.isPending,error:p,onSave:e=>b.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function Me({profiles:e}){let{t}=U(),n=d(),i=a({queryKey:le,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(h,{children:l(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:fe.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),r(`select`,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[l(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!a.some(e=>e.id===c)&&l(`option`,{value:c,children:d?.name??c}),a.map(e=>r(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Ne=5e3;function Pe(e){return`${(e/1e9).toFixed(1)} GB`}function Fe(){let{t:e}=U(),t=d(),n=a({queryKey:J,refetchInterval:Ne,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(_,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(_,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Pe(e.disk.modelsBytes)})},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(G,{icon:F,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(C,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(h,{children:l(w,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:640,bordered:!1,mobileMode:`scroll`,maxBodyHeight:O})})]})}var Ie=`/addon/ai/test-chat`,Le=`/addon/ai/test-chat/chats`,Re=6e5;function ze(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Re)}function Be(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ve(e){if(!Be(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var He=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ue(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Be(t))return null;switch(t.kind){case`status`:{let e=He.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Ve(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*We(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
- `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Ue(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=Ue(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Ge(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ke(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function qe(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function Je(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function Ye(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var Xe=[`deviceManager`,`listAll`,`cameras`],Ze=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Qe=360*60*1e3,$e=40,et=160,$={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function tt(){let{t:n}=U(),o=d(),[c,f]=s(``),[p,m]=s(``),[g,_]=s(``),[b,S]=s([]),[w,T]=s(null),[E,D]=s(`none`),[O,k]=s(`throwaway`),[A,j]=s(null),[M,ne]=s([]),[N,P]=s(null),[F,I]=s(null),L=t(null);u(()=>()=>L.current?.abort(),[]);let z=e(async()=>{let e=await fetch(Le,{credentials:`same-origin`});e.ok&&ne((await e.json()).chats??[])},[]);u(()=>{O===`persistent`&&z()},[O,z]);let B=a({queryKey:se,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),H=i(()=>(B.data??[]).filter(e=>e.enabled),[B.data]),W=H.find(e=>e.id===c)??null,K=F!==null,q=e(async(e,t)=>{let r=new AbortController;L.current=r,P(null);let i=ze(W??{});I({...$,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(Ie,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...p.trim()===``?{}:{system:p.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...O===`persistent`?{persist:!0,...A===null?{}:{conversationId:A}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of We(n.body))switch(e.kind){case`status`:I(t=>({...t??$,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,I(t=>({...t??$,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,I(e=>({...e??$,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||P(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{L.current=null,I(null)}d!==void 0&&(j(d),z());let f=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!f||S(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[O,A,W,c,z,p,n]),ce=e(()=>{let e=g.trim();if(e===``||c===``||K)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...w===null?{}:{attachmentLabel:w.label,attachmentKind:w.ref.kind}},n=[...b,t];S(n),_(``);let r=w?.ref;T(null),D(`none`),q(O===`persistent`&&A!==null?[{role:`user`,content:e}]:Ge(n),r)},[O,A,g,w,c,q,K,b]),le=()=>L.current?.abort(),J=()=>{L.current?.abort(),S([]),T(null),_(``),P(null),I(null),j(null)},ue=async e=>{L.current?.abort();let t=await fetch(`${Le}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),S(qe(n)),I(null),P(null)};return r(G,{icon:ee,title:n(`ai.testTitle`,`Test chat`),subtitle:n(O===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,O===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:r(v,{size:`sm`,variant:`secondary`,type:`button`,disabled:b.length===0&&w===null,onClick:J,children:[l(ae,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(h,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(y,{id:`ai-test-profile`,value:c,onChange:e=>f(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...H.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),H.length===0&&!B.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(x,{id:`ai-test-system`,value:p,onChange:e=>m(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(v,{size:`sm`,variant:O===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{k(`throwaway`),j(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(v,{size:`sm`,variant:O===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>k(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),O===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(v,{size:`sm`,variant:`secondary`,type:`button`,onClick:J,children:[l(oe,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),M.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>l(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===A?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),W!==null&&!W.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),N!==null&&l(C,{title:n(`ai.chatFailed`,`The test call failed`),message:N}),l(nt,{turns:b,live:F}),r(h,{className:`space-y-2 p-3`,children:[w!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[w.ref.kind===`snapshot`?l(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:w.label}),l(v,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T(null),children:l(ie,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(v,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`snapshot`?`none`:`snapshot`),children:[l(V,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(v,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>D(E===`track`?`none`:`track`),children:[l(R,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&l(at,{onPick:e=>{T({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),D(`none`)}}),E===`track`&&l(st,{onPick:(e,t)=>{T({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),D(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(x,{value:g,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ce())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),K?r(v,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[l(re,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(v,{size:`sm`,type:`button`,disabled:g.trim()===``||c===``,onClick:ce,children:[l(te,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function nt({turns:e,live:t}){let{t:n}=U();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(h,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(rt,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(it,{attachment:t.mediaSent}),t.text.length>0&&l(rt,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(I,{className:`h-3.5 w-3.5 animate-spin`}),Ye(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function rt({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(it,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(R,{className:`h-3 w-3`}):l(V,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(V,{className:`h-3 w-3`}):l(R,{className:`h-3 w-3`}),Je(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function it({attachment:e}){let t=Ke(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function at({onPick:e}){let{t}=U(),n=d(),r=a({queryKey:Xe,queryFn:()=>n.trpcClient.deviceManager.listAll.query({isCamera:!0,projection:`slim`})}),i=(r.data??[]).filter(e=>!e.disabled);return r.isLoading?l(I,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):i.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:i.map(t=>l(ot,{device:t,onPick:e},t.id))})}function ot({device:e,onPick:t}){let{src:n}=f(e.id,{width:et});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(_,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function st({onPick:e}){let{t}=U(),n=d(),o=a({queryKey:Xe,queryFn:()=>n.trpcClient.deviceManager.listAll.query({isCamera:!0,projection:`slim`})}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...Ze,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-Qe,limit:$e,projection:`slim`})});if(o.isLoading||u.isLoading)return l(I,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let f=u.data?.tracks??[];return f.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:f.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(R,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var ct=1440*60*1e3,lt=[1,7,30,90];function ut(){let{t:e}=U(),t=d(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*ct},[n]),u=a({queryKey:se,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),f=a({queryKey:[...de,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),p=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[p,e]),g=f.data??[];return r(G,{icon:L,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(y,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:lt.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[f.isError&&l(C,{title:e(`ai.usageFailed`,`Failed to read usage`),message:f.error instanceof Error?f.error.message:e(`common.error`,`Error`),onRetry:()=>void f.refetch()}),g.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(h,{children:l(w,{columns:m,rows:g,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:O})})]})}function dt(){let{t:e}=U();return l(`div`,{className:`flex flex-col p-4`,children:l(K,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:j,content:l(je,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:F,content:l(Fe,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:L,content:l(ut,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:ee,content:l(tt,{})}]})})}export{dt as AiProfilesPage,dt as default};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-BDZbxeCH.js";import{Yt as c}from"./src-BO2615nJ.js";import{t as l}from"./circle-check-big-B8rnDG8h.js";import{C as u,F as d,d as f}from"./index-CUen2nrR.js";import{t as p}from"./AdminPage-CCD07UMs.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(u,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[u,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:u};return t(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(d,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,i as c,o as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-BDZbxeCH.js";import{Br as m,Ca as h,Da as g,Dn as _,Ea as v,Et as y,Fs as b,Ft as x,It as S,Lt as C,Nt as w,Pt as T,Ta as E,Yt as D,_a as O,ba as k,da as A,dn as j,fn as M,ha as N,j as P,js as F,la as I,ma as ee,pa as te,qi as L,sa as R,ua as z,va as ne,wa as B,wt as re,xa as V,ya as H}from"./src-BO2615nJ.js";import{Rt as U,at as ie,mt as ae}from"./src-BgxUlUk-.js";import{t as W}from"./clock-DnzOV8EI.js";import{t as oe}from"./copy-B4N78LE2.js";import{t as se}from"./download-BsBZ8S8R.js";import{a as ce,c as G,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-BvcuJvDz.js";import{t as ye}from"./refresh-cw-DLQxYBTF.js";import{t as be}from"./search-C1UMvnoJ.js";import{t as xe}from"./square-check-big-B3-8gxk1.js";import{t as Se}from"./square-ookqWTBx.js";import{t as Ce}from"./star-BwlNFxIs.js";import{t as we}from"./undo-2-DqcWKrwk.js";import{C as K,G as Te,I as Ee,K as q,O as De,P as Oe,R as ke,i as Ae,l as je,s as Me,t as Ne,z as Pe}from"./index-CUen2nrR.js";import{t as Fe}from"./AdminPage-CCD07UMs.js";import{i as Ie,n as Le,t as Re}from"./authed-media-BPd_L9jr.js";import{t as ze}from"./AdminTabs-CX9dEC2O.js";var Be=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Ve=q(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),He=q(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),Ue=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),We=q(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ge=q(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ke=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),qe=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();var Je=`pipeline-analytics`,Ye=`debug.listTracks`,Xe=`debug.analyze`,Ze=`/addon/pipeline-analytics/debug-export`;function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function et(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tt(e){return e===`error`||e===`warn`||e===`info`}function nt(e){if(!Qe(e))return null;let t=$e(e,`code`),n=$e(e,`detail`),r=e.severity;return t===null||n===null||!tt(r)?null:{code:t,severity:r,detail:n}}function rt(e){if(!Qe(e))return null;let t=$e(e,`trackId`),n=J(e,`deviceId`),r=$e(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=et(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$e(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function it(e){let t=rt(e);if(t===null||!Qe(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=nt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function at(e){if(!Qe(e))return null;let t=et(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=rt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function ot(e){if(!Qe(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=it(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var st={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function ct(e){return st[e]??e}var lt={error:0,warn:1,info:2};function ut(e){return e.toSorted((e,t)=>lt[e.severity]-lt[t.severity]||e.code.localeCompare(t.code))}function dt(e){return e.length===0?Ze:`${Ze}?deviceIds=${e.join(`,`)}`}function ft(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var pt=`all`,mt=`The server answered in a shape this build does not understand.`,ht={error:`danger`,warn:`warning`,info:`info`};function gt({findings:e}){return e.length===0?d(S,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:ut(e).map(e=>d(S,{variant:ht[e.severity],title:e.detail,children:ct(e.code)},e.code))})}function _t({track:e,report:t,cameraName:n,analyzing:i}){return r(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:n}),d(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),r(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,ft(e.durationMs)]}),e.active&&d(S,{variant:`default`,children:`still open`}),t!==void 0&&r(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),d(`div`,{className:`flex items-center gap-2`,children:t===void 0?d(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):d(gt,{findings:t.findings})}),d(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function vt(){let e=p(),[t,n]=u(pt),[i,s]=u(!1),[c,l]=u(null),f=m({}),h=a(()=>[{value:pt,label:`All cameras`},...(f.data??[]).map(e=>({value:String(e.id),label:e.name}))],[f.data]),g=a(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.name);return e},[f.data]),_=a(()=>t===pt?[]:[Number.parseInt(t,10)],[t]),v=o({queryKey:[`events-debug`,`list`,_],queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Ye,input:_.length===0?{}:{deviceIds:_}}))}),y=a(()=>(v.data?.tracks??[]).map(e=>e.trackId),[v.data]),b=o({queryKey:[`events-debug`,`analyze`,y],enabled:y.length>0,queryFn:async()=>ot(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Xe,input:{trackIds:y}}))}),S=a(()=>{let e=new Map;for(let t of b.data?.reports??[])e.set(t.trackId,t);return e},[b.data]),T=()=>{v.refetch(),b.refetch()},E=async()=>{s(!0),l(null);try{await Le(dt(_),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},O=v.data?.tracks??[],k=v.data===null||b.data===null;return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(w,{value:t,options:h,onChange:e=>n(e.target.value)})}),r(C,{variant:`secondary`,onClick:T,disabled:v.isFetching,children:[v.isFetching?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(C,{onClick:()=>void E(),disabled:i||O.length===0,children:[i?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(se,{className:`h-3.5 w-3.5`}),`Export all (`,String(O.length),`)`]})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,d(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),v.isError&&d(D,{message:`Could not load the marked tracks.`}),k&&!v.isError&&d(D,{message:mt}),c!==null&&d(D,{message:c}),v.data?.truncated===!0&&d(D,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(b.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(b.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),d(x,{children:v.isLoading?d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):O.length===0?r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Ve,{className:`h-5 w-5 text-foreground-subtle`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):O.map(e=>d(_t,{track:e,report:S.get(e.trackId),cameraName:g.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:b.isFetching},e.trackId))})]})})}function yt(e){return e.subLabel??e.label}var bt=720*60*60*1e3;function xt(e){let t=[];for(let n of e)t.push(...n);return t}function St(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ct(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function wt(e,t){return`${String(e)}:${t}`}function Tt(e,t){let n=new Map,r=new Set;for(let i of e){let e=wt(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Et(e,t){return{since:e.fromMs??t-bt,until:e.toMs??t}}var Y=typeof I==`function`,Dt=`Track deletion arrives with the next server update`;function Ot(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var kt=Y?I:Ot,At=200,jt=3e4;function Mt(e){let t=p(),n=c({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:jt,refetchInterval:jt,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:At,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:St(xt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var Nt=[`events-feed`],Pt=2e3;function Ft(n){let r=l(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,c]=u(!1),d=e(()=>{a.current.invalidateQueries({queryKey:Nt})},[]),p=t(void 0);p.current||=ve({delayMs:Pt,invalidate:()=>{o.current?c(!0):d()}}),f(()=>()=>p.current?.cancel(),[]),f(()=>{i||!s||(c(!1),d())},[i,s,d]);let m=e(()=>{c(!1),d()},[d]);return b(U.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),b(U.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function It({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ne(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||j(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,d(ke,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(be,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:l,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=M(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:d(i?ke:Ee,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:j(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=M(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:j(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lt(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zt=new Set([`detection`,`package`]);function Bt(e,t){return[...Lt(e,t).values()].filter(e=>e.parentKind===null&&zt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vt(e,t){let n=Lt(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();var Ht=1400,Ut=`Admin-gated URL — opens only inside an authenticated session`;function Wt({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ht);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(a?Pe:oe,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function Gt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(Wt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ut}`}),t&&d(Wt,{label:`Public`,value:t,title:`Copy public URL — ${Ut}`})]})}var Kt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function qt(e){return e in Kt}function Jt(e){return qt(e)?Kt[e]:e}function Yt(e,t){return`${e}${Re}/${encodeURIComponent(t)}`}n();var Xt=3e4;function Zt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(Qt,{onOrigin:i}):null}}function Qt({onOrigin:e}){let{data:t}=_({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d($t,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $t({addonId:e,onOrigin:t}){let{data:n}=L({addonId:e},{refetchInterval:Xt,retry:!1});return f(()=>{let e=n?ie.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var en=typeof g==`function`,tn=`Track flags arrive with the next server update`;function nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rn=en?g:nn;function an(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function on({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function sn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=rn(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!en||s.isPending,g=en?void 0:tn,_=n=>{h||(async()=>{try{let r=an(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;l(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(on,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(Ge,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(on,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Ve,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(on,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:d(Ce,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,cn=120,ln={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function un(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function dn(e,t,n){if(e.length===0||t===null)return ln;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ln;let a=un(e,n?.maxPoints??cn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}n();var fn=15e3;function pn(e){return`${Re}/${encodeURIComponent(e)}`}var mn=window.location.origin;function hn({mediaKey:e,label:t}){let{src:n,failed:r}=Ie(pn(e));return n===null?d(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?d(fe,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):d(K,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):d(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var gn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),_n=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function vn(e){let[t,n]=u(null);return f(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function yn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>d(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:d(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function bn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),h=kt(),g=t!==null,_=t?.deviceId??0,v=t?.trackId??``,b=t?.bestEventId??``,x=t?.timestamp??0,S=t?.windowMs??0,{data:w}=ee({deviceId:_,trackId:v},{enabled:g}),{data:T}=k({trackId:v,deviceId:_},{enabled:g}),{data:E}=A({eventId:b,deviceId:_},{enabled:g&&b!==``}),{data:D}=F({deviceId:_,since:x-fn,until:x+S+fn},{enabled:g}),[O,j]=u(null),[M,N]=u(!1),{publicOrigin:P,probes:I}=Zt(g);f(()=>{j(null)},[_,v]);let te=a(()=>{let e=T??[],t=E??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[T,E]),L=O??te,R=Ie(L?pn(L.key):void 0),z=a(()=>{let e=new Set,t=[];for(let n of[...E??[],...T??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[E,T]),ne=a(()=>z.find(e=>gn.has(e.kind))??null,[z]),B=vn(Ie(ne?pn(ne.key):void 0).src),V=a(()=>dn(w?.positions??[],B,{snapshots:(w?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[w?.positions,w?.snapshots,B]),H=e(e=>{let t=z.find(t=>t.key===e);t&&j(t)},[z]);if(t===null)return null;let U=R.src,ie=L?.kind,ae=ie!==void 0&&_n.has(ie)&&B!==null&&(w?.positions.length??0)>=2,W=D&&D.length>0?D[0]:null,oe=()=>{W&&(N(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:W.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{N(!1)}})())},se=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},ce=Math.round(t.importance*100),G=w?.importanceReason?`${String(ce)}% · ${w.importanceReason}`:`${String(ce)}%`,ue=w?.zonesVisited&&w.zonesVisited.length>0?w.zonesVisited.join(`, `):`—`,de=w?.audioLabels&&w.audioLabels.length>0?w.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,me=w?w.totalDistance.toFixed(2):`—`,ge=he(w?w.firstSeen:x),_e=w?he(w.lastSeen):`—`;return d(re,{open:!0,onOpenChange:e=>!e&&o(),children:r(y,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,yt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(t)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),d(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:d(Ae,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[U?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pe,{src:U,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ae?d(yn,{overlay:V,onPickSnapshot:H}):void 0})}):d(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:R.failed?r(s,{children:[d(fe,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(K,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:z.map(e=>{let t=Jt(e.kind),n=Yt(mn,e.key),i=P?Yt(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>j(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${he(e.timestamp)}`,children:d(hn,{mediaKey:e.key,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),d(Gt,{localUrl:n,publicUrl:i})]},e.key)})}),I,W&&r(C,{variant:`secondary`,onClick:oe,disabled:M,children:[M?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(De,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(sn,{deviceId:t.deviceId,trackId:t.trackId,...(w?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:w?.markForTrain??t.markForTrain},...(w?.debug??t.debug)===void 0?{}:{debug:w?.debug??t.debug},...(w?.favourited??t.favourited)===void 0?{}:{favourited:w?.favourited??t.favourited},onChange:l}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d($,{label:`Camera`,value:n}),d($,{label:`Class`,value:t.className}),d($,{label:`Label`,value:t.label??`—`}),d($,{label:`Sub-label`,value:t.subLabel??`—`}),d($,{label:`Importance`,value:G}),d($,{label:`Zones visited`,value:ue}),d($,{label:`Audio heard`,value:de}),d($,{label:`Total distance`,value:me}),d($,{label:`First seen`,value:ge}),d($,{label:`Last seen`,value:_e}),d($,{label:`Track`,value:t.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:i?void 0:Dt,children:r(C,{variant:`secondary`,onClick:se,disabled:!i||h.isPending,children:[h.isPending?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function xn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Sn({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s}){let c=Ie(e.bestEventId?`${Re}/${e.bestEventId}`:void 0),l=Math.round(e.importance*100),u=s===void 0?void 0:Math.round(s*100),f=xn(e.windowMs),p=()=>i(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[c.src?d(`img`,{src:c.src,alt:`Event from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:c.failed?`Key-event media unavailable`:`No key-event media`,children:d(fe,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(wt(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?d(xe,{className:`h-4 w-4 text-primary`}):d(Se,{className:`h-4 w-4`})}),u!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(u),`%`]}),l>0&&d(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(l)}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:d(Ge,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:d(Ve,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:d(Ce,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:p,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,yt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),f&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:f})]})]})]})}n();function Cn(){let[n,r]=u(!1),i=t(null),[a,o]=u(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return f(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var wn=[`events-feed`],Tn=60,En=[{value:`importance`,label:`Importance`,icon:Be},{value:`time`,label:`Recent`,icon:W}];function Dn(){let e=l(),[t,n]=u(_e),[i,o]=u(new Set),[c,p]=u(new Set),[h,g]=u(0),[_,v]=u(`time`),[y,b]=u(new Set),[x,S]=u(null),[w,T]=u(()=>Date.now());f(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>Et({fromMs:t.fromMs,toMs:t.toMs},w),[t.fromMs,t.toMs,w]),O=Cn(),{pending:k,refreshNow:A}=Ft({paused:x!==null||y.size>0||O.scrolledPast}),{data:j}=m({}),M=a(()=>(j??[]).filter(e=>e.type===ae.Camera),[j]),P=a(()=>M.map(e=>e.id),[M]),{data:F,isLoading:I}=N({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),ee=a(()=>Vt(F??[],i),[F,i]),te=kt(),L=te.isPending,{rows:R,isLoading:z}=Mt({deviceIds:P,since:E,until:D,minImportance:h>0?h:void 0,classFilter:c.size===1?[...c][0]:void 0}),ne=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),B=e=>ne.get(e)??`Camera #${String(e)}`,re=a(()=>G(R).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,ne]),V=a(()=>St(Ct(R,{cameras:i,classes:c,minImportance:h}),_),[R,i,c,h,_]),H=me(V,Tn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),h,_,E,D]),[i,c,h,_,E,D])),U=()=>{e.invalidateQueries({queryKey:wn})},ie=()=>b(new Set);function W(e){b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(y.size===0||!Y)return;let e=Tt(R,y),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>te.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{U();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(wt(o,e));else t.push(o)}),b(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>B(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let se=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(ge,{onChange:n}),d(de,{cameras:re,selected:i,onChange:o}),d(It,{groups:ee,selected:c,onChange:p,loading:I}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Min score`}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:h,onChange:e=>g(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(h*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:En.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>v(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${_===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(V.length)} of ${String(R.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),y.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[y.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:r(C,{variant:`secondary`,onClick:oe,disabled:!Y||L,children:[L?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(C,{variant:`ghost`,onClick:ie,disabled:L,children:d(Ae,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&d(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:A,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!z&&V.length>0&&r(s,{children:[d(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>d(Sn,{row:e,cameraName:B(e.deviceId),nowMs:w,selected:y.has(wt(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:S},wt(e.deviceId,e.trackId)))}),d(ce,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),x&&d(bn,{row:x,cameraName:B(x.deviceId),deleteAvailable:Y,onClose:()=>S(null),onDeleted:()=>{U(),S(null)},onFlagsChanged:e=>{S(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var On=50,kn=350,An=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function jn(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Mn({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[h,g]=u(null),_=P(t,kn).trim(),v=_.length>0;f(()=>{e(v)},[v,e]);let[y,b]=u(()=>Date.now());f(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x}=m({}),S=a(()=>(x??[]).filter(e=>e.type===ae.Camera),[x]),C=a(()=>{let e=new Map;for(let t of x??[])e.set(t.id,t.name);return e},[x]),w=e=>C.get(e)??`Camera #${String(e)}`,T=a(()=>S.map(e=>e.id),[S]),{data:D}=N({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),O=a(()=>Bt(D??[],new Set(l===null?[]:[l])),[D,l]);f(()=>{s!==null&&(O.some(e=>e.kind===s)||c(null))},[O,s]);let{data:k,isFetching:A,isError:M,error:F}=E({text:_,minScore:i,limit:On,classFilter:s??void 0,deviceId:l??void 0},{enabled:v}),I=a(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...jn(e),score:e.score})),[k]);function ee(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(be,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&d(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:d(Ae,{className:`h-3.5 w-3.5`})})]}),A&&v&&d(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:O.map(e=>d(`button`,{type:`button`,onClick:()=>ee(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:j(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Camera`}),r(`select`,{value:l===null?``:String(l),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[d(`option`,{value:``,children:`All`}),S.map(e=>d(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Match`}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:An.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),v&&!A&&!M&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[I.length,` match`,I.length===1?``:`es`]})]})]}),v&&r(`div`,{className:`space-y-3`,children:[M&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,F instanceof Error?F.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!M&&A&&I.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!M&&!A&&I.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,_,`”. Try a looser match threshold or a different phrasing.`]}),!M&&I.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:I.map(e=>d(Sn,{row:e,cameraName:w(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&d(bn,{row:h,cameraName:w(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>g(null)})]})}var Nn=15e3;function Pn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:Nn,refetchInterval:Nn,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}n();function Fn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function In({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Ie(i?`${Re}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?d(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(Ke,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Fn(n,e.becameStationaryAt)]})]})]})}function Ln(){let[e,t]=u(!1),n=Date.now(),{data:i}=m({}),o=a(()=>(i??[]).filter(e=>e.type===ae.Camera),[i]),s=a(()=>o.map(e=>e.id),[o]),c=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:l}=Pn(s);return l.length===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(e?ke:Ee,{className:`h-4 w-4 text-foreground-subtle`}),d(Ke,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:l.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:l.map(e=>d(In,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Rn(){let[e,t]=u(!1);return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[d(Mn,{onActiveChange:t}),!e&&d(Ln,{}),!e&&d(Dn,{})]})})}var zn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Bn=new Set(zn);function Vn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Bn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Hn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,d(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):d(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=Vn(e.label),l=Vn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[d(w,{className:`w-28`,value:e.macroClass,options:zn.map(e=>({value:e,label:e})),onChange:e=>{let t=zn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(w,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(S,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(C,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(Me,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(T,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(T,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&d(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&d(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Un(e){return e.every(e=>Vn(e.label)===null&&Vn(e.subLabel)===null&&Bn.has(e.macroClass))}function Wn(e){return e<0?0:e>1?1:e}function Gn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Kn(e,t,n){return{x:Wn((e-n.left)/n.width),y:Wn((t-n.top)/n.height)}}function qn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Jn(e){return e.w>=.01&&e.h>=.01}function Yn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function Xn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function Zn({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:l,onDraw:f}){let p=t(null),[m,h]=u({w:0,h:0}),[g,_]=u(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=Gn(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return Kn(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:qn(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:qn(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),Jn(e)?f(e):l(Xn(s.map(e=>e.bbox),g.start))},children:[d(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=Yn(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return d(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&d(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Yn(g.current,v)})]})}function Qn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function $n({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>d(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[d(Pe,{className:`h-3 w-3 text-success`}),d(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Qn(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[d(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(C,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(K,{className:`h-3 w-3 animate-spin`}):d(t===void 0?We:fe,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:Qn(e.sizeBytes)})]}),t!==void 0&&d(S,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function er(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var tr={untouched:{icon:Ue,label:`to do`,variant:`default`},started:{icon:He,label:`frames only`,variant:`info`},ready:{icon:Oe,label:`annotated`,variant:`success`}};function nr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function rr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):d(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=tr[er(e)],o=t.icon;return d(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[d(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),d(S,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,nr(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}n();var ir=`person`;function ar(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,g]=u(-1),[_,y]=u(new Map),[b,x]=u(null),w=m({projection:`slim`,isCamera:!0}),T=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),E=H({}),D=ne({trackId:t?.trackId??``},{enabled:t!==null}),k=O({trackId:t?.trackId??``},{enabled:t!==null}),A=te({frameId:i??``},{enabled:i!==null}),j=v(),M=z(),N=V(),P=B(),F=R(),I=h();f(()=>{if(i===null){l([]);return}l((k.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),g(-1)},[i,k.data]),f(()=>{let e=D.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[D.data,i]);let ee=e(e=>{n(e),o(null),l([]),y(new Map),x(null)},[]),L=e(async e=>{if(t===null)return;let n=await j.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(_);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);y(e)}n.copied.length>0&&o(n.copied[0].frameId),await D.refetch(),await E.refetch()},[t,j,_,D,E]),re=e(async e=>{t!==null&&(await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await D.refetch(),await k.refetch(),await E.refetch())},[t,M,i,D,k,E]),U=e(async e=>{if(t===null||i===null)return;x(null);let n=await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){x(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}l(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),x(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,N]),ie=e(e=>{l(t=>[...t,{bbox:e,macroClass:ir,kind:`subject`,source:`operator`}]),g(c.length)},[c.length]),ae=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),W=e(e=>{l(t=>t.filter((t,n)=>n!==e)),g(-1)},[]),oe=e(async()=>{t===null||i===null||(await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await k.refetch(),await E.refetch(),x(`Annotations saved.`))},[t,i,c,P,k,E]),se=e(async()=>{if(t===null)return;let e=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await E.refetch(),e.changed&&n(null)},[t,F,E]),ce=e(async()=>{if(t===null)return;let e=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await E.refetch()},[t,I,E]),G=A.data,le=Un(c)&&i!==null;return r(Fe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(C,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[d(we,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(C,{size:`sm`,onClick:()=>void se(),children:[d(Ge,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[b!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:b}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),d(S,{children:E.data?.length??0})]}),d(rr,{tracks:E.data??[],isLoading:E.isLoading,selectedTrackId:t?.trackId??null,deviceNames:T,onSelect:ee})]}),d(`section`,{className:`space-y-3 min-w-0`,children:t===null?d(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[d(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:d($n,{candidates:D.data?.candidates??[],copies:D.data?.copies??[],activeFrameId:i,refusals:_,isSelecting:j.isPending,onSelectCandidate:e=>void L(e),onOpenCopy:o,onRemoveCopy:e=>void re(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[d(`div`,{className:`rounded-md border border-border overflow-hidden`,children:G===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(Zn,{imageSrc:`data:image/jpeg;base64,${G.base64}`,imageWidth:G.width,imageHeight:G.height,boxes:c,selectedIndex:p,onSelect:g,onDraw:ie})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(C,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`objects`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(C,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`package`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Hn,{annotations:c,selectedIndex:p,onSelect:g,onChange:ae,onDelete:W})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),d(C,{size:`sm`,disabled:!le||P.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function or(){return d(`div`,{className:`flex flex-col p-4`,children:d(ze,{tabs:[{id:`feed`,label:`Feed`,icon:Te,content:d(Rn,{})},{id:`retrain`,label:`Retrain`,icon:Ge,content:d(ar,{})},{id:`debug`,label:`Debug`,icon:Ve,content:d(vt,{})}]})})}export{or as EventsPage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,W as r,b as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Kt as s,Rr as c,qt as l,un as u}from"./src-BO2615nJ.js";import{t as d}from"./refresh-cw-DLQxYBTF.js";import{t as f}from"./search-C1UMvnoJ.js";import{C as p,K as m,R as h,i as g,z as _}from"./index-CUen2nrR.js";var v=m(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]);function y({deviceId:e,mode:t}){let{data:r,isLoading:i,isFetching:a,isError:s,refetch:l}=c({deviceId:e},{enabled:Number.isFinite(e)}),u=r?.devices??[];return n(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[n(`div`,{className:`flex items-center justify-between mb-1.5`,children:[n(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,o(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:(r?.mode??t)===`auto`?`children + same location`:`children + manual list`})]}),n(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:a,onClick:()=>void l(),title:`Re-run the resolver`,children:[o(d,{className:`h-3 w-3 ${a?`animate-spin`:``}`}),`Refresh`]})]}),i?n(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[o(p,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?o(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):u.length===0?o(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):o(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>n(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full`,title:e.location??void 0,children:[o(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&n(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[o(v,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}function b(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function x(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=b(e);return n.every(e=>t.includes(e))})}function S(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function C(e){return e>=8}t();var w=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,T=`block text-[11px] font-medium text-foreground mb-1 break-words`,E=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function D({field:t,value:i,onChange:s,disabled:c,translationFn:l}){let d=Array.isArray(i)?i:[],p=c===!0||t.disabled===!0,m=t.maxItems!==void 0&&d.length>=t.maxItems,[v,y]=a(``),[b,C]=a(!1),[D,O]=a(0),k=e(null),A=e(null),{selectedOptions:j}=r(()=>S(t.options,d),[t.options,d]),M=r(()=>x(t.options,v),[t.options,v]),P=e=>{if(!p)if(d.includes(e))s(d.filter(t=>t!==e));else{if(t.maxItems!==void 0&&d.length>=t.maxItems)return;s([...d,e])}},F=e=>{if(e.key===`ArrowDown`)e.preventDefault(),C(!0),O(e=>M.length===0?0:(e+1)%M.length);else if(e.key===`ArrowUp`)e.preventDefault(),C(!0),O(e=>M.length===0?0:(e-1+M.length)%M.length);else if(e.key===`Enter`){e.preventDefault();let t=M[D];t&&P(t.value)}else e.key===`Escape`?C(!1):e.key===`Backspace`&&v===``&&d.length>0&&s(d.slice(0,-1))},I=N(t.label,l),L=N(t.description,l);return n(`div`,{className:`min-w-0`,children:[I!==void 0&&I!==``&&o(`label`,{className:T,children:I}),j.length>0&&o(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:j.map(e=>n(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[e.iconId!==void 0&&o(u,{iconId:e.iconId,size:12}),o(`span`,{className:`truncate`,children:e.label}),!p&&o(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>P(e.value),children:o(g,{className:`h-2.5 w-2.5`})})]},e.value))}),n(`div`,{className:w+(p?` opacity-50`:``),children:[o(f,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),o(`input`,{ref:k,type:`text`,role:`combobox`,"aria-expanded":b,"aria-controls":`msel-${t.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:v,placeholder:m?`Max ${t.maxItems} selected`:t.placeholder??`Search to add…`,disabled:p,onChange:e=>{y(e.target.value),C(!0),O(0)},onFocus:()=>C(!0),onBlur:()=>{A.current=setTimeout(()=>C(!1),120)},onKeyDown:F}),o(h,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),A.current&&clearTimeout(A.current),C(e=>!e),k.current?.focus()}})]}),b&&!p&&o(`div`,{id:`msel-${t.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:M.length===0?n(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,v,`”`]}):M.map((e,t)=>{let r=d.includes(e.value),i=!r&&m;return n(`button`,{type:`button`,role:`option`,"aria-selected":r,disabled:i,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===D?`bg-primary/10`:`hover:bg-surface-hover`,i?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>O(t),onClick:()=>P(e.value),children:[o(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,r?`border-primary bg-primary text-white`:`border-border`].join(` `),children:r&&o(_,{className:`h-2.5 w-2.5`})}),e.iconId!==void 0&&o(u,{iconId:e.iconId,size:13}),o(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),L&&o(`p`,{className:E,children:L})]})}t();var O=`_linkedDevicesMode`,k=`_linkedDeviceIds`;function A(e){return e.type===`multiselect`}function j({field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:c,allFields:u,onAction:d}){return A(e)&&C(e.options.length)?l(e,t,u)?o(D,{field:e,value:t[e.key],onChange:t=>n(e.key,t),disabled:r,translationFn:i}):null:o(s,{field:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:c,allFields:u,onAction:d})}function M(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function N(e,t){if(e!==void 0)return t&&M(e)?t(e):e}function P({section:e,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=a(e.defaultCollapsed??!1),_=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!l(r,t,e.fields),0)===0)return null;let v=e.fields.some(e=>`key`in e&&e.key===O),b=t[O]===`manual`?`manual`:`auto`,x=v&&b!==`manual`?e.fields.filter(e=>!(`key`in e&&e.key===k)):e.fields,S=v?1:e.columns??2,C=S===1?`grid-cols-1`:S===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:S===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,w=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0;return n(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(w!==void 0||!e.title&&!e.description)&&n(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[n(`div`,{children:[e.title&&o(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:N(e.title,u)}),e.description&&o(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:N(e.description,u)})]}),_&&o(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(w===void 0?n(i,{children:[o(`div`,{className:`grid ${C} gap-x-3 gap-y-2.5`,children:x.map(n=>o(j,{field:n,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,externalProbe:f?.[n.key],allFields:e.fields,onAction:p},n.key))}),v&&m!==void 0&&o(y,{deviceId:m,mode:b})]}):o(s,{field:w,values:t,onChange:r,disabled:c,translationFn:u,onTestField:d,externalProbe:f?.[w.key],allFields:e.fields,onAction:p},w.key))]})}function F({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:s,onClearProbe:c,onAction:l,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),c?.(e)};return o(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>o(P,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:s,onAction:l,deviceId:u},`${e.id}-${n}`))})}export{v as n,F as t};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-BDZbxeCH.js";import{$r as d,Br as f,Ci as p,Cr as m,Dr as h,Er as g,F as _,Fr as v,Gr as y,J as b,Mr as x,N as S,Sr as C,T as ee,Tr as w,Ur as T,Wt as E,_i as D,at as O,br as k,gi as A,gn as j,hi as M,jn as N,jr as P,jt as te,nt as ne,w as re,xi as F,xr as I,yi as L,yr as R}from"./src-BO2615nJ.js";import{mt as z}from"./src-BgxUlUk-.js";import{t as B}from"./ProviderIcon-BYY3__KP.js";import{t as ie}from"./circle-x-Bf5Kcelv.js";import{t as V}from"./FormBuilder-1r_2pkuu.js";import{t as H}from"./plus-DDGOU54V.js";import{i as ae,n as U,r as W,t as oe}from"./ScanNetworkModal-B8lG3NsX.js";import{t as se}from"./refresh-cw-DLQxYBTF.js";import{t as G}from"./rotate-cw-ClC0Tfzf.js";import{t as ce}from"./wifi-BUxK1DpB.js";import{A as le,C as K,I as q,J as ue,K as J,P as de,R as fe,W as pe,X as me,Y as he,i as ge,k as _e,m as ve,o as Y,p as ye,s as be,t as xe,z as Se}from"./index-CUen2nrR.js";var Ce=J(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function we(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...we(n.fields));return t}function Te(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...we(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function X(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...X(n.fields));return t}function Z(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Q(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Q(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Ee(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function De({open:t,integrationId:n,addonId:a,onClose:u}){let{t:f}=xe(),p=o(),[m,h]=s({}),[_,y]=s(!1),[x,S]=s(null),[C,ee]=s(Ee),w=T({addonId:a},{enabled:t}),E=w.data?.deviceType??null,D=v({addonId:a,type:E??z.Camera},{enabled:t&&w.isSuccess&&E!==null}),O=D.data??null;l(()=>{t&&(h(O?Q(O.sections.flatMap(e=>e.fields)):{}),ee(Ee()),y(!1),S(null))},[t,n,O]);let k=i(()=>({...m,_probeRequestId:C}),[m,C]),A=g({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=d(),M=e(async(e,t)=>{y(!0);let n=await j.mutateAsync({addonId:a,type:E??z.Camera,key:e,value:t,formValues:k});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Z(e[i])&&!Z(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,a,k,E]),{testAllStatus:N,hasProbeFields:P,probeResults:te,handleTestAll:ne,clearProbeResult:re}=Te(O??{sections:[]},m,M);async function F(e){S(null);try{await A.mutateAsync({addonId:a,type:E??z.Camera,config:m,integrationId:n}),e?h(O?Q(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=X((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>Z(m[e])),L=I.length===0,R=w.isLoading||E!==null&&D.isLoading,B=w.isError||w.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(K,{className:`h-5 w-5 animate-spin text-primary`})}):B?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(Y,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(V,{schema:O,values:m,onChange:h,onTestField:M,probeResults:te,onClearProbe:re})}),!B&&!R&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(ve,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),c(fe,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(b,{addonId:a,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!R&&(x||I.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!B&&P&&r(`button`,{type:`button`,onClick:ne,disabled:N===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[N===`testing`?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(ce,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:B||!L||A.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(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:B||!L||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Oe=1500;function ke({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=R(),s=(C({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Oe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(K,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(Y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(ie,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ae(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,je={id:$,label:`Devices`,isDefault:!0},Me=2e4,Ne=100;function Pe({addonId:n,integrationId:i,onClose:a}){let{t:o}=xe(),[u,d]=s(new Set),[f,p]=s(new Set),[h,g]=s(new Map),[v,y]=s(null),{data:b}=D(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,ee]=s(!0),T=k({addonId:n,integrationId:i}).data?.filters,E=T&&T.length>0?T:[je],[O,A]=s(E.find(e=>e.isDefault)?.id??(E.some(e=>e.id===$)?$:E[0].id)),j=O!==$,M=m(),N=I({addonId:n,integrationId:i,page:1,pageSize:Me,filter:O}),P=N.refetch,te=M.mutate,ne=e(()=>{te({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[te,n,i,P]),F=t(null);l(()=>{let e=`${n}::${i}`;F.current===e||N.isLoading||(F.current=e,(N.data?.candidates.length??0)===0&&ne())},[n,i,N.isLoading,N.data,ne]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ie=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=w(),[H,ae]=s(null),U=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),W=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=e((e,t)=>{g(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),se=e(e=>{let t={};for(let n of e){let e=h.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[h]),ce=e(async()=>{y(null);let e=[...u];if(e.length!==0)try{let t=se(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:C}:{}});ae(r),d(new Set),g(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[u,se,V,n,i,O,x,C]),le=t(null),q=e(()=>{H===null||le.current===H||(le.current=H,P())},[H,P]),ue=e(e=>{A(e),d(new Set),p(new Set),g(new Map),y(null)},[]),J=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:C,onChange:e=>ee(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ge,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??ie??z)&&B.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??ie??z})]})]})}),E.length>1&&c(Fe,{filters:E,activeFilter:O,onSelect:ue}),c(`div`,{className:`flex-1 min-h-0`,children:c(re,{mode:`generic`,items:B,pageSize:Ne,getKey:e=>e.childNativeId,getSearchText:Ae,getFilterType:e=>e.type,filterOptions:S(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&B.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??ie??z)&&B.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:ne,disabled:L,title:o(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(G,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ie,{candidate:e,expandable:!j,expanded:f.has(e.childNativeId),onToggleExpand:()=>W(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=_(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>U(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(Se,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&f.has(e.childNativeId),renderExpanded:j?void 0:e=>c(Le,{candidate:e,hiddenChildIds:h.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>oe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),H!==null&&c(ke,{addonId:n,integrationId:i,jobId:H,onFinished:q}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ce,disabled:J===0||V.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[V.isPending&&c(K,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),J>0?` (${J})`:``]})]})]})]})]})}function Fe({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ie({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?fe:q,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Le({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?le:_e,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Re(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Re(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function ze(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Re(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Be(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ve({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=o(),{data:h,isLoading:g}=L({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=j({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Be(v):null,[v]),x=F(),S=t=>{x.mutate({id:e,settings:t},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ge,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(W,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(U,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:ze(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>S(e),onBack:f}):c(E,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}n();function He(){let{t}=xe(),{integrationId:n}=he(),d=o(),m=ue(),[g,_]=me(),v=u(),[S,C]=s(!1),[w,T]=s(!1),[E,k]=s(!1),[F,I]=s(!1),[L,R]=s(!1),{data:z,isLoading:ie}=A({id:n??``},{enabled:!!n}),{data:V}=j({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:U,isSuccess:W}=D(),G=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,z?.addonId,W]),{data:ce}=P({}),le=i(()=>(ce?.providers??[]).some(e=>e.addonId===z?.addonId),[ce,z?.addonId]),q=G!==null,J=z?.info?.fixed===!0,de=q?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),fe=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,z?.addonId,W]),_e=i(()=>{let e=z?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,z?.addonId,W]),Se=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,z?.addonId,W]);l(()=>{g.get(`add`)===`1`&&q&&(C(!0),_(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[g,q,_]);let we=V!=null&&Array.isArray(V.sections)&&V.sections.some(e=>e.fields.length>0),{data:Te}=f({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=p({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=M({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),I(!1),m(`/integrations`)}}),Ee=N({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=y({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=h({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=x({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Te??[],[Te]),je=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=e(e=>je.get(e)??null,[je]),Ne=e(e=>c(B,{type:e,size:`sm`}),[]),Fe=e(e=>m(`/devices/${String(e)}`),[m]),Ie=i(()=>{let e=z?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,z?.addonId]),Le=i(()=>ee(Ie).length,[Ie]);return ie?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(O,{items:[{label:`Integrations`,onClick:()=>m(`/integrations`)},{label:z.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:`/api/addon-assets/${z.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[le&&r(`button`,{onClick:()=>T(!0),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 network for devices (incl. a different subnet)`,children:[c(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!J&&r(`button`,{onClick:()=>C(!0),disabled:!q,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:de,children:[c(H,{className:`h-3.5 w-3.5`}),de]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(te,{checked:z.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Z.isPending&&c(K,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(we||G===`device-adoption`)&&r(`button`,{onClick:()=>k(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(ye,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>R(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(ve,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ne,{label:`Restart`,icon:se,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:z.addonId})}),!J&&r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),c(re,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:z.addonId,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Fe,batchActions:{remove:Oe.mutate,disable:ke.mutate,enable:Ae.mutate},...J?{}:{onDeleteDevice:e=>Oe.mutate({deviceId:e.id})}}),S&&n&&G===`device-adoption`&&c(Pe,{addonId:z.addonId,integrationId:n,onClose:()=>C(!1)}),S&&n&&G===`device-provider`&&c(De,{open:S,integrationId:n,addonId:z.addonId,onClose:()=>C(!1)}),w&&z&&c(oe,{open:w,scope:{addonId:z.addonId,label:z.name},onClose:()=>T(!1)}),E&&n&&G!==null&&Se!==null&&c(Ve,{integrationId:n,addonId:z.addonId,name:z.name,kind:G,mode:Se,brokerKind:fe,canTest:_e,trpc:v.trpcClient,onClose:()=>k(!1)}),L&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(ve,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:z.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[z.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>R(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(b,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),F&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&I(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(Y,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:z.name,count:Le})})]})]}),Q.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>I(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?r(a,{children:[c(K,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(be,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ce,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>m(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{He as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BDZbxeCH.js";import{Br as u,T as d,_i as f,bi as p,en as m,gn as ee,i as h,kr as g,mi as te,vr as ne,w as _}from"./src-BO2615nJ.js";import{t as v}from"./ProviderIcon-BYY3__KP.js";import{t as y}from"./plus-DDGOU54V.js";import{i as b,n as re,r as x,t as S}from"./ScanNetworkModal-B8lG3NsX.js";import{t as C}from"./refresh-cw-DLQxYBTF.js";import{C as ie,I as w,J as T,R as E,V as D,X as O,i as k,p as A,t as j,v as M,z as N}from"./index-CUen2nrR.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BEgRNMRl.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=j(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let m=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:m.length>0?i(`integrations.foundDevices`,{count:m.length}):i(`integrations.noDevicesFound`)}),m.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:m.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>p(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(N,{className:`h-3 w-3 text-primary-foreground`})}),s(D,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`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.skip`)}),m.length>0&&n(`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:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=j(),a=T(),{data:o,isLoading:c}=f();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},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:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(ie,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(w,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(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 z=2e4;function se({open:e,onClose:t}){let{t:l}=j(),u=T(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[S,C]=o(null),[w,E]=o(``),[D,O]=o(null),[A,M]=o(null),[N,ae]=o(!1),{data:P}=ee({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),se=r(()=>P?oe(P):null,[P]),B=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let H=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(h(e),ae(s),b(n),E(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:e.name,settings:e.config});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function K(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:w,settings:{brokerId:e}});O(t.id),v(t.id),q(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:m,candidate:e,...D===null?{}:{integrationId:D}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),C(null),E(``),O(null),M(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?m:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,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:s(k,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&m&&s(re,{addonId:m,configSchema:se??null,canTest:N,onSave:G,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(x,{kind:S,onResolved:e=>{K(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(L,{providerId:_,onImport:le,onSkip:q})]}),X&&n(`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:[s(ie,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`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:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(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:s(t?E:w,{className:`h-3.5 w-3.5`})}),s(v,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{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=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=j(),a=T(),c=l(),[f]=O(),[ee,g]=o(!1),te=e(()=>g(!0),[]),ne=e(()=>g(!1),[]),[re,x]=o(!1),ie=e(()=>x(!0),[]),w=e(()=>x(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:D,refetch:k}=p(void 0),{data:A,isLoading:N,refetch:P}=u({}),F=r(()=>A??[],[A]),I=r(()=>E??[],[E]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of d(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=f.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,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`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(v,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(_,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{k(),P()},[k,P]),Q=D||N,ue=I.length>0;return n(ae,{icon:M,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:Z,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:s(C,{className:m(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:ie,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:[s(b,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:te,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(y,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(_,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:ee,onClose:ne}),s(S,{open:re,onClose:w})]})}export{U as IntegrationsPage};
@@ -1,2 +0,0 @@
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{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d}from"./player-overlays-BDZbxeCH.js";import{Jt as f,S as p,rn as m}from"./src-BO2615nJ.js";import{t as h}from"./circle-check-big-B8rnDG8h.js";import{t as g}from"./copy-B4N78LE2.js";import{t as _}from"./key-round-B46YLw7m.js";import{t as v}from"./pencil-BQJAwzya.js";import{C as y,F as b,S as x,k as S,r as C,s as w,u as T,w as E,x as D}from"./index-CUen2nrR.js";import{t as O}from"./AdminPage-CCD07UMs.js";n();function k({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{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`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}n();var A={view:{icon:S,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:w,cls:`bg-danger/15 text-danger`}};function j(){let{user:e,logout:t}=C();if(!e)return l(O,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(O,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`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()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`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:[l(E,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`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.`})]})]}),l(M,{}),l(P,{username:e.username}),l(F,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`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:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?p(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=A[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`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:[l(D,{className:`h-3 w-3`}),`Sign out`]})})]})}function M(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=i.length>0&&o.length>0&&i!==o,v=i.length>0&&i.length<8,S=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(N,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l(N,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l(N,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(g||v)&&l(`div`,{className:`text-[11px] text-danger`,children:g?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(h,{className:`h-3 w-3`}):l(b,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!S||m.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:[m.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(x,{className:`h-3 w-3`}),`Update password`]})})]})]})}function N({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,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`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function P({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[_,v]=s(``),[x,S]=s(null),[C,w]=s(!1),E=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),v(``),S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!C)return;let e=setTimeout(()=>w(!1),1500);return()=>clearTimeout(e)},[C]);let A=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(T,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&r(o,{children:[l(`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.`}),l(`div`,{className:`flex justify-end`,children:r(`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?l(y,{className:`h-3 w-3 animate-spin`}):l(T,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(k,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>w(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[C?l(h,{className:`h-3 w-3 text-emerald-500`}):l(g,{className:`h-3 w-3`}),C?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`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&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`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?l(y,{className:`h-3 w-3 animate-spin`}):l(h,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&f&&r(o,{children:[r(`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:[l(h,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),x&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{S(null),O.mutate()},disabled:O.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:[O.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(T,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function F(){return m(`auth-webauthn/passkey-enrollment`)?l(f,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{j as MyAccessPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BDZbxeCH.js";import{Ai as u,Bi as d,Di as f,Dn as p,En as m,Fi as h,Ft as g,Hi as _,Ii as v,It as y,Ji as b,Li as x,Lt as S,Mi as ee,Mt as C,Ni as w,Oi as te,Pi as ne,Ri as re,Ui as T,Vi as E,Wi as ie,Yi as ae,Yt as oe,et as D,hs as O,ji as se,ki as ce,nt as k,qi as A,zi as j}from"./src-BO2615nJ.js";import{at as M,et as N}from"./src-BgxUlUk-.js";import{t as P}from"./boxes-6foKhsHw.js";import{t as F}from"./copy-B4N78LE2.js";import{t as I}from"./play-DoOoBM0P.js";import{t as le}from"./refresh-cw-DLQxYBTF.js";import{t as ue}from"./rotate-ccw-wXYD6bC7.js";import{t as L}from"./server-ZhEvwONi.js";import{t as R}from"./shield-4rMaNiMB.js";import{t as z}from"./square-ookqWTBx.js";import{t as B}from"./wifi-BUxK1DpB.js";import{C as V,E as H,K as U,S as W,i as de,j as G,l as fe,o as K,x as pe,y as q,z as me}from"./index-CUen2nrR.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-CX9dEC2O.js";import{t as _e}from"./NodeAddonsSettingsPanel-ptvTM4Ri.js";import{t as J}from"./AddonCollectionPage-BeuyrbPU.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var ve=U(`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`}]]),ye=U(`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`}]]),be=U(`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`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=p({capName:`network-access`},{refetchInterval:X}),n=m(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),h=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},g=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},_=b({onSuccess:h,onError:g}),v=ae({onSuccess:h,onError:g});return s(J,{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:H,itemIcon:H,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,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=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),_.mutate({addonId:e})},onStop:e=>{u(e),v.mutate({addonId:e})}})})}function Ce(e){let{data:t}=A({addonId:e},{refetchInterval:X,retry:!1}),n=t?M.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`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&&n(`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:[s(G,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(S,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(V,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`}),`Stop`]}):n(S,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(V,{className:`h-3 w-3 animate-spin`}):s(I,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=p({capName:`turn-provider`},{refetchInterval:Ee}),t=m(void 0,{refetchInterval:Ee}),i=O(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:q,itemIcon:q,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(S,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`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&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=O({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:q,wifi:B,docker:P,vpn:W,loopback:L,other:L},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??L,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`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&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`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&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`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:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`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))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=ee(void 0,{refetchInterval:3e4}),u=f(void 0),d=v({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=ne({onSuccess:t=>{y(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=r(()=>i.data?.interfaces??[],[i.data]),h=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}),[_,y]=o([]),[b,w]=o(!1);c(()=>{!b&&u.data&&(y(u.data.addresses),w(!0))},[u.data,b]);let T=u.data?.addresses??[],E=r(()=>{if(_.length!==T.length)return!0;let e=[..._].toSorted(),t=[...T].toSorted();return e.some((e,n)=>e!==t[n])},[_,T]),ie=()=>{d.mutate({addresses:[..._]})},ae=()=>{y(T)},oe=()=>{y([])},O=()=>{i.refetch(),h.refetch(),u.refetch(),A.refetch(),M.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ce(),j=x({onSuccess:()=>void A.refetch()}),M=se(),N=re({onSuccess:()=>void M.refetch()}),P=h.data?.endpoints??[],F=A.data?.baseUrl??null,I=A.data?.resolved??null,L=M.data?.baseUrls??[],R=L.length===0,z=F===null,B=e=>R?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:L.includes(e.baseUrl),V=e=>F===null?I===e.baseUrl:F===e.baseUrl,H=e=>{if(!Z(e))return;let t=R?P.filter(e=>Z(e)&&B(e)).map(e=>e.baseUrl):[...L],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];N.mutate({baseUrls:n})},U=e=>{if(Fe(e)){if(V(e)){z||j.mutate({baseUrl:null});return}j.mutate({baseUrl:e.baseUrl})}},W=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,R?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(C,{checked:t&&B(e),disabled:!t||N.isPending,onChange:()=>H(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(C,{checked:t&&V(e),disabled:!t||j.isPending,onChange:()=>U(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[R,z,L,F,I,N.isPending,j.isPending,P]);return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(S,{size:`sm`,variant:`secondary`,onClick:O,disabled:i.isLoading,children:[s(le,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(S,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:_.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${_.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(S,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(fe,{className:`h-3 w-3`}),p.isPending?`Detecting…`:`Best match`]}),n(S,{size:`sm`,variant:`secondary`,onClick:oe,disabled:_.length===0||d.isPending,children:[s(ue,{className:`h-3 w-3`}),`Clear`]}),E&&s(S,{size:`sm`,variant:`secondary`,onClick:ae,disabled:d.isPending,children:`Discard`}),n(S,{size:`sm`,variant:`primary`,onClick:ie,disabled:!E||d.isPending,children:[s(ye,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:m,value:_,onChange:y,disabled:d.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!R&&s(S,{size:`sm`,variant:`secondary`,disabled:N.isPending,onClick:()=>N.mutate({baseUrls:[]}),children:`Viewer → auto`}),!z&&s(S,{size:`sm`,variant:`secondary`,disabled:j.isPending,onClick:()=>j.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),z&&I===null&&s(`p`,{className:`px-4 pt-3 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.`}),s(D,{columns:W,rows:P,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:h.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=p({capName:`mesh-network`},{refetchInterval:Q}),t=m(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:P,itemIcon:q,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(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=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=d({addonId:e},{refetchInterval:Q,retry:!1}),r=t?N.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`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&&n(`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 He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),p=l(),{status:m}=$(t),h=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),g=ie(),_=E({onSuccess:h}),v=T({onSuccess:h}),y=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?N.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:m.joined?n(i,{children:[n(S,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(S,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]}):c?n(S,{size:`sm`,variant:`ghost`,onClick:b,children:[s(de,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(S,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(S,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=_({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(oe,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(H,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`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:[s(G,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`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?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(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 Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(y,{variant:`info`,children:`self`}),e.exitNodeOption&&s(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(y,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(V,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(D,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(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 Ye(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 Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=u(void 0,{refetchInterval:15e3}),r=w({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=h({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=j({onSuccess:()=>{f(!1),m(``),v(``),b(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[d,f]=o(!1),[p,m]=o(``),[_,v]=o(``),[y,b]=o(``),x=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},ee=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(R,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:ee})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(k,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(S,{size:`sm`,variant:`outline`,onClick:()=>f(e=>!e),children:`Upload`}),l?.caCertPem&&s(S,{size:`sm`,variant:`outline`,onClick:x,children:`Download CA`}),l?.mode===`uploaded`&&s(k,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),d&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:_,onChange:e=>v(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(S,{size:`sm`,disabled:!p.trim()||!_.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:_,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:B,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:L,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:H,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:P,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:q,content:s(Oe,{})}]})})}export{$e as NetworkPage};