@camstack/addon-admin-ui 1.2.480 → 1.2.482
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-Dl8uxsbh.js → AddonAssetIcon-5z0Vljts.js} +1 -1
- package/dist/assets/Addons-CZCGnQMQ.js +5 -0
- package/dist/assets/{AdminPage-CSXKwqkg.js → AdminPage-BGeHUp9l.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BKgqha3i.js → AdminSectionedPage-DDyHO_ip.js} +1 -1
- package/dist/assets/AiProfiles--zkaLy_B.js +3 -0
- package/dist/assets/{BrokerForm-DXNZ4XDs.js → BrokerForm-B2kpU1t2.js} +1 -1
- package/dist/assets/Build-rWgY-SZM.js +40 -0
- package/dist/assets/{Calendars-BMYW6Lcd.js → Calendars-iNmeiE9F.js} +1 -1
- package/dist/assets/{Cluster-DcCFmoWl.js → Cluster-VomkBaK2.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-CS7j_Q0n.js → CompositionBlockEditor-BkEr_zwe.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BzXIuasc.js → CompositionEditorPage-DbJxXBa9.js} +1 -1
- package/dist/assets/Data-CCEKKeDE.js +2 -0
- package/dist/assets/{DeviceDetail-DTa2bPN4.js → DeviceDetail-D9LiDoGw.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-C0BliAs3.js → DeviceDoActionFields-CLGT6wrU.js} +1 -1
- package/dist/assets/{Devices-BF451zpL.js → Devices-CeNeFo6w.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BYk9lSle.js → EmbedPlayerPage-DhPeEblh.js} +1 -1
- package/dist/assets/HelperWizard-Uk1HvQ9Z.js +2 -0
- package/dist/assets/{History-DwCuiCyt.js → History-BSXemVAg.js} +1 -1
- package/dist/assets/Identity-DUUQUaLn.js +1 -0
- package/dist/assets/IntegrationDetail-Cg5a23zE.js +1 -0
- package/dist/assets/{IntegrationHub-CurQ0MIP.js → IntegrationHub-C0mqR6_4.js} +1 -1
- package/dist/assets/Integrations-B7G_Cpwv.js +1 -0
- package/dist/assets/Integrations-J8r1M--P.js +1 -0
- package/dist/assets/{Library-DP1Wr2c7.js → Library-B32BJFM3.js} +1 -1
- package/dist/assets/Locations-qBrWJ5eA.js +3 -0
- package/dist/assets/{Logs-Bd5V0nh-.js → Logs-Bdustfdg.js} +1 -1
- package/dist/assets/MyAccess-BkcUaVmh.js +2 -0
- package/dist/assets/Network-BrDFqhC5.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-DkJRjjUs.js → NodeAddonsSettingsPanel-DsSbHT51.js} +1 -1
- package/dist/assets/{Notifications-BKotbSiz.js → Notifications-BPK2WNL-.js} +1 -1
- package/dist/assets/{Pipeline-DdvNlpdi.js → Pipeline-CNlBiPEC.js} +1 -1
- package/dist/assets/Recordings-BrCuLKqt.js +1 -0
- package/dist/assets/{ScanNetworkModal-DoDbqBMU.js → ScanNetworkModal-tiMZttK7.js} +1 -1
- package/dist/assets/SessionsList-fLonifFr.js +2 -0
- package/dist/assets/{Showroom-DX5blOP5.js → Showroom-BuzmfCLW.js} +1 -1
- package/dist/assets/{System-Cj0zNzyx.js → System-B5axMnbq.js} +1 -1
- package/dist/assets/{Terminal-CrQfybLK.js → Terminal-BxmZLjAl.js} +3 -3
- package/dist/assets/{Viewer-NPWQx4Po.js → Viewer-DKhlTfCg.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-vDZqJbgM.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-ChRFbBue.js} +1 -1
- package/dist/assets/{addon-icons-context-C_QjLbbK.js → addon-icons-context-DY_rAsap.js} +1 -1
- package/dist/assets/{assignment-candidates-B-td3IjI.js → assignment-candidates-BpQXQnWA.js} +1 -1
- package/dist/assets/{authed-media-DmqjjIKA.js → authed-media-vxjhgNZq.js} +1 -1
- package/dist/assets/{board-model-j7i6ZAYf.js → board-model-BpmGz42d.js} +1 -1
- package/dist/assets/{device-integration-icon-Ch_ZPOzM.js → device-integration-icon-CPDmGsoD.js} +1 -1
- package/dist/assets/device-picker-model-Z8NhIJHV.js +1 -0
- package/dist/assets/{format-uKtM7bQx.js → format-D4oZ2Oti.js} +1 -1
- package/dist/assets/{hostInit-BW_Uzp68.js → hostInit-DVizgo6V.js} +1 -1
- package/dist/assets/i18n-DRa6-1Ye.js +1 -0
- package/dist/assets/index-BO95XcLa.js +4 -0
- package/dist/assets/{linked-devices-model-ou0VkTvM.js → linked-devices-model-Cnqr55pr.js} +1 -1
- package/dist/assets/{location-owned-usage-CQzY3VS7.js → location-owned-usage-pJJy4BTC.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a83f6fea.js → mf-entry-bootstrap-0-be603f7b.js} +2 -2
- package/dist/assets/mount-Z8NhIJHV.js +1 -0
- package/dist/assets/remoteEntry-ClU628tf.js +1 -0
- package/dist/assets/{src-Kh1mC91U.js → src-BZ8j9Q2T.js} +9 -9
- package/dist/assets/{step-inspector-model-X_yncKWE.js → step-inspector-model-BvwTAgYG.js} +1 -1
- package/dist/assets/{use-scenes-feed-tvKKb38m.js → use-scenes-feed-16-Xn-4f.js} +1 -1
- package/dist/assets/{use-stationary-objects-CXoxdg6S.js → use-stationary-objects-Dfi4P7en.js} +1 -1
- package/dist/assets/useEventInvalidation-Z8NhIJHV.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BKeCycvy.js → useNodeUrlSelection-C6820-b7.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qrmMxESr.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D6C0Wijv.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-D0-Lkqak.js +0 -5
- package/dist/assets/AiProfiles-PVMMhQkj.js +0 -3
- package/dist/assets/Build-CoXA7FyI.js +0 -40
- package/dist/assets/Data-xdGxogBF.js +0 -2
- package/dist/assets/HelperWizard-Dne7XMRs.js +0 -2
- package/dist/assets/Identity-BxOtJf9f.js +0 -1
- package/dist/assets/IntegrationDetail-CNdjHgkg.js +0 -1
- package/dist/assets/Integrations-BDnjzX7X.js +0 -1
- package/dist/assets/Integrations-CkJHWfhP.js +0 -1
- package/dist/assets/Locations-J4ikH0b7.js +0 -3
- package/dist/assets/MyAccess-BjobXXGx.js +0 -2
- package/dist/assets/Network-xmsnvwQH.js +0 -1
- package/dist/assets/Recordings-Bc6TV4zS.js +0 -1
- package/dist/assets/SessionsList-Ci2UotT9.js +0 -2
- package/dist/assets/device-picker-model-Ch3e43SQ.js +0 -1
- package/dist/assets/i18n-D1Cc22Zf.js +0 -1
- package/dist/assets/index-C8EgBFV_.js +0 -4
- package/dist/assets/mount-Ch3e43SQ.js +0 -1
- package/dist/assets/remoteEntry-Bisv2xsg.js +0 -1
- package/dist/assets/useEventInvalidation-Ch3e43SQ.js +0 -1
|
@@ -1,5 +0,0 @@
|
|
|
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{It as d,Nt as f,Ot as p,Q as m,Rn as h,Si as g,Tn as _,Wr as v,ai as y,bn as b,dt as x,fn as S,or as C,pi as ee,pn as w,tn as T,un as E,vi as te,xi as D}from"./player-overlays-By2E2OWX.js";import{Pa as ne}from"./client-COfGFdJB.js";import{i as O,l as re}from"./video-DKRf0Ic4.js";import{$r as k,$s as ie,$u as ae,Ai as oe,Bn as A,Di as j,Ei as M,Fi as se,Hn as N,Ii as P,Ju as F,Kr as I,Li as ce,Mi as L,Ni as le,Oi as ue,Si as R,Ti as de,Un as z,Ur as B,Vn as V,Wr as fe,_i as pe,_r as me,bi as H,bt as U,gi as he,hd as W,hi as ge,hr as G,ji as _e,kt as ve,mr as K,nn as ye,pi as be,pr as q,tn as xe,vd as Se,vi as Ce,vr as we,wi as Te,xi as Ee,yi as De,yr as J}from"./src-Kh1mC91U.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import"./mount-Ch3e43SQ.js";import{gr as Oe,mr as X,ur as Z}from"./index-C8EgBFV_.js";import{t as ke}from"./AdminPage-CSXKwqkg.js";import{t as Ae}from"./NodeAddonsSettingsPanel-DkJRjjUs.js";import{n as Q,t as je}from"./useNodeUrlSelection-BKeCycvy.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:C,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:b,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:g,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}=Y(),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}=de({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=Se(ne.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:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:C,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:g,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}=Y(),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
|
-
`)}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
|
-
`)}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
|
-
`)}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}=Y(),c=l(),u=fe(),f=B(),p=Te(Je,{staleTime:Ye}),m=p.data?.installations??[],h=(p.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=P({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await f({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 f({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 p.refetch()).data;if(t===void 0){await f({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(d,{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(re,{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}=Y(),f=r===`upload`||r===`local`,[m,h]=s(!1),{data:_,isLoading:y,isError:b}=H({name:e}),S=_?$e(_,m):[],ee=_?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(x,{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(p,{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(Z,{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(C,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),b&&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.`)}),S.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:S.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(g,{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&&!b&&_&&_.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),ee>0&&a(I,{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:()=>h(e=>!e),children:m?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:ee})})]})}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?m(`/api/addon-assets/${r}/${i}`):null,g=!!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:g?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?h:_,{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(p,{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:d}=Y();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(C,{className:`h-3 w-3 animate-spin`}),d(`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:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(v,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`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:d(`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`}=he({addonId:e}),r=L({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:d,jobProgress:f,bundle:p,bulkItem:m,disabledByBulk:g,isSystem:_,selectedNode:v}){let{t:y}=Y(),[S,C]=s(!1),[ee,T]=s(!1),[ne,re]=s(null);o(()=>{re(null)},[i]);let k=ne??i,[ie,ae]=s(!1),[A,j]=s(!1),[M,se]=s(`logs`),N=l(),P=X(),{manifest:F}=e,ce=!p&&!F.protected&&F.removable!==!1,L=!!p,le=p?.displayName??F.name,R=p?.packageName??F.packageName,de=p?.version??F.packageVersion??F.version,z=p?.installSource??e.installSource,B=p?p.bundle?.description??p.addons[0]?.manifest.description:F.description,V=ue({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]})}}),fe=Ee({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]}),N.invalidateQueries({queryKey:[[`integrations`]]})}}),pe=oe({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`alerts`]]})}}),H=e.health,U=H?.phase===`failed`&&!H.inGracePeriod,he=U&&H?.nextRetryAt&&!H.retrying,W=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:y(`addons.addonCard.failedToLoad`,{attempt:H.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:H.lastError?.message??y(`addons.addonCard.unknownError`,`Unknown error`)}),he&&H.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:y(`addons.addonCard.autoRetryAt`,{time:new Date(H.nextRetryAt).toLocaleTimeString()})})]}),t(`button`,{type:`button`,disabled:pe.isPending||H.retrying,onClick:e=>{e.stopPropagation(),pe.mutate({packageName:R})},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:y(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(b,{className:`h-3 w-3 ${pe.isPending||H.retrying?`animate-spin`:``}`}),y(`addons.addonCard.retryNow`,`Retry now`)]})]}),W!==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:y(`addons.addonCard.processProblem.${W.kind}`)}),W.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:W.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(at,{isBundle:L||!!F.components&&F.components.length>1,installSource:z,addonId:L?p.addons[0]?.manifest.id:F.id,iconPath:L?p.bundle?.icon??p.addons[0]?.manifest.icon:F.icon,color:L?p.addons[0]?.manifest.color:F.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:le}),!r&&a(ot,{version:de,availableUpdate:i,...k===void 0?{}:{selectedVersion:k},isUpdating:d,installSource:z,disabled:g,...c&&k!==void 0?{onUpdate:()=>c(k)}:{},onOpenPicker:()=>T(e=>!e),children:ee&&a(tt,{packageName:R,currentVersion:de,...z?{installSource:z}:{},...i!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{re(e),T(!1)}}:{},onInstall:e=>{T(!1),fe.mutate({packageName:R,version:e})},onClose:()=>T(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[R!==le&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:R}),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(h,{className:`h-3 w-3`}),p.addons.length]}),_&&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:y(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(b,{className:`h-3 w-3`}),y(`addons.addonCard.system`,`System`)]}),m!=null&&a(Pe,{item:m}),f!=null&&a(Ve,{progress:f})]}),B&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:B}),!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`?y(`addons.addonCard.forked`):y(`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`:W===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(),V.mutate({addonId:F.id})},disabled:V.isPending||g,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(b,{className:`h-3 w-3 ${V.isPending?`animate-spin`:``}`}),y(`addons.addonCard.restart`,`Restart`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ae(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ie?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(w,{className:`h-3 w-3`}),y(`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 ${A?`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(E,{className:`h-3 w-3`}),y(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),ce&&a(Ze,{packageName:F.packageName,displayName:F.name,selectedNode:v??ct,disabled:g})]}),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:y(`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:y(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:y(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:y(`common.synced`)})]},e.nodeId))})]}),ie&&!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:()=>se(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:y(`addons.addonCard.logs`,`Logs`)}),a(`button`,{type:`button`,onClick:()=>se(`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:y(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ae(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(x,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&a(ye,{addonId:F.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&a(xe,{addonId:F.id,category:`addon.*`,maxHeight:`max-h-64`})]}),L&&t(u,{children:[a(`button`,{type:`button`,onClick:()=>C(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(S?te:D,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),S&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:p.addons.map(e=>a(lt,{addon:e,hideVersion:!0},e.manifest.id))})]}),A&&!L&&a(q,{open:!0,onOpenChange:e=>!e&&j(!1),children:t(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(we,{children:t(J,{className:`flex items-center gap-2`,children:[a(E,{className:`h-4 w-4 text-primary`}),y(`addons.addonCard.settingsTitle`,{name:le})]})}),t(K,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:y(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Ae,{nodeId:null,addonIds:[F.id],level:`global`,fieldScope:`cluster`,emptyMessage:y(`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(F)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.deviceExport`,`Device export`)}),a(ve,{addonId:F.id,onOpenDevice:e=>P(`/devices/${e}`)})]}),it(z)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(st,{addonId:F.id})]}),F.components&&F.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.components`,{count:F.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:F.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(me,{children:a(I,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:y(`common.close`,`Close`)})})]})})]})}c();var ut=`.tgz,.tar.gz,.zip`;function dt({onUploadSuccess:e}){let{t:r}=Y(),[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(m(`/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(C,{className:`w-3.5 h-3.5 animate-spin`}):a(p,{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(`
|
|
5
|
-
`),r=[],i=[],o=[],s=0,c=()=>{if(i.length===0)return;let e=i.join(` `).trim();i=[],e.length!==0&&(r.push(a(`p`,{className:`mb-2 last:mb-0`,children:ht(e,`${t}-p-${s}`)},`${t}-p-${s}`)),s+=1)},l=()=>{if(o.length===0)return;let e=o;o=[],r.push(a(`ul`,{className:`mb-2 list-disc pl-4 last:mb-0`,children:e.map((e,n)=>a(`li`,{children:ht(e,`${t}-li-${s}-${n}`)},`${t}-li-${s}-${n}`))},`${t}-ul-${s}`)),s+=1};for(let e of n){let n=/^(#{1,3})\s+(.*)$/.exec(e),u=/^\s*[-*]\s+(.*)$/.exec(e);if(n){c(),l();let e=n[1]?.length??1,i=ht(n[2]??``,`${t}-h-${s}`),o=e===1?`text-sm font-semibold mb-2`:`text-xs font-semibold mb-1.5 mt-2`;r.push(a(e===1?`h3`:`h4`,{className:o,children:i},`${t}-h-${s}`)),s+=1;continue}if(u){c(),o=[...o,u[1]??``];continue}if(e.trim().length===0){c(),l();continue}l(),i=[...i,e.trim()]}return c(),l(),r}function _t({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:pt(e).map((e,t)=>e.kind===`code`?a(`pre`,{className:`mb-2 overflow-auto rounded-md bg-surface-hover p-2 font-mono text-[10px] last:mb-0`,children:e.body.replace(/\n$/,``)},`code-${t}`):a(`div`,{children:gt(e.body,`b${t}`)},`text-${t}`))})}c();function vt(e){return e.replace(/^@camstack\/(addon-)?/,``)}function yt(e,t,n){let r=$e(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function bt({pending:e,failed:n,body:r,missing:i}){let{t:o}=Y();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(C,{className:`h-3.5 w-3.5 animate-spin`}),o(`addons.installDialog.loadingDocument`,`Loading…`)]}):n||r===void 0?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.couldNotLoadDocument`,`Could not load this file from the registry.`)}):r.status===`ok`&&r.markdown!==void 0?a(_t,{markdown:r.markdown}):r.status===`error`?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.documentError`,`Could not load this file. {{message}}`,{message:r.message??``})}):a(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:i})}function xt({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=Y(),[l,u]=s(e.version),[d,f]=s(!1),p=H({name:e.name}),m=De({name:e.name,version:l}),h=p.data??[],g=et(h),_=yt(h,l,d),v=m.data;return a(q,{open:!0,onOpenChange:e=>!e&&i(),children:t(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(we,{children:a(J,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:vt(e.name)})})}),t(K,{className:`space-y-3`,children:[a(`p`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.name}),e.description.length>0&&a(`p`,{className:`text-xs text-foreground`,children:e.description}),t(`div`,{className:`space-y-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`addons.installDialog.version`,`Version`)}),a(F,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:_.map(e=>({value:e.version,label:Qe(e)?c(`addons.installDialog.deprecatedVersion`,`{{version}} (deprecated)`,{version:e.version}):e.version})),onChange:e=>u(e.target.value)}),p.isError&&a(`p`,{className:`text-[10px] text-danger`,children:c(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),g>0&&a(I,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto justify-start px-0 text-[10px] font-normal text-foreground-subtle underline`,onClick:()=>f(e=>!e),children:d?c(`addons.versionPicker.hideOlder`,`Hide older versions`):c(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:g})})]}),t(A,{defaultValue:`readme`,children:[t(N,{children:[a(z,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(z,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(V,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(bt,{pending:m.isPending,failed:m.isError,body:v?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(V,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(bt,{pending:m.isPending,failed:m.isError,body:v?.changelog,missing:c(`addons.installDialog.missingChangelog`,`This package has no CHANGELOG.`)})})})]}),r!=null&&r.length>0&&a(`p`,{className:`text-xs text-danger`,children:r})]}),t(me,{children:[a(I,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(I,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(C,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}var St=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function Ct(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||St.has(r.packageName)||!t.isHub&&r.nodeId!==t.id)continue;let e=n.get(r.packageName)??[];e.push(r),n.set(r.packageName,e)}return[...n].map(([e,t])=>({packageName:e,rows:t})).sort((e,t)=>e.packageName.localeCompare(t.packageName))}function wt({selectedNode:e}){let{t:n}=Y(),{data:r}=Te(Je,{staleTime:Ye});if(r===void 0)return null;let i=Ct(r.installations,e),o=r.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return i.length===0&&o.length===0?null:t(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[t(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[a(f,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?n(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):n(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),o.length>0&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`addons.nodeOnlyPackagesPanel.unreachable`,{nodes:o.map(e=>e.nodeId).join(`, `)})}),i.map(n=>t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[t(`div`,{className:`min-w-0`,children:[a(`div`,{className:`text-xs font-mono text-foreground break-all`,children:n.packageName}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),a(Ze,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function Tt({addon:e,installing:n,onInstall:r}){let{t:i}=Y();return t(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[a(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[a(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),t(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),a(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&a(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?a(k,{variant:`success`,icon:a(g,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(I,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(C,{className:`h-3 w-3 animate-spin`}):a(v,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Et({capability:e,installing:n,onInstall:r}){let{t:i}=Y(),{data:o,isPending:s,isError:c}=_e({capability:e}),l;if(c)l=a(`div`,{className:`px-3 py-2 text-xs text-danger`,children:i(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(s||o===void 0)l=t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[a(C,{className:`h-3 w-3 animate-spin`}),i(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let t=o.filter(e=>!e.installed);l=t.length===0?a(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:o.length===0?i(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):i(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):a(`div`,{className:`divide-y divide-border`,children:t.map(e=>a(Tt,{addon:e,installing:n,onInstall:r},e.name))})}return t(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":i(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[a(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:i(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),l]})}c();function Dt(e){return e===`npm`||e===`dev`?e:null}var Ot=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,kt=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,At=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],jt=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function Mt(e){return e!==void 0&&jt.has(e)}var Nt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Pt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ft(e){return e===`local`?`dev`:`npm`}function It(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`,...r.reason===void 0?{}:{reason:r.reason}}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Lt(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Rt({addons:c,clusterStatus:u,selectedNode:d,onRefresh:f,listPhase:p}){let{t:m}=Y(),h=l(),[g,_]=s(``),y=e(g),[x,w]=s(!1),T=n(null);o(()=>{if(!x)return;let e=e=>{T.current&&!T.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[x]);let{data:E}=M({nodeId:d.id}),te=r(()=>{let e=new Map;for(let t of E??[])e.set(t.name,t.latestVersion);return e},[E]),D=r(()=>(E??[]).filter(e=>!e.isSystem).length,[E]),[ne,O]=s(()=>new Set),[re,k]=s(()=>new Map),ie=i(e=>{O(t=>new Set(t).add(e))},[]),oe=i(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),A=i((e,t)=>{k(n=>new Map(n).set(e,t))},[]),j=i(e=>{k(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),N=ce({onMutate:e=>{ie(e.name),j(e.name)},onSuccess:(e,t)=>{oe(t.name);let n=e;if(n&&n.success===!1){A(t.name,n.error??`Update failed (no error message returned by server)`);return}h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{oe(t.name),A(t.name,e instanceof Error?e.message:String(e))}}),P=ze(),F=n(new Set);o(()=>{let e=new Set;for(let[t,n]of P)Le(n)&&e.add(t);let t=[...F.current].some(t=>!e.has(t));F.current=e,t&&(h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[P,h]);let{data:I}=pe(void 0),L=be({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),ue=le({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:R,isFetching:de}=_e({query:y||void 0},{enabled:x}),z=se(),{data:B}=Ce(void 0),V=B?.requestedAt,[me,H]=s(null),[U,he]=s(!1);o(()=>{if(B?.kind===`framework-bulk-update`&&B.requestedAt!==me){H(B.requestedAt),he(!0);let e=window.setTimeout(()=>he(!1),6e3);return()=>window.clearTimeout(e)}},[V,me,B]),fe();let W=i(async()=>{let e=(E??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await N.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await z.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[E,d.id,d.isHub,z,N]),[ge,G]=s(null),[ve,K]=s(null),ye=e=>{K(null),G(e)},q=Ee({onSuccess:()=>{G(null),K(null),h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addonPages`]]}),h.invalidateQueries({queryKey:[[`capabilities`]]}),h.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{K(e instanceof Error?e.message:`Install failed`)}}),[xe,Se]=s(`type`),[we,Te]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),De=e=>{Te(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[J,X]=Oe(),Z=J.get(`capability`),ke=J.get(`updatable`)===`1`,Ae=J.get(`error`)===`1`,Q=Dt(J.get(`source`)),je=i(e=>{let t=new URLSearchParams(J);e?t.set(`updatable`,`1`):t.delete(`updatable`),X(t,{replace:!0})},[J,X]),Ne=i(e=>{let t=new URLSearchParams(J);e?t.set(`error`,`1`):t.delete(`error`),X(t,{replace:!0})},[J,X]),Pe=i(e=>{let t=new URLSearchParams(J);e===null?t.delete(`source`):t.set(`source`,e),X(t,{replace:!0})},[J,X]),Fe=r(()=>c.filter(e=>Me(e.process)!==null).length,[c]),Ie=r(()=>{let e=c.filter(e=>!Mt(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Pt(e.placement,d.isHub))),Z&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),ke&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&te.has(t)})),Q!==null&&(e=e.filter(e=>Ft(e.installSource)===Q)),Ae&&(e=e.filter(e=>Me(e.process)!==null)),e},[c,d.isHub,Z,ke,Q,Ae,te]),Re=()=>{let e=new URLSearchParams(J);e.delete(`capability`),X(e,{replace:!0})},Be=we===`flat`?Ie:Lt(Ie),Ve=r(()=>{let e=[...Be];switch(xe){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Be,xe]);return t(`div`,{className:`space-y-3`,children:[[...re.entries()].map(([e,n])=>a(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:t(`div`,{className:`flex items-start justify-between gap-3`,children:[t(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`font-medium text-danger`,children:m(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(`button`,{type:`button`,onClick:()=>j(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:m(`common.dismiss`)})]})},e)),t(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.sort`,`Sort:`)}),t(`select`,{value:xe,onChange:e=>Se(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[a(`option`,{value:`type`,children:m(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:m(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:m(`admin.system.addons.installSource`,`Install source`)})]})]}),t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.view`,`View:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>a(`button`,{type:`button`,onClick:()=>De(e),className:`px-2 py-1 transition-colors capitalize ${we===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?m(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):m(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(b,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>a(`button`,{type:`button`,onClick:()=>L.mutate({channel:e}),disabled:L.isPending,className:`px-2 py-1 transition-colors capitalize ${I?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.checkEvery`,`Check every:`)}),a(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:I?.updateCheckIntervalSeconds??21600,disabled:ue.isPending||I===void 0,onChange:e=>{I!==void 0&&ue.mutate({channel:I.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:At.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),D>0&&t(`button`,{type:`button`,onClick:()=>void W(),disabled:z.isPending,className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[z.isPending?a(C,{className:`w-3 h-3 animate-spin`}):a(v,{className:`w-3 h-3`}),z.isPending?m(`admin.system.addons.updating`,`Updating…`):m(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:D})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":m(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.filter`,`Filter:`)}),[{id:`updatable`,label:m(`admin.system.addons.updatable`,`Updatable`),pressed:ke,toggle:()=>je(!ke)},{id:`error`,label:m(`admin.system.addons.inError`,`In error ({{count}})`,{count:Fe}),pressed:Ae,toggle:()=>Ne(!Ae)},{id:`npm`,label:`npm`,pressed:Q===`npm`,toggle:()=>Pe(Q===`npm`?null:`npm`)},{id:`dev`,label:m(`admin.system.addons.dev`,`Dev`),pressed:Q===`dev`,toggle:()=>Pe(Q===`dev`?null:`dev`)}].map(e=>a(`button`,{type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?Ot:kt,children:e.label},e.id))]}),t(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[t(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:T,children:[a(ae,{type:`text`,value:g,onChange:e=>{_(e.target.value),w(!0)},onFocus:()=>w(!0),placeholder:m(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":m(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:z.isPending,leftSlot:a(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:de?a(C,{className:`h-3 w-3 animate-spin`}):void 0}),x&&R&&R.length>0&&t(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-md border border-border bg-surface shadow-xl overflow-hidden`,children:[R.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:m(`systemPage.addons.npmResults`,{count:R.length})}),R&&R.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:R.map(e=>a(Tt,{addon:e,installing:q.isPending,onInstall:e=>ye({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(dt,{onUploadSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Z&&t(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-primary/10 border border-primary/30 text-xs`,children:[a(`span`,{className:`text-foreground-subtle`,children:m(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),a(`button`,{type:`button`,onClick:Re,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:m(`admin.system.addons.clear`,`Clear`)})]}),Z&&a(Et,{capability:Z,installing:q.isPending,onInstall:e=>ye({name:e.name,version:e.version,description:e.description})}),Z&&Ie.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:m(`admin.system.addons.installed`,`Installed`)}),U&&t(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[a(ee,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),t(`div`,{children:[a(`div`,{className:`text-[11px] font-semibold text-foreground`,children:m(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:m(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),p===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(C,{className:`h-3 w-3 animate-spin`}),m(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),p===`error`&&a(`div`,{className:`text-xs text-danger`,children:m(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),p===`ready`&&Ie.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?m(`admin.system.addons.noAddonsInstalled`,`No addons installed`):Z?m(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:Z}):m(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:d.name})}),a(`div`,{className:`space-y-1.5`,children:p===`ready`&&Ve.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=te.get(t),r=$(e)?e.representative:e,i=n?e=>N.mutate({name:t,version:e,nodeId:d.id}):void 0,o=P.get(t)??null,s=o!==null&&Le(o);return a(lt,{addon:r,clusterStatus:u?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:ne.has(t)||s,jobProgress:o,onUpdate:i,disabledByBulk:z.isPending,selectedNode:d},$(e)?t:e.manifest.id)})}),ge!==null&&a(xt,{target:ge,installing:q.isPending,installError:ve,onClose:()=>G(null),onInstall:(e,t)=>q.mutate({packageName:e,version:t})})]})}function zt(){let{t:e}=Y(),r=l(),{data:i}=ie(void 0),{nodes:s}=W(),{selection:c,selectNode:u,requestedNodeId:d}=je(s.length>0?s:[Nt]),f=c.node??Nt,p=f.id,m=s.length>0?c.staleNodeId:null,{data:h,isLoading:g,isError:_}=R({nodeId:p}),v=ge(),y=j(),x=v.isPending||y.isPending,S=async()=>{await v.mutateAsync({nodeId:p}),await y.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},C=n(v);C.current=v;let ee=n(d??`hub`);o(()=>{C.current.mutate({nodeId:ee.current})},[]);let w=(h??[]).map(It).filter(e=>e!==null);return t(ke,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(U,{selectedNodeId:p,onSelect:u}),t(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!g&&!_&&a(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:e(`systemPage.addons.installedCount`,{count:w.length})}),t(`button`,{type:`button`,onClick:()=>void S(),disabled:x,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:e(`admin.system.addons.reFetchAddonsCheckNpm`,`Re-fetch addons + check npm for new versions`),children:[a(b,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(Q,{staleNodeId:m,shownNodeName:f.name}),a(wt,{selectedNode:f}),a(Rt,{addons:w,clusterStatus:i,selectedNode:f,onRefresh:()=>void S(),listPhase:g?`pending`:_?`error`:`ready`})]})}export{zt as AddonsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
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{$r as d,D as f,Di as p,Fn as m,G as h,It as g,L as _,Mi as v,On as y,Or as b,Q as x,Wr as S,Xi as C,Xr as w,Yt as T,Zt as E,bn as D,dn as O,dt as k,fn as A,ji as j,kn as M,or as N,ot as P}from"./player-overlays-By2E2OWX.js";import{Ar as F,ja as ee,jr as I}from"./client-COfGFdJB.js";import{n as L,t as R}from"./send-x-DGZeSf.js";import{t as te}from"./message-square-plus-CEVi2ZAP.js";import{$r as z,$u as B,Ar as V,Ct as H,Dr as U,Ju as ne,Kn as W,Kr as G,Or as K,Sn as q,St as J,Tn as Y,Wn as re,Wr as ie,cr as X,ed as ae,er as oe,fo as se,gt as ce,it as le,kr as ue,mt as de,wn as fe}from"./src-Kh1mC91U.js";import{t as Z}from"./i18n-D1Cc22Zf.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-Ch3e43SQ.js";import{S as pe,gr as me}from"./index-C8EgBFV_.js";import{t as he}from"./AdminSectionedPage-BKgqha3i.js";import{t as ge}from"./AdminPage-CSXKwqkg.js";c();var _e=`__redacted__`,ve=[`llm`,`listProfiles`],ye=[`llm`,`listProfileKinds`],be=[`llm`,`getDefaults`],xe=[`llm`,`listRuntimeNodes`],Se=[`llm`,`listModelCatalog`],Ce=[`llm`,`getUsage`],we=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],Te=new Map([[`cloud`,d],[`plug`,y],[`cpu`,w],[`server`,O],[`sparkles`,E]]);function Ee(e){return Te.get(e)??v}function De(e){return typeof e==`string`&&e.length>0?e:void 0}function Oe(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 ke(e){return e===!0}function Ae(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 je={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 Me(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=je[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 Ne={ready:`success`,downloading:`info`,starting:`info`,stopped:`danger`,crashed:`danger`,failed:`danger`};function Pe(e){return e.reachable?e.status===void 0?`success`:Ne[e.status.state]:`danger`}function Fe(e){if(!e.reachable)return[];let t=[],n=e.apple;if(n?.state===`available`)t.push({id:`apple`,labelKey:`ai.featureApple`,tone:`success`,detail:Me(e).detail}),n.imageInput&&t.push({id:`apple-images`,labelKey:`ai.featureAppleImages`,tone:`success`,detail:null});else if(n?.state===`unavailable`){let n=Me(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 Ie(){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:I.totalMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutTotalHint`)}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutConnect`),min:500,default:I.connectMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutConnectHint`)}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutFirstToken`),min:1e3,default:I.firstTokenMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutFirstTokenHint`)}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutIdle`),min:1e3,default:I.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 Le=[`temperature`,`topP`,`topK`,`maxTokens`,`contextLength`,`systemPrompt`],Re=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function ze(e,t){let n=Ie();return t.filter(t=>e.includes(t)).flatMap(e=>n[e])}function Be(e){let t=ze(e,Le);return t.length===0?null:{sections:[{id:`generation`,title:Z.t(`helpers.aiProfileForm.generation`),fields:t}]}}function Ve(e){let t=ze(e,Re);return t.length===0?null:{sections:[{id:`bounds`,title:Z.t(`helpers.aiProfileForm.bounds`),fields:t}]}}function He(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 Ue(e,t){return{...e.features,...t?.features}}function We(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function Ge(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?Oe(i[e])??t:n??t,o=e=>r.includes(e)?Oe(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`systemPrompt`)?De(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`,I.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,I.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,I.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,I.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:ke(i.retryEnabled),maxAttempts:Oe(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?ke(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 Ke=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function qe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Je({nodeId:t,value:r,onChange:a}){let{t:c}=Q(),u=P(),[d,f]=o(``),[p,m]=o(null),[h,g]=o(!1),_=s({queryKey:Se,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:xe,enabled:b.isPending,refetchInterval:b.isPending?Ke:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,C=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]),w=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(H,{label:c(`ai.model`,`Model`),required:!0,children:i(ne,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:qe(r),options:C,onChange:e=>w(e.target.value)})}),i(H,{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(B,{"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(G,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||y.isPending,onClick:()=>T(),children:[y.isPending?i(N,{className:`h-3.5 w-3.5 animate-spin`}):i(A,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),y.isError&&i(U,{message:y.error instanceof Error?y.error.message:c(`common.error`,`Error`)}),p?.ok===!1&&i(U,{message:p.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>i(G,{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(G,{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(z,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),i(z,{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(G,{size:`sm`,type:`button`,disabled:b.isPending||h,onClick:()=>b.mutate(p.model),children:[b.isPending?i(N,{className:`h-3.5 w-3.5 animate-spin`}):i(S,{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(U,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)})]})]})}function Ye({value:t,onChange:n}){let{t:r}=Q(),a=P(),o=s({queryKey:xe,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(N,{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=Me(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(z,{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 Xe(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Ze({providerConfig:e,onProviderConfigChange:t}){return i(Ye,{value:Xe(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Qe({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=F.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Je,{nodeId:Xe(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 $e=new Map([[`ai/apple-node`,Ze],[`ai/managed-model`,Qe]]);function et(e){return $e.get(e)??null}c();function tt({kind:e,className:t}){return i(Ee(e.icon),{className:t,"aria-hidden":!0})}function nt({kinds:e,onPick:t,onCancel:r}){let{t:a}=Q(),o=n(()=>Ae(e),[e]),s=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return i(ce,{open:!0,onClose:r,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:i(J,{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(tt,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function rt(e){return(e?.sections??[]).flatMap(e=>e.fields)}function it(...e){let t={};for(let n of e)for(let e of rt(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function at(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function ot(e,t){return rt(e).filter(e=>`required`in e&&e.required===!0&&!at(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var st={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 ct(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:Ue(e,n).vision}}function lt({kind:t,existing:r,onSave:a,onCancel:s,onChangeKind:c,saving:d,error:p}){let{t:m}=Q(),h=P(),[g,v]=o(r?.name??t.label),[y,b]=o(()=>r===null?it(t.connectionSchema,t.advancedSchema):{...r.providerConfig}),[x,S]=o(()=>He(r)),[w,T]=o(()=>ct(t,r)),[E,O]=o(!1),k=t.providerWidgets??[],A=k.filter(e=>e.placement===`connection`),j=k.find(e=>e.placement===`model`)??null,M=n(()=>[...ee(t.connectionSchema)].some(e=>r?.providerConfig[e]===_e),[r,t.connectionSchema]),F=l({mutationFn:()=>h.trpcClient.llm.listModels.mutate({addonId:t.addonId,kind:t.kind,connection:y,...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:Ue(t,r).vision}})}}),I=We(t,F.data?.ok===!0?F.data.models:null),L=I.find(e=>e.id===w.id),R=Ue(t,L),te=Be(t.profileFields),V=Ve(t.profileFields),W=ot(t.connectionSchema,y),K=k.some(e=>(e.requires??[]).some(e=>!at(y[e]))),J=t.modelCatalog===`fetch`&&j===null,Y=rt(t.connectionSchema).length>0||A.length>0,ie=e=>{T({id:e,supportsVision:Ue(t,I.find(t=>t.id===e)).vision})},ae=d||g.trim()===``||w.id.trim()===``||W.length>0||K,se=()=>{a(Ge(t,r,{name:g.trim(),model:w.id.trim(),supportsVision:t.visionEditable?w.supportsVision:!1,common:x,providerConfig:y}))},le=r===null?m(`ai.newProfile`,`New {{kind}} profile`,{kind:t.label}):m(`ai.editProfile`,`Edit {{name}}`,{name:r.name}),ue=e=>{let n=et(e);return n===null?i(U,{variant:`warning`,message:m(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})}):i(n,{descriptor:t,providerConfig:y,onProviderConfigChange:b,model:w,onModelChange:T},e)};return i(ce,{open:!0,onClose:s,title:le,error:p,width:`lg`,testId:`ai-profile-editor`,footer:e(u,{children:[W.length>0&&i(z,{variant:`warning`,children:m(`ai.missingRequired`,`required: {{fields}}`,{fields:W.join(`, `)})}),W.length===0&&K&&i(z,{variant:`warning`,children:m(`ai.completeProvider`,`complete the provider settings`)}),W.length===0&&!K&&w.id.trim()===``&&i(z,{variant:`warning`,children:m(`ai.pickModelFirst`,`pick a model`)}),e(G,{size:`sm`,type:`button`,disabled:ae,onClick:se,children:[d&&i(N,{className:`h-3.5 w-3.5 animate-spin`}),r===null?m(`ai.createProfile`,`Create profile`):m(`ai.saveChanges`,`Save changes`)]})]}),children:e(`div`,{className:_,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[i(tt,{kind:t,className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-xs font-medium text-foreground`,children:t.label}),i(z,{variant:`neutral`,children:t.addonId}),c!==void 0&&e(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:c,children:[i(C,{className:`h-3.5 w-3.5`}),m(`ai.changeKind`,`Change type`)]})]}),i(H,{label:m(`ai.name`,`Name`),required:!0,children:i(B,{id:`ai-profile-name`,"aria-label":m(`ai.name`,`Name`),value:g,onChange:e=>v(e.target.value),placeholder:t.label})}),Y&&i(q,{headingId:`ai-editor-connection`,title:m(`ai.sectionConnection`,`Connection`),actions:J?e(G,{size:`sm`,variant:`secondary`,type:`button`,disabled:F.isPending,onClick:()=>F.mutate(),"data-testid":`ai-verify-models`,children:[F.isPending?i(N,{className:`h-3.5 w-3.5 animate-spin`}):i(D,{className:`h-3.5 w-3.5`}),m(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[rt(t.connectionSchema).length>0&&i(X,{bare:!0,schema:t.connectionSchema,values:y,onChange:b}),A.map(e=>ue(e.id)),M&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:m(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),F.data?.ok===!0&&i(z,{variant:`success`,"data-testid":`ai-models-found`,children:m(`ai.modelsFound`,`{{count}} models found`,{count:F.data.models.length})}),F.data?.ok===!1&&i(U,{title:m(st[F.data.code]?.key??`ai.listNetwork`,st[F.data.code]?.fallback??`Endpoint unreachable`),message:F.data.message}),F.isError&&i(U,{message:F.error instanceof Error?F.error.message:m(`common.error`,`Error`)})]})}),i(q,{headingId:`ai-editor-model`,title:m(`ai.sectionModel`,`Model`),children:e(`div`,{className:`${f} space-y-3`,children:[j===null?e(u,{children:[I.length>0&&i(ne,{id:`ai-model-pick`,"aria-label":m(`ai.selectModel`,`Select a model…`),value:L===void 0?``:L.id,options:[{value:``,label:m(`ai.selectModel`,`Select a model…`)},...I.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&ie(e.target.value)}}),i(H,{label:m(`ai.customModel`,`Model id`),description:m(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:i(B,{id:`ai-model-id`,"aria-label":m(`ai.customModel`,`Model id`),value:w.id,onChange:e=>T({...w,id:e.target.value}),placeholder:I[0]?.id??`model-id`})})]}):ue(j.id),e(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(w.supportsVision||!t.visionEditable&&R.vision)&&i(z,{variant:`info`,children:m(`ai.featureVision`,`vision`)}),R.tools&&i(z,{variant:`neutral`,children:m(`ai.featureTools`,`tools`)}),R.streaming&&i(z,{variant:`neutral`,children:m(`ai.featureStreaming`,`streaming`)})]}),t.visionEditable&&i(H,{orientation:`horizontal`,label:m(`ai.supportsVision`,`Supports vision`),description:m(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:i(re,{checked:w.supportsVision,onCheckedChange:e=>T({...w,supportsVision:e}),"aria-label":m(`ai.supportsVision`,`Supports vision`)})})]})}),te!==null&&i(q,{headingId:`ai-editor-generation`,title:m(`ai.sectionGeneration`,`Generation`),children:i(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:i(X,{bare:!0,schema:te,values:x,onChange:S})})}),(V!==null||t.advancedSchema!==void 0)&&i(oe,{expanded:E,onExpandedChange:O,header:i(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:m(`ai.sectionAdvanced`,`Advanced`)}),children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[V!==null&&i(X,{bare:!0,schema:V,values:x,onChange:S}),t.advancedSchema!==void 0&&i(X,{bare:!0,schema:t.advancedSchema,values:y,onChange:b})]})})]})})}c();function ut(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(tt,{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(z,{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(z,{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(re,{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(G,{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(N,{className:`h-3.5 w-3.5 animate-spin`}):i(R,{className:`h-3.5 w-3.5`})}),i(G,{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(m,{className:`h-3.5 w-3.5`})}),i(G,{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(g,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function dt(){let{t}=Q(),c=P(),{state:u,openEdit:d,close:p}=de(),m=ie(),[h,g]=o(null),[v,y]=o(null),[b,x]=o(null),S=s({queryKey:ve,queryFn:()=>c.trpcClient.llm.listProfiles.query({})}),C=s({queryKey:ye,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(()=>{g(null),x(null),p()},[p]);a(()=>{u.mode===`closed`&&g(null)},[u.mode]);let D=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}),k=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}`})}),A=S.data??[],j=n(()=>C.data??[],[C.data]),M=n(()=>{let e=new Map;for(let t of j)e.set(t.kind,t);return e},[j]),N=u.mode===`edit`?A.find(e=>e.id===u.id)??null:null,F=N===null?null:M.get(N.kind)??null,ee=u.mode===`new`&&h===null,I=u.mode===`new`?h:F,L=u.mode===`edit`?N:null,R=I!==null&&(u.mode===`new`||L!==null),te=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:_,children:[i(ft,{profiles:A}),i(q,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:S.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-profiles-loading`,children:[i(V,{className:`h-8 w-full`}),i(V,{className:`h-8 w-full`}),i(V,{className:`h-8 w-full`})]}):S.isError?i(`div`,{className:f,children:i(U,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:t(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):A.length===0?i(K,{icon:E,title:t(`ai.noProfilesTitle`,`No AI profiles yet`),description:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):i(fe,{columns:ut({kindByName:M,testResult:v,testingId:k.isPending?k.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled}),onTest:e=>k.mutate(e),onEdit:e=>{M.has(e.kind)&&(x(null),g(null),d(e.id))},onDelete:e=>void te(e)}),rows:A,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:Y})}),ee&&i(nt,{kinds:j,onCancel:T,onPick:e=>{x(null),g(e)}}),R&&I!==null&&i(lt,{kind:I,existing:L,saving:D.isPending,error:b,onSave:e=>D.mutate(e),onCancel:T,...u.mode===`new`?{onChangeKind:()=>{x(null),g(null)}}:{}})]})}function ft({profiles:t}){let{t:n}=Q(),r=P(),a=s({queryKey:be,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(q,{headingId:`ai-profiles-defaults`,title:n(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:we.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(W,{className:`mb-1 block`,htmlFor:`llm-default-${r}`,children:u(r)}),i(ne,{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 pt=5e3;function mt(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function ht(){let{t}=Q(),r=P(),a=s({queryKey:xe,refetchInterval:pt,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(z,{variant:Pe(n),children:n.reachable?n.status?.state??t(`ai.ready`,`ready`):t(`ai.unreachable`,`unreachable`)}),n.status?.downloadProgress!==void 0&&i(z,{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?`—`:mt(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeatures`,`Features`),render:n=>{let r=Fe(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(z,{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(q,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(V,{className:`h-8 w-full`}),i(V,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(U,{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(K,{icon:O,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(fe,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:Y})})}var gt=x(`/addon/ai/test-chat`),_t=x(`/addon/ai/test-chat/chats`),vt=6e5;function yt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),vt)}function bt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xt(e){if(!bt(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 St=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ct(e){let t;try{t=JSON.parse(e)}catch{return null}if(!bt(t))return null;switch(t.kind){case`status`:{let e=St.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:xt(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*wt(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
|
|
2
|
-
`);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Ct(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
|
-
`)}}let e=r.trim();if(e.length>0){let t=Ct(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Tt(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Et(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Dt(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 Ot(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 kt(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 At=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],jt=360*60*1e3,Mt=40,Nt=160,Pt={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Ft(){let{t:c}=Q(),l=P(),[u,d]=o(``),[m,h]=o(``),[v,y]=o(``),[b,x]=o([]),[S,C]=o(null),[w,E]=o(`none`),[D,O]=o(`throwaway`),[A,M]=o(null),[N,F]=o([]),[ee,I]=o(null),[L,z]=o(null),V=t(null);a(()=>()=>V.current?.abort(),[]);let H=r(async()=>{let e=await fetch(_t,{credentials:`same-origin`});e.ok&&F((await e.json()).chats??[])},[]);a(()=>{D===`persistent`&&H()},[D,H]);let K=s({queryKey:ve,queryFn:()=>l.trpcClient.llm.listProfiles.query({})}),J=n(()=>(K.data??[]).filter(e=>e.enabled),[K.data]),Y=J.find(e=>e.id===u)??null,re=L!==null,ie=r(async(e,t)=>{let n=new AbortController;V.current=n,I(null);let r=yt(Y??{});z({...Pt,firstTokenTimeoutMs:r??0});let i=``,a=null,o,s=null,l=null,d;try{let c=await fetch(gt,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:u,messages:e,...m.trim()===``?{}:{system:m.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...D===`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 wt(c.body))switch(e.kind){case`status`:z(t=>({...t??Pt,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,z(t=>({...t??Pt,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,z(e=>({...e??Pt,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||I(e instanceof Error?e.message:c(`common.error`,`Error`))}finally{V.current=null,z(null)}d!==void 0&&(M(d),H());let f=n.signal.aborted&&i.length>0;s===null&&i.length===0&&!f||x(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}])},[D,A,Y,u,H,m,c]),X=r(()=>{let e=v.trim();if(e===``||u===``||re)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...b,t];x(n),y(``);let r=S?.ref;C(null),E(`none`),ie(D===`persistent`&&A!==null?[{role:`user`,content:e}]:Tt(n),r)},[D,A,v,S,u,ie,re,b]),oe=()=>V.current?.abort(),se=()=>{V.current?.abort(),x([]),C(null),y(``),I(null),z(null),M(null)},ce=async e=>{V.current?.abort();let t=await fetch(`${_t}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();M(e),x(Dt(n)),z(null),I(null)};return e(`div`,{className:_,children:[i(q,{headingId:`ai-test-setup`,title:c(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${f} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(W,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:c(`ai.profile`,`Profile`)}),i(ne,{id:`ai-test-profile`,value:u,onChange:e=>d(e.target.value),options:[{value:``,label:c(`ai.selectProfile`,`Select a profile…`)},...J.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),J.length===0&&!K.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(W,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:c(`ai.systemPrompt`,`System prompt (optional)`)}),i(B,{id:`ai-test-system`,value:m,onChange:e=>h(e.target.value),placeholder:c(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(le,{label:c(`ai.chatMode`,`Conversation mode`),value:D,options:[{value:`throwaway`,label:c(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:c(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{O(e),e===`throwaway`&&M(null)}}),D===`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(G,{size:`sm`,variant:`secondary`,type:`button`,onClick:se,children:[i(te,{className:`h-3.5 w-3.5`}),c(`ai.newChat`,`New chat`)]}),N.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:N.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.`)}),Y!==null&&!Y.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.`)})]})}),ee!==null&&i(U,{title:c(`ai.chatFailed`,`The test call failed`),message:ee}),e(q,{headingId:`ai-test-conversation`,title:c(`ai.testConversation`,`Conversation`),actions:e(G,{size:`sm`,variant:`ghost`,type:`button`,disabled:b.length===0&&S===null,onClick:se,children:[i(g,{className:`h-3.5 w-3.5`}),c(`ai.clearChat`,`Clear`)]}),children:[i(It,{turns:b,live:L}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[S!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?i(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(j,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:S.label}),i(ae,{size:`sm`,variant:`ghost`,type:`button`,icon:k,"aria-label":c(`ai.removeAttachment`,`Remove attachment`),onClick:()=>C(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(G,{size:`sm`,variant:w===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>E(w===`snapshot`?`none`:`snapshot`),children:[i(p,{className:`h-3.5 w-3.5`}),c(`ai.attachSnapshot`,`Camera snapshot`)]}),e(G,{size:`sm`,variant:w===`track`?`primary`:`outline`,type:`button`,onClick:()=>E(w===`track`?`none`:`track`),children:[i(j,{className:`h-3.5 w-3.5`}),c(`ai.attachTrack`,`Recent track`)]})]}),w===`snapshot`&&i(zt,{onPick:e=>{C({ref:{kind:`snapshot`,deviceId:e.id},label:c(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),E(`none`)}}),w===`track`&&i(Vt,{onPick:(e,t)=>{C({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(B,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),X())},placeholder:c(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":c(`ai.message`,`Message`)}),re?e(G,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[i(T,{className:`h-3.5 w-3.5`}),c(`ai.stop`,`Stop`)]}):e(G,{size:`sm`,type:`button`,disabled:v.trim()===``||u===``,onClick:X,children:[i(R,{className:`h-3.5 w-3.5`}),c(`ai.send`,`Send`)]})]})]})]})]})}function It({turns:t,live:n}){let{t:r}=Q();return t.length===0&&n===null?i(K,{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 ${f}`,children:[t.map(e=>i(Lt,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(Rt,{attachment:n.mediaSent}),n.text.length>0&&i(Lt,{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(N,{className:`h-3.5 w-3.5 animate-spin`}),kt(n.phase,n.firstTokenTimeoutMs)]})]})]})}function Lt({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(Rt,{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(j,{className:`h-3 w-3`}):i(p,{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(p,{className:`h-3 w-3`}):i(j,{className:`h-3 w-3`}),Ot(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 Rt({attachment:e}){let{t}=Q(),n=Et(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 zt({onPick:e}){let{t}=Q(),n=se({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(N,{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(Bt,{device:t,onPick:e},t.id))})}function Bt({device:t,onPick:n}){let{t:r}=Q(),{src:a}=h(t.id,{width:Nt});return e(`button`,{type:`button`,onClick:()=>n(t),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:a!==null&&i(`img`,{src:a,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(z,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:t.name})]})]})}function Vt({onPick:t}){let{t:r}=Q(),a=P(),o=se({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:[...At,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-jt,limit:Mt,projection:`slim`})});if(o.isLoading||u.isLoading)return i(N,{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(j,{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 Ht=1440*60*1e3,Ut=[1,7,30,90];function Wt(){let{t}=Q(),r=P(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*Ht},[a]),u=s({queryKey:ve,queryFn:()=>r.trpcClient.llm.listProfiles.query({})}),d=s({queryKey:[...Ce,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=d.data??[],g=i(`div`,{className:`w-36`,children:i(ne,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:Ut.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(q,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:g,children:d.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(V,{className:`h-8 w-full`}),i(V,{className:`h-8 w-full`}),i(V,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(U,{title:t(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:t(`common.error`,`Error`),onRetry:()=>void d.refetch()})}):h.length===0?i(K,{icon:b,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(fe,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:Y})})}var Gt=`llm`,Kt=[`profiles`,`runtimes`,`usage`,`test`],qt=[`new`,`edit`];function Jt(e){return Kt.some(t=>t===e)}function Yt(){let{t}=Q(),n=ue(Gt),[r]=me(),{openNew:a}=de(),o=pe(`/system/ai`,{t,isAdmin:!0})??{icon:E,title:t(`system.ai`,`AI`)};if(n!==`present`)return i(ge,{icon:o.icon,title:o.title,children:i(Xt,{presence:n})});let s=r.get(`tab`),c=Jt(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(G,{size:`sm`,type:`button`,"data-testid":`ai-add-profile`,onClick:a,children:[i(M,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]}):void 0;return i(he,{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(dt,{}),ownedParams:qt},{id:`runtimes`,label:t(`ai.tabRuntimes`,`Runtimes`),content:i(ht,{})},{id:`usage`,label:t(`ai.tabUsage`,`Usage`),content:i(Wt,{})},{id:`test`,label:t(`ai.tabTest`,`Test`),content:i(Ft,{})}]})}function Xt({presence:t}){let{t:n}=Q();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(V,{className:`h-8 w-64`}),i(V,{className:`h-40 w-full`})]}):t===`unknown`?i(U,{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(K,{icon:E,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{Yt as AiProfilesPage,Yt as default};
|
|
@@ -1,40 +0,0 @@
|
|
|
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{An as p,Fn as m,It as h,Nt as g,Zi as _,kn as v,or as y,ot as b,pi as x,pn as S,pt as C,qi as w,sa as T,vn as E,wr as D,xi as O,yi as k}from"./player-overlays-By2E2OWX.js";import{Di as A,Ei as j,Li as M,Oi as N,Pa as P,Ri as F,Ti as I,bi as L,dn as R,ei as z,gi as B,ki as V,ni as ee,pi as te,ri as ne,ui as re,xi as ie,ya as ae}from"./client-COfGFdJB.js";import{t as H}from"./boxes-BP6lUc_5.js";import{n as oe,r as se,t as ce}from"./ungroup-B8d2LiRM.js";import{s as le}from"./video-DKRf0Ic4.js";import{$r as U,$t as ue,$u as W,Aa as de,Ca as fe,Dr as G,Gn as pe,Jt as me,Ju as K,Kr as q,No as he,Oa as ge,Qu as _e,Sr as ve,Tn as ye,Wr as be,Xu as xe,Zu as Se,_o as Ce,an as we,bt as Te,co as Ee,fd as De,fo as Oe,gt as ke,ja as Ae,ka as je,md as Me,mt as Ne,nn as Pe,vn as Fe,wa as Ie,wn as Le,xa as Re}from"./src-Kh1mC91U.js";import{t as J}from"./i18n-D1Cc22Zf.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{F as ze,S as Be,dr as Ve,gr as He,h as Ue,m as We,mr as Ge,or as Ke,ur as X}from"./index-C8EgBFV_.js";import{t as qe}from"./AdminSectionedPage-BKgqha3i.js";import{t as Je}from"./DeviceDoActionFields-C0BliAs3.js";import{p as Ye,t as Xe,u as Ze,z as Qe}from"./HelperWizard-Dne7XMRs.js";import{t as $e}from"./CompositionBlockEditor-CS7j_Q0n.js";var et=`const AUTOMATION_RECIPE =`,tt=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
-
// here the editor could re-open this block and overwrite everything below.`;function nt(e){return e.includes(et)}function rt(e){let t=e.indexOf(et);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 it(e){let t=rt(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=j.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 at(e){let t=rt(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)}${tt}${e.slice(i)}`}u();var ot=6e4;function st(){let e=Oe({projection:`slim`});return r(()=>(e.data??[]).filter(e=>R(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 ct(e){let t=b();return l({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:ot,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function lt(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 ut(e){let t=ct(e.deviceId);if(t.data!==void 0)return lt(t.data,e.cap).find(t=>t.path===e.fieldPath)}function dt({value:t,devices:n,onChange:r}){let{t:i}=Y(),a=ct(t.deviceId),s=a.data??[],c=lt(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:ft(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 ft(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 pt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function mt(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 pt}}function ht(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 gt(e){return mt(e).map(e=>({value:e,label:ht(e)}))}function _t(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 vt={triggers:[],actions:[]};function yt(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 bt(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
|
-
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function xt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function St(){return{kind:`expression`,expr:``,bindings:{}}}function Ct(e,t,n){return e.map((e,r)=>r===t?n:e)}function wt(e,t){return e.filter((e,n)=>n!==t)}function Tt(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=wt(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Et(e,t){return{...e,triggers:[...t]}}function Dt(e,t){return{...e,actions:[...t]}}var Ot=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function kt({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(U,{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(Ct(t,c,bt(At(e.target.value)))),options:Ot.map(e=>({value:e.value,label:a(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(q,{variant:`ghost`,disabled:c===0,onClick:()=>i(Tt(t,c,c-1)),title:a(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(w,{className:`h-3.5 w-3.5`})}),o(q,{variant:`ghost`,disabled:c===t.length-1,onClick:()=>i(Tt(t,c,c+1)),title:a(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(_,{className:`h-3.5 w-3.5`})}),o(q,{variant:`ghost`,onClick:()=>i(wt(t,c)),title:a(`automation.actionList.removeThisStep`,`Remove this step`),children:o(h,{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(W,{type:`number`,min:0,max:300,value:String(s.seconds),onChange:e=>i(Ct(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(Ct(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(Mt,{action:s,devices:n,devicesState:r,onChange:e=>i(Ct(t,c,e))})]},`${s.kind}-${String(c)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(q,{variant:`outline`,onClick:()=>i([...t,bt(`cap`)]),children:[o(v,{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 At(e){return Ot.find(t=>t.value===e)?.value??`cap`}function jt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function Mt({action:e,devices:t,devicesState:n,onChange:r}){return o(Je,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:jt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function Nt({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=zt(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(W,{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(W,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Pt({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=zt(t,n,r);return o(W,{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 Ft(e){return typeof e==`object`}function It(e){return Ft(e)?e[0]??``:e}function Lt(e){return Ft(e)?e:typeof e==`boolean`?[]:[e]}function Rt(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function zt(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=Ee({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=ae(o)?o:void 0,c=Rt(e?.quantity,s);if(c===void 0)return;let l=a?.display;return ue({quantity:c,display:l,capName:n})}function Bt({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=ut(a),c=gt(s?.kind),l=t.operator===`in`,u=e=>{r({...t,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},d=e=>{let n=Vt(e,c);r({...t,operator:n,value:n===`in`?Lt(t.value):It(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(dt,{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(Pt,{value:Lt(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})}):o(Nt,{value:It(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Vt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Ht={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Ut({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(W,{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(Wt,{alias:e,source:r,devices:n,onRename:n=>s(Xt(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(Zt(t.bindings,e))},e)),e(q,{variant:`ghost`,onClick:()=>s({...t.bindings,[Yt(t.bindings)]:Ht}),children:[o(v,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function Wt({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:qt(r,Kt(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(W,{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:``}:Ht),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(W,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Gt(e.target.value)})})]}):o(dt,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:Jt(r,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),o(q,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(h,{className:`h-3.5 w-3.5`})})]})}function Gt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Kt(e){return e.kind===`global`?e.sourceStableId:``}function qt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Jt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Yt(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 Xt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Zt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function Qt(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:Qt(t)?t:{kind:`all`,children:[t]}}function $t(e,t){return t===null||Qt(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function en(e){return $t(e,Q(e))}function tn(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?tn(e.child,r):null;if(!Qt(e))return null;let i=e.children[n];return i===void 0?null:tn(i,r)}function nn(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=nn(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!Qt(e))return e;let a=e.children[r];if(a===void 0)return e;let o=nn(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 rn(e){return e===null?null:V({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function an(e){let t=Q(e);return{depth:t.children.length===0?0:A(t),leaves:t.children.length===0?0:N(t),depthLimit:3,leafLimit:32}}function on(e,t){let n=rn(t);return n===null?{ok:!0,recipe:$t(e,t)}:{ok:!1,reason:n}}function sn(e,t){let n=Q(e);return on(e,{kind:n.kind,children:[...n.children,t]})}function cn(e,t,n){return $t(e,nn(Q(e),t,()=>n))}function ln(e,t){return $t(e,nn(Q(e),t,()=>null))}function un(e,t,n){return $t(e,nn(Q(e),t,e=>Qt(e)?{kind:n,children:e.children}:e))}function dn(e,t){return tn(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:on(e,nn(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function fn(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 pn(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=fn(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=tn(i,r.path);if(a===null||!Qt(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 on(e,nn(i,r.path,()=>d))}function mn(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=tn(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return on(e,nn(n,t,()=>r.child));if(!Qt(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=fn(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=tn(n,i.path);if(a===null||!Qt(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 on(e,nn(n,i.path,()=>o))}u();var hn=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function gn(e){return e.join(`/`)}function _n(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function vn({recipe:t,devices:n,onChange:i}){let{t:a}=Y(),[s,l]=c([]),[u,d]=c(null),f=Q(t),p=an(t),m=r(()=>s.map(_n),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},g=pn(t,m,`all`),_=pn(t,m,`any`),y=m.length===1?dn(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(cn(t,e,n)),onRemove:e=>{l([]),i(ln(t,e))},onSetKind:(e,n)=>i(un(t,e,n)),onUngroup:e=>h(mn(t,e))};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(U,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),o(`div`,{className:`w-32`,children:o(K,{value:f.kind,onChange:e=>i(un(t,[],yn(e.target.value))),options:hn.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(bn,{container:f,path:[],handlers:b}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(q,{variant:`outline`,onClick:()=>h(sn(t,xt())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(v,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(q,{variant:`outline`,onClick:()=>h(sn(t,St())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(se,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(q,{variant:`ghost`,disabled:!g.ok,onClick:()=>h(g),title:g.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):g.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(q,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):_.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),o(q,{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 yn(e){return e===`any`?`any`:`all`}function bn({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(xn,{node:e,path:[...t,r],handlers:n},gn([...t,r])))})}function xn({node:t,path:n,handlers:r}){let{t:i}=Y(),a=gn(n),s=o(pe,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return Qt(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,yn(e.target.value)),options:hn.map(e=>({value:e.value,label:i(e.labelKey)}))})}),e(q,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[o(ce,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.ungroup`)]}),o(q,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:o(h,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(bn,{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(U,{variant:`warning`,children:`NOT`}),e(q,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[o(ce,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(xn,{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(Bt,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(Ut,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)})}),o(q,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(h,{className:`h-3.5 w-3.5`})})]})}u();function Sn({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=be(),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(q,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?O:k,{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(q,{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(le,{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(Fe,{maxHeight:420,children:t})})]})}var Cn=[`device-state`,`device-event`,`schedule`,`manual`],wn=Object.values(P).sort((e,t)=>e.localeCompare(t));function Tn({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(En,{trigger:e,devices:n,position:i,onChange:e=>r(Ct(t,i,e)),onRemove:()=>r(wt(t,i))},`${e.kind}-${String(i)}`)),e(q,{variant:`outline`,onClick:()=>r([...t,yt(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(v,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function En({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(U,{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(yt(Dn(e.target.value))),options:Cn.map(e=>({value:e,label:_t(e)}))})]}),o(q,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(h,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o(kn,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(jn,{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(W,{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 Dn(e){return Cn.find(t=>t===e)??`manual`}function On(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 kn({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=ut(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(dt,{value:a,devices:n,onChange:e=>r(On(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(pe,{checked:t.becomes===void 0,onChange:e=>r(On(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Nt,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(On(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(pe,{checked:t.edge===!0,onChange:e=>r(On(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(W,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(On(a,{...c,forMs:An(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(W,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(On(a,{...c,debounceMs:An(e.target.value)}))})]})]})}function An(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function jn({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…`)},...wn.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 Mn=`hub`;function Nn({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(()=>en(n)),[_,v]=c(!1),b=st(),x=V(h),C=r(()=>Fn(h),[h]),w=r(()=>In(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),T=p.trim()===``,E=T||x!==null||C!==null||w.code===null;return e(`div`,{className:`space-y-4`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(U,{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(W,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(Pn,{step:`1`,title:f(`automation.automationEditor.when`,`When`),subtitle:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(Tn,{triggers:h.triggers,devices:b,onChange:e=>g(Et(h,e))})}),o(Pn,{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(vn,{recipe:h,devices:b,onChange:g})}),o(Pn,{step:`3`,title:f(`automation.automationEditor.then`,`Then`),subtitle:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(kt,{actions:h.actions,devices:b,onChange:e=>g(Dt(h,e))})}),o(Sn,{code:w.code,error:w.error,canEject:t!==null,ejecting:s,onEject:u}),x!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),x===null&&C!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:C}),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(q,{onClick:()=>{w.code!==null&&l({name:p.trim(),code:w.code,enabled:t?.enabled??!0,placement:Mn})},disabled:i||E,children:[i&&o(y,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(q,{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(S,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(q,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),T&&o(U,{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:z(t.id)},components:{code:o(`code`,{})}})}),o(Pe,{addonId:z(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Pn({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 Fn(e){let t=j.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 In(e,t){try{return{code:I({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Ln(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 Rn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function zn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Bn(e){let t=e=>{let t=Ln(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 Vn(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>Ln(e).tone===`error`).length,n=e.filter(e=>Ln(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 Hn({block:t,busy:n,confirming:r,logsOpen:i,unreadable:a,onEdit:s,onToggle:c,onToggleLogs:l,onAskDelete:u,onCancelDelete:d,onConfirmDelete:f}){let g=T(),{t:_}=Y(),v=Ln(t),y=me(t.updatedAt,g);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(U,{variant:Rn(v.tone),children:v.label}),y!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:_(`common.edited`,{when:y})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:v.detail}),a!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:_(`automation.editor.listUnreadable`,{reason:a})})]}),r?e(`div`,{className:`flex justify-end gap-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:_(`automation.automationList.deleteThisAutomation`,`Delete this automation?`)}),o(q,{variant:`danger`,onClick:e=>{e.stopPropagation(),f()},disabled:n,children:_(`common.delete`,`Delete`)}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),d()},children:_(`common.cancel`,`Cancel`)})]}):e(`div`,{className:`flex justify-end gap-1`,children:[o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),s()},disabled:a!==null,title:a===null?_(`common.edit`,`Edit`):_(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:o(m,{className:`h-4 w-4`})}),e(xe,{children:[o(_e,{children:o(q,{variant:`ghost`,disabled:!0,title:_(`automation.automationList.runActions`,`Run actions`),children:o(p,{className:`h-4 w-4`})})}),o(Se,{children:_(`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(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:_(`automation.automationList.logs`,`Logs`),children:o(S,{className:`h-4 w-4`})}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c(!t.enabled)},disabled:n,title:t.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`),children:t.enabled?_(`common.disable`,`Disable`):_(`common.enable`,`Enable`)}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),u()},title:_(`common.delete`,`Delete`),children:o(h,{className:`h-4 w-4`})})]})]}),i&&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:z(t.id)},components:{code:o(`code`,{})}})}),o(Pe,{addonId:z(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Un({onCreate:t}){let{t:n}=Y();return o(ve,{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(q,{onClick:t,children:n(`automation.automationList.newAutomation`,`New automation`)})]})})}u();var Wn=[`coreBlocks`,`list`],Gn=5e3;function Kn(e){return e instanceof Error?e.message:String(e)}function qn({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:f}){let{t:p}=Y(),m=b(),{state:h,openNew:g,openEdit:_,close:v}=Ne({editKey:`block`,newKey:`new`}),[y,x]=c(null),[S,w]=c(null),[T,E]=c(null),D=n(null),O=h.mode!==`closed`;s(()=>{u&&(x(null),g(),a?.(null),f?.())},[u,f,a,g]);let k=l({queryKey:Wn,refetchInterval:Gn,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&&nt(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=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),N=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),_(e.block.id),a?.(e.block.id),A()}}),P=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{w(null),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:at(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),x(null),A(),t(e.block.id)}}),L=k.data,R=Bn((L??[]).filter(e=>nt(e.code))),z=L!==void 0&&R.length===0,B=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,V=h.mode===`new`||B===null?null:zn(R,B),ee=V===null?null:it(V.code),te=M.error===null?N.error===null?I.error===null?null:Kn(I.error):Kn(N.error):Kn(M.error),ne=r(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=it(e.code);return o(`ul`,{className:`list-none`,children:o(Hn,{block:e,busy:F.isPending||P.isPending,confirming:S===e.id,logsOpen:T===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{x(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>E(T===e.id?null:e.id),onAskDelete:()=>w(e.id),onCancelDelete:()=>w(null),onConfirmDelete:()=>P.mutate(e.id)})})},sortValue:e=>e.name}],[S,T,a,_,P,F,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:Vn(R)}),k.error!=null&&o(G,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Kn(k.error),onRetry:A}),z?o(Un,{onCreate:()=>{x(null),g(),a?.(null)}}):o(Le,{columns:ne,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:ye,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{x(e),_(e.id),a?.(e.id)}}),o(ke,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),x(null),v(),a?.(null)},title:V===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:V.name}),icon:C,width:`xl`,testId:`automation-editor-panel`,children:o(Nn,{existing:V,initialRecipe:ee!==null&&ee.ok?ee.recipe:vt,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{V===null?M.mutate(e):N.mutate({blockId:V.id,block:e})},onEject:()=>{V!==null&&I.mutate(V)},onCancel:()=>{M.reset(),N.reset(),I.reset(),x(null),v(),a?.(null)}},V?.id??`new`)}),P.error!=null&&o(G,{message:Kn(P.error)}),F.error!=null&&o(G,{message:Kn(F.error)})]})}u();function Jn({mode:e,onTitle:t}){return o(e===`helper`?Yn:Xn,{onTitle:t})}function Yn({onTitle:e}){let{t}=Y(),n=Ge(),r=Re(),i=he(),a=Ce({addonId:`composer`}),[l,u]=c(null),d=Qn(l,t);return s(()=>{e(d)},[e,d]),o(`div`,{className:`flex flex-col gap-3`,"data-testid":`composition-create-form`,children:o(Xe,{purpose:`create`,initial:null,start:`template`,saving:r.isPending,onDraftChange:u,onSave:async(e,o)=>{let s=null,c=await Ye(e,async(e,c)=>{let{block:l}=await r.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:e}}),u=await $n(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(Ue(u),{replace:!0})}),l=s;return c.length>0||l===null?{kind:`refused`,lines:er(c,t)}:{kind:`saved`,deviceId:l}}})})}function Xn({onTitle:t}){let{t:n}=Y(),r=T(),i=Ge(),a=Re(),l=he(),u=Ce({addonId:`composer`}),[d,f]=c(F.Sensor),[p,m]=c(M.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(F).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(F).map(e=>({value:e,label:Me(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(M).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(M).map(e=>({value:e,label:De(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(W,{"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(q,{disabled:y===null||a.isPending,onClick:()=>{y!==null&&Zn({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(We(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function Zn(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 $n(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 Qn(e,t){if(e===null)return t(`helper.newHelper`);let n=re(e.templateId);return t(n===null?`helper.newHelper`:`helper.newTitle.${n.id}`)}async function $n(e,t){let n=`${te}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}function er(e,t){return e.length>0?e:Ze(t(`helper.devicePending`))}function tr(e){return{state:`answered`,byRef:new Map(e.map(e=>[L(e),e]))}}function nr(e,t){if(e.state!==`unanswered`)return e.byRef.get(L(t))??null}function rr(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function ir(e){return ie(e).map(e=>e.source)}function ar(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(...ir(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...ir(e))}let r=new Set;return n.filter(e=>{let t=L(e);return r.has(t)?!1:(r.add(t),!0)})}function or(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 sr(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return or(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 cr(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 sr(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 lr(e){return L(e)}function ur(e,t){let n=nr(t,e);return{key:L(e),label:n?n.name:lr(e),presence:rr(n),deviceId:n?n.id:null}}function dr(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function fr(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:B(e.block.id),a=L(i),o=ar(e).filter(e=>L(e)!==a).map(e=>ur(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=nr(t,i),l=dr(e),u=cr(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=rr(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:lr(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function pr(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function mr(e,t){return pr(e)-pr(t)||e.name.localeCompare(t.name)}function hr(e,t){let n=e.flatMap(e=>{let n=fr(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(mr),customizations:n.filter(e=>e.kind===`customization`).toSorted(mr)}}u();var gr=1e4;function _r(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function vr(){let e=Ke();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:_r(e.error)})}:tr(e.data)}function yr(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function br({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=He(),s=ge({},{refetchInterval:gr}),l=vr(),u=Ne({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,p=d===null?yr(i.get(`new`),t):null,m=p!==null,[h,g]=c(``),_=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},v=s.data;return e(f,{children:[Sr(v,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e)}),o(ke,{open:m||d!==null,onClose:_,title:m?h||r(p===`blank`?`helper.newComposition`:`helper.newHelper`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:H,width:`xl`,testId:`composed-device-editor`,children:m&&p!==null?o(Jn,{mode:p,onTitle:g},p):d===null?null:o($e,{blockId:d})})]})}function xr(t){return o(ve,{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 Sr(e,t,n,r,i){if(t!=null&&e===void 0)return o(G,{title:J.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:_r(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 xr(e.reason);let a=t==null?null:_r(t);return o(Cr,{lists:hr(e.views,r),fleet:r,refreshError:a,onEditComposed:i.onEditComposed})}function Cr({lists:t,fleet:n,refreshError:r,onEditComposed: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(wr,{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`,onEditComposed:i}),o(wr,{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`,onEditComposed:i})]})}function wr({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,onEditComposed:c}){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(ve,{variant:`flat`,className:`p-0`,children:o(Le,{columns:Tr(i,s,c),rows:r,rowKey:e=>e.blockId,minWidthPx:760,bordered:!1,maxBodyHeight:ye,emptyMessage:a,onRowClick:s===`composed`?e=>c(e.blockId):void 0})})]})}function Tr(t,n,r){let i=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(Er,{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(U,{variant:Rn(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(Or,{sources:e.sources})}];return n===`composed`&&i.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>o(`div`,{className:`flex justify-end gap-1`,children:o(q,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),r(e.blockId)},children:J.t(`common.edit`,`Edit`)})})}),i}function Er({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(Dr,{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 Dr({row:e}){let{t}=Y();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:e.name})}):o(Ve,{to:e.kind===`composed`?Ue(e.reportedDeviceId):We(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:e.name})}function Or({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(Ve,{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 kr(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 Ar(e){if(Array.isArray(e))return e}function jr(e,t,n){return(t=Br(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Mr(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 Nr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Pr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Fr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Pr(Object(n),!0).forEach(function(t){jr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Pr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ir(e,t){if(e==null)return{};var n,r,i=Lr(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Lr(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Rr(e,t){return Ar(e)||Mr(e,t)||Vr(e,t)||Nr()}function zr(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Br(e){var t=zr(e,`string`);return typeof t==`symbol`?t:t+``}function Vr(e,t){if(e){if(typeof e==`string`)return kr(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?kr(e,t):void 0}}function Hr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ur(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Wr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ur(Object(n),!0).forEach(function(t){Hr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ur(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Gr(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Kr(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function qr(e){return{}.toString.call(e).includes(`Object`)}function Jr(e){return!Object.keys(e).length}function Yr(e){return typeof e==`function`}function Xr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Zr(e,t){return qr(t)||ni(`changeType`),Object.keys(t).some(function(t){return!Xr(e,t)})&&ni(`changeField`),t}function Qr(e){Yr(e)||ni(`selectorType`)}function $r(e){Yr(e)||qr(e)||ni(`handlerType`),qr(e)&&Object.values(e).some(function(e){return!Yr(e)})&&ni(`handlersType`)}function ei(e){e||ni(`initialIsRequired`),qr(e)||ni(`initialType`),Jr(e)&&ni(`initialContent`)}function ti(e,t){throw Error(e[t]||e.default)}var ni=Kr(ti)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),ri={changes:Zr,selector:Qr,handler:$r,initial:ei};function ii(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ri.initial(e),ri.handler(t);var n={current:e},r=Kr(si)(n,t),i=Kr(oi)(n),a=Kr(ri.changes)(e),o=Kr(ai)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return ri.selector(e),e(n.current)}function c(e){Gr(r,i,a,o)(e)}return[s,c]}function ai(e,t){return Yr(t)?t(e.current):t}function oi(e,t){return e.current=Wr(Wr({},e.current),t),t}function si(e,t,n){return Yr(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var ci={create:ii},li={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function ui(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function di(e){return{}.toString.call(e).includes(`Object`)}function fi(e){return e||gi(`configIsRequired`),di(e)||gi(`configType`),e.urls?(pi(),{paths:{vs:e.urls.monacoBase}}):e}function pi(){console.warn(hi.deprecation)}function mi(e,t){throw Error(e[t]||e.default)}var hi={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
6
|
-
You are using deprecated way of configuration.
|
|
7
|
-
|
|
8
|
-
Instead of using
|
|
9
|
-
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
-
use
|
|
11
|
-
monaco.config({ paths: { vs: '...' } })
|
|
12
|
-
|
|
13
|
-
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
-
`},gi=ui(mi)(hi),_i={config:fi},vi=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function yi(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],yi(e[n],t[n]))}),Fr(Fr({},e),t)}var bi={type:`cancelation`,msg:`operation is manually canceled`};function xi(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(bi):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Si=[`monaco`],Ci=Rr(ci.create({config:li,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),wi=Ci[0],Ti=Ci[1];function Ei(e){var t=_i.config(e),n=t.monaco,r=Ir(t,Si);Ti(function(e){return{config:yi(e.config,r),monaco:n}})}function Di(){var e=wi(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Ti({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),xi(Pi);if(window.monaco&&window.monaco.editor)return Mi(window.monaco),e.resolve(window.monaco),xi(Pi);vi(Oi,Ai)(ji)}return xi(Pi)}function Oi(e){return document.body.appendChild(e)}function ki(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Ai(e){var t=wi(function(e){return{config:e.config,reject:e.reject}}),n=ki(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function ji(){var e=wi(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;Mi(n),e.resolve(n)},function(t){e.reject(t)})}function Mi(e){wi().monaco||Ti({monaco:e})}function Ni(){return wi(function(e){return e.monaco})}var Pi=new Promise(function(e,t){return Ti({resolve:e,reject:t})}),Fi={config:Ei,init:Di,__getMonacoInstance:Ni};u();var Ii={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},Li={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Ri({children:e}){return t.createElement(`div`,{style:Li.container},e)}var zi=Ri;function Bi({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...Ii.wrapper,width:e,height:n},...s},!r&&t.createElement(zi,null,i),t.createElement(`div`,{ref:a,style:{...Ii.fullWidth,...!r&&Ii.hide},className:o}))}var Vi=i(Bi);function Hi(e){s(e,[])}var Ui=Hi;function Wi(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Wi;function Gi(){}function Ki(e,t,n,r){return qi(e,r)||Ji(e,t,n,r)}function qi(e,t){return e.editor.getModel(Yi(e,t))}function Ji(e,t,n,r){return e.editor.createModel(t,n,r?Yi(e,r):void 0)}function Yi(e,t){return e.Uri.parse(t)}function Xi({original:e,modified:r,language:i,originalLanguage:o,modifiedLanguage:l,originalModelPath:u,modifiedModelPath:d,keepCurrentOriginalModel:f=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=Gi,onMount:S=Gi}){let[C,w]=c(!1),[T,E]=c(!0),D=n(null),O=n(null),k=n(null),A=n(S),j=n(x),M=n(!1);Ui(()=>{let e=Fi.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),$(()=>{if(D.current&&O.current){let t=D.current.getOriginalEditor(),n=Ki(O.current,e||``,o||i||`text`,u||``);n!==t.getModel()&&t.setModel(n)}},[u],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Ki(O.current,r||``,l||i||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,l||i||`text`)},[i,o,l],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=a(()=>{if(!O.current)return;j.current(O.current);let t=Ki(O.current,e||``,o||i||`text`,u||``),n=Ki(O.current,r||``,l||i||`text`,d||``);D.current?.setModel({original:t,modified:n})},[i,r,l,e,o,u,d]),P=a(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);s(()=>{C&&A.current(D.current,O.current)},[C]),s(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();f||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return t.createElement(Vi,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(Xi);function Zi(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var Qi=Zi,$i=new Map;function ea({defaultValue:e,defaultLanguage:r,defaultPath:i,value:o,language:l,path:u,theme:d=`light`,line:f,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=Gi,onMount:C=Gi,onChange:w,onValidate:T=Gi}){let[E,D]=c(!1),[O,k]=c(!0),A=n(null),j=n(null),M=n(null),N=n(C),P=n(S),F=n(),I=n(o),L=Qi(u),R=n(!1),z=n(!1);Ui(()=>{let e=Fi.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?V():e.cancel()}),$(()=>{let t=Ki(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&$i.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState($i.get(u)))},[u],E),$(()=>{j.current?.updateOptions(m)},[m],E),$(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(z.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),z.current=!1))},[o],E),$(()=>{let e=j.current?.getModel();e&&l&&A.current?.editor.setModelLanguage(e,l)},[l],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let B=a(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=u||i,n=Ki(A.current,o||e||``,r||l||``,t||``);j.current=A.current?.editor.create(M.current,{model:n,automaticLayout:!0,...m},h),g&&j.current.restoreViewState($i.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),R.current=!0}},[e,r,i,o,l,u,m,h,g,d,f]);s(()=>{E&&N.current(j.current,A.current)},[E]),s(()=>{!O&&!E&&B()},[O,E,B]),I.current=o,s(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{z.current||w(j.current.getValue(),e)}))},[E,w]),s(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function V(){F.current?.dispose(),_?g&&$i.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(Vi,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var ta=i(ea);u();function na(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}var ra={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function ia(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...ra}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function aa({value:e,onChange:t,extraLibs:r=[],path:i=`file:///block.ts`,onDiagnostics:c,readOnly:l=!1,heightPx:u=420,dark:d=!0}){let f=n(null),p=a((e,t)=>{if(f.current=t,ia(t,r),c===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{c(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(i),i()},[r,c]);return s(()=>{let e=f.current;e!==null&&ia(e,r)},[r]),o(ta,{height:u,defaultLanguage:`typescript`,path:i,theme:d?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:p,options:{readOnly:l,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function oa(e){return e.some(e=>e.severity>=8)}var sa=[{id:`blank`,name:`Blank script`,get description(){return J.t(`helpers.buildExamples.blankDescription`)},entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
-
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
-
*
|
|
20
|
-
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
-
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
22
|
-
*/
|
|
23
|
-
export default function block(ctx: AddonContext) {
|
|
24
|
-
ctx.logger.info('hello from a core block')
|
|
25
|
-
|
|
26
|
-
const timer = setInterval(() => {
|
|
27
|
-
ctx.logger.info('tick')
|
|
28
|
-
}, 60_000)
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
clearInterval(timer)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`}}];function ca(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var la=sa.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
-
|
|
36
|
-
export default function block(ctx: AddonContext) {
|
|
37
|
-
ctx.logger.info('hello from a core block')
|
|
38
|
-
return () => undefined
|
|
39
|
-
}
|
|
40
|
-
`;function ua({existing:e,dirty:t,saving:n,restarting:r}){return e===null?J.t(`helpers.restartGate.saveFirstNoProcess`):n?J.t(`helpers.restartGate.saving`):r?J.t(`helpers.restartGate.restarting`):t?J.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:J.t(`helpers.restartGate.disabled`)}u();var da=5e3;function fa(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function pa({blockId:t}){let{t:n}=Y(),i=z(t),a=Oe({addonId:i,projection:`slim`},{refetchInterval:da}),s=r(()=>fa(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptDevicesPanel.loading`)]}):a.isError?e(`p`,{className:`text-xs text-danger`,children:[n(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,a.error instanceof Error?a.error.message:String(a.error)]}):e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptDevicesPanel.devices`,`Devices`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:i},components:{code:o(`code`,{className:`text-[11px]`})}})})]}),o(U,{variant:`default`,children:s.length})]}),s.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:o(`code`,{})}})}):o(`ul`,{className:`space-y-3`,children:s.map(t=>o(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${t.id}`,children:e(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(Ve,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:t.name}),o(U,{variant:`info`,style:`outline`,children:t.type}),t.stableId!==void 0&&e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,o(`code`,{children:t.stableId})]}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.id]})]})},t.id))})]})}u();function ma(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function ha(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function ga(e){switch(e){case`refresh-channel-catalog`:return J.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return J.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return J.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return J.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return J.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return J.t(`build.scriptSettingsPanel.enableUnifi`)}}function _a(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function va(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function ya(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=_a(e);n!==null&&(t[n]=va(e))}return t}function ba(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function xa({blockId:t}){let{t:n}=Y(),i=b(),s=fe({blockId:t},{retry:!1}),l=Ie({blockId:t},{refetchInterval:1e4,retry:!1}),u=Ae({onSuccess:()=>{l.refetch()}}),d=je(),f=de(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[x,S]=c(!1),C=ba(l.data)?l.data:null,w=r(()=>C===null?{}:ya(C),[C]),T=p??w,E=a(e=>{m(e)},[]),D=p!==null,O=a(()=>{p!==null&&(g(null),u.mutate({blockId:t,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,p,u]),k=a(async(e,n)=>{if(ma(e)){S(!0),g(null),v(null);try{p!==null&&(await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:p}),m(null)),await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:ha(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(ga(e))),await d.mutateAsync({blockId:t}),await l.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{S(!1)}}},[t,s.data?.block?.enabled,p,d,f,l,i.trpcClient.coreBlocks]);return l.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptSettingsPanel.loading`)]}):l.isError?e(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[n(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,l.error instanceof Error?l.error.message:String(l.error)]}):C===null?null:e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptSettingsPanel.settings`,`Settings`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:o(`code`,{})}})})]}),e(q,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||u.isPending||x,children:[u.isPending&&o(y,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(ze,{schema:C,values:T,onChange:E,onAction:k}),h===null?null:o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:o(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}u();var Sa=`hub`;function Ca({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:p,onSave:m,onCancel:h}){let{t:_}=Y(),v=b(),C=be(),{resolvedMode:w}=we(),T=ne({code:t?.code??la,files:t?.files,entry:t?.entry}),[D,O]=c(t?.name??``),[k,A]=c(T.files),[j,M]=c(T.entry),[N,P]=c(T.entry),[F,I]=c(t?.placement??Sa),[L,R]=c(t?.integrationId??``),[B,V]=c([]),[ee,te]=c(!1),[re,ie]=c(`blank`),[ae,H]=c(null),[oe,se]=c(``),ce=k[N]??``,le=e=>{A(t=>({...t,[N]:e}))},ue=Object.keys(k).toSorted(),de=sa.length>1,fe=r(()=>[...n?.libs??[],...na(k,N)],[n?.libs,k,N]),G=d({mutationFn:()=>v.trpcClient.coreBlocks.compile.mutate({files:k,entry:j})}),pe=r(()=>B.filter(e=>e.severity>=8),[B]),me=oa(B),K=D.trim()===``,he=t===null?null:ne(t),ge=t===null||he===null||JSON.stringify(k)!==JSON.stringify(he.files)||j!==he.entry||D.trim()!==t.name||F!==t.placement||(L.trim()===``?void 0:L.trim())!==t.integrationId,_e=()=>{G.reset(),m({name:D.trim(),files:k,entry:j,enabled:t?.enabled??!0,placement:F,...L.trim()===``?{}:{integrationId:L.trim()}})},ve=()=>{let e=ca(Object.keys(k));A(t=>({...t,[e]:``})),P(e),H(e),se(e)},ye=e=>{H(e),se(e)},xe=()=>{if(ae===null)return;let e=ae,t=oe.trim();if(H(null),!(t===``||t===e)){if(k[t]!==void 0){P(t);return}A(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),j===e&&M(t),P(t)}},Se=async e=>{let t=sa.find(t=>t.id===e);if(t===void 0)return;let n=sa.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(k)===JSON.stringify(n.files)&&j===n.entry)&&!await C({title:_(`build.blockEditor.loadExample`,`Load example`),message:_(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:_(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ie(e),A({...t.files}),M(t.entry),P(t.entry),(D.trim()===``||re===`blank`)&&O(t.id===`blank`?``:t.name))},Ce=t===null?null:Ln(t),Ee=ua({existing:t,dirty:ge,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[Ce!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(U,{variant:Rn(Ce.tone),children:Ce.label})}),e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.name`,`Name`)}),o(W,{className:`mt-1`,value:D,onChange:e=>O(e.target.value),placeholder:_(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),o(W,{className:`mt-1`,value:L,onChange:e=>R(e.target.value),placeholder:_(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),t===null&&de&&e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.startFrom`,`Start from`)}),o(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:re,onChange:e=>void Se(e.target.value),"data-testid":`script-example-select`,children:sa.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(Te,{selectedNodeId:F,onSelect:I,label:_(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),F!==Sa&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),o(`span`,{children:o(X,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:o(`strong`,{})}})})]})]}),e(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ue.map(t=>ae===t?o(W,{value:oe,onChange:e=>se(e.target.value),onBlur:()=>xe(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),xe()),e.key===`Escape`&&(e.preventDefault(),H(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":_(`build.blockEditor.renameFile`,`Rename file`)},t):e(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${t===N?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>P(t),onDoubleClick:()=>ye(t),title:_(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${t}`,children:[t,t===j?` · ${_(`build.blockEditor.entry`)}`:``]},t)),o(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:ve,"data-testid":`script-file-add`,children:_(`build.blockEditor.file`,`+ file`)}),N!==j&&o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>M(N),title:_(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:_(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:_(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):o(aa,{value:ce,onChange:le,path:`file:///${N}`,extraLibs:fe,onDiagnostics:V,dark:w===`dark`,heightPx:560})]}),n!==void 0&&n.libs.length===0&&o(`p`,{className:`text-xs text-warning`,children:_(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),pe.length>0&&e(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[o(`p`,{className:`font-medium text-danger`,children:_(`build.blockEditor.errorsCannotSave`,{count:pe.length})}),pe.slice(0,5).map(e=>o(`p`,{className:`text-danger`,children:_(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),pe.length>5&&o(`p`,{className:`text-foreground-subtle`,children:_(`build.blockEditor.moreErrors`,{count:pe.length-5})})]}),G.data!==void 0&&(G.data.ok?e(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[o(x,{className:`h-3.5 w-3.5`}),` `,_(`build.blockEditor.compiledOk`)]}):e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[G.data.line!==void 0&&o(`span`,{className:`mr-1`,children:_(`build.blockEditor.errorLine`,{line:String(G.data.line)})}),G.data.error??_(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),G.error!==null&&e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[_(`build.blockEditor.couldNotReachTheCompiler`,`Could not reach the compiler:`),` `,wa(G.error)]}),s!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),t!==null&&e(`div`,{className:`space-y-3`,children:[o(xa,{blockId:t.id}),o(pa,{blockId:t.id})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(q,{variant:`outline`,onClick:()=>G.mutate(),disabled:G.isPending||a,title:_(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[G.isPending&&o(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.compile`)]}),e(q,{onClick:_e,disabled:a||me||K,children:[a&&o(y,{className:`h-4 w-4 animate-spin`}),` `,_(`common.save`)]}),e(q,{variant:`outline`,onClick:()=>p?.(),disabled:Ee!==null||p===void 0,title:Ee??_(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(E,{className:`h-4 w-4 animate-spin`}):o(E,{className:`h-4 w-4`}),` `,_(`build.blockEditor.restart`,`Restart`)]}),e(q,{variant:`ghost`,onClick:()=>te(!ee),title:_(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[o(S,{className:`h-4 w-4`}),` `,_(`common.logs`),` `,ee?`▾`:`▸`]}),o(q,{variant:`ghost`,onClick:h,disabled:a,children:_(`common.close`,`Close`)}),e(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[_(`build.blockEditor.errorsCount`,{count:pe.length}),ge&&t!==null?` · ${_(`build.blockEditor.unsavedChanges`)}`:``]}),K&&o(U,{variant:`warning`,children:_(`build.blockEditor.nameRequired`,`Name required`)})]}),ee&&e(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:t===null?_(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):o(f,{children:o(X,{i18nKey:`build.blockEditor.logsOf`,values:{id:z(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o(Pe,{addonId:z(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function wa(e){return e instanceof Error?e.message:String(e)}u();var Ta=[`coreBlocks`,`list`],Ea=[`coreBlocks`,`getTypeDefs`],Da=5e3;function Oa(e){return e instanceof Error?e.message:String(e)}function ka({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let f=T(),{t:p}=Y(),m=b(),{state:g,openNew:_,openEdit:v,close:y}=Ne({editKey:`block`,newKey:`new`}),[x,C]=c(null),[w,D]=c(null),[O,k]=c(null),A=l({queryKey:Ta,refetchInterval:Da,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),j=g.mode!==`closed`,M=l({queryKey:Ea,enabled:j,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),N=()=>{A.refetch()},P=n(null),F=A.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&ee(e)===`code`)!==void 0&&(P.current=t,v(t),i?.(t))},[t,F,v,i]),s(()=>{a&&(C(null),_(),i?.(null),u?.())},[a,u,i,_]);let I=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),N()}}),L=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),N()}}),R=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{D(null),N()}}),B=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:N}),V=d({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:N}),te=Bn((A.data??[]).filter(e=>ee(e)===`code`)),ne=A.data!==void 0&&te.length===0,re=I.isPending||L.isPending,ie=I.error===null?L.error===null?null:Oa(L.error):Oa(I.error),ae=g.mode===`edit`?te.find(e=>e.id===g.id)??(x!==null&&x.id===g.id?x:null):null,H=g.mode===`new`||ae===null?null:zn(te,ae),se=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=Ln(t),r=me(t.updatedAt,f);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(U,{variant:Rn(n.tone),children:n.label}),o(U,{variant:`info`,children:t.placement}),r!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:r})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:n.detail}),O===t.id&&e(`div`,{className:`mt-2 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:z(t.id)},components:{code:o(`code`,{})}})}),o(Pe,{addonId:z(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:t=>{let n=B.isPending||R.isPending,r=V.isPending&&V.variables===t.id;return w===t.id?e(`div`,{className:`flex justify-end gap-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`)}),o(q,{variant:`danger`,onClick:()=>R.mutate(t.id),disabled:n,children:p(`common.delete`,`Delete`)}),o(q,{variant:`ghost`,onClick:()=>D(null),children:p(`common.cancel`,`Cancel`)})]}):e(`div`,{className:`flex justify-end gap-1`,children:[o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),C(t),v(t.id),i?.(t.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),V.mutate(t.id)},disabled:n||r||!t.enabled,title:t.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:o(E,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),k(O===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(S,{className:`h-4 w-4`})}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),B.mutate({blockId:t.id,enabled:!t.enabled})},disabled:n,title:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),o(q,{variant:`ghost`,onClick:e=>{e.stopPropagation(),D(t.id)},title:p(`common.delete`,`Delete`),children:o(h,{className:`h-4 w-4`})})]})}}],[w,O,i,v,R,V.isPending,V.variables,B,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:A.data===void 0?``:Vn(te)}),A.error!=null&&o(G,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:Oa(A.error),onRetry:N}),o(Le,{columns:se,rows:te,rowKey:e=>e.id,pageSize:25,maxBodyHeight:ye,emptyMessage:ne?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):A.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{C(e),v(e.id),i?.(e.id)}}),o(ke,{open:j,onClose:()=>{I.reset(),L.reset(),V.reset(),C(null),y(),i?.(null)},title:H===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:H.name}),icon:oe,width:`xl`,testId:`script-editor-panel`,children:o(Ca,{existing:H,typeDefs:M.data,typeDefsLoading:M.isLoading,saving:re,saveError:ie,restarting:V.isPending,restartError:V.error===null?null:Oa(V.error),onRestart:H===null?void 0:()=>V.mutate(H.id),onSave:e=>{let t=H;t===null?I.mutate(e):L.mutate({blockId:t.id,block:e})},onCancel:()=>{I.reset(),L.reset(),V.reset(),C(null),y(),i?.(null)}})}),R.error!=null&&o(G,{message:Oa(R.error)}),B.error!=null&&o(G,{message:Oa(B.error)}),V.error!=null&&o(G,{message:Oa(V.error)})]})}var Aa=[`automations`,`scripts`,`custom-device`];function ja(e){return e!==null&&Aa.some(t=>t===e)}var Ma=[`coreBlocks`,`list`,`build-counts`],Na=[`block`,`create`,`new`];function Pa(e){return e.filter(e=>ee(e)===`code`).length}function Fa(e){return e.filter(e=>nt(e.code)).length}function Ia(e,t){return t===null?e:`${e} (${String(t)})`}function La(){let{t}=Y(),n=b(),[r,i]=He(),a=r.get(`tab`),s=ja(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:Ma,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:Pa(u),f=u===void 0?null:Fa(u),p=l({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>n.trpcClient.coreBlocks.listCompositions.query({})}),m=p.data?.state===`loaded`?p.data.views.length:null,h=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},g=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},_=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},y=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},x=e=>{i(()=>{let t=new URLSearchParams(window.location.search);return t.set(`tab`,`custom-device`),t.delete(`block`),t.delete(`create`),t.set(`new`,e),t},{replace:!0})},S=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},C=s===`automations`?`New automation`:`New script`,w=Be(`/build`,{t,isAdmin:!0})??{icon:D,title:t(`nav.build`,`Build-your-self`)};return o(qe,{icon:w.icon,title:w.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${w.title} sections`,fill:!0,actions:s===`custom-device`?e(`div`,{className:`flex flex-wrap gap-2`,children:[e(q,{type:`button`,variant:`outline`,onClick:()=>x(`blank`),"data-testid":`build-new-composition`,children:[o(v,{className:`h-4 w-4`}),` `,t(`helper.newComposition`)]}),e(q,{type:`button`,onClick:()=>x(`helper`),"data-testid":`build-new-helper`,children:[o(v,{className:`h-4 w-4`}),` `,t(`helper.newHelper`)]})]}):e(q,{type:`button`,onClick:y,"data-testid":`build-new`,children:[o(v,{className:`h-4 w-4`}),` `,C]}),sections:[{id:`automations`,label:Ia(`Automations`,f),ownedParams:Na,content:o(qn,{onOpenScripts:h,initialBlockId:s===`automations`?r.get(`block`)??void 0:void 0,onBlockIdChange:g,createRequested:s===`automations`&&c,onCreateConsumed:S})},{id:`scripts`,label:Ia(`Scripts`,d),ownedParams:Na,content:o(ka,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:_,createRequested:s===`scripts`&&c,onCreateConsumed:S})},{id:`custom-device`,label:Ia(`Custom Device`,m),ownedParams:Na,content:o(br,{createRequested:s===`custom-device`&&c,onCreateConsumed:S})}]})}export{La as BuildPage};
|