@camstack/addon-admin-ui 1.2.495 → 1.2.496
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{AddonAssetIcon-CFX3RwXW.js → AddonAssetIcon-DIGI0J-I.js} +1 -1
- package/dist/assets/{Addons-DpVH9nAf.js → Addons-BXBVaw0C.js} +1 -1
- package/dist/assets/{AdminPage-BJaaesfk.js → AdminPage-rM4C_UeK.js} +1 -1
- package/dist/assets/{AdminSectionedPage-CNjLEAGW.js → AdminSectionedPage-hs_sRKSH.js} +1 -1
- package/dist/assets/{AiProfiles-BJRJ5zJK.js → AiProfiles-FyDOlZrB.js} +1 -1
- package/dist/assets/BrokerEditorDialog-CpjjEowc.js +1 -0
- package/dist/assets/{Build-3M_d0_rj.js → Build-BHWi77ox.js} +1 -1
- package/dist/assets/{Calendars-DxftJ_an.js → Calendars-DpfM0tWi.js} +1 -1
- package/dist/assets/{Cluster-HHqJRHI1.js → Cluster-CGbK_RcF.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-DXfPsKQ0.js → CompositionBlockEditor-C-oGyTOT.js} +1 -1
- package/dist/assets/{CompositionEditorPage-D9VfeM5q.js → CompositionEditorPage--pC-fQTK.js} +1 -1
- package/dist/assets/{Data-4tIzvoZk.js → Data-5YjPSX0u.js} +1 -1
- package/dist/assets/{DeviceDetail-DSCDR1Cp.js → DeviceDetail-MgYrZi-H.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-B8m61VBx.js → DeviceDoActionFields-C8dC5weu.js} +1 -1
- package/dist/assets/{Devices-DMgEOarQ.js → Devices-BDxPWKee.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-kdaZaPUi.js → EmbedPlayerPage-CXfoZEoy.js} +1 -1
- package/dist/assets/{HelperWizard-CrfZ5Vv0.js → HelperWizard-DPb6SH1D.js} +1 -1
- package/dist/assets/{History-BOBC6XKv.js → History-CgY-ADwx.js} +1 -1
- package/dist/assets/{Identity-CKhLFZy8.js → Identity-CngM910j.js} +1 -1
- package/dist/assets/{IntegrationDetail-CwztjSvz.js → IntegrationDetail-tLO3mmbA.js} +1 -1
- package/dist/assets/{IntegrationHub-BnLIS74H.js → IntegrationHub-M6BlF8kI.js} +1 -1
- package/dist/assets/{Integrations-BjjqLgHB.js → Integrations-CEbaKS2K.js} +1 -1
- package/dist/assets/{Integrations-D9JKfDPr.js → Integrations-lFHvSwS1.js} +1 -1
- package/dist/assets/{Library-CIoEX1yM.js → Library-owv8dCJn.js} +1 -1
- package/dist/assets/{Locations-CeULSBbP.js → Locations-CIbPLu6Y.js} +1 -1
- package/dist/assets/{Logs-DqMDFyDI.js → Logs-BkVwtIoJ.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-5TYDYckS.js → MaskShapeCanvas-BdJHOhru.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BnEAkRqe.js → MotionZonesSettings-eigY1-yb.js} +1 -1
- package/dist/assets/{MyAccess-C9ZlQjl7.js → MyAccess-kMqHvFdO.js} +1 -1
- package/dist/assets/{Network-DWsy6sps.js → Network-DNgds3SY.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BWoo8ZpJ.js → NodeAddonsSettingsPanel-BTLr6xzq.js} +1 -1
- package/dist/assets/{Notifications-D45pUZf1.js → Notifications-3HA167No.js} +1 -1
- package/dist/assets/{Pipeline-DtXlNNOZ.js → Pipeline-Duxnzw0u.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CozNRgQC.js → PrivacyMaskSettings-DQxuAo8I.js} +1 -1
- package/dist/assets/{Recordings-C7QC3Pxj.js → Recordings-DNM6KFbT.js} +1 -1
- package/dist/assets/{ScanNetworkModal-Bq6Sr4qL.js → ScanNetworkModal-DGxeTl6N.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DtTzOArV.js → SceneMonitorEditor-D7lPRwkb.js} +1 -1
- package/dist/assets/{SessionsList-BHjPSf3H.js → SessionsList-v1GWS7lS.js} +1 -1
- package/dist/assets/{Showroom-33b_lNAT.js → Showroom-BQjG5SEZ.js} +1 -1
- package/dist/assets/{System-8xlWQY0F.js → System-1vAVXVvO.js} +1 -1
- package/dist/assets/{Terminal-DxLUTA7D.js → Terminal-CAeZSUkp.js} +1 -1
- package/dist/assets/{Viewer-BeUf0fdC.js → Viewer-CoaaY2ah.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BopscExo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dt6nbTOI.js} +1 -1
- package/dist/assets/{addon-icons-context-DGXC9vor.js → addon-icons-context-B-CR3D5Y.js} +1 -1
- package/dist/assets/{archive-CvXjfAJ5.js → archive-Caq0fiUd.js} +1 -1
- package/dist/assets/{assignment-candidates-YyTJV_56.js → assignment-candidates-oUf0MmfV.js} +1 -1
- package/dist/assets/{authed-media-LqwyDFYD.js → authed-media-rsowuJD_.js} +1 -1
- package/dist/assets/{bell-off-DQjR_xqX.js → bell-off-7NO0NCk5.js} +1 -1
- package/dist/assets/{board-model-DHqTtLge.js → board-model-CXoBU-My.js} +1 -1
- package/dist/assets/{boxes-g1SWI3TC.js → boxes-CfX2DaXN.js} +1 -1
- package/dist/assets/circle-slash-CNw3qaX5.js +1 -0
- package/dist/assets/client-UkFHArbd.js +648 -0
- package/dist/assets/{cloud-upload-BsaCZZve.js → cloud-upload-Bha3MQZ0.js} +1 -1
- package/dist/assets/crop-KD442bNz.js +1 -0
- package/dist/assets/{device-integration-icon-B4EhX_LL.js → device-integration-icon-Ca6J7BrE.js} +1 -1
- package/dist/assets/device-picker-model-C0bjqXeS.js +1 -0
- package/dist/assets/{dist-C-xa27xq.js → dist-Bm86l9VH.js} +1 -1
- package/dist/assets/dist-Db-bCS6Y.js +648 -0
- package/dist/assets/{eraser-Cayo_0zK.js → eraser-DcRrD8r0.js} +1 -1
- package/dist/assets/{format-BA7Kq5Xz.js → format-B-Mz_Gp5.js} +1 -1
- package/dist/assets/{hard-drive-download-DDQriCJk.js → hard-drive-download-Ds3LLqZ_.js} +1 -1
- package/dist/assets/{hostInit-CzNFxC77.js → hostInit-CLJxS8C0.js} +1 -1
- package/dist/assets/i18n-Dodsa0QQ.js +1 -0
- package/dist/assets/{icons-BPbbdJnj.js → icons-CxLU2kUU.js} +1 -1
- package/dist/assets/{index-5eo6U8kw.js → index-DAYRmkvA.js} +3 -3
- package/dist/assets/{key-BSu0zrWB.js → key-CPCN1bXO.js} +1 -1
- package/dist/assets/{key-round-DvMZJgfp.js → key-round-DSSlw3bb.js} +1 -1
- package/dist/assets/{layers-DF_k6hWC.js → layers-Au38YP9x.js} +1 -1
- package/dist/assets/{linked-devices-model-C-5bW2__.js → linked-devices-model-CAcKgihZ.js} +1 -1
- package/dist/assets/{list-ordered-BY9cDz4x.js → list-ordered-BcEAxRcq.js} +1 -1
- package/dist/assets/{location-owned-usage-FBzPOvfn.js → location-owned-usage-DC8YfZHt.js} +1 -1
- package/dist/assets/{log-in-S_8y8Jt7.js → log-in-BIF-VHyB.js} +1 -1
- package/dist/assets/{memory-stick-N7YG8WDr.js → memory-stick-dd2TtD8X.js} +1 -1
- package/dist/assets/{message-square-plus-B6OMDBFd.js → message-square-plus--EqwnnsY.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-05b5b10f.js → mf-entry-bootstrap-0-d8302735.js} +2 -2
- package/dist/assets/{mic-off-wSLIBpcb.js → mic-off-C4AEP_LS.js} +1 -1
- package/dist/assets/{monitor-off-BPkjr8Kb.js → monitor-off-BMFLRGf9.js} +1 -1
- package/dist/assets/{monitor-smartphone-BaKbWsBX.js → monitor-smartphone-BKJ1_LnF.js} +1 -1
- package/dist/assets/mount-C0bjqXeS.js +1 -0
- package/dist/assets/{player-overlays-BpkVlGCk.js → player-overlays-DVETFMIk.js} +1 -1
- package/dist/assets/{recycle-BpmmXPs6.js → recycle-BayFw4ej.js} +1 -1
- package/dist/assets/remoteEntry-BkQqqD-X.js +1 -0
- package/dist/assets/{scan-eye-Cu1C2mB8.js → scan-eye-BrzMkZIm.js} +1 -1
- package/dist/assets/{scissors-CfgqlM1P.js → scissors-Cdea5FpP.js} +1 -1
- package/dist/assets/{search-x-D03g42iG.js → search-x-D5U75yFR.js} +1 -1
- package/dist/assets/{send-Ct8Iyrnk.js → send-DdLpBXJo.js} +1 -1
- package/dist/assets/{settings-2-DcFFzE15.js → settings-2-E7MRkJ8L.js} +1 -1
- package/dist/assets/{sigma-BBZ6UUbV.js → sigma-DQ448qdQ.js} +1 -1
- package/dist/assets/{speaker-B0avnbSb.js → speaker-8vDFm1aL.js} +1 -1
- package/dist/assets/src-CJMN3ac7.js +67 -0
- package/dist/assets/{step-inspector-model-DSf88Gyc.js → step-inspector-model-DrrErQ-Z.js} +1 -1
- package/dist/assets/{table-2-DMA3aZl4.js → table-2-BWAe4fOI.js} +1 -1
- package/dist/assets/{timer-reset-Bbx4AGN0.js → timer-reset-BlrgM8RC.js} +1 -1
- package/dist/assets/{ungroup-BQn6cqqW.js → ungroup-D9nsaCkT.js} +1 -1
- package/dist/assets/{unlink-4NHoJGD6.js → unlink-BZggCuRp.js} +1 -1
- package/dist/assets/{usb-7LyYlbOn.js → usb-CnowURs8.js} +1 -1
- package/dist/assets/{use-scenes-feed-BMxBsO4L.js → use-scenes-feed-CKTWN5k9.js} +1 -1
- package/dist/assets/{use-stationary-objects-vMMZk1OF.js → use-stationary-objects-CFZh0JGL.js} +1 -1
- package/dist/assets/useEventInvalidation-C0bjqXeS.js +1 -0
- package/dist/assets/{useNodeUrlSelection-D50tuj4_.js → useNodeUrlSelection-CPhmr6x9.js} +1 -1
- package/dist/assets/user-round-DX7v4O3o.js +1 -0
- package/dist/assets/{user-x-BjoN1Vho.js → user-x-S0MRC6zp.js} +1 -1
- package/dist/assets/{video-1DOXNRH4.js → video-oLlCkBIP.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DBgm9Tfr.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Ddnry646.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +649 -71
- package/package.json +1 -1
- package/dist/assets/BrokerEditorDialog-DfJWCNWC.js +0 -1
- package/dist/assets/circle-slash-Be75TgNF.js +0 -1
- package/dist/assets/client-Boy4MYN9.js +0 -358
- package/dist/assets/crop-ChAbNHDL.js +0 -1
- package/dist/assets/device-picker-model-DgqPui1o.js +0 -1
- package/dist/assets/dist-CoizE_WQ.js +0 -358
- package/dist/assets/i18n-BKbDJexS.js +0 -1
- package/dist/assets/mount-DgqPui1o.js +0 -1
- package/dist/assets/remoteEntry-TI8zrKEx.js +0 -1
- package/dist/assets/src-B1DsO1Ze.js +0 -67
- package/dist/assets/useEventInvalidation-DgqPui1o.js +0 -1
- package/dist/assets/user-round-Dk_iTJlv.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.496] - 2026-10-27
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- The broker sign-in panel shows the sign-in link, says to open it from the hub's network, and warns when this page cannot reach it
|
|
15
|
+
|
|
10
16
|
## [1.2.495] - 2026-10-27
|
|
11
17
|
|
|
12
18
|
### Fixed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,Y as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{n as r}from"./addon-icons-context-
|
|
1
|
+
import{S as e,Y as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{n as r}from"./addon-icons-context-B-CR3D5Y.js";n();var i={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function a({addonId:n,fallback:a,tileClassName:o,size:s=`md`}){let[c,l]=t(!1),u=r(n),d=i[s];return e(`div`,{className:`${d.tile} flex items-center justify-center shrink-0 ${o}`,children:c||!u?e(a,{className:d.fallback,"aria-hidden":!0}):e(`img`,{src:u,alt:``,className:`${d.img} bg-white ring-1 ring-black/5`,onError:()=>l(!0)})})}export{a as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as d,En as f,Ht as p,Oi as m,Pt as h,Q as g,Wn as _,Xr as v,di as y,fr as b,gn as x,gt as S,jn as C,ot as w,sn as T,st as ee,vn as E,wi as te,yi as ne,yn as re,zt as ie}from"./player-overlays-
|
|
1
|
+
import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as d,En as f,Ht as p,Oi as m,Pt as h,Q as g,Wn as _,Xr as v,di as y,fr as b,gn as x,gt as S,jn as C,ot as w,sn as T,st as ee,vn as E,wi as te,yi as ne,yn as re,zt as ie}from"./player-overlays-DVETFMIk.js";import{no as D}from"./client-UkFHArbd.js";import{i as O,l as k}from"./video-oLlCkBIP.js";import{$t as ae,Ai as A,Bi as oe,Bn as j,Ci as M,Di as N,Dt as se,Fi as P,Ii as ce,Ni as F,Oi as I,Pi as le,Ri as L,Rn as R,Si as z,Ti as ue,Vn as B,Yr as V,_r as de,ad as fe,bi as pe,dr as me,ed as he,en as ge,fr as _e,gi as ve,gr as ye,hr as be,ji as xe,ki as H,ni as U,oc as W,pr as Se,vi as G,vt as Ce,wd as we,wi as Te,xd as Ee,xi as De,yi as Oe,zi as ke,zn as K}from"./src-CJMN3ac7.js";import{t as q}from"./useTranslation-BJr-n0es.js";import"./mount-C0bjqXeS.js";import{gr as Ae,mr as J,ur as Y}from"./index-DAYRmkvA.js";import{t as X}from"./AdminPage-rM4C_UeK.js";import{t as Z}from"./NodeAddonsSettingsPanel-BTLr6xzq.js";import{n as Q,t as je}from"./useNodeUrlSelection-CPhmr6x9.js";function Me(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Ne={queued:{icon:y,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:b,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:f,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:m,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:O,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Pe({item:e}){let{t:n}=q(),r=Ne[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Fe=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),Ie=new Set([`done`,`failed`,`skipped`]);function Le(e){return!Ie.has(e.phase)&&!Fe.has(e.jobState)}function Re(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Fe.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function ze(){let{data:e}=I({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=we(D.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return Re([...n.values()],Date.now())},[e,t])}var Be={queued:{icon:y,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:b,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:b,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:b,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:b,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:b,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:b,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:m,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:O,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:T,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function Ve({progress:e}){let{t:n}=q(),r=Be[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function He(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function Ue(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function We(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(Ue)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
|
|
2
2
|
`)}function Ge(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
|
|
3
3
|
`)}var Ke={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function qe(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${Ke[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
|
|
4
4
|
`)}var Je={},Ye=3e4,Xe=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function Ze({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=q(),c=l(),u=ee(),d=w(),f=N(Je,{staleTime:Ye}),m=f.data?.installations??[],h=(f.data?.unreachable??[]).map(e=>e.nodeId),g=He(m,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),v=ke({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:qe(e,_),variant:e.success?`default`:`danger`})},b=async t=>{try{await y(await v.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:Ge(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(r.isHub?{}:{nodeId:r.id})},S=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=He(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:We(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},C=v.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:C,className:Xe,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(p,{className:`h-3 w-3`}),v.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||i===!0||h.length>0)&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:C,className:Xe,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(k,{className:`h-3 w-3`}),g.length>0?s(`addons.uninstallControls.everywhereCount`,{count:g.length}):s(`addons.uninstallControls.everywhere`)]})]})}function Qe(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function $e(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!Qe(e))}function et(e){return e.length-$e(e,!1).length}c();function tt({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:d}=q(),f=r===`upload`||r===`local`,[p,g]=s(!1),{data:_,isLoading:y,isError:x}=M({name:e}),C=_?$e(_,p):[],w=_?et(_):0;return t(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:d(`addons.versionPicker.versions`,`Versions`)}),a(`button`,{type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(S,{className:`h-3 w-3`})})]}),f&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(h,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:d(`addons.versionPicker.inPlace`,{kind:r===`upload`?d(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):d(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Y,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),y&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(b,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),x&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:d(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),C.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:C.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:d(`common.current`)}),e.distTags.map(e=>a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),Qe(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:d(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(`button`,{type:`button`,"aria-label":d(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,o?a(m,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a(`button`,{type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?d(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):d(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(v,{className:`h-3 w-3`})})]},e.version)})}),!y&&!x&&_&&_.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),w>0&&a(V,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>g(e=>!e),children:p?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:w})})]})}c();var nt=`device-export`;function rt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===nt)}function it(e){return e!==`local`&&e!==`upload`}function at({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=r&&i?g(`/api/addon-assets/${r}/${i}`):null,p=!!f&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:p?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?_:C,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),it(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:a(h,{className:`h-2.5 w-2.5 text-white`})})]})}function ot({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:f}=q();if(i)return t(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[a(b,{className:`h-3 w-3 animate-spin`}),f(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:f(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(v,{className:`h-3 w-3`}),f(`addons.addonCard.update`,`Update`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":f(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:f(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(d,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,o===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:f(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(d,{className:`h-3 w-3 opacity-50`})]}),u]})}function st({addonId:e}){let t=l(),{data:n=`inherit`}=Oe({addonId:e}),r=P({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var ct={id:`hub`,name:`Hub`,isHub:!0};function lt({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,onUpdate:c,isUpdating:p,jobProgress:m,bundle:h,bulkItem:g,disabledByBulk:v,isSystem:y,selectedNode:b}){let{t:C}=q(),[w,T]=s(!1),[ee,E]=s(!1),[ne,ie]=s(null);o(()=>{ie(null)},[i]);let D=ne??i,[k,A]=s(!1),[oe,j]=s(!1),[M,N]=s(`logs`),P=l(),ce=J(),{manifest:I}=e,le=!h&&!I.protected&&I.removable!==!1,L=!!h,R=h?.displayName??I.name,z=h?.packageName??I.packageName,ue=h?.version??I.packageVersion??I.version,B=h?.installSource??e.installSource,fe=h?h.bundle?.description??h.addons[0]?.manifest.description:I.description,pe=xe({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),he=Te({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),ve=F({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),H=e.health,U=H?.phase===`failed`&&!H.inGracePeriod,W=U&&H?.nextRetryAt&&!H.retrying,G=Me(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${U?`border-red-500/50`:`border-border`}`,children:[U&&H&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(O,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:C(`addons.addonCard.failedToLoad`,{attempt:H.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:H.lastError?.message??C(`addons.addonCard.unknownError`,`Unknown error`)}),W&&H.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:C(`addons.addonCard.autoRetryAt`,{time:new Date(H.nextRetryAt).toLocaleTimeString()})})]}),t(`button`,{type:`button`,disabled:ve.isPending||H.retrying,onClick:e=>{e.stopPropagation(),ve.mutate({packageName:z})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:C(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(f,{className:`h-3 w-3 ${ve.isPending||H.retrying?`animate-spin`:``}`}),C(`addons.addonCard.retryNow`,`Retry now`)]})]}),G!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(O,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:C(`addons.addonCard.processProblem.${G.kind}`)}),G.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:G.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(at,{isBundle:L||!!I.components&&I.components.length>1,installSource:B,addonId:L?h.addons[0]?.manifest.id:I.id,iconPath:L?h.bundle?.icon??h.addons[0]?.manifest.icon:I.icon,color:L?h.addons[0]?.manifest.color:I.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:R}),!r&&a(ot,{version:ue,availableUpdate:i,...D===void 0?{}:{selectedVersion:D},isUpdating:p,installSource:B,disabled:v,...c&&D!==void 0?{onUpdate:()=>c(D)}:{},onOpenPicker:()=>E(e=>!e),children:ee&&a(tt,{packageName:z,currentVersion:ue,...B?{installSource:B}:{},...i!==void 0&&D!==void 0?{selectedVersion:D,onSelect:e=>{ie(e),E(!1)}}:{},onInstall:e=>{E(!1),he.mutate({packageName:z,version:e})},onClose:()=>E(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[z!==R&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:z}),L&&t(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[a(_,{className:`h-3 w-3`}),h.addons.length]}),y&&t(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:C(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(f,{className:`h-3 w-3`}),C(`addons.addonCard.system`,`System`)]}),g!=null&&a(Pe,{item:g}),m!=null&&a(Ve,{progress:m})]}),fe&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:fe}),!L&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?C(`addons.addonCard.forked`):C(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:G===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!L&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),pe.mutate({addonId:I.id})},disabled:pe.isPending||v,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[a(f,{className:`h-3 w-3 ${pe.isPending?`animate-spin`:``}`}),C(`addons.addonCard.restart`,`Restart`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${k?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(re,{className:`h-3 w-3`}),C(`addons.addonCard.logs`,`Logs`)]}),!L&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${oe?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(x,{className:`h-3 w-3`}),C(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),le&&a(Ze,{packageName:I.packageName,displayName:I.name,selectedNode:b??ct,disabled:v})]}),n&&n.nodes.length>1&&!L&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:C(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:C(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:C(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:C(`common.synced`)})]},e.nodeId))})]}),k&&!L&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(`button`,{type:`button`,onClick:()=>N(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:C(`addons.addonCard.logs`,`Logs`)}),a(`button`,{type:`button`,onClick:()=>N(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:C(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(S,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&a(ge,{addonId:I.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&a(ae,{addonId:I.id,category:`addon.*`,maxHeight:`max-h-64`})]}),L&&t(u,{children:[a(`button`,{type:`button`,onClick:()=>T(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(w?te:d,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),w&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:h.addons.map(e=>a(lt,{addon:e,hideVersion:!0},e.manifest.id))})]}),oe&&!L&&a(me,{open:!0,onOpenChange:e=>!e&&j(!1),children:t(Se,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(ye,{children:t(de,{className:`flex items-center gap-2`,children:[a(x,{className:`h-4 w-4 text-primary`}),C(`addons.addonCard.settingsTitle`,{name:R})]})}),t(_e,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:C(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Z,{nodeId:null,addonIds:[I.id],level:`global`,fieldScope:`cluster`,emptyMessage:C(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),rt(I)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.deviceExport`,`Device export`)}),a(se,{addonId:I.id,onOpenDevice:e=>ce(`/devices/${e}`)})]}),it(B)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(st,{addonId:I.id})]}),I.components&&I.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.components`,{count:I.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:I.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(be,{children:a(V,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:C(`common.close`,`Close`)})})]})})]})}c();var ut=`.tgz,.tar.gz,.zip`;function dt({onUploadSuccess:e}){let{t:r}=q(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(g(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(`input`,{ref:l,type:`file`,accept:ut,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(`button`,{type:`button`,onClick:()=>l.current?.click(),disabled:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[o?a(b,{className:`w-3.5 h-3.5 animate-spin`}):a(h,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var ft=/```[^\n]*\n([\s\S]*?)```/g;function pt(e){let t=[],n=0;for(let r of e.matchAll(ft)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function mt(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function ht(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?mt(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function gt(e,t){let n=e.split(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{_t as n}from"./src-
|
|
1
|
+
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{_t as n}from"./src-CJMN3ac7.js";function r({icon:r,title:i,subtitle:a,actions:o,nav:s,embedded:c=!1,children:l}){return c?e(t,{children:l}):e(n,{icon:r,title:i,subtitle:a,actions:o,nav:s,children:l})}export{r as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{ht as r}from"./src-
|
|
1
|
+
import{R as e,S as t,et as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{ht as r}from"./src-CJMN3ac7.js";import{gr as i}from"./index-DAYRmkvA.js";n();function a({paramName:n=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(n),f=o.some(e=>e.id===d)?d??u:u,p=e((e,t)=>{l(r=>{let i=new URLSearchParams(r);for(let e of t)i.delete(e);return i.set(n,e),i},{replace:!0})},[n,l]);return t(r,{...s,paramName:n,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,t as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as d,En as f,Fn as p,G as m,Ht as h,L as g,Li as _,Ni as v,Pn as y,Pr as b,Q as x,Ri as S,Vn as C,Xr as w,_n as T,ai as E,dt as D,fr as O,gt as ee,na as k,ni as A,rn as j,st as M,tn as N,vn as P}from"./player-overlays-BpkVlGCk.js";import{$a as te,Br as F,zr as I}from"./client-Boy4MYN9.js";import{n as L,t as ne}from"./send-Ct8Iyrnk.js";import{t as R}from"./message-square-plus-B6OMDBFd.js";import{Cn as z,Dr as B,Er as V,Fr as re,Hn as H,Or as U,Qn as ie,Sn as W,Tr as G,Wn as ae,Yr as K,_o as oe,ad as q,bn as J,bt as Y,ed as se,ft as ce,mt as le,ni as X,od as ue,or as de,rt as fe,xt as pe}from"./src-B1DsO1Ze.js";import{t as Z}from"./i18n-BKbDJexS.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-DgqPui1o.js";import{S as me,gr as he}from"./index-5eo6U8kw.js";import{t as ge}from"./AdminSectionedPage-CNjLEAGW.js";import{t as _e}from"./AdminPage-BJaaesfk.js";c();var ve=`__redacted__`,ye=[`llm`,`listProfiles`],be=[`llm`,`listProfileKinds`],xe=[`llm`,`getDefaults`],Se=[`llm`,`listRuntimeNodes`],Ce=[`llm`,`listModelCatalog`],we=[`llm`,`getUsage`],Te=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],Ee=new Map([[`cloud`,E],[`plug`,y],[`cpu`,A],[`server`,T],[`sparkles`,j]]);function De(e){return Ee.get(e)??S}function Oe(e){return typeof e==`string`&&e.length>0?e:void 0}function ke(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 Ae(e){return e===!0}function je(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 Me={deviceNotEligible:{key:`ai.appleNotEligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,tone:`danger`}};function Ne(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:Z.t(`ai.appleUnknown`),detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:Z.t(`ai.appleAvailable`),detail:Z.t(n.imageInput?`helpers.aiPage.appleDetailImages`:`helpers.aiPage.appleDetailText`,{version:n.osVersion}),tone:`success`};case`unavailable`:{let t=Me[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:Z.t(t.key),detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:Z.t(`ai.appleNotMac`),detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Pe={ready:`success`,downloading:`info`,starting:`info`,stopped:`danger`,crashed:`danger`,failed:`danger`};function Fe(e){return e.reachable?e.status===void 0?`success`:Pe[e.status.state]:`danger`}function Ie(e){if(!e.reachable)return[];let t=[],n=e.apple;if(n?.state===`available`)t.push({id:`apple`,labelKey:`ai.featureApple`,tone:`success`,detail:Ne(e).detail}),n.imageInput&&t.push({id:`apple-images`,labelKey:`ai.featureAppleImages`,tone:`success`,detail:null});else if(n?.state===`unavailable`){let n=Ne(e);t.push({id:`apple`,labelKey:`ai.featureApple`,tone:n.tone,detail:n.labelDefault})}let r=e.status?.vramBytes;return r!==void 0&&r>0&&t.push({id:`gpu`,labelKey:`ai.featureGpu`,tone:`info`,detail:null}),t}function Le(){return{temperature:[{type:`slider`,key:`temperature`,label:Z.t(`helpers.aiProfileForm.temperature`),min:0,max:2,step:.1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`,description:Z.t(`helpers.aiProfileForm.temperatureHint`)}],topP:[{type:`slider`,key:`topP`,label:Z.t(`helpers.aiProfileForm.topP`),min:0,max:1,step:.05,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`}],topK:[{type:`number`,key:`topK`,label:Z.t(`helpers.aiProfileForm.topK`),min:1}],maxTokens:[{type:`number`,key:`maxTokens`,label:Z.t(`helpers.aiProfileForm.maxTokens`),min:1}],contextLength:[{type:`number`,key:`contextLength`,label:Z.t(`helpers.aiProfileForm.contextLength`),min:512,unit:`tokens`,description:Z.t(`helpers.aiProfileForm.contextLengthHint`)}],systemPrompt:[{type:`textarea`,key:`systemPrompt`,label:Z.t(`helpers.aiProfileForm.systemPrompt`),rows:4,maxLength:4e3,span:2,description:Z.t(`helpers.aiProfileForm.systemPromptHint`)}],timeoutMs:[{type:`number`,key:`timeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutTotal`),min:1e3,default:F.totalMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutTotalHint`)}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutConnect`),min:500,default:F.connectMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutConnectHint`)}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutFirstToken`),min:1e3,default:F.firstTokenMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutFirstTokenHint`)}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutIdle`),min:1e3,default:F.idleMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutIdleHint`)}],retry:[{type:`boolean`,key:`retryEnabled`,label:Z.t(`helpers.aiProfileForm.retry`),description:Z.t(`helpers.aiProfileForm.retryHint`)},{type:`number`,key:`retryMaxAttempts`,label:Z.t(`helpers.aiProfileForm.retryMaxAttempts`),min:1,max:5,default:1,showWhen:{field:`retryEnabled`,equals:!0}}],toolsEnabled:[{type:`boolean`,key:`toolsEnabled`,label:Z.t(`helpers.aiProfileForm.toolsEnabled`),description:Z.t(`helpers.aiProfileForm.toolsEnabledHint`)}]}}var Re=[`temperature`,`topP`,`topK`,`maxTokens`,`contextLength`,`systemPrompt`],ze=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function Be(e,t){let n=Le();return t.filter(t=>e.includes(t)).flatMap(e=>n[e])}function Ve(e){let t=Be(e,Re);return t.length===0?null:{sections:[{id:`generation`,title:Z.t(`helpers.aiProfileForm.generation`),fields:t}]}}function He(e){let t=Be(e,ze);return t.length===0?null:{sections:[{id:`bounds`,title:Z.t(`helpers.aiProfileForm.bounds`),fields:t}]}}function Ue(e){return e===null?{}:{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}}function We(e,t){return{...e.features,...t?.features}}function Ge(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function Ke(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?ke(i[e])??t:n??t,o=e=>r.includes(e)?ke(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`systemPrompt`)?Oe(i.systemPrompt):t?.systemPrompt;return{id:t?.id??crypto.randomUUID(),name:n.name,kind:e.kind,addonId:e.addonId.length>0?e.addonId:`ai`,enabled:t?.enabled??!0,model:n.model,supportsVision:n.supportsVision,timeoutMs:a(`timeoutMs`,F.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,F.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,F.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,F.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:Ae(i.retryEnabled),maxAttempts:ke(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?Ae(i.toolsEnabled):t?.toolsEnabled??!1,...s===void 0?{}:{temperature:s},...c===void 0?{}:{topP:c},...l===void 0?{}:{topK:l},...u===void 0?{}:{maxTokens:u},...d===void 0?{}:{contextLength:d},...f===void 0?{}:{systemPrompt:f},providerConfig:n.providerConfig}}var qe=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function Je(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Ye({nodeId:t,value:r,onChange:a}){let{t:c}=Q(),u=D(),[d,f]=o(``),[p,m]=o(null),[h,g]=o(!1),_=s({queryKey:Ce,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),v=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:t})}),y=l({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{m(e),g(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),b=l({mutationFn:e=>u.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{g(!0),v.refetch()}}),x=s({queryKey:Se,enabled:b.isPending,refetchInterval:b.isPending?qe:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,S=n(()=>{let e=(_.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(v.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:$(e.sizeBytes),node:t})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[_.data,v.data,p,t,c]),C=e=>{if(e===``){a(null);return}if(e===`custom`){if(p?.ok!==!0)return;a({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=_.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=v.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},T=e=>{d.trim()!==``&&y.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(pe,{label:c(`ai.model`,`Model`),required:!0,children:i(se,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:Je(r),options:S,onChange:e=>C(e.target.value)})}),i(pe,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`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.`),children:e(`div`,{className:`flex gap-2`,children:[i(q,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:d,onChange:e=>f(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),T())}}),e(K,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||y.isPending,onClick:()=>T(),children:[y.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(P,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),y.isError&&i(G,{message:y.error instanceof Error?y.error.message:c(`common.error`,`Error`)}),p?.ok===!1&&i(G,{message:p.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>i(K,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),y.mutate({ref:t})},children:e},e)),p.requiredBytes!==void 0&&i(K,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>T(p.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]})}),p?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),i(X,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),i(X,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(K,{size:`sm`,type:`button`,disabled:b.isPending||h,onClick:()=>b.mutate(p.model),children:[b.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),h?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),x!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:x.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:x.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:x.file,index:x.fileIndex,count:x.fileCount,done:$(x.downloadedBytes),total:x.totalBytes===void 0?``:` / ${$(x.totalBytes)}`})})]}),b.isError&&i(G,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)})]})]})}function Xe({value:t,onChange:n}){let{t:r}=Q(),a=D(),o=s({queryKey:Se,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(O,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=Ne(a),s=o.nodeId===t;return e(`button`,{type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(X,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}function Ze(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Qe({providerConfig:e,onProviderConfigChange:t}){return i(Xe,{value:Ze(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function $e({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=I.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Ye,{nodeId:Ze(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var et=new Map([[`ai/apple-node`,Qe],[`ai/managed-model`,$e]]);function tt(e){return et.get(e)??null}c();function nt({kind:e,className:t}){return i(De(e.icon),{className:t,"aria-hidden":!0})}function rt({kinds:e,onPick:t,onCancel:r}){let{t:a}=Q(),o=n(()=>je(e),[e]),s=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return i(le,{open:!0,onClose:r,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:i(Y,{emptyMessage:a(`ai.noKinds`,`No AI provider is installed.`),onPick:e=>{let n=s.get(e);n!==void 0&&t(n)},groups:o.map(e=>({id:e.addonId,label:e.addonId,tiles:e.kinds.map(t=>({key:`${e.addonId}:${t.kind}`,label:t.label,testId:`ai-kind-${t.kind}`,icon:i(nt,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function it(e){return(e?.sections??[]).flatMap(e=>e.fields)}function at(...e){let t={};for(let n of e)for(let e of it(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function ot(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function st(e,t){return it(e).filter(e=>`required`in e&&e.required===!0&&!ot(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var ct={auth:{key:`ai.listAuth`,fallback:`Credentials refused`},network:{key:`ai.listNetwork`,fallback:`Endpoint unreachable`},unsupported:{key:`ai.listUnsupported`,fallback:`No model list`},invalid:{key:`ai.listInvalid`,fallback:`Connection incomplete`}};function lt(e,t){if(t!==null)return{id:t.model,supportsVision:t.supportsVision};let n=e.modelCatalog===`static`&&e.staticModels?.length===1?e.staticModels?.[0]:void 0;return{id:n?.id??``,supportsVision:We(e,n).vision}}function ut({kind:t,existing:r,onSave:a,onCancel:s,onChangeKind:c,saving:p,error:m}){let{t:h}=Q(),_=D(),[v,y]=o(r?.name??t.label),[b,x]=o(()=>r===null?at(t.connectionSchema,t.advancedSchema):{...r.providerConfig}),[S,C]=o(()=>Ue(r)),[w,T]=o(()=>lt(t,r)),[E,ee]=o(!1),A=t.providerWidgets??[],j=A.filter(e=>e.placement===`connection`),M=A.find(e=>e.placement===`model`)??null,N=n(()=>[...te(t.connectionSchema)].some(e=>r?.providerConfig[e]===ve),[r,t.connectionSchema]),P=l({mutationFn:()=>_.trpcClient.llm.listModels.mutate({addonId:t.addonId,kind:t.kind,connection:b,...r===null?{}:{profileId:r.id}}),onSuccess:e=>{e.ok&&T(n=>{let r=e.models.find(e=>e.id===n.id);return r===void 0?n:{id:n.id,supportsVision:We(t,r).vision}})}}),F=Ge(t,P.data?.ok===!0?P.data.models:null),I=F.find(e=>e.id===w.id),L=We(t,I),ne=Ve(t.profileFields),R=He(t.profileFields),z=st(t.connectionSchema,b),B=A.some(e=>(e.requires??[]).some(e=>!ot(b[e]))),V=t.modelCatalog===`fetch`&&M===null,re=it(t.connectionSchema).length>0||j.length>0,U=e=>{T({id:e,supportsVision:We(t,F.find(t=>t.id===e)).vision})},W=p||v.trim()===``||w.id.trim()===``||z.length>0||B,ae=()=>{a(Ke(t,r,{name:v.trim(),model:w.id.trim(),supportsVision:t.visionEditable?w.supportsVision:!1,common:S,providerConfig:b}))},oe=r===null?h(`ai.newProfile`,`New {{kind}} profile`,{kind:t.label}):h(`ai.editProfile`,`Edit {{name}}`,{name:r.name}),Y=e=>{let n=tt(e);return n===null?i(G,{variant:`warning`,message:h(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})}):i(n,{descriptor:t,providerConfig:b,onProviderConfigChange:x,model:w,onModelChange:T},e)};return i(le,{open:!0,onClose:s,title:oe,error:m,width:`lg`,testId:`ai-profile-editor`,footer:e(u,{children:[z.length>0&&i(X,{variant:`warning`,children:h(`ai.missingRequired`,`required: {{fields}}`,{fields:z.join(`, `)})}),z.length===0&&B&&i(X,{variant:`warning`,children:h(`ai.completeProvider`,`complete the provider settings`)}),z.length===0&&!B&&w.id.trim()===``&&i(X,{variant:`warning`,children:h(`ai.pickModelFirst`,`pick a model`)}),e(K,{size:`sm`,type:`button`,disabled:W,onClick:ae,children:[p&&i(O,{className:`h-3.5 w-3.5 animate-spin`}),r===null?h(`ai.createProfile`,`Create profile`):h(`ai.saveChanges`,`Save changes`)]})]}),children:e(`div`,{className:g,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[i(nt,{kind:t,className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-xs font-medium text-foreground`,children:t.label}),i(X,{variant:`neutral`,children:t.addonId}),c!==void 0&&e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:c,children:[i(k,{className:`h-3.5 w-3.5`}),h(`ai.changeKind`,`Change type`)]})]}),i(pe,{label:h(`ai.name`,`Name`),required:!0,children:i(q,{id:`ai-profile-name`,"aria-label":h(`ai.name`,`Name`),value:v,onChange:e=>y(e.target.value),placeholder:t.label})}),re&&i(J,{headingId:`ai-editor-connection`,title:h(`ai.sectionConnection`,`Connection`),actions:V?e(K,{size:`sm`,variant:`secondary`,type:`button`,disabled:P.isPending,onClick:()=>P.mutate(),"data-testid":`ai-verify-models`,children:[P.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(f,{className:`h-3.5 w-3.5`}),h(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[it(t.connectionSchema).length>0&&i(de,{bare:!0,schema:t.connectionSchema,values:b,onChange:x}),j.map(e=>Y(e.id)),N&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:h(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),P.data?.ok===!0&&i(X,{variant:`success`,"data-testid":`ai-models-found`,children:h(`ai.modelsFound`,`{{count}} models found`,{count:P.data.models.length})}),P.data?.ok===!1&&i(G,{title:h(ct[P.data.code]?.key??`ai.listNetwork`,ct[P.data.code]?.fallback??`Endpoint unreachable`),message:P.data.message}),P.isError&&i(G,{message:P.error instanceof Error?P.error.message:h(`common.error`,`Error`)})]})}),i(J,{headingId:`ai-editor-model`,title:h(`ai.sectionModel`,`Model`),children:e(`div`,{className:`${d} space-y-3`,children:[M===null?e(u,{children:[F.length>0&&i(se,{id:`ai-model-pick`,"aria-label":h(`ai.selectModel`,`Select a model…`),value:I===void 0?``:I.id,options:[{value:``,label:h(`ai.selectModel`,`Select a model…`)},...F.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&U(e.target.value)}}),i(pe,{label:h(`ai.customModel`,`Model id`),description:h(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:i(q,{id:`ai-model-id`,"aria-label":h(`ai.customModel`,`Model id`),value:w.id,onChange:e=>T({...w,id:e.target.value}),placeholder:F[0]?.id??`model-id`})})]}):Y(M.id),e(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(w.supportsVision||!t.visionEditable&&L.vision)&&i(X,{variant:`info`,children:h(`ai.featureVision`,`vision`)}),L.tools&&i(X,{variant:`neutral`,children:h(`ai.featureTools`,`tools`)}),L.streaming&&i(X,{variant:`neutral`,children:h(`ai.featureStreaming`,`streaming`)})]}),t.visionEditable&&i(pe,{orientation:`horizontal`,label:h(`ai.supportsVision`,`Supports vision`),description:h(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:i(H,{checked:w.supportsVision,onCheckedChange:e=>T({...w,supportsVision:e}),"aria-label":h(`ai.supportsVision`,`Supports vision`)})})]})}),ne!==null&&i(J,{headingId:`ai-editor-generation`,title:h(`ai.sectionGeneration`,`Generation`),children:i(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:i(de,{bare:!0,schema:ne,values:S,onChange:C})})}),(R!==null||t.advancedSchema!==void 0)&&i(ie,{expanded:E,onExpandedChange:ee,header:i(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:h(`ai.sectionAdvanced`,`Advanced`)}),children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[R!==null&&i(de,{bare:!0,schema:R,values:S,onChange:C}),t.advancedSchema!==void 0&&i(de,{bare:!0,schema:t.advancedSchema,values:b,onChange:x})]})})]})})}c();function dt(t){return[{key:`name`,header:t.t(`ai.colProfile`,`Profile`),render:n=>{let r=t.kindByName.get(n.kind);return e(`span`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:r?.label??n.kind,children:r===void 0?i(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):i(nt,{kind:r,className:`h-4 w-4 text-foreground-subtle`})}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block truncate font-medium text-foreground`,children:n.name}),t.testResult?.id===n.id&&i(`span`,{className:`block truncate ${t.testResult.ok?`text-success`:`text-danger`}`,children:t.testResult.text})]})]})}},{key:`kind`,header:t.t(`ai.colKind`,`Kind`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground-muted`,children:t.kindByName.get(e.kind)?.label??e.kind})},{key:`model`,header:t.t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.model})},{key:`vision`,header:t.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:e=>e.supportsVision?i(X,{variant:`info`,style:`outline`,children:t.t(`ai.vision`,`vision`)}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`node`,header:t.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>typeof e.providerConfig.nodeId==`string`?i(X,{variant:`default`,children:e.providerConfig.nodeId}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`enabled`,header:t.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:e=>i(H,{checked:e.enabled,onCheckedChange:()=>t.onToggle(e),"aria-label":Z.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:e.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[i(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest(n),"aria-label":t.t(`ai.test`,`Test`),title:t.t(`ai.test`,`Test`),children:t.testingId===n.id?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(ne,{className:`h-3.5 w-3.5`})}),i(K,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t.kindByName.has(n.kind),onClick:()=>t.onEdit(n),"aria-label":t.t(`common.edit`,`Edit`),title:t.t(`common.edit`,`Edit`),children:i(C,{className:`h-3.5 w-3.5`})}),i(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(n),"aria-label":t.t(`common.delete`,`Delete`),title:t.t(`common.delete`,`Delete`),children:i(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function ft(){let{t}=Q(),c=D(),{state:u,openEdit:f,close:p}=ce(),m=M(),[h,_]=o(null),[v,y]=o(null),[b,x]=o(null),S=s({queryKey:ye,queryFn:()=>c.trpcClient.llm.listProfiles.query({})}),C=s({queryKey:be,queryFn:async()=>(await c.trpcClient.llm.listProfileKinds.query({})).map(({connectionSchema:e,advancedSchema:t,...n})=>({...n,connectionSchema:e,...t===void 0?{}:{advancedSchema:t}}))}),w=()=>{S.refetch()},T=r(()=>{_(null),x(null),p()},[p]);a(()=>{u.mode===`closed`&&_(null)},[u.mode]);let E=l({mutationFn:e=>c.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{T(),w()},onError:e=>x(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),O=l({mutationFn:e=>c.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),ee=l({mutationFn:e=>c.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>y({id:t.id,ok:e.ok,text:e.ok?Z.t(`system.aiProfilesTab.testOk`,{text:e.text,tokens:e.usage.outputTokens,ms:e.latencyMs}):`${e.code}: ${e.message}`})}),k=S.data??[],A=n(()=>C.data??[],[C.data]),N=n(()=>{let e=new Map;for(let t of A)e.set(t.kind,t);return e},[A]),P=u.mode===`edit`?k.find(e=>e.id===u.id)??null:null,te=P===null?null:N.get(P.kind)??null,F=u.mode===`new`&&h===null,I=u.mode===`new`?h:te,L=u.mode===`edit`?P:null,ne=I!==null&&(u.mode===`new`||L!==null),R=async e=>{await m({title:t(`ai.deleteProfileTitle`,`Delete profile?`),message:t(`ai.deleteProfileMessage`,`Delete "{{name}}". Features that name it will no longer get an answer from it.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&O.mutate(e)};return e(`div`,{className:g,children:[i(pt,{profiles:k}),i(J,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:S.isPending?e(`div`,{className:`${d} space-y-2`,"data-testid":`ai-profiles-loading`,children:[i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`})]}):S.isError?i(`div`,{className:d,children:i(G,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:t(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):k.length===0?i(V,{icon:j,title:t(`ai.noProfilesTitle`,`No AI profiles yet`),description:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):i(W,{columns:dt({kindByName:N,testResult:v,testingId:ee.isPending?ee.variables?.id??null:null,t,onToggle:e=>E.mutate({...e,enabled:!e.enabled}),onTest:e=>ee.mutate(e),onEdit:e=>{N.has(e.kind)&&(x(null),_(null),f(e.id))},onDelete:e=>void R(e)}),rows:k,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:z})}),F&&i(rt,{kinds:A,onCancel:T,onPick:e=>{x(null),_(e)}}),ne&&I!==null&&i(ut,{kind:I,existing:L,saving:E.isPending,error:b,onSave:e=>E.mutate(e),onCancel:T,...u.mode===`new`?{onChangeKind:()=>{x(null),_(null)}}:{}})]})}function pt({profiles:t}){let{t:n}=Q(),r=D(),a=s({queryKey:xe,queryFn:()=>r.trpcClient.llm.getDefaults.query({})}),o=l({mutationFn:e=>r.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?n(`ai.defaultVision`,`Default vision profile`):n(`ai.defaultText`,`Default text profile`);return i(J,{headingId:`ai-profiles-defaults`,title:n(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:Te.map(({purpose:r,visionOnly:a})=>{let s=a?t.filter(e=>e.supportsVision):t,l=c(r),d=t.find(e=>e.id===l);return e(`div`,{children:[i(ae,{className:`mb-1 block`,htmlFor:`llm-default-${r}`,children:u(r)}),i(se,{id:`llm-default-${r}`,"aria-label":u(r),value:l,onChange:e=>o.mutate({purpose:r,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:n(`ai.none`,`None`)},...l!==``&&!s.some(e=>e.id===l)?[{value:l,label:d?.name??l}]:[],...s.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),l!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:n(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:n(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},r)})})})}c();var mt=5e3;function ht(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function gt(){let{t}=Q(),r=D(),a=s({queryKey:Se,refetchInterval:mt,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(X,{variant:Fe(n),children:n.reachable?n.status?.state??t(`ai.ready`,`ready`):t(`ai.unreachable`,`unreachable`)}),n.status?.downloadProgress!==void 0&&i(X,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:ht(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeatures`,`Features`),render:n=>{let r=Ie(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(X,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(J,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${d} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:d,children:i(G,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(V,{icon:T,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(W,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:z})})}var _t=x(`/addon/ai/test-chat`),vt=x(`/addon/ai/test-chat/chats`),yt=6e5;function bt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),yt)}function xt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function St(e){if(!xt(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 Ct=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function wt(e){let t;try{t=JSON.parse(e)}catch{return null}if(!xt(t))return null;switch(t.kind){case`status`:{let e=Ct.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:St(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:Z.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Tt(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(`
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,t as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as d,En as f,Fn as p,G as m,Ht as h,L as g,Li as _,Ni as v,Pn as y,Pr as b,Q as x,Ri as S,Vn as C,Xr as w,_n as T,ai as E,dt as D,fr as O,gt as ee,na as k,ni as A,rn as j,st as M,tn as N,vn as P}from"./player-overlays-DVETFMIk.js";import{$a as te,Br as F,zr as I}from"./client-UkFHArbd.js";import{n as L,t as ne}from"./send-DdLpBXJo.js";import{t as R}from"./message-square-plus--EqwnnsY.js";import{Cn as z,Dr as B,Er as V,Fr as re,Hn as H,Or as U,Qn as ie,Sn as W,Tr as G,Wn as ae,Yr as K,_o as oe,ad as q,bn as J,bt as Y,ed as se,ft as ce,mt as le,ni as X,od as ue,or as de,rt as fe,xt as pe}from"./src-CJMN3ac7.js";import{t as Z}from"./i18n-Dodsa0QQ.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-C0bjqXeS.js";import{S as me,gr as he}from"./index-DAYRmkvA.js";import{t as ge}from"./AdminSectionedPage-hs_sRKSH.js";import{t as _e}from"./AdminPage-rM4C_UeK.js";c();var ve=`__redacted__`,ye=[`llm`,`listProfiles`],be=[`llm`,`listProfileKinds`],xe=[`llm`,`getDefaults`],Se=[`llm`,`listRuntimeNodes`],Ce=[`llm`,`listModelCatalog`],we=[`llm`,`getUsage`],Te=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],Ee=new Map([[`cloud`,E],[`plug`,y],[`cpu`,A],[`server`,T],[`sparkles`,j]]);function De(e){return Ee.get(e)??S}function Oe(e){return typeof e==`string`&&e.length>0?e:void 0}function ke(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 Ae(e){return e===!0}function je(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 Me={deviceNotEligible:{key:`ai.appleNotEligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,tone:`danger`}};function Ne(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:Z.t(`ai.appleUnknown`),detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:Z.t(`ai.appleAvailable`),detail:Z.t(n.imageInput?`helpers.aiPage.appleDetailImages`:`helpers.aiPage.appleDetailText`,{version:n.osVersion}),tone:`success`};case`unavailable`:{let t=Me[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:Z.t(t.key),detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:Z.t(`ai.appleNotMac`),detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Pe={ready:`success`,downloading:`info`,starting:`info`,stopped:`danger`,crashed:`danger`,failed:`danger`};function Fe(e){return e.reachable?e.status===void 0?`success`:Pe[e.status.state]:`danger`}function Ie(e){if(!e.reachable)return[];let t=[],n=e.apple;if(n?.state===`available`)t.push({id:`apple`,labelKey:`ai.featureApple`,tone:`success`,detail:Ne(e).detail}),n.imageInput&&t.push({id:`apple-images`,labelKey:`ai.featureAppleImages`,tone:`success`,detail:null});else if(n?.state===`unavailable`){let n=Ne(e);t.push({id:`apple`,labelKey:`ai.featureApple`,tone:n.tone,detail:n.labelDefault})}let r=e.status?.vramBytes;return r!==void 0&&r>0&&t.push({id:`gpu`,labelKey:`ai.featureGpu`,tone:`info`,detail:null}),t}function Le(){return{temperature:[{type:`slider`,key:`temperature`,label:Z.t(`helpers.aiProfileForm.temperature`),min:0,max:2,step:.1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`,description:Z.t(`helpers.aiProfileForm.temperatureHint`)}],topP:[{type:`slider`,key:`topP`,label:Z.t(`helpers.aiProfileForm.topP`),min:0,max:1,step:.05,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`}],topK:[{type:`number`,key:`topK`,label:Z.t(`helpers.aiProfileForm.topK`),min:1}],maxTokens:[{type:`number`,key:`maxTokens`,label:Z.t(`helpers.aiProfileForm.maxTokens`),min:1}],contextLength:[{type:`number`,key:`contextLength`,label:Z.t(`helpers.aiProfileForm.contextLength`),min:512,unit:`tokens`,description:Z.t(`helpers.aiProfileForm.contextLengthHint`)}],systemPrompt:[{type:`textarea`,key:`systemPrompt`,label:Z.t(`helpers.aiProfileForm.systemPrompt`),rows:4,maxLength:4e3,span:2,description:Z.t(`helpers.aiProfileForm.systemPromptHint`)}],timeoutMs:[{type:`number`,key:`timeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutTotal`),min:1e3,default:F.totalMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutTotalHint`)}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutConnect`),min:500,default:F.connectMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutConnectHint`)}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutFirstToken`),min:1e3,default:F.firstTokenMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutFirstTokenHint`)}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutIdle`),min:1e3,default:F.idleMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutIdleHint`)}],retry:[{type:`boolean`,key:`retryEnabled`,label:Z.t(`helpers.aiProfileForm.retry`),description:Z.t(`helpers.aiProfileForm.retryHint`)},{type:`number`,key:`retryMaxAttempts`,label:Z.t(`helpers.aiProfileForm.retryMaxAttempts`),min:1,max:5,default:1,showWhen:{field:`retryEnabled`,equals:!0}}],toolsEnabled:[{type:`boolean`,key:`toolsEnabled`,label:Z.t(`helpers.aiProfileForm.toolsEnabled`),description:Z.t(`helpers.aiProfileForm.toolsEnabledHint`)}]}}var Re=[`temperature`,`topP`,`topK`,`maxTokens`,`contextLength`,`systemPrompt`],ze=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function Be(e,t){let n=Le();return t.filter(t=>e.includes(t)).flatMap(e=>n[e])}function Ve(e){let t=Be(e,Re);return t.length===0?null:{sections:[{id:`generation`,title:Z.t(`helpers.aiProfileForm.generation`),fields:t}]}}function He(e){let t=Be(e,ze);return t.length===0?null:{sections:[{id:`bounds`,title:Z.t(`helpers.aiProfileForm.bounds`),fields:t}]}}function Ue(e){return e===null?{}:{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}}function We(e,t){return{...e.features,...t?.features}}function Ge(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function Ke(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?ke(i[e])??t:n??t,o=e=>r.includes(e)?ke(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`systemPrompt`)?Oe(i.systemPrompt):t?.systemPrompt;return{id:t?.id??crypto.randomUUID(),name:n.name,kind:e.kind,addonId:e.addonId.length>0?e.addonId:`ai`,enabled:t?.enabled??!0,model:n.model,supportsVision:n.supportsVision,timeoutMs:a(`timeoutMs`,F.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,F.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,F.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,F.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:Ae(i.retryEnabled),maxAttempts:ke(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?Ae(i.toolsEnabled):t?.toolsEnabled??!1,...s===void 0?{}:{temperature:s},...c===void 0?{}:{topP:c},...l===void 0?{}:{topK:l},...u===void 0?{}:{maxTokens:u},...d===void 0?{}:{contextLength:d},...f===void 0?{}:{systemPrompt:f},providerConfig:n.providerConfig}}var qe=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function Je(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Ye({nodeId:t,value:r,onChange:a}){let{t:c}=Q(),u=D(),[d,f]=o(``),[p,m]=o(null),[h,g]=o(!1),_=s({queryKey:Ce,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),v=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:t})}),y=l({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{m(e),g(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),b=l({mutationFn:e=>u.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{g(!0),v.refetch()}}),x=s({queryKey:Se,enabled:b.isPending,refetchInterval:b.isPending?qe:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,S=n(()=>{let e=(_.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(v.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:$(e.sizeBytes),node:t})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[_.data,v.data,p,t,c]),C=e=>{if(e===``){a(null);return}if(e===`custom`){if(p?.ok!==!0)return;a({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=_.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=v.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},T=e=>{d.trim()!==``&&y.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(pe,{label:c(`ai.model`,`Model`),required:!0,children:i(se,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:Je(r),options:S,onChange:e=>C(e.target.value)})}),i(pe,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`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.`),children:e(`div`,{className:`flex gap-2`,children:[i(q,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:d,onChange:e=>f(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),T())}}),e(K,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||y.isPending,onClick:()=>T(),children:[y.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(P,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),y.isError&&i(G,{message:y.error instanceof Error?y.error.message:c(`common.error`,`Error`)}),p?.ok===!1&&i(G,{message:p.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>i(K,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),y.mutate({ref:t})},children:e},e)),p.requiredBytes!==void 0&&i(K,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>T(p.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]})}),p?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),i(X,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),i(X,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(K,{size:`sm`,type:`button`,disabled:b.isPending||h,onClick:()=>b.mutate(p.model),children:[b.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),h?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),x!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:x.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:x.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:x.file,index:x.fileIndex,count:x.fileCount,done:$(x.downloadedBytes),total:x.totalBytes===void 0?``:` / ${$(x.totalBytes)}`})})]}),b.isError&&i(G,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)})]})]})}function Xe({value:t,onChange:n}){let{t:r}=Q(),a=D(),o=s({queryKey:Se,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(O,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=Ne(a),s=o.nodeId===t;return e(`button`,{type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(X,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}function Ze(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Qe({providerConfig:e,onProviderConfigChange:t}){return i(Xe,{value:Ze(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function $e({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=I.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Ye,{nodeId:Ze(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var et=new Map([[`ai/apple-node`,Qe],[`ai/managed-model`,$e]]);function tt(e){return et.get(e)??null}c();function nt({kind:e,className:t}){return i(De(e.icon),{className:t,"aria-hidden":!0})}function rt({kinds:e,onPick:t,onCancel:r}){let{t:a}=Q(),o=n(()=>je(e),[e]),s=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return i(le,{open:!0,onClose:r,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:i(Y,{emptyMessage:a(`ai.noKinds`,`No AI provider is installed.`),onPick:e=>{let n=s.get(e);n!==void 0&&t(n)},groups:o.map(e=>({id:e.addonId,label:e.addonId,tiles:e.kinds.map(t=>({key:`${e.addonId}:${t.kind}`,label:t.label,testId:`ai-kind-${t.kind}`,icon:i(nt,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function it(e){return(e?.sections??[]).flatMap(e=>e.fields)}function at(...e){let t={};for(let n of e)for(let e of it(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function ot(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function st(e,t){return it(e).filter(e=>`required`in e&&e.required===!0&&!ot(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var ct={auth:{key:`ai.listAuth`,fallback:`Credentials refused`},network:{key:`ai.listNetwork`,fallback:`Endpoint unreachable`},unsupported:{key:`ai.listUnsupported`,fallback:`No model list`},invalid:{key:`ai.listInvalid`,fallback:`Connection incomplete`}};function lt(e,t){if(t!==null)return{id:t.model,supportsVision:t.supportsVision};let n=e.modelCatalog===`static`&&e.staticModels?.length===1?e.staticModels?.[0]:void 0;return{id:n?.id??``,supportsVision:We(e,n).vision}}function ut({kind:t,existing:r,onSave:a,onCancel:s,onChangeKind:c,saving:p,error:m}){let{t:h}=Q(),_=D(),[v,y]=o(r?.name??t.label),[b,x]=o(()=>r===null?at(t.connectionSchema,t.advancedSchema):{...r.providerConfig}),[S,C]=o(()=>Ue(r)),[w,T]=o(()=>lt(t,r)),[E,ee]=o(!1),A=t.providerWidgets??[],j=A.filter(e=>e.placement===`connection`),M=A.find(e=>e.placement===`model`)??null,N=n(()=>[...te(t.connectionSchema)].some(e=>r?.providerConfig[e]===ve),[r,t.connectionSchema]),P=l({mutationFn:()=>_.trpcClient.llm.listModels.mutate({addonId:t.addonId,kind:t.kind,connection:b,...r===null?{}:{profileId:r.id}}),onSuccess:e=>{e.ok&&T(n=>{let r=e.models.find(e=>e.id===n.id);return r===void 0?n:{id:n.id,supportsVision:We(t,r).vision}})}}),F=Ge(t,P.data?.ok===!0?P.data.models:null),I=F.find(e=>e.id===w.id),L=We(t,I),ne=Ve(t.profileFields),R=He(t.profileFields),z=st(t.connectionSchema,b),B=A.some(e=>(e.requires??[]).some(e=>!ot(b[e]))),V=t.modelCatalog===`fetch`&&M===null,re=it(t.connectionSchema).length>0||j.length>0,U=e=>{T({id:e,supportsVision:We(t,F.find(t=>t.id===e)).vision})},W=p||v.trim()===``||w.id.trim()===``||z.length>0||B,ae=()=>{a(Ke(t,r,{name:v.trim(),model:w.id.trim(),supportsVision:t.visionEditable?w.supportsVision:!1,common:S,providerConfig:b}))},oe=r===null?h(`ai.newProfile`,`New {{kind}} profile`,{kind:t.label}):h(`ai.editProfile`,`Edit {{name}}`,{name:r.name}),Y=e=>{let n=tt(e);return n===null?i(G,{variant:`warning`,message:h(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})}):i(n,{descriptor:t,providerConfig:b,onProviderConfigChange:x,model:w,onModelChange:T},e)};return i(le,{open:!0,onClose:s,title:oe,error:m,width:`lg`,testId:`ai-profile-editor`,footer:e(u,{children:[z.length>0&&i(X,{variant:`warning`,children:h(`ai.missingRequired`,`required: {{fields}}`,{fields:z.join(`, `)})}),z.length===0&&B&&i(X,{variant:`warning`,children:h(`ai.completeProvider`,`complete the provider settings`)}),z.length===0&&!B&&w.id.trim()===``&&i(X,{variant:`warning`,children:h(`ai.pickModelFirst`,`pick a model`)}),e(K,{size:`sm`,type:`button`,disabled:W,onClick:ae,children:[p&&i(O,{className:`h-3.5 w-3.5 animate-spin`}),r===null?h(`ai.createProfile`,`Create profile`):h(`ai.saveChanges`,`Save changes`)]})]}),children:e(`div`,{className:g,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[i(nt,{kind:t,className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-xs font-medium text-foreground`,children:t.label}),i(X,{variant:`neutral`,children:t.addonId}),c!==void 0&&e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:c,children:[i(k,{className:`h-3.5 w-3.5`}),h(`ai.changeKind`,`Change type`)]})]}),i(pe,{label:h(`ai.name`,`Name`),required:!0,children:i(q,{id:`ai-profile-name`,"aria-label":h(`ai.name`,`Name`),value:v,onChange:e=>y(e.target.value),placeholder:t.label})}),re&&i(J,{headingId:`ai-editor-connection`,title:h(`ai.sectionConnection`,`Connection`),actions:V?e(K,{size:`sm`,variant:`secondary`,type:`button`,disabled:P.isPending,onClick:()=>P.mutate(),"data-testid":`ai-verify-models`,children:[P.isPending?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(f,{className:`h-3.5 w-3.5`}),h(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[it(t.connectionSchema).length>0&&i(de,{bare:!0,schema:t.connectionSchema,values:b,onChange:x}),j.map(e=>Y(e.id)),N&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:h(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),P.data?.ok===!0&&i(X,{variant:`success`,"data-testid":`ai-models-found`,children:h(`ai.modelsFound`,`{{count}} models found`,{count:P.data.models.length})}),P.data?.ok===!1&&i(G,{title:h(ct[P.data.code]?.key??`ai.listNetwork`,ct[P.data.code]?.fallback??`Endpoint unreachable`),message:P.data.message}),P.isError&&i(G,{message:P.error instanceof Error?P.error.message:h(`common.error`,`Error`)})]})}),i(J,{headingId:`ai-editor-model`,title:h(`ai.sectionModel`,`Model`),children:e(`div`,{className:`${d} space-y-3`,children:[M===null?e(u,{children:[F.length>0&&i(se,{id:`ai-model-pick`,"aria-label":h(`ai.selectModel`,`Select a model…`),value:I===void 0?``:I.id,options:[{value:``,label:h(`ai.selectModel`,`Select a model…`)},...F.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&U(e.target.value)}}),i(pe,{label:h(`ai.customModel`,`Model id`),description:h(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:i(q,{id:`ai-model-id`,"aria-label":h(`ai.customModel`,`Model id`),value:w.id,onChange:e=>T({...w,id:e.target.value}),placeholder:F[0]?.id??`model-id`})})]}):Y(M.id),e(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(w.supportsVision||!t.visionEditable&&L.vision)&&i(X,{variant:`info`,children:h(`ai.featureVision`,`vision`)}),L.tools&&i(X,{variant:`neutral`,children:h(`ai.featureTools`,`tools`)}),L.streaming&&i(X,{variant:`neutral`,children:h(`ai.featureStreaming`,`streaming`)})]}),t.visionEditable&&i(pe,{orientation:`horizontal`,label:h(`ai.supportsVision`,`Supports vision`),description:h(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:i(H,{checked:w.supportsVision,onCheckedChange:e=>T({...w,supportsVision:e}),"aria-label":h(`ai.supportsVision`,`Supports vision`)})})]})}),ne!==null&&i(J,{headingId:`ai-editor-generation`,title:h(`ai.sectionGeneration`,`Generation`),children:i(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:i(de,{bare:!0,schema:ne,values:S,onChange:C})})}),(R!==null||t.advancedSchema!==void 0)&&i(ie,{expanded:E,onExpandedChange:ee,header:i(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:h(`ai.sectionAdvanced`,`Advanced`)}),children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[R!==null&&i(de,{bare:!0,schema:R,values:S,onChange:C}),t.advancedSchema!==void 0&&i(de,{bare:!0,schema:t.advancedSchema,values:b,onChange:x})]})})]})})}c();function dt(t){return[{key:`name`,header:t.t(`ai.colProfile`,`Profile`),render:n=>{let r=t.kindByName.get(n.kind);return e(`span`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:r?.label??n.kind,children:r===void 0?i(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):i(nt,{kind:r,className:`h-4 w-4 text-foreground-subtle`})}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block truncate font-medium text-foreground`,children:n.name}),t.testResult?.id===n.id&&i(`span`,{className:`block truncate ${t.testResult.ok?`text-success`:`text-danger`}`,children:t.testResult.text})]})]})}},{key:`kind`,header:t.t(`ai.colKind`,`Kind`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground-muted`,children:t.kindByName.get(e.kind)?.label??e.kind})},{key:`model`,header:t.t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.model})},{key:`vision`,header:t.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:e=>e.supportsVision?i(X,{variant:`info`,style:`outline`,children:t.t(`ai.vision`,`vision`)}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`node`,header:t.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>typeof e.providerConfig.nodeId==`string`?i(X,{variant:`default`,children:e.providerConfig.nodeId}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`enabled`,header:t.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:e=>i(H,{checked:e.enabled,onCheckedChange:()=>t.onToggle(e),"aria-label":Z.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:e.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[i(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest(n),"aria-label":t.t(`ai.test`,`Test`),title:t.t(`ai.test`,`Test`),children:t.testingId===n.id?i(O,{className:`h-3.5 w-3.5 animate-spin`}):i(ne,{className:`h-3.5 w-3.5`})}),i(K,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t.kindByName.has(n.kind),onClick:()=>t.onEdit(n),"aria-label":t.t(`common.edit`,`Edit`),title:t.t(`common.edit`,`Edit`),children:i(C,{className:`h-3.5 w-3.5`})}),i(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(n),"aria-label":t.t(`common.delete`,`Delete`),title:t.t(`common.delete`,`Delete`),children:i(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function ft(){let{t}=Q(),c=D(),{state:u,openEdit:f,close:p}=ce(),m=M(),[h,_]=o(null),[v,y]=o(null),[b,x]=o(null),S=s({queryKey:ye,queryFn:()=>c.trpcClient.llm.listProfiles.query({})}),C=s({queryKey:be,queryFn:async()=>(await c.trpcClient.llm.listProfileKinds.query({})).map(({connectionSchema:e,advancedSchema:t,...n})=>({...n,connectionSchema:e,...t===void 0?{}:{advancedSchema:t}}))}),w=()=>{S.refetch()},T=r(()=>{_(null),x(null),p()},[p]);a(()=>{u.mode===`closed`&&_(null)},[u.mode]);let E=l({mutationFn:e=>c.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{T(),w()},onError:e=>x(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),O=l({mutationFn:e=>c.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),ee=l({mutationFn:e=>c.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>y({id:t.id,ok:e.ok,text:e.ok?Z.t(`system.aiProfilesTab.testOk`,{text:e.text,tokens:e.usage.outputTokens,ms:e.latencyMs}):`${e.code}: ${e.message}`})}),k=S.data??[],A=n(()=>C.data??[],[C.data]),N=n(()=>{let e=new Map;for(let t of A)e.set(t.kind,t);return e},[A]),P=u.mode===`edit`?k.find(e=>e.id===u.id)??null:null,te=P===null?null:N.get(P.kind)??null,F=u.mode===`new`&&h===null,I=u.mode===`new`?h:te,L=u.mode===`edit`?P:null,ne=I!==null&&(u.mode===`new`||L!==null),R=async e=>{await m({title:t(`ai.deleteProfileTitle`,`Delete profile?`),message:t(`ai.deleteProfileMessage`,`Delete "{{name}}". Features that name it will no longer get an answer from it.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&O.mutate(e)};return e(`div`,{className:g,children:[i(pt,{profiles:k}),i(J,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:S.isPending?e(`div`,{className:`${d} space-y-2`,"data-testid":`ai-profiles-loading`,children:[i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`})]}):S.isError?i(`div`,{className:d,children:i(G,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:t(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):k.length===0?i(V,{icon:j,title:t(`ai.noProfilesTitle`,`No AI profiles yet`),description:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):i(W,{columns:dt({kindByName:N,testResult:v,testingId:ee.isPending?ee.variables?.id??null:null,t,onToggle:e=>E.mutate({...e,enabled:!e.enabled}),onTest:e=>ee.mutate(e),onEdit:e=>{N.has(e.kind)&&(x(null),_(null),f(e.id))},onDelete:e=>void R(e)}),rows:k,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:z})}),F&&i(rt,{kinds:A,onCancel:T,onPick:e=>{x(null),_(e)}}),ne&&I!==null&&i(ut,{kind:I,existing:L,saving:E.isPending,error:b,onSave:e=>E.mutate(e),onCancel:T,...u.mode===`new`?{onChangeKind:()=>{x(null),_(null)}}:{}})]})}function pt({profiles:t}){let{t:n}=Q(),r=D(),a=s({queryKey:xe,queryFn:()=>r.trpcClient.llm.getDefaults.query({})}),o=l({mutationFn:e=>r.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?n(`ai.defaultVision`,`Default vision profile`):n(`ai.defaultText`,`Default text profile`);return i(J,{headingId:`ai-profiles-defaults`,title:n(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:Te.map(({purpose:r,visionOnly:a})=>{let s=a?t.filter(e=>e.supportsVision):t,l=c(r),d=t.find(e=>e.id===l);return e(`div`,{children:[i(ae,{className:`mb-1 block`,htmlFor:`llm-default-${r}`,children:u(r)}),i(se,{id:`llm-default-${r}`,"aria-label":u(r),value:l,onChange:e=>o.mutate({purpose:r,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:n(`ai.none`,`None`)},...l!==``&&!s.some(e=>e.id===l)?[{value:l,label:d?.name??l}]:[],...s.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),l!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:n(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:n(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},r)})})})}c();var mt=5e3;function ht(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function gt(){let{t}=Q(),r=D(),a=s({queryKey:Se,refetchInterval:mt,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(X,{variant:Fe(n),children:n.reachable?n.status?.state??t(`ai.ready`,`ready`):t(`ai.unreachable`,`unreachable`)}),n.status?.downloadProgress!==void 0&&i(X,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:ht(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeatures`,`Features`),render:n=>{let r=Ie(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(X,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(J,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${d} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:d,children:i(G,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(V,{icon:T,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(W,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:z})})}var _t=x(`/addon/ai/test-chat`),vt=x(`/addon/ai/test-chat/chats`),yt=6e5;function bt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),yt)}function xt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function St(e){if(!xt(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 Ct=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function wt(e){let t;try{t=JSON.parse(e)}catch{return null}if(!xt(t))return null;switch(t.kind){case`status`:{let e=Ct.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:St(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:Z.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Tt(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
2
|
`);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=wt(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
3
|
`)}}let e=r.trim();if(e.length>0){let t=wt(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Et(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Dt(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Ot(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 kt(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 At(e,t){switch(e){case`resolving-image`:return Z.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return Z.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?Z.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):Z.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return Z.t(`helpers.aiTestChat.phaseAnswering`)}}c();var jt=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Mt=360*60*1e3,Nt=40,Pt=160,Ft={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function It(){let{t:c}=Q(),l=D(),[u,f]=o(``),[p,m]=o(``),[y,b]=o(``),[x,S]=o([]),[C,w]=o(null),[T,E]=o(`none`),[O,k]=o(`throwaway`),[A,j]=o(null),[M,P]=o([]),[te,F]=o(null),[I,L]=o(null),z=t(null);a(()=>()=>z.current?.abort(),[]);let B=r(async()=>{let e=await fetch(vt,{credentials:`same-origin`});e.ok&&P((await e.json()).chats??[])},[]);a(()=>{O===`persistent`&&B()},[O,B]);let V=s({queryKey:ye,queryFn:()=>l.trpcClient.llm.listProfiles.query({})}),re=n(()=>(V.data??[]).filter(e=>e.enabled),[V.data]),H=re.find(e=>e.id===u)??null,U=I!==null,ie=r(async(e,t)=>{let n=new AbortController;z.current=n,F(null);let r=bt(H??{});L({...Ft,firstTokenTimeoutMs:r??0});let i=``,a=null,o,s=null,l=null,d;try{let c=await fetch(_t,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:u,messages:e,...p.trim()===``?{}:{system:p.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...O===`persistent`?{persist:!0,...A===null?{}:{conversationId:A}}:{}})});if(!c.ok||c.body===null){let e=await c.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(c.status)}`)}for await(let e of Tt(c.body))switch(e.kind){case`status`:L(t=>({...t??Ft,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,L(t=>({...t??Ft,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,L(e=>({...e??Ft,text:i}));break;case`done`:l={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:s=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||F(e instanceof Error?e.message:c(`common.error`,`Error`))}finally{z.current=null,L(null)}d!==void 0&&(j(d),B());let f=n.signal.aborted&&i.length>0;s===null&&i.length===0&&!f||S(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:s??i,...s===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&s===null?{model:o}:{},...l===null?{}:l}])},[O,A,H,u,B,p,c]),W=r(()=>{let e=y.trim();if(e===``||u===``||U)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...C===null?{}:{attachmentLabel:C.label,attachmentKind:C.ref.kind}},n=[...x,t];S(n),b(``);let r=C?.ref;w(null),E(`none`),ie(O===`persistent`&&A!==null?[{role:`user`,content:e}]:Et(n),r)},[O,A,y,C,u,ie,U,x]),oe=()=>z.current?.abort(),Y=()=>{z.current?.abort(),S([]),w(null),b(``),F(null),L(null),j(null)},ce=async e=>{z.current?.abort();let t=await fetch(`${vt}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),S(Ot(n)),L(null),F(null)};return e(`div`,{className:g,children:[i(J,{headingId:`ai-test-setup`,title:c(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${d} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(ae,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:c(`ai.profile`,`Profile`)}),i(se,{id:`ai-test-profile`,value:u,onChange:e=>f(e.target.value),options:[{value:``,label:c(`ai.selectProfile`,`Select a profile…`)},...re.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),re.length===0&&!V.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:c(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(ae,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:c(`ai.systemPrompt`,`System prompt (optional)`)}),i(q,{id:`ai-test-system`,value:p,onChange:e=>m(e.target.value),placeholder:c(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(fe,{label:c(`ai.chatMode`,`Conversation mode`),value:O,options:[{value:`throwaway`,label:c(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:c(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{k(e),e===`throwaway`&&j(null)}}),O===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(K,{size:`sm`,variant:`secondary`,type:`button`,onClick:Y,children:[i(R,{className:`h-3.5 w-3.5`}),c(`ai.newChat`,`New chat`)]}),M.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>i(`button`,{type:`button`,onClick:()=>void ce(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===A?`bg-primary/10`:``}`,children:i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`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.`)}),H!==null&&!H.supportsVision&&i(`p`,{className:`text-xs text-warning`,children:c(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),te!==null&&i(G,{title:c(`ai.chatFailed`,`The test call failed`),message:te}),e(J,{headingId:`ai-test-conversation`,title:c(`ai.testConversation`,`Conversation`),actions:e(K,{size:`sm`,variant:`ghost`,type:`button`,disabled:x.length===0&&C===null,onClick:Y,children:[i(h,{className:`h-3.5 w-3.5`}),c(`ai.clearChat`,`Clear`)]}),children:[i(Lt,{turns:x,live:I}),e(`div`,{className:`${d} space-y-2 border-t border-border`,children:[C!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[C.ref.kind===`snapshot`?i(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:C.label}),i(ue,{size:`sm`,variant:`ghost`,type:`button`,icon:ee,"aria-label":c(`ai.removeAttachment`,`Remove attachment`),onClick:()=>w(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(K,{size:`sm`,variant:T===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>E(T===`snapshot`?`none`:`snapshot`),children:[i(v,{className:`h-3.5 w-3.5`}),c(`ai.attachSnapshot`,`Camera snapshot`)]}),e(K,{size:`sm`,variant:T===`track`?`primary`:`outline`,type:`button`,onClick:()=>E(T===`track`?`none`:`track`),children:[i(_,{className:`h-3.5 w-3.5`}),c(`ai.attachTrack`,`Recent track`)]})]}),T===`snapshot`&&i(Bt,{onPick:(e,t)=>{w({ref:{kind:`snapshot`,deviceId:e.id},label:c(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t})}),E(`none`)}}),T===`track`&&i(Ht,{onPick:(e,t)=>{w({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:c(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),E(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(q,{value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),W())},placeholder:c(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":c(`ai.message`,`Message`)}),U?e(K,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[i(N,{className:`h-3.5 w-3.5`}),c(`ai.stop`,`Stop`)]}):e(K,{size:`sm`,type:`button`,disabled:y.trim()===``||u===``,onClick:W,children:[i(ne,{className:`h-3.5 w-3.5`}),c(`ai.send`,`Send`)]})]})]})]})]})}function Lt({turns:t,live:n}){let{t:r}=Q();return t.length===0&&n===null?i(V,{icon:L,title:r(`ai.chatEmptyTitle`,`No messages yet`),description:r(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):e(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${d}`,children:[t.map(e=>i(Rt,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(zt,{attachment:n.mediaSent}),n.text.length>0&&i(Rt,{turn:{id:`live`,role:`assistant`,content:n.text},streaming:!0}),e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(O,{className:`h-3.5 w-3.5 animate-spin`}),At(n.phase,n.firstTokenTimeoutMs)]})]})]})}function Rt({turn:t,streaming:n=!1}){let{t:r}=Q(),a=t.role===`user`,o=t.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return i(`div`,{className:`flex ${a?`justify-end`:`justify-start`}`,children:e(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${a?`border-primary/40 bg-primary/10`:o}`,children:[e(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[t.content,n&&i(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),t.attachment!==void 0&&i(zt,{attachment:t.attachment}),t.attachmentLabel!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachmentKind===`track`?i(_,{className:`h-3 w-3`}):i(v,{className:`h-3 w-3`}),t.attachmentLabel]}),t.attachment!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachment.kind===`snapshot`?i(v,{className:`h-3 w-3`}):i(_,{className:`h-3 w-3`}),kt(t.attachment)]}),t.model!==void 0&&i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:t.model,value2:String(t.outputTokens??0),value3:String(t.latencyMs??0)})})]})})}function zt({attachment:e}){let{t}=Q(),n=Dt(e);return n===null?null:i(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function Bt({onPick:e}){let{t}=Q(),n=oe({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(O,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):i(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>i(Vt,{device:t,onPick:e},t.id))})}function Vt({device:t,onPick:n}){let{t:r}=Q(),a=re(t,`compact`),{src:o}=m(t.id,{width:Pt});return e(`button`,{type:`button`,onClick:()=>n(t,a),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[i(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:o!==null&&i(`img`,{src:o,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),e(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!t.online&&i(X,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:a})]})]})}function Ht({onPick:t}){let{t:r}=Q(),a=D(),o=oe({isCamera:!0,projection:`slim`}),c=n(()=>(o.data??[]).map(e=>e.id),[o.data]),l=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=s({queryKey:[...jt,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-Mt,limit:Nt,projection:`slim`})});if(o.isLoading||u.isLoading)return i(O,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noTracks`,`No track in the last 6 hours.`)}):i(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(n=>e(`button`,{type:`button`,onClick:()=>t(n,l.get(n.deviceId)??String(n.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[i(_,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:n.label??n.className}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:l.get(n.deviceId)??n.deviceId}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(n.lastSeen).toLocaleTimeString()})]},n.trackId))})}c();var Ut=1440*60*1e3,Wt=[1,7,30,90];function Gt(){let{t}=Q(),r=D(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*Ut},[a]),u=s({queryKey:ye,queryFn:()=>r.trpcClient.llm.listProfiles.query({})}),f=s({queryKey:[...we,a],queryFn:()=>r.trpcClient.llm.getUsage.query({since:l})}),p=n(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=n(()=>[{key:`day`,header:t(`ai.colDay`,`Day`),nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:t(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:t(`ai.colProfile`,`Profile`),render:e=>i(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:t(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:t(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:t(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:t(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,t]),h=f.data??[],g=i(`div`,{className:`w-36`,children:i(se,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:Wt.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(J,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:g,children:f.isPending?e(`div`,{className:`${d} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`}),i(U,{className:`h-8 w-full`})]}):f.isError?i(`div`,{className:d,children:i(G,{title:t(`ai.usageFailed`,`Failed to read usage`),message:f.error instanceof Error?f.error.message:t(`common.error`,`Error`),onRetry:()=>void f.refetch()})}):h.length===0?i(V,{icon:b,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(W,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:z})})}var Kt=`llm`,qt=[`profiles`,`runtimes`,`usage`,`test`],Jt=[`new`,`edit`];function Yt(e){return qt.some(t=>t===e)}function Xt(){let{t}=Q(),n=B(Kt),[r]=he(),{openNew:a}=ce(),o=me(`/system/ai`,{t,isAdmin:!0})??{icon:j,title:t(`system.ai`,`AI`)};if(n!==`present`)return i(_e,{icon:o.icon,title:o.title,children:i(Zt,{presence:n})});let s=r.get(`tab`),c=Yt(s)?s:`profiles`,l={profiles:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes:t(`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.`),usage:t(`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.`),test:t(`ai.testSubtitle`,`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.`)},u=c===`profiles`?e(K,{size:`sm`,type:`button`,"data-testid":`ai-add-profile`,onClick:a,children:[i(p,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]}):void 0;return i(ge,{icon:o.icon,title:o.title,subtitle:l[c],actions:u,defaultSection:`profiles`,sectionsLabel:`${o.title} sections`,sections:[{id:`profiles`,label:t(`ai.tabProfiles`,`Profiles`),content:i(ft,{}),ownedParams:Jt},{id:`runtimes`,label:t(`ai.tabRuntimes`,`Runtimes`),content:i(gt,{})},{id:`usage`,label:t(`ai.tabUsage`,`Usage`),content:i(Gt,{})},{id:`test`,label:t(`ai.tabTest`,`Test`),content:i(It,{})}]})}function Zt({presence:t}){let{t:n}=Q();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(U,{className:`h-8 w-64`}),i(U,{className:`h-40 w-full`})]}):t===`unknown`?i(G,{title:n(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:n(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):i(V,{icon:j,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{Xt as AiProfilesPage,Xt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Kr as u,Q as d,fr as f}from"./player-overlays-DVETFMIk.js";import{Ka as p}from"./client-UkFHArbd.js";import{t as m}from"./log-in-BIF-VHyB.js";import{Tr as h,Yr as g,_r as _,cr as v,da as y,dr as b,fa as x,fr as S,ga as C,gr as w,ha as T,mr as E,pr as D,ua as O,xa as k,ya as A}from"./src-CJMN3ac7.js";import{t as j}from"./i18n-Dodsa0QQ.js";import{t as M}from"./useTranslation-BJr-n0es.js";import"./mount-C0bjqXeS.js";import{P as N,g as ee,ur as P}from"./index-DAYRmkvA.js";s();function F(e,t){let n=e=>e.map(e=>e.type===`group`?{...e,fields:n(e.fields)}:e.type===`sub-tabs`?{...e,tabs:e.tabs.map(e=>({...e,fields:n(e.fields)}))}:e.type===`info`&&typeof e.content==`string`?{...e,content:e.content.split(`{{brokerId}}`).join(t)}:e);return{...e,sections:e.sections.map(e=>({...e,fields:n(e.fields)}))}}var I=`broker-advanced`;function L(e){return`key`in e&&typeof e.key==`string`&&`label`in e}function R(e){let t=new Set;for(let n of e){if(!L(n))continue;let e=n.showWhen;if(e===void 0)continue;let r=Array.isArray(e)?e:[e];for(let e of r)typeof e==`object`&&e&&`field`in e&&typeof e.field==`string`&&t.add(e.field)}return t}function te(e,t,n){return!L(e)||e.showWhen!==void 0||t.has(e.key)?!1:n&&e.filledBySignIn===!0?!0:e.default!==void 0||e.defaultByCountry!==void 0}function ne(e,t){let n=[],r=[];for(let i of e.sections){let e=R(i.fields),a=[];for(let r of i.fields)te(r,e,t.hasSignIn)?n.push(r):a.push(r);if(a.length>0)r.push({...i,fields:a});else if(i.description!==void 0){let{description:e,...t}=i;r.push({...t,fields:[{type:`info`,key:`${i.id}-note`,label:``,content:e}]})}}return n.length>0&&r.push({id:I,title:t.advancedTitle,style:`accordion`,defaultCollapsed:!0,columns:1,fields:n}),{...e,sections:r}}function re(e){if(e===void 0)return null;let t=/[-_]([A-Za-z]{2})(?:[-_]|$)/.exec(e);return t?.[1]===void 0?null:t[1].toUpperCase()}function ie(e,t,n){if(e===void 0||t===null)return{};let r={};for(let i of e.sections)for(let e of i.fields){if(!L(e)||n[e.key]!==void 0)continue;let i=e.defaultByCountry;i!==void 0&&t in i&&(r[e.key]=i[t])}return r}var ae=[`starting`,`awaiting-login`,`captured`,`error`,`cancelled`];function z(e){return typeof e==`object`&&!!e}function oe(e){return z(e)&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function se(e){return z(e)&&typeof e.sessionId==`string`&&typeof e.phase==`string`&&ae.includes(e.phase)}function ce(e){return z(e)&&typeof e.brokerId==`string`}function B(){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`}}function V(e){let t=z(e)&&typeof e.error==`string`?e.error:`Unknown error`;return Error(t)}async function H(e,t,n){let r=await fetch(d(e),{method:`POST`,headers:B(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok)throw V(i);if(!n(i))throw Error(`Unexpected response from server`);return i}function le(e,t){return H(`${e}/start`,t,oe)}async function ue(e,t){let n=new URLSearchParams({sessionId:t}),r=await fetch(d(`${e}/status?${n.toString()}`),{headers:{Authorization:B().Authorization??``}}),i=await r.json();if(!r.ok)throw V(i);if(!se(i))throw Error(`Unexpected status response from server`);return i}function de(e,t){return H(`${e}/commit`,{...t},ce)}async function fe(e,t){try{await fetch(d(`${e}/cancel`),{method:`POST`,headers:B(),body:JSON.stringify({sessionId:t})})}catch{}}var pe=2e3;function me(e){try{return window.location.protocol===`https:`?!0:new URL(e).hostname!==window.location.hostname}catch{return!1}}function he({basePath:n,name:s,brokerId:c,getSettings:d,disabled:p,onSignedIn:_}){let{t:v}=M(),[y,b]=o({kind:`idle`}),x=t(!0),S=t(null),C=t(null),w=r(()=>{C.current!==null&&clearInterval(C.current),C.current=null},[]),T=r(()=>{w();let e=S.current;S.current=null,e!==null&&fe(n,e)},[n,w]);a(()=>(x.current=!0,()=>{x.current=!1,T()}),[T]);let E=r(e=>{w(),x.current&&b({kind:`error`,message:e})},[w]),D=r(async e=>{w(),x.current&&b({kind:`committing`});try{let t=await de(n,{sessionId:e,name:s,...c===void 0?{}:{brokerId:c}});S.current=null,x.current&&_(t.brokerId)}catch(e){E(e instanceof Error?e.message:String(e))}},[n,c,E,s,_,w]),O=r(e=>{w(),C.current=setInterval(()=>{(async()=>{try{let t=await ue(n,e);if(t.phase===`captured`)return void await D(e);if(t.phase===`error`)return E(t.error??v(`brokers.signIn.proxyError`));if(t.phase===`cancelled`){w(),x.current&&b({kind:`idle`});return}x.current&&b({kind:`waiting`,loginUrl:t.loginUrl,ready:t.phase===`awaiting-login`})}catch{}})()},pe)},[n,D,E,w,v]),k=async()=>{T(),b({kind:`starting`});try{let e=await le(n,d());S.current=e.sessionId,b({kind:`waiting`,loginUrl:e.loginUrl,ready:!1}),O(e.sessionId)}catch(e){E(e instanceof Error?e.message:String(e))}};return y.kind===`idle`||y.kind===`error`?e(`div`,{className:`space-y-2`,children:[y.kind===`error`&&i(h,{message:y.message}),i(`p`,{className:`text-xs text-foreground-muted`,children:v(`brokers.signIn.intro`)}),e(g,{variant:`primary`,size:`sm`,disabled:p===!0||s.trim().length===0,onClick:()=>void k(),children:[i(m,{className:`h-3.5 w-3.5`}),` `,y.kind===`error`?v(`common.retry`):v(`brokers.signIn.start`)]})]}):y.kind===`starting`||y.kind===`committing`?e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(f,{className:`h-4 w-4 animate-spin flex-shrink-0`}),y.kind===`starting`?v(`brokers.signIn.starting`):v(`brokers.signIn.saving`)]}):e(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:[y.ready?e(l,{children:[i(`p`,{className:`text-xs font-semibold text-foreground`,children:v(`brokers.signIn.openLink`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:v(`brokers.signIn.afterLogin`)}),i(`p`,{className:`break-all font-mono text-[11px] text-foreground`,children:y.loginUrl}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:v(`brokers.signIn.sameNetwork`)}),me(y.loginUrl)&&i(h,{variant:`warning`,message:v(`brokers.signIn.proxyHostWarning`)}),e(g,{variant:`primary`,size:`sm`,onClick:()=>window.open(y.loginUrl,`_blank`,`noopener,noreferrer`),children:[i(u,{className:`h-3.5 w-3.5`}),` `,v(`brokers.signIn.openLoginPage`)]}),i(`p`,{className:`text-[11px] text-warning`,children:v(`brokers.signIn.reachability`)})]}):e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-4 w-4 animate-spin flex-shrink-0`}),v(`brokers.signIn.waitingForProxy`)]}),e(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[e(`span`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(f,{className:`h-3 w-3 animate-spin`}),` `,v(`brokers.signIn.waitingForLogin`)]}),i(g,{variant:`outline`,size:`sm`,onClick:()=>{T(),b({kind:`idle`})},children:v(`brokers.signIn.cancel`)})]})]})}s();function U(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||v(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function W({kind:t,addonId:r,brokerId:s,initialValues:c,onSubmit:l,onCancel:u,submitLabel:d,disabled:m,signIn:h}){let{t:_}=M(),[v,y]=o(c??{}),[b,S]=o(null),C=x({kind:t,...r===void 0?{}:{addonId:r}}),w=n(()=>{let e=C.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections)){let t=e;return ne(p(s===void 0?t:F(t,s),v),{hasSignIn:h!==void 0,advancedTitle:_(`brokers.brokerForm.advanced`)})}},[C.data,s,v,h!==void 0,_]);a(()=>{c!==void 0&&y(c)},[c]);let T=re(typeof navigator>`u`?void 0:navigator.language);a(()=>{if(c!==void 0)return;let e=ie(w,T,v);Object.keys(e).length>0&&y(t=>({...e,...t}))},[w,T,c,v]);let E=k(),D=async()=>{S(null);let e=U(w,v);try{let n=await E.mutateAsync({kind:t,settings:e,...r===void 0?{}:{addonId:r}});S(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){S({ok:!1,error:e instanceof Error?e.message:String(e)})}},O=()=>{let{_calendarCatalog:e,...t}=U(w,v);l(t)},A=()=>{let e=new Set;for(let t of w?.sections??[])for(let n of t.fields)L(n)&&n.filledBySignIn===!0&&e.add(n.key);let t=U(w,v);return Object.fromEntries(Object.entries(t).filter(([t])=>!e.has(t)))};return e(`div`,{className:`space-y-3`,children:[h!==void 0&&i(he,{basePath:h.basePath,name:h.name,...h.brokerId===void 0?{}:{brokerId:h.brokerId},getSettings:A,disabled:m===!0,onSignedIn:h.onSignedIn}),C.isLoading&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,_(`brokers.brokerForm.loadingSchema`)]}),w&&i(N,{schema:w,values:v,onChange:y}),C.isError&&e(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[_(`brokers.brokerForm.failedToLoadSettingsSchema`,`Failed to load settings schema:`),` `,C.error instanceof Error?C.error.message:_(`brokers.brokerForm.unknownError`,`Unknown error`)]}),!w&&!C.isLoading&&!C.isError&&i(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:i(P,{i18nKey:`brokers.brokerForm.noSchema`,values:{kind:t},components:{code:i(`code`,{className:`font-mono`})}})}),b&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${b.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:b.ok?_(`brokers.brokerForm.connectionOk`,`Connection OK.`):_(`brokers.brokerForm.testFailed`,`Test failed: {{value1}}`,{value1:b.error??`unknown error`})}),e(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(g,{variant:`outline`,size:`sm`,onClick:u,children:_(`common.cancel`,`Cancel`)}),e(`div`,{className:`flex items-center gap-2`,children:[i(g,{variant:`outline`,size:`sm`,onClick:()=>{D()},disabled:E.isPending||!w,children:E.isPending?_(`brokers.brokerForm.testing`,`Testing…`):_(`brokers.brokerForm.testConnection`,`Test connection`)}),i(g,{variant:h===void 0?`primary`:`outline`,size:`sm`,onClick:O,disabled:!w||m,children:d??_(`common.save`,`Save`)})]})]})]})}s();function G(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function K(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function ge(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}function q(e){return typeof e==`string`&&e.length>0?e:void 0}function _e(e){let t=new Map;for(let n of e.providers)if(!(e.addonId!==void 0&&n.addonId!==e.addonId))for(let r of n.kinds){if(e.kind!==void 0&&r.kind!==e.kind)continue;let i=q(r.interactiveConnectPath),a=q(r.interactiveDisconnectPath),o=q(r.signIn?.basePath);t.set(`${n.addonId}::${r.kind}`,{addonId:n.addonId,kind:r.kind,label:r.label,...i===void 0?{}:{interactiveConnectPath:i},...a===void 0?{}:{interactiveDisconnectPath:a},...o===void 0?{}:{signInBasePath:o}})}for(let n of e.brokers)e.kind!==void 0&&n.kind!==e.kind||[...t.values()].some(e=>e.kind===n.kind)||t.set(`::${n.kind}`,{kind:n.kind,label:n.kind});return[...t.values()]}function J(e){let t=C(),r=T(e.kind===void 0?{}:{kind:e.kind});return{options:n(()=>_e({providers:ge(t.data),brokers:K(r.data).filter(t=>e.addonId===void 0||t.addonId===e.addonId),...e.addonId===void 0?{}:{addonId:e.addonId},...e.kind===void 0?{}:{kind:e.kind}}),[t.data,r.data,e.addonId,e.kind]),isLoading:t.isLoading===!0}}var Y=`kind`,X=`name`,Z=`restore`,Q=`restoreId`;function ve(e,t={allowRestore:!0}){let n=[];return e.length>1&&n.push({type:`select`,key:Y,label:j.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label}))}),n.push({type:`text`,key:X,label:j.t(`helpers.brokerIdentitySchema.name`),placeholder:j.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0}),t.allowRestore&&n.push({type:`boolean`,key:Z,label:j.t(`helpers.brokerIdentitySchema.restore`),description:j.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Q,label:j.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Z,equals:!0}}),{sections:[{id:`broker-identity`,title:j.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:n}]}}function ye(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(Y);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(X);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Q);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}s();function $({title:t,subtitle:n,onClose:r,children:a}){return i(b,{open:!0,onOpenChange:e=>!e&&r(),children:e(D,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(w,{children:[i(_,{children:t}),n&&i(E,{children:n})]}),i(S,{className:`space-y-3 pr-1`,children:a})]})})}function be(e,t){let n=new Set(t.map(e=>e.trim().toLowerCase()));if(!n.has(e.toLowerCase()))return e;for(let t=2;;t++){let r=`${e} ${t}`;if(!n.has(r.toLowerCase()))return r}}function xe(e){return e.broker===void 0?i(Se,{...e}):i(Ce,{...e,broker:e.broker})}function Se({kind:r,addonId:s,onClose:u,onSaved:d}){let{t:p}=M(),m=c(),{options:g,isLoading:_}=J({...s===void 0?{}:{addonId:s},...r===void 0?{}:{kind:r}}),v=T({}),y=n(()=>K(v.data).map(e=>e.name),[v.data]),[b,x]=o({[X]:``,[Z]:!1,[Q]:``}),[S,C]=o(null),w=g.find(e=>G(e)===b.kind)??g[0],E=G(w),D=w===void 0?``:be(w.label,y),k=t(``);a(()=>{E!==``&&x(e=>{let t=typeof e.name==`string`?e[X]:``,n=t===``||t===k.current;k.current=D;let r=n?D:t;return e.kind===E&&t===r?e:{...e,[Y]:E,[X]:r}})},[E,D]);let A=n(()=>ve(g.map(e=>({key:G(e),label:e.label})),{allowRestore:w?.signInBasePath===void 0}),[g,w?.signInBasePath]),j=e=>{m.invalidateQueries({queryKey:[[`broker`,`list`]]}),d(e)},P=O({onSuccess:e=>{let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null,n=w?.interactiveConnectPath;t!==null&&n!==void 0&&ee(n,t,()=>{m.invalidateQueries({queryKey:[[`broker`,`list`]]})}),t!==null&&j(t)}}),F=ye(b),I=F.ok?F.identity.name:``,L=e=>{if(w!==void 0){if(!F.ok){C(F.problem);return}C(null),P.mutate({kind:w.kind,name:F.identity.name,settings:e,...F.identity.restoreId===null?{}:{id:F.identity.restoreId},...w.addonId===void 0?{}:{addonId:w.addonId}})}},R=P.isPending;return i($,{title:p(`brokers.editor.createTitle`),subtitle:p(`brokers.editor.createSubtitle`),onClose:R?()=>{}:u,children:_&&g.length===0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,p(`brokers.editor.loadingKinds`)]}):w===void 0?i(h,{message:p(`brokers.editor.noProvider`)}):e(l,{children:[i(N,{schema:A,values:b,onChange:x}),S!==null&&i(h,{message:S}),P.isError&&i(h,{message:P.error instanceof Error?P.error.message:String(P.error)}),i(W,{kind:w.kind,...w.addonId===void 0?{}:{addonId:w.addonId},onSubmit:L,onCancel:u,submitLabel:p(R?`brokers.editor.creating`:`brokers.editor.create`),disabled:R,...w.signInBasePath===void 0?{}:{signIn:{basePath:w.signInBasePath,name:I,onSignedIn:j}}},E)]})})}function Ce({broker:t,onClose:r,onSaved:a}){let{t:o}=M(),s=c(),{options:l}=J({addonId:t.addonId,kind:t.kind}),u=l.find(e=>e.kind===t.kind)?.signInBasePath,d=y({id:t.id,addonId:t.addonId}),p=A({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:t.id,addonId:t.addonId}}]}),a(t.id)}}),m=n(()=>{let e=d.data;return e&&typeof e==`object`?{...e}:{}},[d.data]),_=p.isPending;return i($,{title:o(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:t.name}),subtitle:`${t.kind} · ${t.id}`,onClose:_?()=>{}:r,children:d.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.brokerManager.loadingSettings`)]}):d.isError?e(`div`,{className:`space-y-3`,children:[i(h,{message:o(`brokers.brokerManager.loadSettingsFailed`,{message:d.error instanceof Error?d.error.message:o(`common.unknownError`)})}),i(`div`,{className:`flex justify-end`,children:i(g,{variant:`outline`,size:`sm`,onClick:r,children:o(`common.close`,`Close`)})})]}):e(`div`,{className:`space-y-3`,children:[p.isError&&i(h,{message:p.error instanceof Error?p.error.message:String(p.error)}),i(W,{kind:t.kind,addonId:t.addonId,brokerId:t.id,initialValues:m,onSubmit:e=>p.mutate({id:t.id,settings:e,addonId:t.addonId}),onCancel:r,submitLabel:_?o(`brokers.brokerManager.saving`):o(`common.save`,`Save`),disabled:_,...u===void 0?{}:{signIn:{basePath:u,name:t.name,brokerId:t.id,onSignedIn:e=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),a(e)}}}})]})})}export{K as n,J as r,xe as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,t as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as p,Ar as m,Di as h,Fn as g,Ht as _,In as v,Ti as y,Vn as b,dt as x,fr as S,pa as C,ra as w,st as T,vt as E,wn as D,yi as O,yn as k,zt as A}from"./player-overlays-
|
|
1
|
+
import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,t as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as p,Ar as m,Di as h,Fn as g,Ht as _,In as v,Ti as y,Vn as b,dt as x,fr as S,pa as C,ra as w,st as T,vt as E,wn as D,yi as O,yn as k,zt as A}from"./player-overlays-DVETFMIk.js";import{Di as j,Ji as M,Mi as N,Va as P,Xi as F,Yi as I,Zi as L,aa as R,di as ee,fi as z,ji as B,li as V,no as te,oa as ne,qi as re,un as ie,wi as ae,xi as oe}from"./client-UkFHArbd.js";import{t as se}from"./boxes-CfX2DaXN.js";import{n as ce,r as le,t as ue}from"./ungroup-D9nsaCkT.js";import{s as de}from"./video-oLlCkBIP.js";import{Cn as fe,Da as pe,Ea as me,Fa as H,Ia as he,Ir as ge,Kt as _e,Na as ve,Nr as ye,Oa as be,Pa as xe,Ro as Se,Sn as Ce,So as we,Tr as U,Un as Te,Yr as W,Zt as Ee,_o as De,ad as G,bd as Oe,br as ke,ed as K,en as Ae,ft as je,gn as Me,id as Ne,ka as Pe,mt as Fe,nd as Ie,ni as q,po as Le,rd as Re,rn as ze,vd as Be,vt as Ve}from"./src-CJMN3ac7.js";import{t as J}from"./i18n-Dodsa0QQ.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{P as He,S as Ue,dr as We,gr as Ge,h as Ke,m as qe,mr as Je,or as Ye,ur as X}from"./index-DAYRmkvA.js";import{t as Xe}from"./AdminSectionedPage-hs_sRKSH.js";import{t as Ze}from"./DeviceDoActionFields-C8dC5weu.js";import{V as Qe,p as $e,t as et,u as tt}from"./HelperWizard-DPb6SH1D.js";import{t as nt}from"./CompositionBlockEditor-C-oGyTOT.js";var rt=`const AUTOMATION_RECIPE =`,it=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
2
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
3
|
// here the editor could re-open this block and overwrite everything below.`;function at(e){return e.includes(rt)}function ot(e){let t=e.indexOf(rt);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function st(e){let t=ot(e);if(t===null)return{ok:!1,reason:J.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:J.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=M.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?J.t(`helpers.recipeFromCode.schemaMismatch`):J.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function ct(e){let t=ot(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${it}${e.slice(i)}`}u();var lt=6e4;function ut(){let e=De({projection:`slim`});return r(()=>(e.data??[]).filter(e=>ie(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function dt(e){let t=x();return l({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:lt,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function ft(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Z({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function pt(e){let t=dt(e.deviceId);if(t.data!==void 0)return ft(t.data,e.cap).find(t=>t.path===e.fieldPath)}function mt({value:t,devices:n,onChange:r}){let{t:i}=Y(),a=dt(t.deviceId),s=a.data??[],c=ft(s,t.cap);return e(f,{children:[e(`label`,{className:`min-w-[10rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.device`,`Device`)}),o(K,{value:String(t.deviceId),onChange:e=>r({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:i(`automation.fieldPicker.selectADevice`,`Select a device…`)},...n.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.capability`,`Capability`)}),o(K,{value:t.cap,disabled:t.deviceId===0,onChange:e=>r({...t,cap:e.target.value,fieldPath:``}),options:[{value:``,label:ht(t.deviceId,s.length,a.isLoading)},...s.map(e=>({value:e.cap,label:e.cap}))]})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.field`,`Field`)}),o(K,{value:t.fieldPath,disabled:t.cap===``,onChange:e=>r({...t,fieldPath:e.target.value}),options:[{value:``,label:c.length===0?i(`automation.fieldPicker.noReadableFields`,`No readable fields`):i(`automation.fieldPicker.selectAField`,`Select a field…`)},...c.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function ht(e,t,n){return e===0?J.t(`automation.fieldPicker.pickDeviceFirst`):n?J.t(`automation.fieldPicker.readingDevice`):t===0?J.t(`automation.fieldPicker.noReadableCaps`):J.t(`automation.fieldPicker.selectCap`)}var gt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function _t(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return gt}}function vt(e){switch(e){case`eq`:return J.t(`helpers.recipeParts.op_eq`);case`ne`:return J.t(`helpers.recipeParts.op_ne`);case`gt`:return J.t(`helpers.recipeParts.op_gt`);case`gte`:return J.t(`helpers.recipeParts.op_gte`);case`lt`:return J.t(`helpers.recipeParts.op_lt`);case`lte`:return J.t(`helpers.recipeParts.op_lte`);case`contains`:return J.t(`helpers.recipeParts.op_contains`);default:return J.t(`helpers.recipeParts.op_in`)}}function yt(e){return _t(e).map(e=>({value:e,label:vt(e)}))}function bt(e){switch(e){case`device-state`:return J.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return J.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return J.t(`helpers.recipeParts.trigger_schedule`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var xt={triggers:[],actions:[]};function St(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Ct(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
4
|
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function wt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Tt(){return{kind:`expression`,expr:``,bindings:{}}}function Et(e,t,n){return e.map((e,r)=>r===t?n:e)}function Dt(e,t){return e.filter((e,n)=>n!==t)}function Ot(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Dt(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function kt(e,t){return{...e,triggers:[...t]}}function At(e,t){return{...e,actions:[...t]}}var jt=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function Mt({actions:t,devices:n,devicesState:r=`answered`,onChange:i}){let{t:a}=Y();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:a(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),t.map((s,c)=>e(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:c+1}),e(`label`,{className:`w-40`,children:[o(Z,{children:a(`automation.actionList.step`,`Step`)}),o(K,{value:s.kind,onChange:e=>i(Et(t,c,Ct(Nt(e.target.value)))),options:jt.map(e=>({value:e.value,label:a(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(W,{variant:`ghost`,disabled:c===0,onClick:()=>i(Ot(t,c,c-1)),title:a(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(p,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,disabled:c===t.length-1,onClick:()=>i(Ot(t,c,c+1)),title:a(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(w,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,onClick:()=>i(Dt(t,c)),title:a(`automation.actionList.removeThisStep`,`Remove this step`),children:o(_,{className:`h-3.5 w-3.5`})})]})]}),s.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Z,{children:a(`automation.actionList.seconds`,`Seconds`)}),o(G,{type:`number`,min:0,max:300,value:String(s.seconds),onChange:e=>i(Et(t,c,{kind:`wait`,seconds:Number(e.target.value)}))})]}),s.kind===`code`&&e(`label`,{className:`block`,children:[o(Z,{children:a(`automation.actionList.code`,`Code`)}),o(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:s.code,spellCheck:!1,onChange:e=>i(Et(t,c,{kind:`code`,code:e.target.value}))}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.actionList.codeHint`,components:{code:o(`code`,{})}})})]}),s.kind===`cap`&&o(Ft,{action:s,devices:n,devicesState:r,onChange:e=>i(Et(t,c,e))})]},`${s.kind}-${String(c)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>i([...t,Ct(`cap`)]),children:[o(g,{className:`h-4 w-4`}),` `,a(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function Nt(e){return jt.find(t=>t.value===e)?.value??`cap`}function Pt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function Ft({action:e,devices:t,devicesState:n,onChange:r}){return o(Ze,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:Pt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function It({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=Ht(n,r,i);if(n?.kind===`boolean`)return o(K,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(K,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(G,{type:`number`,value:typeof n==`number`?String(n):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&a(c?c.fromDisplayValue(t):t)}}),c!==void 0&&c.unit.length>0?o(`span`,{className:`text-xs text-foreground-subtle`,children:c.unit}):null]})}return o(G,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Lt({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=Ht(t,n,r);return o(G,{value:(s?e.map(e=>typeof e==`number`?s.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>s?s.fromDisplayValue(e):e):n)}})}function Rt(e){return typeof e==`object`}function zt(e){return Rt(e)?e[0]??``:e}function Bt(e){return Rt(e)?e:typeof e==`boolean`?[]:[e]}function Vt(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Ht(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=Le({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=P(o)?o:void 0,c=Vt(e?.quantity,s);if(c===void 0)return;let l=a?.display;return Ee({quantity:c,display:l,capName:n})}function Ut({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=pt(a),c=yt(s?.kind),l=t.operator===`in`,u=e=>{r({...t,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},d=e=>{let n=Wt(e,c);r({...t,operator:n,value:n===`in`?Bt(t.value):zt(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(mt,{value:a,devices:n,onChange:u}),e(`label`,{className:`min-w-[8rem]`,children:[o(Z,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(K,{value:t.operator,onChange:e=>d(e.target.value),options:c.map(e=>({value:e.value,label:e.label}))})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.conditionRow.value`,`Value`)}),l?o(Lt,{value:Bt(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})}):o(It,{value:zt(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Wt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Gt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Kt({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=Object.entries(t.bindings),s=e=>{r({kind:`expression`,expr:t.expr,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`label`,{className:`block`,children:[o(Z,{children:i(`automation.expressionLeafRow.expression`,`Expression`)}),o(G,{value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:e=>r({kind:`expression`,expr:e.target.value,bindings:t.bindings})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`)})]}),e(`div`,{className:`space-y-1.5`,children:[a.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([e,r])=>o(qt,{alias:e,source:r,devices:n,onRename:n=>s($t(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(en(t.bindings,e))},e)),e(W,{variant:`ghost`,onClick:()=>s({...t.bindings,[Qt(t.bindings)]:Gt}),children:[o(g,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function qt({alias:t,source:n,devices:r,onRename:i,onChange:a,onRemove:s}){let{t:c}=Y(),l=n.kind===`literal`,u=l?{deviceId:0,cap:``,fieldPath:``}:{deviceId:Xt(r,Yt(n)),cap:n.cap,fieldPath:n.fieldPath};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[e(`label`,{className:`w-32`,children:[o(Z,{children:c(`automation.expressionLeafRow.name`,`Name`)}),o(G,{value:t,placeholder:c(`automation.expressionLeafRow.aliasExample`),onChange:e=>i(e.target.value)})]}),e(`label`,{className:`w-36`,children:[o(Z,{children:c(`automation.expressionLeafRow.reads`,`Reads`)}),o(K,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Gt),options:[{value:`global`,label:c(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:c(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),l?e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:c(`automation.expressionLeafRow.constant`,`Constant`)}),o(G,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Jt(e.target.value)})})]}):o(mt,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:Zt(r,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),o(W,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(_,{className:`h-3.5 w-3.5`})})]})}function Jt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Yt(e){return e.kind===`global`?e.sourceStableId:``}function Xt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Zt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Qt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function $t(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function en(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function tn(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:tn(t)?t:{kind:`all`,children:[t]}}function nn(e,t){return t===null||tn(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function rn(e){return nn(e,Q(e))}function an(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?an(e.child,r):null;if(!tn(e))return null;let i=e.children[n];return i===void 0?null:an(i,r)}function on(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=on(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!tn(e))return e;let a=e.children[r];if(a===void 0)return e;let o=on(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function sn(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function cn(e){let t=Q(e);return{depth:t.children.length===0?0:I(t),leaves:t.children.length===0?0:F(t),depthLimit:3,leafLimit:32}}function ln(e,t){let n=sn(t);return n===null?{ok:!0,recipe:nn(e,t)}:{ok:!1,reason:n}}function un(e,t){let n=Q(e);return ln(e,{kind:n.kind,children:[...n.children,t]})}function dn(e,t,n){return nn(e,on(Q(e),t,()=>n))}function fn(e,t){return nn(e,on(Q(e),t,()=>null))}function pn(e,t,n){return nn(e,on(Q(e),t,e=>tn(e)?{kind:n,children:e.children}:e))}function mn(e,t){return an(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:ln(e,on(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function hn(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function gn(e,t,n){if(t.length<2)return{ok:!1,reason:J.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:J.t(`helpers.recipeOps.differentGroups`)};let r=hn(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=an(i,r.path);if(a===null||!tn(a))return{ok:!1,reason:J.t(`helpers.recipeOps.insideNot`)};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:J.t(`helpers.recipeOps.selectedGone`)};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return ln(e,on(i,r.path,()=>d))}function _n(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=an(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return ln(e,on(n,t,()=>r.child));if(!tn(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=hn(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=an(n,i.path);if(a===null||!tn(a))return{ok:!1,reason:J.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return ln(e,on(n,i.path,()=>o))}u();var vn=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function yn(e){return e.join(`/`)}function bn(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function xn({recipe:t,devices:n,onChange:i}){let{t:a}=Y(),[s,l]=c([]),[u,d]=c(null),f=Q(t),p=cn(t),m=r(()=>s.map(bn),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},_=gn(t,m,`all`),v=gn(t,m,`any`),y=m.length===1?mn(t,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},b={devices:n,selected:new Set(s),onToggleSelect:e=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(e,n)=>i(dn(t,e,n)),onRemove:e=>{l([]),i(fn(t,e))},onSetKind:(e,n)=>i(pn(t,e,n)),onUngroup:e=>h(_n(t,e))};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),o(`div`,{className:`w-32`,children:o(K,{value:f.kind,onChange:e=>i(pn(t,[],Sn(e.target.value))),options:vn.map(e=>({value:e.value,label:a(e.labelKey)}))})}),o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),f.children.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):o(Cn,{container:f,path:[],handlers:b}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>h(un(t,wt())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(g,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(W,{variant:`outline`,onClick:()=>h(un(t,Tt())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(le,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(W,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):_.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(W,{variant:`ghost`,disabled:!v.ok,onClick:()=>h(v),title:v.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):v.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),o(W,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),s.length>0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),u!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:u})]})}function Sn(e){return e===`any`?`any`:`all`}function Cn({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(wn,{node:e,path:[...t,r],handlers:n},yn([...t,r])))})}function wn({node:t,path:n,handlers:r}){let{t:i}=Y(),a=yn(n),s=o(Te,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return tn(t)?e(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(`div`,{className:`w-32`,children:o(K,{value:t.kind,onChange:e=>r.onSetKind(n,Sn(e.target.value)),options:vn.map(e=>({value:e.value,label:i(e.labelKey)}))})}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[o(ue,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.ungroup`)]}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(Cn,{container:t,path:n,handlers:r})})]}):t.kind===`not`?e(`div`,{className:`rounded border border-border p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(q,{variant:`warning`,children:`NOT`}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[o(ue,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(wn,{node:t.child,path:[...n,0],handlers:r})})]}):e(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[o(`div`,{className:`pt-6`,children:s}),o(`div`,{className:`min-w-0 flex-1`,children:t.kind===`condition`?o(Ut,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(Kt,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)})}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(_,{className:`h-3.5 w-3.5`})})]})}u();function Tn({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=T(),f=async()=>{await d({title:s(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:s(`automation.generatedCodePanel.theRecipeIsRemovedFrom`,`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`),confirmLabel:s(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:s(`automation.generatedCodePanel.keepItVisual`,`Keep it visual`),variant:`warning`})&&a()};return e(`div`,{className:`rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[e(W,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?h:y,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),e(W,{className:`ml-auto`,variant:`ghost`,disabled:!r||t===null||i,onClick:()=>void f(),title:r?s(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):s(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[o(de,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),l&&o(`div`,{className:`border-t border-border p-3`,children:t===null?o(`p`,{className:`text-xs text-warning`,children:n??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):o(Me,{maxHeight:420,children:t})})]})}var En=[`device-state`,`device-event`,`schedule`,`manual`],Dn=Object.values(te).sort((e,t)=>e.localeCompare(t));function On({triggers:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:i(`automation.triggerEditor.noTriggersYetWithoutOne`,`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`)}),t.map((e,i)=>o(kn,{trigger:e,devices:n,position:i,onChange:e=>r(Et(t,i,e)),onRemove:()=>r(Dt(t,i))},`${e.kind}-${String(i)}`)),e(W,{variant:`outline`,onClick:()=>r([...t,St(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(g,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function kn({trigger:t,devices:n,position:r,onChange:i,onRemove:a}){let{t:s}=Y();return e(`div`,{className:`rounded border border-border p-3`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:r===0?s(`automation.triggerEditor.when`,`When`):s(`automation.triggerEditor.orWhen`,`or when`)}),e(`label`,{className:`min-w-[13rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.trigger`,`Trigger`)}),o(K,{value:t.kind,onChange:e=>i(St(An(e.target.value))),options:En.map(e=>({value:e,label:bt(e)}))})]}),o(W,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(_,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o(Mn,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(Pn,{trigger:t,devices:n,onChange:i}),t.kind===`schedule`&&e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(G,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>i({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]}),t.kind===`manual`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})]})]})}function An(e){return En.find(t=>t===e)??`manual`}function jn(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Mn({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=pt(a),c={...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}};return e(f,{children:[o(mt,{value:a,devices:n,onChange:e=>r(jn(e,c))}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),e(`div`,{className:`flex items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Te,{checked:t.becomes===void 0,onChange:e=>r(jn(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(It,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(jn(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Te,{checked:t.edge===!0,onChange:e=>r(jn(a,{...c,...e.target.checked?{edge:!0}:{edge:void 0}}))}),i(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.heldForS`,`Held for (s)`)}),o(G,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(jn(a,{...c,forMs:Nn(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(G,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(jn(a,{...c,debounceMs:Nn(e.target.value)}))})]})]})}function Nn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Pn({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(f,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(K,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...Dn.map(e=>({value:e,label:e}))]})]}),e(`label`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(K,{value:t.deviceId===void 0?``:String(t.deviceId),onChange:e=>r({kind:`device-event`,category:t.category,...e.target.value===``?{}:{deviceId:Number(e.target.value)}}),options:[{value:``,label:i(`automation.triggerEditor.anyDevice`,`Any device`)},...n.map(e=>({value:String(e.id),label:e.name}))]})]})]})}u();var Fn=`hub`;function In({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=Y(),[p,m]=c(t?.name??``),[h,g]=c(()=>rn(n)),[_,v]=c(!1),y=ut(),b=L(h),x=r(()=>Rn(h),[h]),C=r(()=>zn(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),w=p.trim()===``,T=w||b!==null||x!==null||C.code===null;return e(`div`,{className:`space-y-4`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:`info`,children:f(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(G,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(Ln,{step:`1`,title:f(`automation.automationEditor.when`,`When`),subtitle:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(On,{triggers:h.triggers,devices:y,onChange:e=>g(kt(h,e))})}),o(Ln,{step:`2`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),subtitle:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:o(xn,{recipe:h,devices:y,onChange:g})}),o(Ln,{step:`3`,title:f(`automation.automationEditor.then`,`Then`),subtitle:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Mt,{actions:h.actions,devices:y,onChange:e=>g(At(h,e))})}),o(Tn,{code:C.code,error:C.error,canEject:t!==null,ejecting:s,onEject:u}),b!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),a!==null&&o(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{onClick:()=>{C.code!==null&&l({name:p.trim(),code:C.code,enabled:t?.enabled??!0,placement:Fn})},disabled:i||T,children:[i&&o(S,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(W,{variant:`ghost`,onClick:()=>v(!_),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[o(k,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(W,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),w&&o(q,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&t!==null&&e(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:V(t.id)},components:{code:o(`code`,{})}})}),o(Ae,{addonId:V(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Ln({step:t,title:n,subtitle:r,children:i}){return e(`section`,{className:`border-l-2 border-border pl-4`,children:[e(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[o(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:t}),o(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:n}),o(`span`,{className:`text-xs text-foreground-subtle`,children:r})]}),i]})}function Rn(e){let t=M.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?J.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function zn(e,t){try{return{code:re({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Bn(e){if(!e.enabled)return{tone:`idle`,label:J.t(`helpers.coreBlockStatus.disabled`),detail:J.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:J.t(`helpers.coreBlockStatus.running`),detail:J.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??J.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??J.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??J.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function Vn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Hn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Un(e){let t=e=>{let t=Bn(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function Wn(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>Bn(e).tone===`error`).length,n=e.filter(e=>Bn(e).tone===`ok`).length,r=[J.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(J.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(J.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}function Gn({block:t,busy:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onDelete:l}){let u=C(),{t:d}=Y(),f=Bn(t),p=_e(t.updatedAt,u);return e(`li`,{className:`flex flex-col gap-2 p-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:Vn(f.tone),children:f.label}),p!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:d(`common.edited`,{when:p})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:f.detail}),i!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:d(`automation.editor.listUnreadable`,{reason:i})})]}),e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a()},disabled:i!==null,title:i===null?d(`common.edit`,`Edit`):d(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:o(b,{className:`h-4 w-4`})}),e(Ie,{children:[o(Ne,{children:o(W,{variant:`ghost`,disabled:!0,title:d(`automation.automationList.runActions`,`Run actions`),children:o(v,{className:`h-4 w-4`})})}),o(Re,{children:d(`automation.automationList.runningAnAutomationByHand`,`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`)})]}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:d(`automation.automationList.logs`,`Logs`),children:o(k,{className:`h-4 w-4`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),s(!t.enabled)},disabled:n,title:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`),children:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:d(`common.delete`,`Delete`),children:o(_,{className:`h-4 w-4`})})]})]}),r&&e(`div`,{className:`rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:V(t.id)},components:{code:o(`code`,{})}})}),o(Ae,{addonId:V(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Kn({onCreate:t}){let{t:n}=Y();return o(ke,{children:e(`div`,{className:`space-y-2 p-4`,children:[o(`p`,{className:`text-sm text-foreground`,children:n(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),o(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:n(`automation.automationList.anAutomationIsATrigger`,`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`)}),o(W,{onClick:t,children:n(`automation.automationList.newAutomation`,`New automation`)})]})})}u();var qn=[`coreBlocks`,`list`],Jn=5e3;function Yn(e){return e instanceof Error?e.message:String(e)}function Xn({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:f}){let{t:p}=Y(),m=x(),{state:h,openNew:g,openEdit:_,close:v}=je({editKey:`block`,newKey:`new`}),[y,b]=c(null),S=T(),[C,w]=c(null),D=n(null),O=h.mode!==`closed`;s(()=>{u&&(b(null),g(),a?.(null),f?.())},[u,f,a,g]);let k=l({queryKey:qn,refetchInterval:Jn,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),A=()=>{k.refetch()},j=k.data;s(()=>{i===void 0||D.current===i||j?.find(e=>e.id===i&&at(e.code))!==void 0&&(D.current=i,_(i),a?.(i))},[i,j,_,a]);let M=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),A()}}),N=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),A()}}),P=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:A}),F=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:A}),I=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:ct(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),b(null),A(),t(e.block.id)}}),L=k.data,R=Un((L??[]).filter(e=>at(e.code))),ee=L!==void 0&&R.length===0,z=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,B=h.mode===`new`||z===null?null:Hn(R,z),V=B===null?null:st(B.code),te=M.error===null?N.error===null?I.error===null?null:Yn(I.error):Yn(N.error):Yn(M.error),ne=r(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=st(e.code);return o(`ul`,{className:`list-none`,children:o(Gn,{block:e,busy:F.isPending||P.isPending,logsOpen:C===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{b(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>w(C===e.id?null:e.id),onDelete:()=>{S({title:p(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:p(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&P.mutate(e.id)})}})})},sortValue:e=>e.name}],[S,C,a,_,P,F,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:Wn(R)}),k.error!=null&&o(U,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Yn(k.error),onRetry:A}),ee?o(Kn,{onCreate:()=>{b(null),g(),a?.(null)}}):o(Ce,{columns:ne,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:fe,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{b(e),_(e.id),a?.(e.id)}}),o(Fe,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)},title:B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name}),icon:E,width:`xl`,testId:`automation-editor-panel`,children:o(In,{existing:B,initialRecipe:V!==null&&V.ok?V.recipe:xt,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)}},B?.id??`new`)}),P.error!=null&&o(U,{message:Yn(P.error)}),F.error!=null&&o(U,{message:Yn(F.error)})]})}u();function Zn({mode:e,onTitle:t}){return o(e===`helper`?Qn:$n,{onTitle:t})}function Qn({onTitle:e}){let{t}=Y(),n=Je(),r=me(),i=Se(),a=we({addonId:`composer`}),[l,u]=c(null),d=tr(l,t);return s(()=>{e(d)},[e,d]),o(`div`,{className:`flex flex-col gap-3`,"data-testid":`composition-create-form`,children:o(et,{purpose:`create`,initial:null,start:`template`,saving:r.isPending,onDraftChange:u,onSave:async(e,o)=>{let s=null,c=await $e(e,async(e,c)=>{let{block:l}=await r.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:e}}),u=await nr(l.id,async()=>(await a.refetch()).data??a.data);if(u===null)throw Error(t(`helper.devicePending`));s=u,c!==``&&await i.mutateAsync({deviceId:u,name:c}),o===`open`&&n(Ke(u),{replace:!0})}),l=s;return c.length>0||l===null?{kind:`refused`,lines:rr(c,t)}:{kind:`saved`,deviceId:l}}})})}function $n({onTitle:t}){let{t:n}=Y(),r=C(),i=Je(),a=me(),l=Se(),u=we({addonId:`composer`}),[d,f]=c(ne.Sensor),[p,m]=c(R.TemperatureSensor),[h,g]=c(``),[_,v]=c(null),y=Qe({type:d,role:p});return s(()=>{t(n(`helper.newComposition`))},[t,n]),e(`div`,{className:`flex flex-col gap-3`,"data-testid":`blank-composition-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(K,{value:d,onChange:e=>{let t=Object.values(ne).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(ne).map(e=>({value:e,label:Oe(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.identity.role`),o(K,{value:p??``,onChange:e=>m(Object.values(R).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(R).map(e=>({value:e,label:Be(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(G,{"aria-label":n(`compositionEditor.name`),value:h,onChange:e=>g(e.target.value)})]})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(W,{disabled:y===null||a.isPending,onClick:()=>{y!==null&&er({composition:y,name:h,create:e=>a.mutateAsync({block:e}),rename:(e,t)=>l.mutateAsync({deviceId:e,name:t}),readFleet:async()=>(await u.refetch()).data??u.data,onError:e=>v(e),onOpen:e=>i(qe(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function er(e){e.onError(null);try{let t=e.name.trim(),{block:n}=await e.create({...t===``?{}:{name:t},enabled:!0,composition:e.composition}),r=await nr(n.id,e.readFleet);if(r===null){e.onError(e.pending);return}t!==``&&await e.rename(r,t),e.onOpen(r)}catch(t){e.onError(t instanceof Error?t.message:String(t))}}function tr(e,t){if(e===null)return t(`helper.newHelper`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);if(e.templateId===`appliance`&&e.appliance!==null)return t(`helper.newTitle.${e.appliance}`);if(e.templateId===`appliance`)return t(`helper.newHelper`);let n=oe(e.templateId);return t(n===null?`helper.newHelper`:`helper.newTitle.${n.id}`)}async function nr(e,t){let n=`${ae}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}function rr(e,t){return e.length>0?e:tt(t(`helper.devicePending`))}function ir(e){return{state:`answered`,byRef:new Map(e.map(e=>[B(e),e]))}}function ar(e,t){if(e.state!==`unanswered`)return e.byRef.get(B(t))??null}function or(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function sr(e){return N(e).map(e=>e.source)}function cr(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...sr(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...sr(e))}let r=new Set;return n.filter(e=>{let t=B(e);return r.has(t)?!1:(r.add(t),!0)})}function lr(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:J.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[J.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[J.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??J.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function ur(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return lr(e);case`degraded`:return{tone:`pending`,label:J.t(`helpers.compositionRows.degraded`),reason:n??J.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:J.t(`helpers.compositionRows.failed`),reason:n??J.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:J.t(`helpers.compositionRows.notRunning`),reason:n??J.t(`helpers.compositionRows.notRunningReason`)}}}function dr(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:J.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:J.t(`helpers.compositionRows.unknown`),reason:J.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return ur(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.notReported`),reason:J.t(`helpers.compositionRows.noRecord`,{stored:r})}}function fr(e){return B(e)}function pr(e,t){let n=ar(t,e);return{key:B(e),label:n?n.name:fr(e),presence:or(n),deviceId:n?n.id:null}}function mr(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function hr(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:j(e.block.id),a=B(i),o=cr(e).filter(e=>B(e)!==a).map(e=>pr(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=ar(t,i),l=mr(e),u=dr(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=or(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:fr(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function gr(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function _r(e,t){return gr(e)-gr(t)||e.name.localeCompare(t.name)}function vr(e,t){let n=e.flatMap(e=>{let n=hr(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(_r),customizations:n.filter(e=>e.kind===`customization`).toSorted(_r)}}u();var yr=1e4;function br(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function xr(){let e=Ye();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:br(e.error)})}:ir(e.data)}function Sr(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function Cr({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=Ge(),s=ve({},{refetchInterval:yr}),l=xr(),u=je({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,p=d===null?Sr(i.get(`new`),t):null,m=p!==null,[h,g]=c(``),_=T(),v=pe(),y=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},b=s.data;return e(f,{children:[Tr(b,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e),deleting:v.isPending,onDelete:e=>{_({title:r(`build.customDeviceTab.deleteThisComposedDevice`,`Delete this composed device?`),message:r(`build.customDeviceTab.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&v.mutate({blockId:e.blockId},{onSuccess:()=>void s.refetch()})})}}),o(Fe,{open:m||d!==null,onClose:y,title:m?h||r(p===`blank`?`helper.newComposition`:`helper.newHelper`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:se,width:`xl`,testId:`composed-device-editor`,children:m&&p!==null?o(Zn,{mode:p,onTitle:g},p):d===null?null:o(nt,{blockId:d})}),v.error!=null&&o(U,{message:br(v.error)})]})}function wr(t){return o(ke,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:J.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[J.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function Tr(e,t,n,r,i){if(t!=null&&e===void 0)return o(U,{title:J.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:br(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:J.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return wr(e.reason);let a=t==null?null:br(t);return o(Er,{lists:vr(e.views,r),fleet:r,refreshError:a,handlers:i})}function Er({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=Y();return e(`div`,{className:`space-y-4`,children:[r!==null&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,r]}),n.state===`unanswered`&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,n.reason,`. No source is marked missing until it has.`]}),o(Dr,{title:a(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:a(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:t.composed,nameHeader:`Name`,emptyMessage:a(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,handlers:i}),o(Dr,{title:a(`build.customDeviceTab.customizations`,`Customizations`),hint:a(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:t.customizations,nameHeader:`Device`,emptyMessage:a(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,handlers:i})]})}function Dr({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=Y();return e(`section`,{className:`space-y-2`,"aria-label":t,children:[e(`div`,{children:[o(`h3`,{className:`font-medium`,children:t}),o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(Ce,{columns:Or(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:fe,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function Or(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(kr,{row:e})},{key:`type`,header:J.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??J.t(`common.unknownWord`)})},{key:`state`,header:J.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:t=>e(`div`,{className:`space-y-0.5`,children:[o(q,{variant:Vn(t.state.tone),children:t.state.label}),t.state.reason!==null&&o(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:t.state.reason})]})},{key:`sources`,header:J.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(jr,{sources:e.sources})}];return n===`composed`&&a.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:t=>e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(W,{variant:`ghost`,title:i(`common.delete`,`Delete`),disabled:r.deleting,"aria-label":i(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),r.onDelete(t)},children:o(_,{className:`h-4 w-4`})})]})}),a}function kr({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(Ar,{row:t}),t.namePresence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`build.customDeviceTab.deviceMissing`,`device missing`)}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:t.features.join(`, `)})]})}function Ar({row:e}){let{t}=Y(),n=ge(e.reportedDeviceId??0,`compact`,e.name),r=e.reportedDeviceId===null?e.name:n;return e.reportedDeviceId===null?e.kind===`composed`?o(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):o(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:r})}):o(We,{to:e.kind===`composed`?Ke(e.reportedDeviceId):qe(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function jr({sources:t}){let{t:n}=Y();return t.length===0?o(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):o(`ul`,{className:`space-y-0.5`,children:t.map(t=>e(`li`,{className:`text-xs`,children:[t.deviceId===null?o(`span`,{className:t.presence===`missing`?`text-danger`:`text-foreground`,children:t.label}):o(We,{to:`/devices/${String(t.deviceId)}`,className:`hover:underline`,children:t.label}),t.presence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`common.missing`)})]},t.key))})}function Mr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Nr(e){if(Array.isArray(e))return e}function Pr(e,t,n){return(t=Ur(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Fr(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Ir(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|