local-operator-ui 0.32.3 → 0.32.4
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/out/main/index.js +34 -2
- package/out/renderer/assets/{_basePickBy-B8Qlf7Er.js → _basePickBy-CjK8J1ko.js} +1 -1
- package/out/renderer/assets/{_baseUniq-Dsdryz8Q.js → _baseUniq-iXcRyKXm.js} +1 -1
- package/out/renderer/assets/{agent-details-page-D3M6i4Zf.js → agent-details-page-BzANbiHv.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-4mSQ6ykI.js → agent-hub-page-CO896V5d.js} +3 -3
- package/out/renderer/assets/{agents-page-_DauTxks.js → agents-page-C1YYkATW.js} +3 -3
- package/out/renderer/assets/{arc-DIKk33c1.js → arc-DSzdvb-p.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-D_iXTZhU.js → architectureDiagram-IEHRJDOE-Btaox3jN.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-CFQBvLl2.js → blockDiagram-JOT3LUYC-C-fhdoup.js} +1 -1
- package/out/renderer/assets/{browser-page-COd60oBu.js → browser-page-CXnz4yK0.js} +1 -1
- package/out/renderer/assets/{browser-webauthn-prompt-CCnbkKBw.js → browser-webauthn-prompt-D60RMWTt.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-hSZ61XP8.js → c4Diagram-VJAJSXHY-BV8WjI_N.js} +1 -1
- package/out/renderer/assets/channel-YjlaLMSb.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-ByvUxlwL.js → chunk-4BMEZGHF-DLe3c9GX.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-C7I3LSLt.js → chunk-A2AXSNBT-2USPa4Dy.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-DlcbhveB.js → chunk-AEK57VVT-dVGtqA7z.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-Vr6-1rCd.js → chunk-D6G4REZN-B4_EX1rg.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-Ce1S3X33.js → chunk-RZ5BOZE2-Bta5D-vX.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-CpwBuqyP.js → chunk-XZIHB7SX-i4ArBNLI.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-BHFyS6ei.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-BHFyS6ei.js +1 -0
- package/out/renderer/assets/clone-DBH_QsN1.js +1 -0
- package/out/renderer/assets/{conversation-input-sync-ztF2uENp.js → conversation-input-sync-CyctUEWr.js} +239 -239
- package/out/renderer/assets/{dagre-OKDRZEBW-CFuwTnbl.js → dagre-OKDRZEBW-EyHSAPT7.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-eW1-TMoM.js → diagram-SSKATNLV-D_Ci5F6Q.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-COtG874c.js → diagram-VNBRO52H-C8dvE9sI.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-DCpuAzid.js → erDiagram-Q7BY3M3F-DxjXnfZw.js} +1 -1
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-D0OpPVjR.js → flowDiagram-4HSFHLVR-BkJ35sqU.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-uZoJ5M51.js → ganttDiagram-APWFNJXF-BgeRhVdz.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-dEbJyobF.js → gitGraphDiagram-7IBYFJ6S-CsNXwJ1Z.js} +1 -1
- package/out/renderer/assets/{graph-Bf2xoA4c.js → graph-vn67EOK3.js} +1 -1
- package/out/renderer/assets/{index-2LU4Cd3s.js → index-Bu7e3rSb.js} +187 -187
- package/out/renderer/assets/{index-CNArcL7T.js → index-Cx-WVD9G.js} +1 -1
- package/out/renderer/assets/{index-DtU-En7k.js → index-DS9vxVaQ.js} +1 -1
- package/out/renderer/assets/{infoDiagram-PH2N3AL5-BhEM5meY.js → infoDiagram-PH2N3AL5-CV-g-mjS.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-HXNpm8Jj.js → journeyDiagram-U35MCT3I-I57ox-dW.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-BAtAUqHM.js → kanban-definition-NDS4AKOZ-km2hq1fY.js} +1 -1
- package/out/renderer/assets/{layout-CpstO-oE.js → layout-CJ42RoVR.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-DCOC8Tle.js → legacy-agents-page-r2Xc2fks.js} +1 -1
- package/out/renderer/assets/{mermaid.core-DmRnOx5f.js → mermaid.core-DQsftHid.js} +5 -5
- package/out/renderer/assets/mesh-page-DejMbpGY.js +1 -0
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-BoIsKamK.js → mindmap-definition-ALO5MXBD-B_Hx68jr.js} +1 -1
- package/out/renderer/assets/{mini-Jvr5I_Rk.js → mini-BzGdxFI_.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-CVVzZd9o.js → org-surface-gate-CNy4oo3A.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-CfH05_IM.js → pieDiagram-IB7DONF6-CM8q0hlY.js} +1 -1
- package/out/renderer/assets/{projects-page-BGGVrY3C.js → projects-page-bHdWZ0Kx.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-CAYKVWdZ.js → quadrantDiagram-7GDLP6J5-DqoQ8lz2.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-CiWFQ2gN.js → radar-MK3ICKWK-C-OrPLEs.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-DDa7dmwu.js → radient-auth-buttons-Cju8RhKQ.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-DiB5rNkI.js → requirementDiagram-KVF5MWMF-DtpTdYbV.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-ZBkoa531.js → sankeyDiagram-QLVOVGJD-BFX_LBnO.js} +1 -1
- package/out/renderer/assets/{schedules-page-D29ivDk1.js → schedules-page-D9mb_-BC.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-BIfJ5ZAM.js → sequenceDiagram-X6HHIX6F-lUYP-LDw.js} +1 -1
- package/out/renderer/assets/{settings-page-DFBspqht.js → settings-page-DUIyql2W.js} +7 -7
- package/out/renderer/assets/{stateDiagram-DGXRK772-DPnXecEL.js → stateDiagram-DGXRK772-BPJsQn4b.js} +1 -1
- package/out/renderer/assets/{stateDiagram-v2-YXO3MK2T-w326tl_e.js → stateDiagram-v2-YXO3MK2T-DFNM7_ku.js} +1 -1
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-B-Kq_ROU.js → timeline-definition-BDJGKUSR-jwbIRZBB.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-CDNzydiw.js → use-download-agent-mutation-B9PktiM4.js} +1 -1
- package/out/renderer/assets/{use-memberships-query-CX0l7_F8.js → use-memberships-query-DjBVKN3g.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-CEzW9qk7.js → xychartDiagram-VJFVF3MP-C7CoMzZa.js} +1 -1
- package/out/renderer/index.html +2 -2
- package/out/renderer/mini.html +2 -2
- package/package.json +2 -2
- package/out/renderer/assets/channel-CEa21TjA.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-BclaHtGg.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-BclaHtGg.js +0 -1
- package/out/renderer/assets/clone-CEOncWhu.js +0 -1
- package/out/renderer/assets/mesh-page-Xh_-o655.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as i,j as t,c as ce,t as $n}from"./index-DkZDDEqx.js";import{cq as lt,cr as Un,cs as Tt,ct as ge,bK as Pn,aG as ke,a7 as tn,a8 as vt,ax as nn,u as sn,aN as zn,aO as Kn,cu as
|
|
1
|
+
import{r as i,j as t,c as ce,t as $n}from"./index-DkZDDEqx.js";import{cq as lt,cr as Un,cs as Tt,ct as ge,bK as Pn,aG as ke,a7 as tn,a8 as vt,ax as nn,u as sn,aN as zn,aO as Kn,cu as Hn,cv as Bn,cw as Vn,cx as Gn,cy as an,cz as bt,a5 as on,cA as He,cB as qn,aS as Yn,cC as Et,S as jt,cD as Wn,cE as Qn,aw as rn,aU as dt,aV as ut,cF as Zn,aZ as Jn,cG as Xn,c4 as mt,a as cn,d as It,ah as Ge,cH as es,cI as ts,cJ as ns,X as ye,cK as ht,cL as ss,cM as as,cN as os,aQ as rs,bc as is,cO as ln,cP as cs,cQ as ls,cR as ds,aM as us,cS as dn,aT as un,cT as mn,cU as ms,cV as hs,aH as ps,bh as hn,a_ as fs,b0 as gs,cW as Ie,cX as pt,cY as Lt,cZ as ys,c_ as xs,c$ as ks,d0 as vs,d1 as pn,d2 as bs,b5 as js,bN as ws,bM as _s,d3 as Ns,d4 as Ss,d5 as Cs,d6 as Ms,d7 as As}from"./conversation-input-sync-CyctUEWr.js";import{u as Oe,b as Rs,d as fn}from"./ui-preferences-store-BcI6fr9b.js";import{aY as gn,aZ as Ts,a_ as Es,an as Ot,a$ as Is,b0 as Ls,b1 as Be,S as Os,aJ as Fs,b2 as Ds,b3 as $s,b4 as Us,b5 as Ps,b6 as zs,b7 as Ks,az as Ft,au as Hs,aG as Dt,b8 as Bs,aH as Vs,aI as Gs,b9 as qs,ba as Ys}from"./index-Bu7e3rSb.js";import{P as Ws}from"./page-header-DuslXJJm.js";import{c as b,B as P,S as re,x as Qs,s as Zs,t as Js,u as Xs,v as ea,w as ta,f as $e,J as Qe,L as xe,I as Ae,z as ft,F as gt,G as Fe,_ as $t,T as yn,O as na,D as sa,l as aa,m as oa,o as ra,p as Ut,k as ia,A as te,j as ca,E as la,$ as da,Q as ua,C as ma,e as xn}from"./error-boundary-Chq_L-1d.js";import{S as ne,I as Ze,a as oe,N as ha}from"./settings-section-BYsjs9LS.js";import{R as pa}from"./radient-auth-buttons-Cju8RhKQ.js";import{B as fa}from"./book-open-Dm0X0_nl.js";import{a as ga,p as at}from"./parseISO-CZfAC2_J.js";import{i as ya,a as Ne,f as xa}from"./format-CZUObkkr.js";import{t as ka}from"./en-US-BcB1DWxG.js";import"./console-mirror-CFdbeNFe.js";/**
|
|
2
2
|
* @license lucide-react v0.507.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -58,12 +58,12 @@ import{r as i,j as t,c as ce,t as $n}from"./index-DkZDDEqx.js";import{cq as lt,c
|
|
|
58
58
|
*
|
|
59
59
|
* This source code is licensed under the ISC license.
|
|
60
60
|
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const Ka=[["path",{d:"M6 16.326A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 .5 8.973",key:"1cez44"}],["path",{d:"m13 12-3 5h4l-3 5",key:"1t22er"}]],
|
|
61
|
+
*/const Ka=[["path",{d:"M6 16.326A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 .5 8.973",key:"1cez44"}],["path",{d:"m13 12-3 5h4l-3 5",key:"1t22er"}]],Ha=b("cloud-lightning",Ka);/**
|
|
62
62
|
* @license lucide-react v0.507.0 - ISC
|
|
63
63
|
*
|
|
64
64
|
* This source code is licensed under the ISC license.
|
|
65
65
|
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const
|
|
66
|
+
*/const Ba=[["path",{d:"M10.188 8.5A6 6 0 0 1 16 4a1 1 0 0 0 6 6 6 6 0 0 1-3 5.197",key:"erj67n"}],["path",{d:"M13 16a3 3 0 1 1 0 6H7a5 5 0 1 1 4.9-6Z",key:"p44pc9"}]],Va=b("cloud-moon",Ba);/**
|
|
67
67
|
* @license lucide-react v0.507.0 - ISC
|
|
68
68
|
*
|
|
69
69
|
* This source code is licensed under the ISC license.
|
|
@@ -193,12 +193,12 @@ import{r as i,j as t,c as ce,t as $n}from"./index-DkZDDEqx.js";import{cq as lt,c
|
|
|
193
193
|
*
|
|
194
194
|
* This source code is licensed under the ISC license.
|
|
195
195
|
* See the LICENSE file in the root directory of this source tree.
|
|
196
|
-
*/const Ko=[["path",{d:"m8 3 4 8 5-5 5 15H2L8 3z",key:"otkl63"}]],
|
|
196
|
+
*/const Ko=[["path",{d:"m8 3 4 8 5-5 5 15H2L8 3z",key:"otkl63"}]],Ho=b("mountain",Ko);/**
|
|
197
197
|
* @license lucide-react v0.507.0 - ISC
|
|
198
198
|
*
|
|
199
199
|
* This source code is licensed under the ISC license.
|
|
200
200
|
* See the LICENSE file in the root directory of this source tree.
|
|
201
|
-
*/const
|
|
201
|
+
*/const Bo=[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]],Vo=b("radio",Bo);/**
|
|
202
202
|
* @license lucide-react v0.507.0 - ISC
|
|
203
203
|
*
|
|
204
204
|
* This source code is licensed under the ISC license.
|
|
@@ -288,5 +288,5 @@ import{r as i,j as t,c as ce,t as $n}from"./index-DkZDDEqx.js";import{cq as lt,c
|
|
|
288
288
|
*
|
|
289
289
|
* This source code is licensed under the ISC license.
|
|
290
290
|
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
-
*/const Sr=[["path",{d:"M12.8 19.6A2 2 0 1 0 14 16H2",key:"148xed"}],["path",{d:"M17.5 8a2.5 2.5 0 1 1 2 4H2",key:"1u4tom"}],["path",{d:"M9.8 4.4A2 2 0 1 1 11 8H2",key:"75valh"}]],Cr=b("wind",Sr),Mr=({appVersion:e=null,slowWaitHintMs:n})=>{const s="https://local-operator.com/download",[a,o]=i.useState(!1),r=gn(a,n??Ts),[d,u]=i.useState(!1),[c,m]=i.useState(null),[y,j]=i.useState("info"),[w,h]=i.useState(null),[v,R]=i.useState(null),C=e?.trim()?e.trim():null,V=i.useRef(!1),_=lt(L=>L.openDetail),B=i.useRef(!1),$=i.useRef(0),M=i.useRef(!1),S=i.useCallback((L,D)=>{B.current=!1,m(L),j(D),u(!0)},[]),W=i.useCallback(L=>{B.current=!0,m(L),j("success"),u(!0)},[]),q=i.useCallback(()=>{B.current&&(B.current=!1,u(!1),m(null))},[]),{clearDeferredUpdate:Z}=Un();i.useEffect(()=>{const L=window.api.updater.onUpdateError(p=>{V.current&&p.includes("manually")&&(h({message:"The server is installed outside the app, so use the tool you installed it with - uv, pipx or pip.",command:""}),B.current=!1,m(null),j("warning"),u(!0))}),D=window.api.updater.onBackendUpdateDevMode(p=>{V.current&&S(p,"info")}),O=()=>{M.current=!0,q()},z=window.api.updater.onUpdateAvailable(O),K=window.api.updater.onUpdateNpxAvailable(O),se=window.api.updater.onBackendUpdateAvailable(O);return()=>{L(),D(),z(),K(),se()}},[q,S]),i.useEffect(()=>{let L=!1;const D=()=>{window.api.updater.getLastInstallAttempt().then(z=>{L||R(z)}).catch(()=>{})};D();const O=window.api.updater.onUpdateInstallFailed(()=>D());return()=>{L=!0,O()}},[]);const T=async()=>{const L=++$.current;q(),M.current=!1;try{o(!0),V.current=!0,Z(ge.UI),Z(ge.BACKEND);const D=await window.api.updater.checkForAllUpdates({manual:!0});if(L!==$.current)return;D.app==="available"&&_(ge.UI),D.server==="available"&&_(ge.BACKEND),D?.affirmation&&!M.current?W(D.affirmation):q()}catch(D){if(L!==$.current)return;console.warn(`Update check failed; the app-level alert owns the report: ${Es(D)}`)}finally{L===$.current&&o(!1),setTimeout(()=>{V.current=!1},2e3)}},ee=()=>{B.current=!1,u(!1),m(null)};return t.jsxs(t.Fragment,{children:[v&&t.jsxs("div",{className:"mb-3 rounded-sm bg-sunken p-3",children:[t.jsxs("p",{className:"text-body-sm text-ink",children:["The last update to version ",v.targetVersion," didn't finish",v.attempts>1?` (${v.attempts} attempts)`:"",".",C?` Version ${C} is running.`:null]}),t.jsxs("p",{className:"mt-1 text-meta text-ink-dim",children:["Detected"," ",v.detectedAt?new Date(v.detectedAt).toLocaleString():"at an unknown time",". ",v.detail]}),t.jsx(P,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>void window.api.openExternal(s),children:"Download a fresh copy"})]}),t.jsxs(P,{variant:"outline",onClick:()=>void T(),disabled:a,children:[a?t.jsx(re,{size:"sm"}):null,a?"Checking...":"Check for updates"]}),r&&t.jsx("p",{className:"mt-2 text-meta text-ink-muted",children:"Still checking. A slow or stalled connection can hold this for about a minute and a half - the app stops waiting on its own."}),w&&t.jsxs(Tt,{open:d,autoHideDuration:1e4,onClose:ee,variant:"warning",children:[t.jsx("p",{className:"text-body-sm",children:w.message}),w.command&&t.jsx("code",{className:"mt-2 block rounded-sm bg-sunken p-2 text-mono-sm text-ink",children:w.command})]}),c&&y!=="danger"&&t.jsx(Tt,{open:d,autoHideDuration:6e3,onClose:ee,variant:y,children:c})]})},qe=["system-prompt"],Ar=()=>{const{shouldEnableQuery:e}=Pn();return ke({enabled:e({bypassInternetCheck:!0}),queryKey:qe,queryFn:async()=>{try{const s=await tn(vt.baseUrl).config.getSystemPrompt();if(s===null)return null;if(s.status>=400)throw new Error(s.message||"Failed to fetch system prompt");return s.result}catch(n){const s=n instanceof Error?n.message:"An unknown error occurred while fetching system prompt";throw nn(s),n}},refetchOnWindowFocus:!1,staleTime:5e3})},Rr=()=>{const e=sn(),n=tn(vt.baseUrl);return zn({mutationFn:async s=>{try{const a=await n.config.updateSystemPrompt(s);if(a.status>=400)throw new Error(a.message||"Failed to update system prompt");return a.result}catch(a){const o=a instanceof Error?a.message:"An unknown error occurred while updating system prompt";throw nn(o),a}},onSuccess:async s=>{await e.invalidateQueries({queryKey:qe,refetchType:"none"}),e.setQueryData(qe,a=>a&&{...a,...s}),await e.refetchQueries({queryKey:qe,type:"all"}),Kn("System prompt updated")},onError:s=>{console.error("Error updating system prompt:",s)}})},Tr=({value:e,label:n,description:s,onChange:a,icon:o,isSaving:r=!1})=>{const[d,u]=i.useState(e),c=i.useId(),m=`${c}-label`,y=`${c}-description`,j=async w=>{if(!r){u(w);try{await a(w)}catch(h){u(!w),console.error("Error toggling setting:",h)}}};return t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("span",{id:m,className:"flex min-h-6 items-center gap-2 text-body text-ink",children:[o&&t.jsx(o,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-dim"}),n]}),s&&t.jsx("p",{id:y,className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:s})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:r?t.jsx(re,{size:"md",label:`Saving ${n}`}):t.jsx(Qs,{checked:d,onCheckedChange:j,"aria-labelledby":m,"aria-describedby":s?y:void 0})})]})};function Pt(e,n){const s=ka(e,n?.in);if(!ya(s))throw new RangeError("Invalid time value");const a=Ne(s.getDate(),2),o=Ne(s.getMonth()+1,2),r=s.getFullYear(),d=Ne(s.getHours(),2),u=Ne(s.getMinutes(),2),c=Ne(s.getSeconds(),2);let m="",y="";const j=s.getTimezoneOffset();if(j!==0){const w=Math.abs(j),h=Ne(Math.trunc(w/60),2),v=Ne(w%60,2);y=`${j<0?"+":"-"}${h}:${v}`}else y="Z";return`${r}-${o}-${a}T${d}:${u}:${c}${m}${y}`}function Er(e,n,s){return ga(e,-30,s)}var Ir=Bn({chartName:"LineChart",GraphicalChild:an,axisComponents:[{axisType:"xAxis",AxisComp:Hn},{axisType:"yAxis",AxisComp:Vn}],formatAxisMap:Gn});const Lr=["radient","creditBalance"],Or=e=>{const{user:n,isAuthenticated:s}=bt(),a=n?.account?.tenant_id,o=s&&!!a&&e?.enabled;return ke({queryKey:[Lr,a],queryFn:async()=>{if(!a)throw new Error("Tenant ID not available");const r=await on({operation:"credits",tenantId:a});if(!r||typeof r.balance!="number")throw new Error("Invalid credit balance response format");return r},enabled:o,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},Fr=["radient","usageRollup"],Dr=(e,n)=>{const{user:s,isAuthenticated:a}=bt(),o=s?.account?.tenant_id,r=a&&!!o&&n?.enabled;return ke({queryKey:[...Fr,o,e],queryFn:async()=>{if(!o)throw new Error("Tenant ID not available");const d={};for(const[c,m]of Object.entries(e))m!=null&&(d[c]=String(m));const u=await on({operation:"usage",tenantId:o,query:d});if(!u)throw new Error("Invalid usage rollup response format");return u},enabled:r,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},zt={[ge.UI]:"Application updates",[ge.BACKEND]:"Server updates"},Kt=({type:e})=>{const n=lt(a=>a.followed[e]),s=lt(a=>a.setFollowedSegment);return t.jsxs("div",{className:"flex flex-col gap-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-6",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-body-sm text-ink",children:zt[e]}),t.jsx("div",{className:"mt-0.5 text-meta text-ink-muted",children:Be[n].description})]}),t.jsxs(Zs,{value:n,onValueChange:a=>s(e,a),children:[t.jsx(Js,{"aria-label":`${zt[e]}: ${Be[n].label}`,className:"w-full sm:w-56","data-followed-segment":e,children:t.jsx(Xs,{})}),t.jsx(ea,{children:qn.map(a=>t.jsx(ta,{value:a,title:Be[a].description,children:Be[a].label},a))})]})]})},$r=()=>t.jsxs("div",{className:ce("flex flex-col gap-3"),children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-heading text-ink",children:"Update notifications"}),t.jsx("p",{className:"mt-1 text-meta text-ink-muted",children:"How much of a version change shows the update notice at the bottom of the window. A check you run yourself always reports what it finds."})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(Kt,{type:ge.UI}),t.jsx(Kt,{type:ge.BACKEND})]})]}),Ur=({appVersion:e})=>t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx($r,{}),t.jsx(Mr,{appVersion:e})]}),Pr=e=>{if(!e)return null;try{return new URL(e).host}catch{return null}},zr=()=>{const[e,n]=i.useState(null),[s,a]=i.useState({value:"Loading...",detail:null,degraded:!1}),[o,r]=i.useState({platform:"Loading...",arch:"...",nodeVersion:"Loading...",electronVersion:"Loading...",chromeVersion:"Loading..."});i.useEffect(()=>{let u=!0;const c=h=>{if(!u)return;const v=Pr(h.url);if(h.state==="connecting"){a({value:"Loading...",detail:null,degraded:!1});return}if(h.state==="detached"){a({value:"Not connected",detail:h.detail||null,degraded:!1});return}if(h.state==="wedged"){a({value:"Not attached",detail:h.detail||null,degraded:!1});return}const R=h.version||"Version unknown";a({value:v?`${R} · ${v}`:R,detail:h.detail||null,degraded:h.state==="degraded"})};let m=!1;const y=window.api?.backend?.onStatusChange(h=>{m=!0,c(h)}),j=async()=>{try{const[h,v]=await Promise.all([window.api.systemInfo.getAppVersion(),window.api.systemInfo.getPlatformInfo()]);u&&(n(h),r(v))}catch(h){console.error("Error fetching app information:",h)}},w=async()=>{try{const h=window.api?.backend;if(h){const C=await h.getStatus();m||c(C);return}const v=await Et.healthCheck(vt.baseUrl),R=Et.getServerVersion(v);u&&a({value:R,detail:null,degraded:!1})}catch(h){console.error("Error fetching server version:",h),u&&a({value:"Unavailable",detail:null,degraded:!1})}};return j(),w(),()=>{u=!1,y?.()}},[]);const d=(u,c,m,y={})=>t.jsx(oe,{label:t.jsx($e,{content:m,children:t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(Qe,{size:12,className:"shrink-0"}),u]})}),valueClassName:y.valueClassName,value:t.jsxs(t.Fragment,{children:[y.valueTooltip?t.jsx($e,{content:y.valueTooltip,children:t.jsx("span",{"data-backend-version":y.valueHoverTarget?"":void 0,children:c})}):c,y.statusNote?t.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:y.statusNote}):null]})});return t.jsx(ne,{title:"Application updates and info",icon:Yn,description:"Check for updates and view information about your Local Operator installation.",dataTourTag:"settings-app-updates-section",children:t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs(Ze,{children:[d("Application version",e??"Loading...","The version of the Local Operator user interface application."),d("Server version",s.value,"The version of the Local Operator API server backend, and the address of the daemon it was read from.",{valueTooltip:s.detail,valueHoverTarget:!0,statusNote:s.degraded?"Not answering":void 0,valueClassName:s.degraded?"text-ink-muted":void 0}),d("Platform",`${o.platform} (${o.arch})`,"The operating system and architecture your application is running on."),d("Node.js version",o.nodeVersion,"The JavaScript runtime environment version."),d("Electron version",o.electronVersion,"The framework version enabling this desktop application.")]}),t.jsx(Ur,{appVersion:e})]})})},Kr=[[[".claude.json"],"Claude Code"],[[".claude",".mcp.json"],"Claude Code"],[[".cursor","mcp.json"],"Cursor"],[[".vscode","mcp.json"],"VS Code"],[[".codex","config.toml"],"Codex CLI"]];function vn(e){if(!e)return null;const n=e.split("\\").join("/").split("/").filter(Boolean);for(const[s,a]of Kr)if(!(n.length<s.length)&&n.slice(-s.length).join("/")===s.join("/"))return a;return null}const Ye=e=>`${e} ${e===1?"tool":"tools"}`,Br=e=>`${e} ${e===1?"integration":"integrations"}`,Hr=["connected","needs_sign_in","not_started","connecting","error"],bn=e=>Hr.includes(e),Re=(e,n)=>[...n].filter(s=>s.name===e&&s.status==="running").sort((s,a)=>a.created_at-s.created_at)[0]??null,Vr={connectedAt:null,connectedToolCount:null,settledGroup:null,pinnedGroup:null,pinnedOperationId:null,needsKey:!1,needsSignIn:!1,disconnectedAt:null,holdUntil:null,lastDecisive:null},Gr=1e12,qr=1e9,Yr=60*60*1e3,jn=(e,n=Date.now())=>{if(typeof e!="number"||!Number.isFinite(e))return null;const s=e>=Gr?e:e<qr?null:e*1e3;return s===null||s>n+Yr?null:Math.min(s,n)},Se=(e,n)=>e?.[n]??Vr,Pe=(e,n,s)=>Zr(e,n)??s?.lastDecisive??null,Wr=e=>({id:e.id,name:e.name,action:e.action,status:e.status,created_at:e.created_at,credential_removed:e.credential_removed,...e.message?{message:e.message}:{}}),wt=(e,n)=>e.status==="not_started"&&typeof e.tool_count=="number"&&(n.connectedAt!==null||e.status_basis==="stored"&&e.tool_count_basis==="last_seen"),Qr=(e,n)=>[...n].filter(s=>s.name===e).sort((s,a)=>a.created_at-s.created_at)[0]??null,Zr=(e,n)=>Qr(e,n.filter(s=>s.status!=="cancelled")),Je=e=>e.actions.includes("set_key")||e.actions.includes("add_key");function Jr(e,n){const s=Math.max(0,Math.round((e-n)/1e3));if(s<60)return"just now";const a=Math.round(s/60);if(a<60)return`${a} min ago`;const o=Math.round(a/60);return o<24?`${o} h ago`:`${Math.round(o/24)} d ago`}function ot(e){if(!e)return null;const n=e.trim();if(!n||/^\/\w/.test(n)||/\/mcp\s+\w+/.test(n))return null;let s=n;for(let a=0;a<3;a+=1){const o=s.replace(/^(?:connection (?:closed|error|refused)|error|closed|failed)\s*:\s*/i,"").trim();if(o===s)break;s=o}return s=s.replace(/\s*\(\s*\d{3}\s*\)/g,"").replace(/\s+([.,;])/g,"$1").replace(/\s{2,}/g," ").trim(),s||null}function Xr(e,n=[],s,a=Date.now()){const o=Se(s,e.name),r=Re(e.name,n);if(r){if(r.action==="login"||r.action==="reauth")return{label:"Signing in…",tone:"info",detail:null,busy:!0};if(r.action==="logout")return{label:"Signing out…",tone:"info",detail:null,busy:!0}}if(!bn(e.status))return{label:"Status unavailable",tone:"neutral",detail:null,busy:!1};const d=Pe(e.name,n,o),u=Xe(d)&&e.status!=="connected",c=wt(e,o),m=St(d)&&e.status!=="connected",y=(d?.action==="login"||d?.action==="reauth")&&d.status==="failed";if(o.disconnectedAt!==null)return{label:"Not connected",tone:"neutral",detail:null,busy:!1};switch(e.status){case"connected":return{label:typeof e.tool_count=="number"?`Connected · ${Ye(e.tool_count)}`:"Connected",tone:"success",detail:null,busy:!1};case"connecting":return{label:"Connecting…",tone:"info",detail:null,busy:!0};case"needs_sign_in":return{label:e.auth.kind==="api_key"||De(e,n,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:ot(e.status_reason),busy:!1};case"error":return{label:"Couldn't start",tone:"danger",detail:ot(e.status_reason)??"No reason was given.",busy:!1};default:if(u)return{label:"Signed out",tone:"warning",detail:null,busy:!1};if(m)return{label:"Sign-out didn't finish",tone:"warning",detail:"The sign-in is still saved.",busy:!1};if(De(e,n,o))return{label:"Needs a key",tone:"warning",detail:null,busy:!1};if(y)return{label:"Sign-in didn't finish",tone:"warning",detail:null,busy:!1};if(o.needsSignIn)return{label:e.auth.kind==="api_key"||De(e,n,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:ot(e.status_reason),busy:!1};if(e.status_basis==="stored"&&c&&o.disconnectedAt===null){const j=o.connectedAt??jn(e.last_seen_at,a);return{label:j!==null?`Worked ${Jr(a,j)} · ${Ye(e.tool_count)}`:`Worked earlier · ${Ye(e.tool_count)}`,tone:"success",detail:null,busy:!1}}return e.status_basis==="live"?{label:"Not connected",tone:"neutral",detail:null,busy:!1}:{label:"Ready",tone:"neutral",detail:null,busy:!1}}}const wn=e=>e===1?"Replace the saved key":"Replace saved keys",ei=/[,;]?\s*(?:or|and)?\s*add (?:its|a|the) key instead\.?\s*$/i;function ti(e,n){const s=e?.trim()??"";if(!s)return null;if(n)return s;const a=s.replace(ei,"").trim();return a?/\.$/.test(a)?a:`${a}.`:s}const ni="Nothing is wrong. It starts when a chat uses it.",si="Not running in this chat.",ai=e=>e.transport==="local_command"?"Local command":"Remote URL";function _n(e){switch(e.source.kind){case"local-operator":case"project-mcp-json":return null;case"claude-code":return"Claude Code";case"cursor":return"Cursor";case"vscode":return"VS Code";case"codex":return"Codex CLI";default:return vn(e.source.path)}}function oi(e,n){const s=[ai(e)];e.status!=="connected"&&e.tool_count_basis==="last_seen"&&typeof e.tool_count=="number"&&s.push(`${Ye(e.tool_count)} when last checked`),n&&s.push(e.scope==="project"?"This project":"Global");const a=_n(e);return a?s.push(`Imported from ${a}`):e.source.editable||s.push("Imported from a project file"),s}const _t=(e,n)=>n.disconnectedAt!==null?"not_started":e.status;function Nt(e,n=[],s){const a=Se(s,e.name),o=Re(e.name,n);if(o)return o.action==="login"||o.action==="reauth"?{kind:"sign_in",label:"Continue sign-in"}:null;const r=y=>e.actions.includes(y),d=Je(e),u=De(e,n,a);if(!bn(e.status))return r("test")?{kind:"test",label:"Check again"}:null;const c=Pe(e.name,n,a),m=c?.status==="failed"&&ze(c);switch(_t(e,a)){case"connected":case"connecting":return null;case"needs_sign_in":return u?{kind:"set_key",label:"Add key"}:r("sign_in")?{kind:"sign_in",label:"Sign in"}:d?{kind:"set_key",label:"Add key"}:r("reauth")?{kind:"reauth",label:"Sign in again"}:{kind:"fix",label:"Fix"};case"error":return r("connect")?{kind:"connect",label:"Reconnect"}:r("test")?{kind:"test",label:"Retry"}:{kind:"fix",label:"Fix"};default:{if(Xe(c)&&r("sign_in"))return{kind:"sign_in",label:"Sign in"};if(St(c)&&r("sign_out"))return{kind:"sign_out",label:"Sign out again"};if(a.disconnectedAt!==null&&r("connect"))return{kind:"connect",label:"Connect"};if(a.needsSignIn){if(u&&d)return{kind:"set_key",label:"Add key"};if(r("sign_in"))return{kind:"sign_in",label:"Sign in"}}return u&&d?{kind:"set_key",label:"Add key"}:m&&r("sign_in")?{kind:"sign_in",label:"Try again"}:wt(e,a)&&!r("connect")?null:r("connect")?{kind:"connect",label:"Connect",...a.connectedAt===null&&e.status_basis!=="live"?{variant:"ghost"}:{}}:r("test")&&e.tool_count===null&&e.tool_count_basis===null?{kind:"test",label:"Test",variant:"ghost"}:null}}}const ze=e=>e.action==="login"||e.action==="reauth",Xe=e=>!!(e&&e.action==="logout"&&e.status==="complete"),St=e=>!!(e&&e.action==="logout"&&e.status!=="running"&&e.status!=="complete"),Nn=/no oauth authorization server/i;function De(e,n,s){if(!Je(e))return!1;const a=Pe(e.name,n,s);return a&&ze(a)&&a.status==="failed"&&Nn.test(a.message??"")?!0:s.needsKey}function ri(e,n=[],s){const a=Nt(e,n,s)?.kind,o=_t(e,Se(s,e.name)),r=c=>e.actions.includes(c),d=[],u=Re(e.name,n);if(u&&d.push({kind:"cancel",label:"Cancel"}),!u&&r("test")&&a!=="test"&&d.push({kind:"test",label:"Test connection"}),r("connect")&&a!=="connect"&&o!=="connected"&&d.push({kind:"connect",label:"Reconnect"}),!u&&r("sign_in")&&a!=="sign_in"&&o!=="connected"&&d.push({kind:"sign_in",label:"Sign in"}),r("reload")&&d.push({kind:"reload",label:"Reload"}),!u&&r("reauth")&&a!=="reauth"&&d.push({kind:"reauth",label:"Sign in again"}),Je(e)&&a!=="set_key"&&d.push({kind:"set_key",label:e.auth.secret_refs.length>0?"Update key":"Add key"}),r("sign_out")&&d.push({kind:"sign_out",label:"Sign out"}),r("disconnect")&&o==="connected"&&d.push({kind:"disconnect",label:"Disconnect"}),r("copy_setup")&&e.setup_prompt&&d.push({kind:"copy_setup",label:"Copy setup prompt"}),a!=="fix"&&d.push({kind:"open_config",label:"Open config file"}),r("remove"))d.push({kind:"remove",label:"Remove",destructive:!0});else if(!e.source.editable){const c=_n(e);d.push({kind:"remove_elsewhere",label:c?`Remove in ${c}`:"Remove in its own file",hint:c?`Defined in ${c}'s config. Remove it there.`:"Defined in a file this app doesn't write. Remove it there."})}return d}const ii={attention:"Needs attention",connected:"Connected",ready:"Available"};function Sn(e,n=[],s){const a=Se(s,e.name),o=Re(e.name,n),r=_t(e,a);if(o&&a.pinnedGroup&&a.pinnedOperationId===o.id)return a.pinnedGroup;if(r==="needs_sign_in"||r==="error")return"attention";const d=Pe(e.name,n,a);return Xe(d)&&r!=="connected"||St(d)&&r!=="connected"?"attention":a.disconnectedAt!==null?"ready":De(e,n,a)||a.needsSignIn&&r!=="connected"||d?.status==="failed"&&ze(d)&&r!=="connected"?"attention":r==="connected"||e.status_basis==="stored"&&wt(e,a)?"connected":o&&o.action!=="test"?"attention":"ready"}function ci(e,n=[],s){return["attention","connected","ready"].map(o=>({id:o,title:ii[o],rows:e.filter(r=>Sn(r,n,s)===o)})).filter(o=>o.rows.length>0)}function li(e,n,s=Date.now()){if(!n)return e??{};const a={};for(const o of n.servers){const r=Se(e,o.name),d=Re(o.name,n.operations),u=Pe(o.name,n.operations,r),c=Xe(u),m=o.status==="connected"&&(o.status_basis==="probe"||o.status_basis==="live"),y=r.holdUntil!==null&&s<r.holdUntil,j=!y&&!c&&r.connectedAt===null&&o.status_basis==="stored"&&o.tool_count_basis==="last_seen"?jn(o.last_seen_at,s):null,w=!c,h=u?.status==="failed"&&ze(u)&&Nn.test(u.message??""),v={connectedAt:m&&!y?s:j!==null?j:w?r.connectedAt:null,connectedToolCount:m&&!y||j!==null?o.tool_count??r.connectedToolCount:w?r.connectedToolCount:null,settledGroup:r.settledGroup,pinnedGroup:d&&r.pinnedOperationId===d.id?r.pinnedGroup:d?r.settledGroup:null,pinnedOperationId:d?d.id:null,needsKey:m?!1:r.needsKey||h,needsSignIn:m||c?!1:r.needsSignIn||o.status==="needs_sign_in",disconnectedAt:m&&!y?null:r.disconnectedAt,holdUntil:y?r.holdUntil:null,lastDecisive:u?Wr(u):null};d||(v.settledGroup=Sn(o,n.operations,{...a,[o.name]:v})),a[o.name]=v}return a}const di=(e,n)=>e!==null&&n===e,yt="local-operator.settings.integrations.row-memory",Cn=(e,n)=>`${e}#${n}`;function ui(e,n){const s={};if(!n)return s;for(const a of n.servers){const o=e[a.name];o&&(s[Cn(a.source.path,a.name)]=o)}return s}function mi(e,n,s){if(!n)return e;let a=null;for(const o of n.servers){if(Object.prototype.hasOwnProperty.call(e,o.name))continue;const r=fi(s[Cn(o.source.path,o.name)]);r&&(a=a??{...e},a[o.name]=r)}return a??e}const hi=["attention","connected","ready"],Mn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ct=e=>typeof e=="number"&&Number.isFinite(e)?e:null,Bt=e=>hi.includes(e)?e:null,rt=e=>{const n=Ct(e);return n!==null&&n>=1e12?n:null};function pi(e){if(!Mn(e)||typeof e.id!="string"||typeof e.name!="string")return null;const n=e.action,s=e.status;return n!=="login"&&n!=="logout"&&n!=="reauth"&&n!=="test"||s!=="running"&&s!=="complete"&&s!=="cancelled"&&s!=="failed"?null:{id:e.id,name:e.name,action:n,status:s,created_at:Ct(e.created_at)??0,credential_removed:e.credential_removed===!0,...typeof e.message=="string"?{message:e.message}:{}}}function fi(e){if(!Mn(e))return null;const n=rt(e.connectedAt),s=rt(e.disconnectedAt),a=e.needsKey===!0,o=e.needsSignIn===!0,r=pi(e.lastDecisive);return n===null&&s===null&&!a&&!o&&!r?null:{connectedAt:n,connectedToolCount:Ct(e.connectedToolCount),settledGroup:Bt(e.settledGroup),pinnedGroup:Bt(e.pinnedGroup),pinnedOperationId:typeof e.pinnedOperationId=="string"?e.pinnedOperationId:null,needsKey:a,needsSignIn:o,disconnectedAt:s,holdUntil:rt(e.holdUntil),lastDecisive:r}}const An=2e3,Ht=8e3;function gi(e){return e&&(e.servers.some(s=>s.status==="connecting")||e.operations.some(s=>s.status==="running"))?An:!1}const yi=/^[A-Za-z0-9_.:-]{1,100}$/,xi=/:\/\//;function ki(e,n){const s=e.trim();return s?yi.test(s)?n.includes(s)?`An integration named ${s} already exists.`:null:"Use letters, numbers, dots, dashes, underscores or colons, with no spaces.":"Give it a name."}function vi(e){const n=e.trim();if(!n)return"Enter the server's URL.";let s;try{s=new URL(n)}catch{return"Enter a full URL, like https://mcp.example.com/mcp."}return s.protocol!=="https:"&&s.protocol!=="http:"?"The URL must start with https:// or http://.":s.hostname?s.username||s.password?"Remove the username or password from the URL. Keys are added after it's saved.":s.search||s.hash?"Remove the ? or # part of the URL. Keys are added after it's saved.":xi.test(n.slice(s.protocol.length+2))?"This looks like two URLs pasted together. Enter just one.":null:"The URL needs a host name."}const bi=e=>e.split(`
|
|
292
|
-
`).map(n=>n.trim()).filter(Boolean);function xt(e,n){const s=!!e?.cold,a=(e?.servers??[]).map(o=>{const r=o.transport==="http",d=o.secret_refs??[],u=o.status==="connected"?"connected":o.status==="connecting"?"connecting":o.status==="auth-required"?"needs_sign_in":"not_started",c=[];u!=="connected"&&c.push("connect"),u==="connected"&&c.push("disconnect"),s||c.push("reload"),r&&o.transport_oauth_supported!==!1&&c.push("sign_in"),d.length>0&&c.push("set_key"),o.owned_scope&&c.push("remove"),o.setup?.text&&c.push("copy_setup");const m=vn(o.source);return{id:o.name,name:o.name,scope:o.owned_scope??"global",project_cwd:null,source:{kind:ji(o.source,m,o.owned_scope),path:o.source??"",editable:o.owned_scope!==null,owned_scope:o.owned_scope},transport:r?"remote_url":"local_command",endpoint:{command:null,url:null,endpoint_redacted:!1},status:u,status_reason:null,status_observed_at:null,last_seen_at:null,status_basis:s?"stored":"live",auth:{kind:d.length?"api_key":r?"unknown":"none",signed_in:null,secret_refs:d.map(y=>({id:y.id,state:"missing"}))},tool_count:typeof o.tool_count=="number"?o.tool_count:null,tool_count_basis:typeof o.tool_count=="number"?"live":null,actions:c,setup_prompt:o.setup?.text??null}});return{cwd:"",project_scope_available:a.some(o=>o.source.owned_scope==="project"),global_path:"",project_path:null,status_source:s?"config":"live",session_id:n,servers:a,operations:(e?.operations??[]).map(o=>({...o}))}}const ji=(e,n,s)=>n==="Claude Code"?"claude-code":n==="Cursor"?"cursor":n==="VS Code"?"vscode":n==="Codex CLI"?"codex":s?"local-operator":e?"project-mcp-json":"local-operator",Vt={invalid_config:"That configuration isn't valid. Check the command or the URL, then try again.",operation_unavailable:"That sign-in or test isn't running any more. Try again.",exists:"An integration with this name already exists. Choose another name.",not_owned:"It's defined in another tool's config, so it can't be changed here. Edit it in that file.",project_scope_unavailable:"There's no separate project config here, so it can only be added globally.",unknown_server:"It no longer exists. The list has been refreshed.",oauth_unsupported:"It doesn't use browser sign-in.",grant_running:"A sign-in or test is already running. Wait for it to finish, or cancel it.",too_many_operations:"Too many sign-ins and tests are waiting. Try again in a moment.",write_failed:"The config file couldn't be written. Check that it isn't read-only.",mcp_starting:"Integrations are still starting. Try again in a moment.",mcp_control_refused:"The server refused it, so nothing was changed."},wi="The server refused it, so nothing was changed. Try again.";function Ve(e,n,s){if(n instanceof jt&&n.status===409){const a=typeof n.code=="string"&&Object.prototype.hasOwnProperty.call(Vt,n.code)?Vt[n.code]:wi;return`${Wn[e]}. ${a}`}return Qn(e,n,s).message}const _i="New chats can use it right away. Open chats pick it up when you start a new chat or reload integrations there.",Ni="Most services give you a URL. Use Local command when their setup says npx or uvx.",Si=({existingNames:e,projectScopeAvailable:n,projectLabel:s,onSubmit:a,onCancel:o,initial:r})=>{const[d,u]=i.useState(r?.name??""),[c,m]=i.useState(r?.mode??"command"),[y,j]=i.useState(r?.command??""),[w,h]=i.useState(r?.args??""),[v,R]=i.useState(r?.url??""),[C,V]=i.useState("global"),[_,B]=i.useState(r?.touched?{name:!0,command:!0,url:!0}:{}),[$,M]=i.useState(!!r?.touched),[S,W]=i.useState(!1),[q,Z]=i.useState(null),T=i.useRef(null),ee=i.useRef(null),L=i.useRef(null);i.useEffect(()=>{T.current?.focus()},[]);const D=ki(d,e),O=c==="command"&&!y.trim()?"Enter the command to run.":null,z=c==="url"?vi(v):null,K=x=>$||_[x],se=async x=>{if(x.preventDefault(),M(!0),D||O||z){D?T.current?.focus():O?ee.current?.focus():L.current?.focus();return}W(!0),Z(null);const H=n?C:"global",G=c==="command"?{name:d.trim(),scope:H,mode:c,command:y.trim(),args:bi(w)}:{name:d.trim(),scope:H,mode:c,url:v.trim()},J=await a(G);W(!1),Z(J)},p=(x,H,G)=>H&&K(G)?t.jsx("p",{id:x,className:"text-body-sm text-danger",children:H}):null,I=x=>x.preventDefault();return t.jsxs("form",{noValidate:!0,"aria-label":"Add integration",className:"flex flex-col gap-4 rounded-lg bg-surface p-4",onSubmit:x=>void se(x),onKeyDown:x=>{x.key==="Escape"&&(x.stopPropagation(),o())},children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-name",children:"Name"}),t.jsx(Ae,{ref:T,id:"integration-add-name",value:d,placeholder:"e.g. notion",autoComplete:"off","aria-invalid":!!(D&&K("name")),"aria-describedby":D&&K("name")?"integration-add-name-error":void 0,onChange:x=>u(x.target.value),onBlur:()=>B(x=>({...x,name:!0}))}),p("integration-add-name-error",D,"name")]}),t.jsxs(ft,{value:c,onValueChange:x=>m(x==="url"?"url":"command"),className:"flex flex-col gap-1.5",children:[t.jsx("span",{id:"integration-add-transport-label",className:"font-medium text-body-sm text-ink",children:"How it runs"}),t.jsxs(gt,{"aria-labelledby":"integration-add-transport-label",children:[t.jsx(Fe,{value:"command","data-integration-transport":"command",children:"Local command"}),t.jsx(Fe,{value:"url","data-integration-transport":"url",children:"Remote URL"})]}),t.jsx("p",{className:"text-ink-dim text-meta",children:Ni}),t.jsxs($t,{value:"command",className:"mt-0 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-command",children:"Command"}),t.jsx(Ae,{ref:ee,id:"integration-add-command",value:y,placeholder:"e.g. npx",autoComplete:"off",className:"font-mono","aria-invalid":!!(O&&K("command")),"aria-describedby":O&&K("command")?"integration-add-command-error":void 0,onChange:x=>j(x.target.value),onBlur:()=>B(x=>({...x,command:!0}))}),p("integration-add-command-error",O,"command")]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs(xe,{htmlFor:"integration-add-args",children:["Arguments"," ",t.jsx("span",{className:"font-normal text-ink-dim",children:"(one per line)"})]}),t.jsx(yn,{id:"integration-add-args",value:w,rows:2,className:"font-mono",onChange:x=>h(x.target.value)})]})]}),t.jsx($t,{value:"url",className:"mt-0 flex flex-col gap-4",children:t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-url",children:"URL"}),t.jsx(Ae,{ref:L,id:"integration-add-url",type:"url",value:v,placeholder:"https://mcp.example.com/mcp",autoComplete:"off",className:"font-mono","aria-invalid":!!(z&&K("url")),"aria-describedby":z&&K("url")?"integration-add-url-error":"integration-add-url-help",onChange:x=>R(x.target.value),onBlur:()=>B(x=>({...x,url:!0}))}),p("integration-add-url-error",z,"url")??t.jsx("p",{id:"integration-add-url-help",className:"text-ink-dim text-meta",children:"If it needs a sign-in or a key, you'll be asked after it's added."})]})})]}),n?t.jsxs(ft,{value:C,onValueChange:x=>V(x==="project"?"project":"global"),className:"flex flex-col gap-1.5",children:[t.jsx("span",{id:"integration-add-scope-label",className:"font-medium text-body-sm text-ink",children:"Available in"}),t.jsxs(gt,{"aria-labelledby":"integration-add-scope-label",children:[t.jsx(Fe,{value:"global","data-integration-scope":"global",children:"All chats"}),t.jsx(Fe,{value:"project","data-integration-scope":"project",children:"This project"})]}),s?t.jsx("p",{className:"text-ink-dim text-meta",children:C==="project"?`Only chats working in ${s}.`:"Every chat, in any folder."}):null]}):null,q?t.jsx("p",{className:"text-body-sm text-danger",role:"alert",children:q}):null,t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsx("p",{className:ce("text-body-sm text-ink-dim"),children:_i}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(P,{type:"button",variant:"ghost",size:"md",onMouseDown:I,onClick:o,children:"Cancel"}),t.jsxs(P,{type:"submit",variant:"primary",size:"md",disabled:S,onMouseDown:I,children:[S?t.jsx(re,{size:"xs"}):null,"Add integration"]})]})]})]})},Ci=4;function Mi(e){return e.rowMoving?e.now+e.windowMs:Math.max(e.hold.until,e.lastMovingAt+e.windowMs)}function Ai(e){return e.now>e.hold.until||e.hold.reanchors>=Ci?"drop":e.hold.landedOn.isConnected&&(!e.candidate||e.candidate===e.hold.landedOn)?"settled":e.active&&e.active!==e.body&&e.active!==e.hold.landedOn?"drop":e.candidate?.isConnected?"restore":"drop"}function Ri(e){const n=Mi({hold:e.hold,now:e.now,windowMs:e.windowMs,rowMoving:e.rowMoving,lastMovingAt:e.lastMovingAt});if(e.now>n)return{hold:null,land:null};const s=e.hold.landedOn??null,a=e.candidate;if(!a)return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},land:null};if(!s)return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:a},land:a};const o=Ai({hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},candidate:a,active:e.active,body:e.body,now:e.now});if(o==="settled")return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},land:null};if(o==="drop")return{hold:null,land:null};const r=!s.isConnected;return{hold:{until:r?e.now+e.windowMs:n,reanchors:r?e.hold.reanchors+1:e.hold.reanchors,landedOn:a},land:a}}function Ti(e){const{row:n,target:s}=e;return!n||!s||typeof s.nodeType!="number"?!1:!n.contains(s)}const Gt=250;function qt(e){return e?!e.disabled:!1}function Ei(e){return qt(e.primary)?e.primary??null:qt(e.overflow)?e.overflow??null:null}function Ii(e){return e.verdict==="finished"?null:e.watchMs}const Rn="key";function Li(e){const{name:n,keyless:s,freeName:a,names:o,values:r,replace:d,canReplace:u}=e;if(s){const c=kt(n,a);return{values:{[c]:(r[Rn]??"").trim()},confirmedReplace:d&&u?[c]:[],header:a.trim()}}return{values:Object.fromEntries(o.map(c=>[c,(r[c]??"").trim()])),confirmedReplace:d&&u?o:[],header:void 0}}function kt(e,n){const s=Yt(e),a=Yt(n);if(!a)return"";const o=[s,a].filter(Boolean).join("_"),r=/^[A-Za-z_]/.test(o)?o:`K_${o}`;if(r.length<=it)return r;const d=Oi(s),u=it-a.length-d.length-2,c=[s.slice(0,Math.max(u,0)),d,a].filter(Boolean).join("_");return c.length<=it?c:c.slice(-128)}const it=128,Yt=e=>e.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,""),Oi=e=>{let n=2166136261;for(let s=0;s<e.length;s+=1)n^=e.charCodeAt(s),n=Math.imul(n,16777619)>>>0;return n.toString(36).toUpperCase().slice(0,5)},Fi=({name:e,keyNames:n,keyless:s=!1,savedKeys:a=[],saving:o,failure:r,onSave:d,onClose:u})=>{const[c,m]=i.useState({}),[y,j]=i.useState(!1),[w,h]=i.useState(""),v=s?[kt(e,w)]:[...n],R=s?[Rn]:v,C=(s?kt(e,w).length>0:!0)&&R.every(_=>(c[_]??"").trim()),V=v.some(_=>a.includes(_));return t.jsx(rn,{open:!0,onClose:u,maxWidth:"xs",title:s||n.length===1?`Add the key for ${e}`:`Add keys for ${e}`,actions:t.jsxs(t.Fragment,{children:[t.jsx(dt,{onClick:u,children:"Cancel"}),t.jsx(ut,{disabled:!C||o,onClick:()=>{const _=Li({name:e,keyless:s,freeName:w,names:v,values:c,replace:y,canReplace:V});d(_.values,_.confirmedReplace,_.header)},children:o?"Saving…":"Save and test"})]}),children:t.jsxs("div",{className:"flex flex-col gap-3 p-1.5 text-body text-ink-muted",children:[t.jsx("p",{className:"-mx-1.5",children:s?"Keys are saved encrypted on this computer. This one is stored under a name derived from this integration, so no other server shares it.":"Keys are saved encrypted on this computer. Other integrations that use the same key name share it."}),s?t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-key-name",children:"The header this server wants the key in"}),t.jsx(Ae,{id:"integration-key-name",autoComplete:"off",placeholder:"e.g. Authorization or X-Api-Key",value:w,onChange:_=>h(_.target.value)}),t.jsx("p",{className:"-mx-1.5 text-ink-dim text-meta",children:"This server declares no key of its own, so Local Operator adds one to its config for you."})]}):null,R.filter(_=>s!==!0||_.trim().length>0).map(_=>t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:`integration-key-${_}`,className:"font-mono",children:s?"Key":_}),t.jsx(Ae,{id:`integration-key-${_}`,type:"password",autoComplete:"off",value:c[_]??"",onChange:B=>m($=>({...$,[_]:B.target.value}))})]},_)),V?t.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[t.jsx(na,{id:"integration-key-replace",checked:y,onCheckedChange:_=>j(_===!0)}),t.jsx(xe,{htmlFor:"integration-key-replace",className:"font-normal",children:wn(v.length)})]}):null,r?t.jsx("p",{className:"-mx-1.5 text-body-sm text-danger",role:"alert",children:r}):null]})})},Di={success:"bg-success",warning:"bg-warning",danger:"bg-danger",info:"bg-info",neutral:"bg-ink-dim"},$i={success:"text-ink-muted",warning:"text-warning",danger:"text-danger",info:"text-ink-muted",neutral:"text-ink-dim"},Wt={Ready:ni,"Not connected":si},Ui=({row:e,operations:n,memories:s,now:a,projectScopeAvailable:o,highlighted:r=!1,rowRef:d,primaryRef:u,overflowRef:c,pending:m,failure:y,confirm:j,onPrimary:w,onOverflow:h,onConfirm:v,onCancelConfirm:R})=>{const C=Xr(e,n,s,a),V=r&&C.tone==="danger"?"text-ink":$i[C.tone],_=Nt(e,n,s),B=ri(e,n,s),$=oi(e,o),M=B.findIndex(S=>S.kind==="remove"||S.kind==="remove_elsewhere");return t.jsxs("li",{ref:d,"data-integration":e.name,"data-status":e.status,className:ce("flex min-h-14 flex-col justify-center gap-1 px-4 py-2.5",r&&"bg-row-selected"),onKeyDown:S=>{!j||S.key!=="Escape"||(S.stopPropagation(),R())},children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:C.busy?t.jsx(re,{size:"xs"}):t.jsx("span",{"aria-hidden":"true","data-tone":C.tone,className:ce("size-2 rounded-full",Di[C.tone])})}),t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:"truncate font-medium text-body text-ink",title:e.name,children:e.name}),t.jsx("span",{className:"truncate text-ink-dim text-meta",children:$.map((S,W)=>t.jsxs("span",{children:[W>0?" · ":null,S.startsWith("Imported from")&&e.source.path?t.jsx($e,{content:Zn(e.source.path),children:t.jsx("span",{className:"underline decoration-dotted underline-offset-2",children:S})}):S]},S))})]}),Wt[C.label]?t.jsx($e,{content:Wt[C.label],children:t.jsx("span",{className:ce("shrink-0 text-body-sm",V),children:C.label})}):t.jsx("span",{className:ce("shrink-0 text-body-sm",V),children:C.label}),_?t.jsxs(P,{ref:u,variant:_.variant??"secondary",size:"sm","aria-label":`${_.label} ${e.name}`,disabled:m,"data-integration-action":_.kind,onClick:()=>w(_),children:[m?t.jsx(re,{size:"xs"}):null,_.label]}):null,t.jsxs(sa,{children:[t.jsx(aa,{asChild:!0,children:t.jsx(P,{ref:c,variant:"ghost",size:"icon-sm","aria-label":`More actions for ${e.name}`,disabled:m,children:t.jsx(Jn,{"aria-hidden":"true"})})}),t.jsx(oa,{align:"end",className:"min-w-48",children:B.map((S,W)=>t.jsx(Pi,{item:S,separated:W===M&&W>0,onSelect:()=>h(S)},S.kind))})]})]}),C.detail?t.jsx("p",{className:ce("pl-7 text-body-sm",C.tone==="danger"?"text-ink-muted":"text-ink-dim"),children:C.detail}):null,y?t.jsx("p",{className:ce("pl-7 text-body-sm",r?"text-ink":"text-danger"),role:"alert",children:y}):null,j?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-7",children:[t.jsx("span",{className:"text-body-sm text-ink",children:j.kind==="remove"?`Remove ${e.name}?`:`Sign out of ${e.name}?`}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:j.kind==="remove"?`Agents in every chat lose access to ${e.name}.`:e.auth.kind==="oauth"?"The saved sign-in is removed too.":"Its saved credential is removed too."}),t.jsx(P,{variant:"danger",size:"sm",onClick:v,"data-integration-confirm":j.kind,children:j.kind==="remove"?"Remove":"Sign out"}),t.jsx(P,{variant:"ghost",size:"sm",onClick:R,children:"Keep"})]}):null]})},Pi=({item:e,separated:n,onSelect:s})=>t.jsxs(t.Fragment,{children:[n?t.jsx(ra,{}):null,e.kind==="remove_elsewhere"?t.jsxs(Ut,{disabled:!0,className:"flex-col items-start gap-0.5",children:[t.jsx("span",{children:e.label}),t.jsx("span",{className:"text-meta text-ink-dim",children:e.hint})]}):t.jsx(Ut,{destructive:e.kind==="remove",onSelect:s,"data-integration-menu":e.kind,children:e.label})]});function zi(e,n,s){return!n||n.status==="running"?n?.browser_opened===!0?{message:`Your browser opened. Approve access to ${e} there, then come back here.`,tone:"progress",link:n.authorization_url??null}:n?.browser_opened===!1?{message:n.authorization_url?"Your browser didn't open. Open this link to approve access:":"Your browser didn't open, and no link was provided. Cancel and try again.",tone:"progress",link:n.authorization_url??null}:{message:`Waiting for you to approve access to ${e}…`,tone:"progress",link:n?.authorization_url??null}:n.status==="complete"?{message:`Signed in to ${e}. Agents can use it now.`,tone:"success",link:null}:n.status==="cancelled"?{message:"Sign-in cancelled.",tone:"failure",link:null,reason:null,nextStep:"Press Try again when you are ready."}:{message:"Sign-in didn't finish.",tone:"failure",link:null,reason:ti(n.message,s)??"The server didn't say why.",nextStep:Ki(n.message??null,s)}}function Ki(e,n){const s=(e??"").toLowerCase();return s.includes("redirect")?n?"This server may not accept sign-ins from Local Operator. Check the server's settings, or add a key instead.":"This server may not accept sign-ins from Local Operator. Check the server's settings, then try again.":s.includes("no oauth")||s.includes("authorization server")?n?"This server doesn't publish a browser sign-in. Add its key instead.":"This server doesn't publish a browser sign-in. Check the server's settings, then try again.":s.includes("network")||s.includes("connect")?"Check the server's URL and your network, then try again.":"Check the server's settings, then try again."}function Bi(e,n){return e.kind==="ready"?"ready":e.kind==="running"&&n&&n.tone!=="progress"?n.tone==="success"?"success":"failure":"running"}const Hi=({name:e,action:n,keyRoute:s,phase:a,onStart:o,onCancel:r,onOpenLink:d,onClose:u})=>{const c=a.kind==="running"?a.operation:null,m=a.kind==="running"?zi(e,c,s):null,y=a.kind==="starting"||a.kind==="running"&&m?.tone==="progress",j=m&&m.tone!=="progress",w=i.useRef(null),h=i.useRef(!1),v=Bi(a,m);i.useEffect(()=>{if(!h.current){h.current=!0;return}v&&w.current?.focus()},[v]);const R=()=>u(m?.tone==="success"?"signed-in":"dismissed");return t.jsx(rn,{open:!0,onClose:R,maxWidth:"xs",fullWidth:!0,title:`Sign in to ${e}`,dialogProps:{onOpenAutoFocus:C=>{C.preventDefault(),w.current?.focus()}},actions:t.jsxs(t.Fragment,{children:[y&&c?t.jsx(dt,{ref:w,onClick:()=>r(c.id),children:"Cancel sign-in"}):t.jsx(dt,{ref:a.kind==="ready"?void 0:w,onClick:R,children:m?.tone==="success"?"Done":"Close"}),a.kind==="ready"?t.jsx(ut,{ref:w,onClick:o,children:"Continue in browser"}):null,a.kind==="refused"||m?.tone==="failure"?t.jsx(ut,{ref:m?.tone==="failure"?w:void 0,onClick:o,children:"Try again"}):null]}),children:t.jsxs("div",{className:"flex flex-col gap-3 p-1.5 text-body text-ink-muted","aria-live":"polite",children:[a.kind==="ready"?t.jsxs("p",{className:"-mx-1.5",children:["Local Operator opens your browser so you can approve access to"," ",e,".",n==="reauth"?" This replaces the sign-in it has now.":""]}):null,a.kind==="starting"?t.jsxs("p",{className:"-mx-1.5 flex items-center gap-2",children:[t.jsx(re,{size:"xs"}),"Starting sign-in…"]}):null,m?t.jsxs("div",{className:"flex flex-col gap-1",role:j?"status":void 0,children:[t.jsxs("p",{className:(m.tone==="success","-mx-1.5 flex items-start gap-2 text-ink"),children:[m.tone==="progress"?t.jsx(re,{size:"xs",className:"mt-0.5"}):null,m.tone==="failure"?t.jsx(ia,{"aria-hidden":"true",className:"mt-0.5 size-4 shrink-0 text-danger"}):null,t.jsx("span",{children:m.message})]}),m.reason?t.jsx("p",{className:"-mx-1.5 text-ink-muted",children:m.reason}):null,m.nextStep?t.jsx("p",{className:"-mx-1.5 text-ink-muted",children:m.nextStep}):null]}):null,m?.link&&m.tone==="progress"?t.jsxs("div",{className:"flex flex-col items-start gap-1",children:[t.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-ink-dim text-mono-sm",title:m.link,children:m.link}),t.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"Copy the sign-in link",title:"Copy the sign-in link",onClick:()=>{navigator.clipboard.writeText(m.link??"").then(()=>mt("Sign-in link copied.")).catch(()=>{})},children:t.jsx(Xn,{"aria-hidden":"true"})})]}),t.jsx(P,{variant:"link",size:"sm",onClick:()=>d(m.link??""),children:"Open the sign-in page"})]}):null,a.kind==="refused"?t.jsx("p",{className:"text-danger",role:"alert",children:a.message}):null]})})},Vi=e=>e.reduce((n,s)=>n?(s.updated_at??0)>(n.updated_at??0)?s:n:s,null),Gi=/^[A-Za-z]:[\\/]/,We=e=>{const n=e?.trim();return n&&(n.startsWith("/")||Gi.test(n))?n:null};function qi(e){const o=e?.payload?.frontend?.snapshot?.cwd;return typeof o=="string"&&o.trim()?o:null}const Ue="local-operator.settings.integrations.last-cwd";function Yi(e,n,s=typeof localStorage>"u"?null:localStorage){const a=We(n);if(!(!e||!a||!s))try{const o=s.getItem(Ue),r=o?JSON.parse(o):{};if(r[e]===a)return;s.setItem(Ue,JSON.stringify({...r,[e]:a}))}catch{}}const Tn=()=>typeof localStorage>"u"?null:localStorage;function En(e=Tn()){if(!e)return{};try{const n=e.getItem(yt);if(!n)return{};const s=JSON.parse(n);return!s||typeof s!="object"||Array.isArray(s)?{}:s}catch{return{}}}const Qt=256;function Wi(e,n=Tn()){if(n)try{const s={...En(n),...e},a=Object.keys(s);if(a.length>Qt){const o={};for(const r of a.slice(-Qt))o[r]=s[r];n.setItem(yt,JSON.stringify(o));return}n.setItem(yt,JSON.stringify(s))}catch{}}function Zt(e,n,s){return e==="saved"?null:e==="replace_confirmation_required"?`A saved value already exists for this key. Tick “${wn(Object.keys(s).length)}” to overwrite it.`:e==="invalid_target"?"That header can't carry this key. It may already be set on the server, or belong to the transport - try a different header name. Nothing was saved.":`Not saved: ${(n.length?n:Object.keys(s)).join(", ")}. The encrypted store may be locked.`}function Qi(e,n=typeof localStorage>"u"?null:localStorage){if(!(!e||!n))try{const s=n.getItem(Ue);if(!s)return;const a=JSON.parse(s);if(!(e in a))return;const o={...a};delete o[e],n.setItem(Ue,JSON.stringify(o))}catch{}}const Zi=e=>!!(e&&typeof e=="object"&&"code"in e&&e.code==="invalid_cwd"),Ji=(e,n)=>n!==null&&e===n?null:e;function Xi(e,n=typeof localStorage>"u"?null:localStorage){if(!e||!n)return null;try{const s=n.getItem(Ue);if(!s)return null;const o=JSON.parse(s)[e];return typeof o=="string"?o:null}catch{return null}}const ec=e=>e.action==="disconnect"?"disconnected":"connected";function tc(e){switch(e.action){case"cancel":return{action:"cancel",operation_id:e.operationId};case"connect":case"disconnect":case"reload":return null;case"test":return{action:"test",name:e.name};default:return{...e,confirmed:!0}}}function nc(e){switch(e.action){case"cancel":return{action:"cancel",operation_id:e.operationId};case"test":case"connect":return{action:"connect",name:e.name};case"reload":return{action:"reload",name:e.name};case"add":return e;case"remove":return{...e,confirmed:!0};default:return{action:e.action,name:e.name,confirmed:!0}}}function sc({sessionId:e}){const n=cn(),s=It(n.data,"mcp_catalog"),a=It(n.data,"mcp"),o=s?"catalog":a?"session":null,[r,d]=i.useState(null),u=sn(),c=Ge(k=>k.sessions),m=Ge(k=>k.fetchSessions),y=Ge(k=>k.loading),j=i.useMemo(()=>c.find(k=>k.session_id===e)??null,[c,e]),w=i.useMemo(()=>o==="session"&&!e?Vi(c):null,[o,e,c]),h=o==="session"?e??w?.session_id??null:null;i.useEffect(()=>{o!=="session"||e||c.length>0||m(es)},[o,e,c.length,m]);const v=o==="catalog"?We(j?.cwd):null,R=o==="catalog"&&!!e&&v===null,C=ke({queryKey:["desktop","session-cwd",e??""],queryFn:()=>ye({op:"sessions.get",sessionId:e??""}),enabled:R,staleTime:Number.POSITIVE_INFINITY,retry:!1}),V=R&&!C.isFetched,_=v??We(qi(C.data))??(C.isFetched?We(Xi(e)):null),B=Ji(_,r),$=o==="catalog"?B:null,M=o==="catalog"?e??null:null,S=ts.catalog($,M);i.useEffect(()=>{o!=="catalog"||!e||!$||Yi(e,$)},[o,e,$]);const W=i.useRef(0),[q,Z]=i.useState(0),T=i.useRef(null),ee=i.useCallback((k,A)=>{const f=Date.now()+Ht;W.current=f,T.current={name:k,expect:A},Z(f)},[]),L=i.useCallback(k=>Date.now()<W.current?An:gi(k),[]),D=ke({queryKey:S,queryFn:()=>as($,M),enabled:o==="catalog"&&!V,staleTime:1e4,refetchInterval:k=>L(k.state.data)}),O=Zi(D.error);i.useEffect(()=>{!O||!_||r===_||(d(_),Qi(e))},[O,_,r,e]);const z=ke({queryKey:ht.list(h??""),queryFn:()=>os(h??""),enabled:o==="session"&&!!h,staleTime:1e4,refetchInterval:k=>L(k.state.data?xt(k.state.data,h??""):void 0)}),K=i.useMemo(()=>{if(o==="catalog")return D.data;if(o==="session"&&z.data&&h)return xt(z.data,h)},[o,D.data,z.data,h]),se=i.useCallback(()=>ac({queryClient:u,route:o,catalogKey:S,sessionId:h}),[o,S,u,h]);i.useEffect(()=>{if(!q)return;const k=T.current;if(!k)return;const A=K?.servers.find(F=>F.name===k.name);!A||!(k.expect==="connected"?A.status==="connected":A.status_basis==="live"&&A.status!=="connected")||(W.current=0,T.current=null,Z(0))},[K,q]);const p=i.useRef({}),[I,x]=i.useState(0),H=i.useMemo(()=>(p.current=li(mi(p.current,K,En()),K),p.current),[K,I]),G=i.useRef("");i.useEffect(()=>{const k=ui(H,K);if(!Object.keys(k).length)return;const A=JSON.stringify(k);A!==G.current&&(G.current=A,Wi(k))},[H,K]);const J=i.useCallback(k=>{const A=Se(p.current,k);A.needsKey||(p.current={...p.current,[k]:{...A,needsKey:!0}},x(f=>f+1))},[]),X=i.useCallback(k=>{if(k.action!=="disconnect"&&k.action!=="connect"&&k.action!=="reload")return;const A=Se(p.current,k.name),f=Date.now()+Ht,F=k.action==="disconnect"?{...A,connectedAt:null,disconnectedAt:Date.now(),holdUntil:f}:{...A,disconnectedAt:null,holdUntil:f};p.current={...p.current,[k.name]:F},ee(k.name,ec(k)),x(E=>E+1)},[ee]),Q=i.useCallback(async k=>{if(o==="catalog"){const A=tc(k);if(!A)return null;try{const f=await ns($,A);return u.setQueryData(S,f),X(k),f.operation?.id??null}catch(f){throw f instanceof jt&&f.status===409&&u.invalidateQueries({queryKey:S}),f}}if(o==="session"&&h){const A=await ye({op:"mcp.control",sessionId:h,control:nc(k)});X(k);const f=ht.list(h),F=A?.data;return F&&"servers"in F&&Array.isArray(F.servers)?(u.setQueryData(f,F),null):(u.invalidateQueries({queryKey:f}),F&&"id"in F&&typeof F.id=="string"?F.id:null)}return null},[o,$,S,u,h,X]),fe=i.useCallback(async k=>{if(o==="catalog"&&M&&(k.action==="connect"||k.action==="disconnect"||k.action==="reload")){try{await ye({op:"mcp.control",sessionId:M,control:{action:k.action,name:k.name,...k.action==="disconnect"?{confirmed:!0}:{}}})}catch(A){throw u.invalidateQueries({queryKey:S}),A}return X(k),await u.invalidateQueries({queryKey:S}),null}return Q(k)},[o,M,u,S,Q,X]),ve=i.useCallback(async(k,A,f,F)=>{if(o==="catalog"){const E=await ss($,k,A,f,F);if(E.catalog&&u.setQueryData(S,E.catalog),E.code!=="saved")return{saved:!1,message:Zt(E.code,E.failed_ids,A)};try{await Q({action:"test",name:k})}catch{}return{saved:!0,message:null}}if(o==="session"&&h){const E=await ye({op:"mcp.credentials.store",sessionId:h,name:k,values:A,confirmedReplace:f});if(E.data?.code!=="saved")return{saved:!1,message:Zt(E.data?.code,E.data?.failed_ids??[],A)};try{await Q({action:"connect",name:k})}catch{}return{saved:!0,message:null}}return{saved:!1,message:null}},[o,$,S,u,Q,h]),me=o==="catalog"?D:z,Ce=i.useCallback(()=>{me.refetch()},[me]);return{enabled:o!==null,route:o,sessionId:o==="catalog"?M:h,borrowed:w,noConversation:o==="session"&&!h&&!y,document:K,isLoading:n.isLoading||o==="catalog"&&(V||D.isLoading)||o==="session"&&(h?z.isLoading:y),isError:me.isError,folderUnavailable:di(r,_),refetch:Ce,readDocument:se,control:fe,storeKeys:ve,memories:H,markNeedsKey:J}}function ac(e){if(e.route==="catalog")return e.queryClient.getQueryData(e.catalogKey);if(e.route==="session"&&e.sessionId){const n=e.queryClient.getQueryData(ht.list(e.sessionId));return n?xt(n,e.sessionId):void 0}}const oc=(e,n)=>{const s=e?.trim();if(!s)return null;const a=ls(s,n);return a.kind==="auth"?{kind:"matched",name:a.name,unresolved:null}:{kind:"miss",asked:s}},rc=6,ct="Integrations",ic="Let agents use your tools and accounts, like Notion, Linear or GitHub.",cc={test:"test",connect:"reconnect",disconnect:"disconnect",reload:"reload",remove:"remove",sign_out:"disconnect",cancel:"cancel",login:"grant",reauth:"grant"},lc=({sessionId:e,sectionRef:n,highlightServer:s})=>{const a=sc({sessionId:e}),{document:o,control:r,readDocument:d}=a,u=rs(),c=o?.servers??[],m=o?.operations??[],y=o?.project_scope_available??!1,[j,w]=i.useState(!1),[h,v]=i.useState(""),[R,C]=i.useState(null),[V,_]=i.useState({}),[B,$]=i.useState(null),[M,S]=i.useState(null),[W,q]=i.useState({kind:"ready"}),[Z,T]=i.useState(null),[ee,L]=i.useState(null),[D,O]=i.useState(!1),z=i.useRef({}),K=i.useRef({}),se=i.useRef({}),p=i.useRef(0),I=i.useRef(null),x=i.useRef(null),H=i.useRef(null),[G,J]=i.useState(null),[X,Q]=i.useState(null),[fe,ve]=i.useState(null),me=i.useCallback(()=>{const l=H.current;H.current=null,S(null),T(null),window.setTimeout(()=>{l?.isConnected&&l.focus()},0)},[]),Ce=i.useCallback(l=>{const g=window.document.activeElement;H.current=g instanceof HTMLElement?g:null,S(l)},[]),k=i.useCallback((l,g)=>{Q({name:l,waitForSignIn:g==="signed-in",until:Date.now()+Le,reanchors:0}),me()},[me]),A=i.useMemo(()=>oc(s,c.map(l=>l.name)),[s,c]),f=A?.kind==="matched"?A.name:null,F=i.useRef(null),E=i.useRef(null),le=h.trim().toLowerCase(),Y=i.useMemo(()=>le?c.filter(l=>l.name.toLowerCase().includes(le)):c,[c,le]),de=i.useMemo(()=>ci(Y,m,a.memories),[Y,m,a.memories]),ie=M?.kind==="sign_in"?c.find(l=>l.name===M.name)??null:null;i.useEffect(()=>{!f||E.current===f||!h||v("")},[f,h]),i.useEffect(()=>{!f||E.current===f||Y.some(l=>l.name===f)&&(E.current=f,F.current?.scrollIntoView({block:"center",behavior:"smooth"}))},[f,Y]),i.useEffect(()=>{if(!Z)return;const l=m.find(g=>g.id===Z)??null;q({kind:"running",operation:l})},[m,Z]);const be=m.some(l=>l.status==="running"),he=l=>{const g=window.document.activeElement;g&&g!==window.document.body&&g.isConnected||Q({name:l,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})},ae=async(l,g,N)=>{C(l),_(({[l]:we,..._e})=>_e);let U=null,ue=!1;try{U=await N()}catch(we){ue=!0,_(_e=>({..._e,[l]:Ve(cc[g]??"status",we,be)}))}finally{C(null),g!=="sign_out"&&(g!=="remove"||ue)&&he(l)}return{operationId:U,failed:ue}},je=l=>c.find(g=>g.name===l),pe=l=>{l.source.path&&ds(l.source.path)},et=async(l,g)=>{q({kind:"starting"}),T(null);try{const N=await r({action:g,name:l});N?T(N):q({kind:"running",operation:null})}catch(N){N instanceof jt&&N.code==="oauth_unsupported"&&a.markNeedsKey(l),q({kind:"refused",message:Ve("grant",N,be)})}},Ke=(l,g)=>{switch(g.kind){case"sign_in":case"reauth":{const N=m.find(U=>U.name===l.name&&U.status==="running");N&&ze(N)?(q({kind:"running",operation:N}),T(N.id)):(q({kind:"ready"}),T(null)),Ce({kind:"sign_in",name:l.name,action:g.kind==="reauth"?"reauth":"login"});return}case"set_key":L(null),Ce({kind:"key",name:l.name,keyNames:l.auth.secret_refs.map(N=>N.id)});return;case"fix":pe(l);return;case"sign_out":$({name:l.name,kind:"sign_out"});return;default:{const N=g.kind;ae(l.name,N,()=>r({action:N,name:l.name}))}}},tt=(l,g)=>{switch(g.kind){case"remove":case"sign_out":$({name:l.name,kind:g.kind});return;case"sign_in":case"reauth":case"set_key":Ke(l,{kind:g.kind,label:g.label});return;case"open_config":pe(l);return;case"copy_setup":navigator.clipboard.writeText(l.setup_prompt??"").then(()=>mt("Setup steps copied. Paste them into a chat.")).catch(()=>{});return;case"cancel":{const N=m.find(U=>U.name===l.name&&U.status==="running");N&&ae(l.name,"cancel",()=>r({action:"cancel",operationId:N.id}));return}case"test":case"connect":case"disconnect":case"reload":{const N=g.kind;ae(l.name,N,()=>r({action:N,name:l.name}));return}default:return}},nt=(l,g)=>{if($(null),g==="remove"){const N=l.source.owned_scope;if(!N)return;const U=Y.findIndex(ue=>ue.name===l.name);ae(l.name,"remove",()=>r({action:"remove",name:l.name,scope:N})).then(({operationId:ue,failed:we})=>{we||ue!==null||(mt(`Removed ${l.name}.`),U>=0&&ve({index:U}))});return}ae(l.name,"sign_out",()=>r({action:"logout",name:l.name})).then(()=>{Q({name:l.name,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})})},Mt=async l=>{try{return await r({action:"add",name:l.name,scope:l.scope,...l.mode==="command"?{command:l.command,args:l.args}:{url:l.url}}),w(!1),J(l.name),null}catch(g){return Ve("add",g,!1)}},Te=t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"text-heading text-ink",children:ct}),t.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:ic})]}),a.enabled&&c.length>0&&!j?t.jsxs(P,{ref:I,variant:"secondary",size:"sm",onClick:()=>w(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(Ot,{"aria-hidden":"true"}),"Add integration"]}):null]});if(!a.enabled&&!a.isLoading)return t.jsx(ne,{title:ct,titleComponent:Te,sectionRef:n,children:t.jsx(te,{variant:"warning",children:"Integrations need a newer Local Operator backend. Update it and restart the app to manage them here."})});const Ee=t.jsx(Si,{existingNames:c.map(l=>l.name),projectScopeAvailable:y,projectLabel:o?.cwd?uc(o.cwd):null,onSubmit:Mt,onCancel:()=>{w(!1),window.setTimeout(()=>I.current?.focus(),0)}}),At=M?je(M.name):void 0,On=Object.entries(V).filter(([l])=>!c.some(g=>g.name===l)),Fn=l=>_(({[l]:g,...N})=>N);i.useEffect(()=>{if(!G)return;const l=z.current[G];if(!l){c.some(g=>g.name===G)&&(K.current[G]?.focus(),J(null));return}l.focus(),J(null)},[G,c]),i.useEffect(()=>{if(!fe)return;const g=Y[Math.min(fe.index,Y.length-1)]??Y.at(-1);if(g){const N=z.current[g.name]??K.current[g.name];if(!N)return;N.focus()}else I.current?.focus();ve(null)},[fe,Y]);const st=i.useCallback((l,g)=>{const N=d()??o,U=N?.servers.find(Dn=>Dn.name===l.name),ue=N?.operations??[],we=U?U.status==="connecting"||Re(U.name,ue)!==null:!1;we&&U&&(p.current=g);const _e=U?Nt(U,ue,a.memories):null;if(U&&l.waitForSignIn&&(_e?.kind==="sign_in"||_e?.kind==="reauth"))return"kept";const Me=Ri({hold:l,now:g,windowMs:Le,rowMoving:we,lastMovingAt:p.current,candidate:U?Ei({primary:_e?z.current[U.name]:null,overflow:K.current[U.name]}):void 0,active:window.document.activeElement,body:window.document.body});if(!Me.hold)return Q(null),"finished";if(!Me.land)return"kept";Q({name:l.name,waitForSignIn:!1,until:Me.hold.until,landedOn:Me.land,reanchors:Me.hold.reanchors});const Rt=Me.land;return window.setTimeout(()=>{Rt.isConnected&&Rt.focus()},0),"landed"},[d,o,a.memories]);return i.useEffect(()=>{if(!X)return;st(X,Date.now());let l=0,g=!1;const N=()=>{if(g)return;const U=Ii({verdict:st(X,Date.now()),watchMs:Gt});U!==null&&(l=window.setTimeout(N,U))};return l=window.setTimeout(N,Gt),()=>{g=!0,window.clearTimeout(l)}},[X,st]),i.useEffect(()=>{if(!X)return;const l=g=>{Ti({target:g.target,row:se.current[X.name]})&&Q(null)};return window.document.addEventListener("pointerdown",l,!0),()=>{window.document.removeEventListener("pointerdown",l,!0)}},[X]),t.jsxs(ne,{title:ct,titleComponent:Te,sectionRef:n,children:[t.jsxs("div",{className:"flex flex-col gap-4",children:[a.route==="session"&&a.borrowed?t.jsxs("p",{className:"text-body-sm text-ink-muted",children:["Showing the integrations for"," ",a.borrowed.title?.trim()||a.borrowed.session_id.slice(0,6),", your most recent chat."]}):null,a.noConversation?t.jsxs("div",{className:"flex flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"Integrations can be managed here once a chat has started."}),t.jsx(P,{variant:"primary",size:"sm",onClick:()=>u("/chat"),children:"Start a chat"}),t.jsx("p",{className:"text-ink-dim text-meta",children:"Updating Local Operator removes this step."})]}):null,a.isLoading?t.jsx("div",{className:"flex h-24 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading integrations"})}):null,a.folderUnavailable?t.jsx(te,{variant:"warning",children:t.jsx("span",{children:"This chat's folder no longer exists, so only global integrations are shown."})}):null,a.isError?t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:"Integrations couldn't be loaded."}),t.jsx(P,{variant:"secondary",size:"sm",onClick:a.refetch,children:"Retry"})]})}):null,On.map(([l,g])=>t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:g}),t.jsx(P,{variant:"ghost",size:"sm",onClick:()=>Fn(l),children:"Dismiss"})]})},l)),j&&c.length>0?Ee:null,c.length>=rc?t.jsxs("div",{className:"relative",children:[t.jsx(is,{"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-dim"}),t.jsx(Ae,{ref:x,value:h,onChange:l=>v(l.target.value),onKeyDown:l=>{l.key!=="Escape"||!h||(l.preventDefault(),v(""))},placeholder:`Search ${Br(c.length)}`,"aria-label":"Search integrations",className:"pl-9"})]}):null,A?.kind==="miss"&&c.length>0?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`No integration matches "${A.asked}".`}):null,A?.kind==="matched"&&A.unresolved?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`Showing "${A.name}" — "${A.unresolved}" is not one of your integrations.`}):null,o&&c.length===0&&!a.isLoading?j?Ee:t.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-lg bg-surface p-6",children:[t.jsx(ln,{"aria-hidden":"true",className:"size-5 text-ink-muted"}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"text-heading text-ink",children:"No integrations yet"}),t.jsx("p",{className:"max-w-xl text-body-sm text-ink-muted",children:"Integrations let agents read and act in your other tools, like Notion or Linear. Add one with a command that runs on this computer, or a server's URL."})]}),t.jsxs(P,{variant:"primary",size:"md",onClick:()=>w(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(Ot,{"aria-hidden":"true"}),"Add integration"]})]}):null,c.length>0&&Y.length===0?t.jsxs("div",{className:"flex flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"No integrations match this search."}),t.jsx(P,{variant:"secondary",size:"sm",onClick:()=>{v(""),window.setTimeout(()=>{(x.current??I.current)?.focus()},0)},children:"Clear search"})]}):null,de.map(l=>t.jsxs("section",{"aria-labelledby":`integrations-group-${l.id}`,className:"flex flex-col gap-1.5",children:[t.jsxs("h3",{id:`integrations-group-${l.id}`,className:"px-1 text-ink-dim text-meta",children:[l.title," · ",l.rows.length]}),t.jsx("ul",{className:"flex flex-col divide-y divide-hairline overflow-hidden rounded-lg bg-surface",children:l.rows.map(g=>t.jsx(Ui,{row:g,operations:m,memories:a.memories,projectScopeAvailable:y,highlighted:g.name===f,rowRef:N=>{se.current[g.name]=N,g.name===f&&(F.current=N)},primaryRef:N=>{z.current[g.name]=N},overflowRef:N=>{K.current[g.name]=N},pending:R===g.name,failure:V[g.name]??null,confirm:B?.name===g.name?{kind:B.kind}:null,onPrimary:N=>Ke(g,N),onOverflow:N=>tt(g,N),onConfirm:()=>B&&nt(g,B.kind),onCancelConfirm:()=>{$(null),window.setTimeout(()=>{K.current[g.name]?.focus()},0)}},g.id))})]},l.id))]}),M?.kind==="sign_in"?t.jsx(Hi,{name:M.name,action:M.action,keyRoute:ie?Je(ie):!1,phase:W,onStart:()=>void et(M.name,M.action),onCancel:l=>void r({action:"cancel",operationId:l}).catch(()=>{}),onOpenLink:l=>void cs(l),onClose:l=>k(M.name,l)}):null,M?.kind==="key"?t.jsx(Fi,{name:M.name,keyNames:M.keyNames.length?M.keyNames:At?.auth.secret_refs.map(l=>l.id)??[],keyless:M.keyNames.length===0,savedKeys:At?.auth.secret_refs.filter(l=>l.state==="encrypted").map(l=>l.id),saving:D,failure:ee,onClose:me,onSave:(l,g,N)=>{O(!0),L(null),a.storeKeys(M.name,l,g,N).then(U=>{if(!U.saved){L(U.message);return}S(null),Q({name:M.name,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})}).catch(U=>L(Ve("key",U,!1))).finally(()=>O(!1))}}):null]})},Le=4e3,dc=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,uc=e=>e.replace(dc,"~"),mc=e=>typeof e!="number"||!Number.isFinite(e)?"your free credits":`$${e.toFixed(2)} in free credits`,hc="https://console.radienthq.com/dashboard/verification",pc=(e,n)=>e==="pending"?{sentence:`Verify your email to claim ${n}. Check your inbox for the link Radient sent.`,action:"Open verification page"}:e==="expired"?{sentence:`The link to claim ${n} has expired. Request a new one from the verification page.`,action:"Request a new link"}:{sentence:"No signup grant is attached to this account. Open the verification page to check the account.",action:"Open verification page"},fc=({verification:e})=>{const{prices:n}=Ls(),s=e.grant_amount??n?.default_new_credits,{sentence:a,action:o}=pc(e.signup_grant,mc(s)),r=e.claim_url||hc;return t.jsxs("div",{className:"mt-8 flex items-start gap-3 rounded-sm border border-hairline bg-surface p-3",children:[t.jsx(Qe,{className:"mt-0.5 size-4 shrink-0 text-ink-muted","aria-hidden":"true"}),t.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink",children:a}),t.jsx(P,{variant:"secondary",size:"sm",onClick:()=>{window.api?.openExternal?window.api.openExternal(r):window.open(r,"_blank")},children:o})]})]})},gc=({onAfterCredentialUpdate:e})=>{const{isAuthenticated:n,user:s,isLoading:a,accountRead:o,signOut:r}=us(),d=dn(j=>j.isSigningOut),u=i.useCallback(async()=>{try{await r()}catch(j){console.error("Error signing out:",j)}},[r]),c=i.useMemo(()=>{if(!n||!s?.radientUser)return null;const{account:j,identity:w,verification:h}=s.radientUser,v=h!=null&&!h.email_verified&&h.signup_grant!=="claimed";return t.jsxs(t.Fragment,{children:[t.jsxs(Ze,{children:[t.jsx(oe,{label:"Status",value:t.jsxs("span",{className:"inline-flex items-center gap-2",children:["Connected",t.jsx(ca,{variant:"success",className:"capitalize",children:j.status})]})}),t.jsx(oe,{label:"Name",value:j.name||"Not provided"}),t.jsx(oe,{label:"Email",value:j.email}),t.jsx(oe,{label:"Account ID",value:t.jsx("span",{className:"text-mono-sm",children:j.id})}),t.jsx(oe,{label:"Tenant ID",value:t.jsx("span",{className:"text-mono-sm",children:j.tenant_id})}),t.jsx(oe,{label:"Provider",value:t.jsx("span",{className:"capitalize",children:w.provider})}),t.jsx(oe,{label:"Created",value:un(j.created_at)})]}),v&&h?t.jsx(fc,{verification:h}):null,t.jsxs("div",{className:"mt-8",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"Need to sign out or switch accounts?"}),t.jsxs(P,{variant:"danger",className:"mt-3",onClick:u,children:[t.jsx(Is,{}),"Sign out from Radient"]})]})]})},[n,s?.radientUser,u]),m=i.useMemo(()=>o==="refused"?"Radient refused the sign-in this app is holding, so your account details could not be read. Signing in again below replaces it.":mn(o)?"Your Radient account could not be read, so this app cannot show your account details.":"You are not currently signed in to Radient.",[o]),y=i.useMemo(()=>n&&s?null:t.jsxs("div",{children:[t.jsxs("p",{className:"text-body-sm text-ink-muted",children:[m," Sign in to access your account details or sign up to get free credits and unified access to models, tools, and more with Radient Pass. Radient's automatic model router will automatically select the best model for your agents to balance cost and performance. It is often cheaper to use Radient Pass than to use single AI providers due to automatic cost optimization."]}),t.jsx("div",{className:"mt-6",children:t.jsx(pa,{titleText:"",onAfterCredentialUpdate:e,descriptionText:"",onSignInSuccess:()=>{}})})]}),[n,s,m,e]);return a||d?t.jsxs("div",{className:"flex min-h-36 flex-col items-center justify-center gap-3",children:[t.jsx(re,{size:"lg",label:"Loading account"}),!d&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Loading your Radient account details…"})]}):n&&s?.radientUser?c:t.jsx("div",{className:"flex flex-col gap-4",children:y})};function yc({metric:e,data:n}){return t.jsx(ms,{title:"",heightClassName:"h-62",yAxisWidth:48,unit:e==="credits"?"credits":"tokens",srSummary:`${e==="credits"?"Credits consumed":"Tokens used"} over the last 30 days, plotted per day across ${n.length} days.`,xTickFormatter:s=>s,yTickFormatter:s=>e==="credits"?`$${s.toFixed(2)}`:hs(s),children:t.jsx(Ir,{data:n,children:t.jsx(an,{type:"monotone",dataKey:"value",strokeWidth:2,dot:!1,activeDot:{r:4,strokeWidth:0},name:e==="credits"?"Credits consumed":"Tokens used"})})})}const xc={all:["desktop","tts-path-resolution"]};function kc(e){return ke({queryKey:xc.all,queryFn:()=>ye({op:"tts.paths"}),enabled:e,staleTime:Number.POSITIVE_INFINITY,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:ps})}const vc=["speech.voice.gender","speech.voice.tone","speech.voice.expressiveness","speech.voice.pace","speech.voice.language","speech.voice.accent","speech.voice.instructions"];function Jt(e){const n=new Map(e.map(o=>[o.key,o])),s=[],a=[];for(const o of vc){const r=n.get(o);r?s.push(r):a.push(o)}return{rows:s,missing:a}}const bc=["provider_tts_radient","provider_tts_elevenlabs","provider_tts_openai","none"];function Xt(e){return typeof e=="string"&&bc.includes(e)}function jc(e){if(e===null||typeof e!="object")return null;const n=e;if(!Xt(n.path)||typeof n.reason!="string"||typeof n.servable!="boolean"||!Array.isArray(n.rungs))return null;const s=[];for(const a of n.rungs){if(a===null||typeof a!="object")return null;const o=a;if(!Xt(o.path)||typeof o.available!="boolean"||typeof o.reason!="string")return null;s.push({path:o.path,available:o.available,reason:o.reason})}return{path:n.path,reason:n.reason,servable:n.servable,rungs:s}}const wc={provider_tts_radient:"Radient Pass",provider_tts_elevenlabs:"ElevenLabs",provider_tts_openai:"OpenAI",none:"No provider"};function In(e){return wc[e]}function _c(e){return{servable:e.servable,serving:e.path==="none"?null:e.path,reason:e.reason,rungs:e.rungs.map(n=>({path:n.path,name:In(n.path),available:n.available,reason:n.reason}))}}const Nc="This backend does not serve the voicing surface. Update the backend to tune how the assistant sounds.",Ln="Speech availability could not be read.",Sc=({resetErrorBoundary:e})=>t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("span",{children:Ln}),t.jsxs(P,{variant:"secondary",onClick:e,children:[t.jsx(da,{"aria-hidden":"true"}),"Try again"]})]})});function Cc(e){return e==="enabled"?"ready":e==="below-version"?"older":"pairing"}const Mc=({sectionRef:e})=>{const n=cn(),s=hn(),a=fs(n.data,"tts"),o=Cc(a),r=ke({queryKey:vs.all,queryFn:()=>ye({op:"settings.list"}),enabled:o==="ready",staleTime:1e4}),d=kc(o==="ready"),{hasRadientApiKey:u,hasRadientSession:c,speechBlock:m}=gs(),y=`${c}:${u}`,j=i.useRef(y),w=d.refetch;i.useEffect(()=>{j.current!==y&&(j.current=y,w())},[y,w]);const h=r.data,v=i.useMemo(()=>Jt(h?.settings??[]),[h]),[R,C]=i.useState({}),[V,_]=i.useState({}),[B,$]=i.useState({});i.useEffect(()=>{h&&C(p=>{let I=!1;const x={...p};for(const H of Jt(h.settings).rows){const G=p[H.key];if(G&&G.value!==Ie(H).value)continue;const J=Ie(H);G&&G.value===J.value&&G.cascadeBase===J.cascadeBase||(x[H.key]=J,I=!0)}return I?x:p})},[h]);const M=(p,I)=>_(x=>({...x,[p]:I})),S=(p,I)=>$(x=>({...x,[p]:I})),W=async p=>{const I=R[p.key];if(!I)return;const x=ks(p,I);if(!x.ok){S(p.key,x.error);return}M(p.key,!0),S(p.key,null);try{await ye(x.request),M(p.key,!1);const G=(await r.refetch()).data?.settings.find(J=>J.key===p.key);G&&C(J=>{const X=J[p.key];return X&&X.value===I.value&&X.cascadeBase===I.cascadeBase?{...J,[p.key]:Ie(G)}:J})}catch(H){M(p.key,!1),S(p.key,H instanceof Error?H.message:"The setting could not be saved.")}},q=async p=>{M(p.key,!0),S(p.key,null);try{await ye({op:"settings.reset",key:p.key}),C(I=>({...I,[p.key]:Ie({...p,value:p.default,is_default:!0})})),M(p.key,!1),await r.refetch()}catch(I){M(p.key,!1),S(p.key,I instanceof Error?I.message:"The setting could not be reset.")}},Z=i.useMemo(()=>jc(d.data),[d.data]),T=Z?_c(Z):null,ee=d.isSuccess&&Z===null,L=(n.data?null:n.error)??null,D=r.error,O="Speech voicing",z="How the assistant sounds when it speaks aloud.";if(o==="pairing"){const{sentence:p}=pt(s??null,"Speech settings could not be loaded.",L);return t.jsx(ne,{title:O,icon:He,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:p})})}if(o==="older")return t.jsx(ne,{title:O,icon:He,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:Nc})});if(D||!h){const{sentence:p,remedy:I}=pt(s??null,"Speech settings could not be loaded.",D);return t.jsx(ne,{title:O,icon:He,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:p}),I&&t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>{r.refetch()},children:"Retry"})]})})})}const K=T?!T.servable:m==="offline",se=T?T.rungs.find(p=>p.path===T.serving)??null:null;return t.jsx(ne,{title:O,icon:He,description:z,sectionRef:e,children:t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs("section",{className:"flex flex-col gap-3",children:[d.isPending&&t.jsxs("p",{className:"flex items-center gap-2 text-body-sm text-ink-muted",children:[t.jsx(re,{}),Lt("checking")]}),(d.isError||ee)&&!T&&m!=="offline"&&t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("span",{children:[Ln," ",d.error instanceof Error?d.error.message:""]}),t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>{d.refetch()},children:"Retry"})]})}),t.jsx(la,{fallbackRender:Sc,resetKeys:[d.dataUpdatedAt],children:T&&t.jsxs(t.Fragment,{children:[t.jsxs(Ze,{children:[t.jsx(oe,{label:"Speaks through",value:T.serving?In(T.serving):"Nothing yet"}),t.jsx(oe,{label:"Availability",value:T.servable?"Ready":"No provider"})]}),T.reason&&T.reason!==se?.reason&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:T.reason}),t.jsx("ul",{className:"flex flex-col gap-1",children:T.rungs.map(p=>t.jsxs("li",{className:"flex flex-col gap-0.5 text-body-sm",children:[t.jsxs("span",{className:p.path===T.serving?"text-ink":"text-ink-muted",children:[p.name,t.jsxs("span",{className:p.path===T.serving?"text-ink-muted":"text-ink-dim",children:[" ",p.available?"(available)":"(not available)"]})]}),t.jsx("span",{className:"text-meta text-ink-dim",children:p.reason})]},p.path))})]})})]}),K&&t.jsx(te,{variant:"warning",children:Lt(m)}),t.jsx("div",{className:"flex flex-col gap-1",children:v.rows.map(p=>t.jsx(ys,{setting:p,draft:R[p.key]??Ie(p),tier:xs(p),saving:!!V[p.key],error:B[p.key]??null,onDraftChange:I=>C(x=>({...x,[p.key]:I})),onSave:()=>{W(p)},onReset:()=>{q(p)}},p.key))}),v.missing.length>0&&t.jsxs("p",{className:"text-meta text-ink-dim",children:["This backend does not register ",v.missing.join(", ")," yet, so those rows are not shown."]})]})})},Ac=()=>{const{data:e,isLoading:n,error:s,refetch:a}=Ar(),o=Rr(),[r,d]=i.useState(""),[u,c]=i.useState(!1);i.useEffect(()=>{d(e?.content??""),c(!1)},[e]);const m=v=>{const R=v.target.value;d(R),c(R!==(e?.content??""))},y=async()=>{if(!(!u||o.isPending))try{const v={content:r};await o.mutateAsync(v),await a(),c(!1)}catch(v){console.error("Error updating system prompt:",v)}},j=()=>{d(e?.content??""),c(!1)},w=o.isPending,h=()=>t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(xe,{htmlFor:"app-system-prompt",children:"Instructions"}),t.jsx(yn,{id:"app-system-prompt",name:"systemPrompt",value:r,onChange:m,placeholder:"Enter instructions for how all agents should behave and respond to your requests...",className:"min-h-50"})]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs(P,{variant:"primary",onClick:y,disabled:!u||w,children:[w?t.jsx(re,{size:"sm"}):t.jsx(Os,{}),w?"Saving...":"Save changes"]}),t.jsx(P,{onClick:j,disabled:!u||w,children:"Cancel"})]}),e?.last_modified&&t.jsxs("p",{className:"text-ink-dim text-meta",children:["Last modified:"," ",t.jsx("span",{className:"font-mono text-mono-sm",children:pn(e.last_modified)})]})]});return t.jsx(ne,{title:"System prompt",icon:ha,description:"Every Local Operator agent receives this prompt in addition to its own instructions, so it is the place for baseline expectations and for details you want every agent to know about you, such as your name, location, or preferences. It is sent to your selected hosting provider.",children:n?t.jsx("div",{className:"flex min-h-50 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading system prompt"})}):s?t.jsxs(te,{variant:"danger",children:["Failed to load system prompt:"," ",s instanceof Error?s.message:"Unknown error"]}):h()})},Rc=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"],Tc=e=>Rc.includes(e),Ec=e=>{const n=[];let s=0;for(const a of e){const o=Math.max(0,Math.floor(a.count)),r=Math.max(1,Math.floor(a.columns));for(let d=0;d<o;d+=r)n.push({start:s+d,count:Math.min(r,o-d)});s+=o}return n},Ic=({index:e,key:n,groups:s})=>{const a=Ec(s),o=a.reduce((r,d)=>r+d.count,0);if(!Number.isInteger(e)||e<0||e>=o)return e;switch(n){case"Home":return 0;case"End":return o-1;case"ArrowLeft":return Math.max(0,e-1);case"ArrowRight":return Math.min(o-1,e+1);case"ArrowUp":case"ArrowDown":{const r=a.findIndex(c=>e>=c.start&&e<c.start+c.count),d=a[r+(n==="ArrowDown"?1:-1)];if(!d)return e;const u=e-a[r].start;return d.start+Math.min(u,d.count-1)}default:return e}},Lc={localOperatorDark:Uo,localOperatorLight:or,dracula:Zo,dune:ho,sage:To,monokai:$s,tokyoNight:Bo,iceberg:Xo,radient:No,neon:bs,obsidian:kn,synth:Na,catppuccinMocha:Za,catppuccinLatte:Oo,tokyoNightStorm:Ba,gruvbox:Ia,nord:Cr,oneDark:wa,solarizedDark:sr,rosePine:yo,rosePineMoon:Do,rosePineDawn:Wa,alucard:ko,gruvboxLight:ao,tokyoNightDay:zo,oneLight:Io,catppuccinFrappe:no,catppuccinMacchiato:Co,palenight:Ds,everforest:kr,everforestLight:yr,kanagawaWave:wr,kanagawaLotus:fo,ayuDark:ro,ayuMirage:co,ayuLight:qo,nightfox:Va,duskfox:lr,synthwave:Vo,matrix:Ca,tron:za,cyberpunk:Fs,vaporwave:fr,outrun:Ta,neonNoir:br,arcade:Ao,forest:hr,ocean:uo,desert:ur,autumn:Nr,lavender:tr,arctic:qa,rosewood:wo,solarizedLight:ir,githubLight:bo,paper:fa,linen:Wo,highContrastLight:ba,mintLight:Aa},en="bg-[color-mix(in_srgb,var(--color-accent)_8%,var(--color-accent-wash))]",Oc=({id:e})=>t.jsxs("div",{"data-theme":e,"aria-hidden":"true",className:"flex h-full bg-canvas",children:[t.jsxs("div",{className:"flex w-1/4 flex-col gap-1 bg-sunken p-1",children:[t.jsx("span",{className:"flex h-2.5 items-center rounded-xs bg-accent-wash px-1",children:t.jsx("span",{className:"h-1 w-full rounded-xs bg-accent"})}),t.jsx("span",{className:"mx-1 h-1 w-2/3 rounded-xs bg-ink-dim"}),t.jsx("span",{className:"mx-1 h-1 w-1/2 rounded-xs bg-ink-dim"})]}),t.jsxs("div",{className:"flex flex-1 flex-col justify-between p-1",children:[t.jsxs("div",{className:"flex flex-col gap-1 rounded-xs bg-surface p-1",children:[t.jsx("span",{className:"h-1 w-3/5 rounded-xs bg-ink"}),t.jsx("span",{className:"h-1 w-full rounded-xs bg-ink-dim"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"h-2.5 w-6 rounded-xs bg-elevated"}),t.jsx("span",{className:"h-2.5 w-5 rounded-xs bg-accent"}),t.jsx("span",{className:"h-2.5 w-4 rounded-xs bg-accent-alt"}),t.jsx("span",{className:"h-2.5 w-4 rounded-xs border border-control"})]})]})]}),Fc=({id:e,name:n,description:s,isSelected:a,isTabStop:o,onSelect:r,onFocusTile:d})=>{const u=Lc[e];return t.jsx($e,{side:"bottom",align:"start",content:s,children:t.jsxs("button",{type:"button","data-theme-tile":e,"aria-pressed":a,tabIndex:o?0:-1,onFocus:d,onClick:r,className:ce("relative flex flex-col gap-1.5 rounded-md p-1 text-left transition-colors duration-fast ease-out-quart",a?en:"hover:bg-surface"),children:[t.jsxs("span",{className:ce("relative block h-10 overflow-hidden rounded-sm border transition-colors duration-fast ease-out-quart",a?"border-accent":"border-hairline"),children:[t.jsx(Oc,{id:e}),a&&t.jsx("span",{className:ce("pointer-events-none absolute top-0.5 right-0.5 flex h-4 w-4 items-center justify-center rounded-full",en),children:t.jsx(ma,{size:12,className:"text-accent","aria-hidden":"true"})})]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(u,{size:12,className:"shrink-0 text-ink-dim","aria-hidden":"true"}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink",children:n})]})]})})},Dc=e=>[...e.querySelectorAll("[data-theme-grid]")].map(n=>{const s=[...n.querySelectorAll("[data-theme-tile]")],a=s[0]?.getBoundingClientRect().top??0;return{count:s.length,columns:Math.max(1,s.filter(o=>Math.abs(o.getBoundingClientRect().top-a)<1).length)}}),$c=()=>{const{themeName:e,setTheme:n}=Oe(),s=i.useMemo(()=>{const u=Object.values($n);return[{label:"Dark",items:u.filter(c=>c.theme.palette.mode==="dark")},{label:"Light",items:u.filter(c=>c.theme.palette.mode==="light")}].filter(c=>c.items.length>0)},[]),[a,o]=i.useState(null),r=i.useMemo(()=>{const u=s.flatMap(c=>c.items.map(m=>m.id));return a&&u.includes(a)?a:u.includes(e)?e:u[0]},[s,a,e]),d=u=>{if(!Tc(u.key))return;const c=[...u.currentTarget.querySelectorAll("[data-theme-tile]")],m=c.indexOf(u.target);if(m<0)return;u.preventDefault();const y=Ic({index:m,key:u.key,groups:Dc(u.currentTarget)});y!==m&&c[y]?.focus()};return t.jsx(ua,{children:t.jsx("div",{onKeyDown:d,className:"flex flex-col gap-6",children:s.map(u=>t.jsxs("div",{children:[t.jsx("h3",{className:"px-1 pb-2 text-meta text-ink-dim",children:u.label}),t.jsx("div",{"data-theme-grid":u.label,className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-2",children:u.items.map(({id:c,name:m,description:y})=>t.jsx(Fc,{id:c,name:m,description:y,isSelected:c===e,isTabStop:c===r,onSelect:()=>n(c),onFocusTile:()=>o(c)},c))})]},u.label))})})},Uc=({value:e,onChange:n})=>{const s=i.useId();return t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{id:s,className:"flex min-h-6 items-center text-body text-ink",children:"Transcript display"}),t.jsx("p",{className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:"By turn condenses each turn to its answer. By response keeps every settled response on screen, with the turn's final answer still marked."})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:t.jsx(ft,{value:e,onValueChange:a=>n(fn(a)),children:t.jsx(gt,{"aria-labelledby":s,children:Rs.map(a=>t.jsx(Fe,{value:a.value,children:a.label},a.value))})})})]})},Pc=()=>{const{data:e,isLoading:n,error:s}=Or({enabled:!0});return t.jsxs("div",{children:[t.jsxs("h3",{className:"mb-3 flex items-center gap-2 text-heading text-ink",children:[t.jsx(eo,{size:16,className:"shrink-0 text-ink-dim"}),"Radient Pass"]}),n&&t.jsx(xn,{className:"h-6 w-36"}),s&&t.jsxs(te,{variant:"warning",children:["Could not load your credit balance. ",s.message]}),e&&!n&&!s&&t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[t.jsxs("p",{className:"flex-1 text-body-sm text-ink-muted",children:["Available credits"," ",t.jsx("span",{className:"font-medium text-ink",children:e.balance.toFixed(2)})]}),t.jsx(P,{variant:"secondary",size:"sm",asChild:!0,children:t.jsxs("a",{href:"https://console.radienthq.com/dashboard/billing",target:"_blank",rel:"noopener noreferrer",children:[t.jsx(Ua,{}),"Add credits"]})})]})]})},zc=[{id:"credits",label:"Credits"},{id:"tokens",label:"Tokens"}],Kc=()=>{const[e,n]=i.useState("credits"),s=i.useMemo(()=>{const u=new Date,c=Er(u);return{start_date:Pt(c),end_date:Pt(u),rollup:"daily"}},[]),{data:a,isLoading:o,error:r}=Dr(s,{enabled:!0}),d=i.useMemo(()=>a?.data_points?[...a.data_points].sort((c,m)=>at(c.timestamp).getTime()-at(m.timestamp).getTime()).map(c=>({bucket:Ms(xa(at(c.timestamp),"yyyy-MM-dd")),value:e==="credits"?Number.parseFloat(c.total_cost.toFixed(2)):c.total_tokens})):[],[a,e]);return t.jsxs("div",{children:[t.jsxs("div",{className:"mb-5 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("h3",{className:"flex items-center gap-2 text-heading text-ink",children:[t.jsx(Oa,{size:16,className:"shrink-0 text-ink-dim"}),"Usage (last 30 days)"]}),t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:"Usage metric"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:zc.map(({id:u,label:c})=>t.jsx(P,{variant:"ghost",size:"sm","aria-pressed":e===u,onClick:()=>n(u),className:ce(e===u&&"bg-surface text-ink hover:bg-surface"),children:c},u))})]})]}),o&&t.jsx(xn,{className:"h-62 w-full"}),r&&t.jsxs(te,{variant:"warning",children:["Could not load your usage data. ",r.message]}),!o&&!r&&a&&d.length>0&&t.jsx(yc,{metric:e,data:d}),!o&&!r&&(!a||d.length===0)&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:"No usage recorded in the last 30 days."})]})},Bc=()=>t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[t.jsx(Ys,{size:16,className:"shrink-0 text-ink-dim"}),"Radient account"]}),t.jsx(P,{variant:"secondary",size:"sm",className:"self-start sm:self-center",asChild:!0,children:t.jsxs("a",{href:"https://console.radienthq.com",target:"_blank",rel:"noopener noreferrer",children:["Go to Radient console",t.jsx(As,{})]})})]}),sl=()=>{const e=js("surface"),n=Oe(f=>f.showAgentReasoning),s=Oe(f=>f.setShowAgentReasoning),a=Oe(f=>f.transcriptDisplayMode),o=Oe(f=>f.setTranscriptDisplayMode),{data:r,isLoading:d,isFetching:u,error:c,refetch:m}=ws(),y=hn(),{sentence:j,remedy:w}=pt(y??null,"Your settings could not be loaded.",c),h=Us(),[v,R]=i.useState(null),C=dn(),{isAuthenticated:V,accountRead:_,isFetching:B,isRefreshing:$,refreshUser:M}=bt(),S=Ge(f=>f.activeSessionId),[W,q]=i.useState("general"),[Z,T]=i.useState(!1),ee=i.useRef(null),L=i.useRef(null),{startTour:D}=Ps(),O=_s(),{data:z,refetch:K}=Ns(),{refreshModels:se}=Ss(),p=i.useMemo(()=>z?.keys?[...z.keys].sort():[],[z?.keys]),I=i.useRef({keys:"",hosting:void 0});i.useEffect(()=>{const f=p.join(","),F=r?.values?.hosting;(I.current.keys!==f||I.current.hosting!==F)&&(I.current={keys:f,hosting:F},se().catch(E=>{console.error("Failed to refresh models after credentials or hosting change:",E)}))},[p,r?.values?.hosting,se]);const x=i.useRef({general:i.useRef(null),radient:i.useRef(null),integrations:i.useRef(null),appearance:i.useRef(null),speech:i.useRef(null),providers:i.useRef(null),backend:i.useRef(null),updates:i.useRef(null)}).current,H=i.useMemo(()=>new URLSearchParams(O.search).get("setting"),[O.search]),G=i.useMemo(()=>new URLSearchParams(O.search).get("filter")??"",[O.search]),J=i.useMemo(()=>new URLSearchParams(O.search).get("mcp")??void 0,[O.search]),X=i.useMemo(()=>new URLSearchParams(O.search).get("provider"),[O.search]),Q=i.useCallback(f=>{q(f),T(!0);const F=x[f],E=L.current;if(F?.current&&E){const Y=F.current.getBoundingClientRect().top-E.getBoundingClientRect().top;E.scrollHeight>E.clientHeight?E.scrollTo({top:Math.max(0,E.scrollTop+Y-80),behavior:"smooth"}):window.scrollTo({top:Math.max(0,F.current.getBoundingClientRect().top+window.scrollY-80),behavior:"smooth"}),clearTimeout(ee.current??void 0),ee.current=setTimeout(()=>{T(!1),ee.current=null},800)}else T(!1)},[x]);i.useEffect(()=>{const f=setTimeout(()=>{const F=L.current;if(!F)return;const E=()=>{if(Z)return;const le=F.getBoundingClientRect(),Y=le.height;let de="",ie=0;for(const[be,he]of Object.entries(x))if(he.current){const ae=he.current.getBoundingClientRect(),je=le.top,pe=ae.top-je,et=ae.bottom-je,Ke=ae.height,tt=Math.max(0,pe),nt=Math.min(Y,et),Te=Math.max(0,nt-tt)/Ke,Ee=Te+(pe<Y*.3?.1:0);Ee>ie&&Te>.1&&(ie=Ee,de=be)}de&&de!==W&&q(de)};return E(),F.addEventListener("scroll",E,{passive:!0}),()=>{F.removeEventListener("scroll",E),clearTimeout(ee.current??void 0)}},100);return()=>clearTimeout(f)},[x,W,Z]),i.useEffect(()=>{const f=new URLSearchParams(O.search),F=f.get("section"),E=f.get("setting")?"backend":F,le=E?x[E]:void 0;if(!E||!le)return;let Y=!1,de=Number.NaN,ie=0;const be=window.setTimeout(()=>{Y||(Y=!0,ae.disconnect(),Q(E))},2e3),he=()=>{if(Y)return;const je=le.current;if(!je){ie=requestAnimationFrame(he);return}const pe=Math.round(je.getBoundingClientRect().top+window.scrollY);if(pe===de&&pe>0){Y=!0,ae.disconnect(),window.clearTimeout(be),Q(E);return}de=pe,ie=requestAnimationFrame(he)},ae=new ResizeObserver(()=>{Y||(cancelAnimationFrame(ie),ie=requestAnimationFrame(he))});return L.current&&ae.observe(L.current),ie=requestAnimationFrame(he),()=>{Y=!0,cancelAnimationFrame(ie),ae.disconnect(),window.clearTimeout(be)}},[O.search,x,Q]);const fe=async(f,F)=>{R(f);try{await h.mutateAsync({[f]:F}),await m()}catch(E){console.error(`Error updating ${f}:`,E)}finally{R(null)}},ve=d,me=_==="checking",Ce=mn(_),k=_==="ready"||_==="checking"||B,A=gn(ve,4e3);return c?t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(te,{variant:"warning",className:"w-full max-w-xl",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:j}),w&&t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>void m(),disabled:u,children:u?"Retrying":"Retry"})]})})}):ve?t.jsxs("div",{role:"status",className:"flex h-full w-full flex-col items-center justify-center gap-3 bg-canvas",children:[t.jsx(re,{size:"lg",label:A?void 0:"Loading settings"}),A&&t.jsx("p",{className:"max-w-sm text-center text-body-sm text-ink-muted",children:"The Local Operator server is taking longer than usual to answer. If it does not respond, you will be able to retry from here."})]}):r?t.jsxs("div",{className:"flex h-full w-full overflow-hidden bg-canvas",children:[t.jsx("div",{ref:e,className:"w-12 shrink-0 overflow-y-auto min-[1040px]:w-55",children:t.jsx(zs,{activeSection:W,onSelectSection:Q,sections:Ks})}),t.jsx("div",{ref:L,"data-settings-content":!0,"data-tour-tag":"settings-general-section",className:"flex-1 overflow-y-auto overflow-x-hidden p-4 sm:p-6 md:p-8",children:t.jsxs("div",{className:"mx-auto flex w-full max-w-4xl flex-col gap-8 pb-8",children:[t.jsx(Ws,{title:"Settings",icon:Ft}),t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsxs("div",{ref:x.general,className:"flex flex-col gap-8",children:[t.jsxs(ne,{title:"User profile",icon:Bs,description:`Your user profile information displayed in the application. This information is not provided to the agents. ${V?"These details are provided through your Radient account.":""}`,children:[me&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Checking your Radient account…"}),Ce&&t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("span",{children:["Your Radient account could not be read, so the name and email below are placeholders rather than your account details.",_==="refused"?" Retry, or sign in to Radient again.":" Retry."]}),t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>M(),disabled:$,children:$?"Retrying":"Retry"})]})}),t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Dt,{value:C.profile.name,label:"Display name",placeholder:"Enter your name...",isSaving:v==="user_name",onSave:async f=>{R("user_name");try{C.updateName(f)}finally{R(null)}},readOnly:k}),t.jsx(Dt,{value:C.profile.email,label:"Email address",placeholder:"Enter your email...",isSaving:v==="user_email",onSave:async f=>{R("user_email");try{C.updateEmail(f)}finally{R(null)}},readOnly:k})]})]}),t.jsx(ne,{title:"Application tour",description:"Missed the application onboarding tour or want a refresher? Start it again here.",children:t.jsxs(P,{variant:"secondary",onClick:()=>{D({forceModalCompleted:!0})},children:[t.jsx(Da,{}),"Take the tour"]})}),t.jsx(ne,{id:"model-settings",title:"Model settings",icon:Hs,description:"Configure the default AI model and hosting providers used for generating responses. This will be used for all agents that don't have a specific model or hosting provider configured. You can override these settings for individual agents in the agent settings.",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Vs,{value:r.values.hosting,isSaving:v==="hosting",onSave:f=>fe("hosting",f),filterByCredentials:!0,allowCustom:!0,allowDefault:!1,emptyHelperText:"No hosting providers available. Sign in to a provider, or add a provider's API key below, under Providers."}),t.jsx(Gs,{value:r.values.model_name,hostingId:r.values.hosting,isSaving:v==="model_name",onSave:f=>fe("model_name",f),allowCustom:!0,allowDefault:!1}),t.jsx(te,{variant:"neutral",icon:t.jsx(Qe,{className:"size-4","aria-hidden":"true"}),children:"You need a Radient account or your own API keys to reach cloud providers. If you don't see more hosting providers and models here, sign in to Radient, or add a provider's API key below, under Providers."})]})}),t.jsx(Ac,{}),t.jsx(ne,{title:"Configuration information",icon:Qe,description:"System information about the current configuration.",children:t.jsxs(Ze,{children:[t.jsx(oe,{label:"Version",value:t.jsx("span",{className:"text-mono-sm",children:r.version})}),t.jsx(oe,{label:"Created",value:un(r.metadata.created_at)}),t.jsx(oe,{label:"Last modified",value:pn(r.metadata.last_modified)}),t.jsx(oe,{label:"Description",value:r.metadata.description||"No description available"})]})})]}),t.jsx(ne,{title:"Appearance",icon:kn,description:"Customize the look and feel of Local Operator",sectionRef:x.appearance,dataTourTag:"settings-appearance-section",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx($c,{}),t.jsx(Tr,{value:n,label:"Show agent reasoning",description:"Adds the agent's Reasoning and Thinking rows to conversations. They stay closed until you open one. Reasoning only: narration the agent writes as prose mid-turn is transcript content, not reasoning — never removed by either display mode (by turn folds it behind the turn's bars, by response keeps it on screen).",onChange:async f=>s(f)}),t.jsx(Uc,{value:fn(a),onChange:f=>o(f)})]})}),t.jsx(Mc,{sectionRef:x.speech}),t.jsx(ne,{title:"Model providers",icon:ln,description:"Sign in to the services your agents think with. New chats use your default model.",sectionRef:x.providers,children:t.jsx(qs,{initialProviderId:X,onChangeModel:()=>Q("general")})}),t.jsx(lc,{sessionId:S??void 0,sectionRef:x.integrations,highlightServer:J}),t.jsx(ne,{title:"Radient account",titleComponent:t.jsx(Bc,{}),description:"Your Radient account, Radient Pass details and credits. To use Radient models, sign in under Model providers.",sectionRef:x.radient,dataTourTag:"settings-radient-account-section",children:t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsx(gc,{onAfterCredentialUpdate:()=>{se(),K()}}),V&&t.jsxs(t.Fragment,{children:[t.jsx(Pc,{}),t.jsx(Kc,{})]})]})}),t.jsx(ne,{title:"Backend settings",icon:Ft,description:"Every setting the backend registry owns, searchable, with typed editors and scopes.",sectionRef:x.backend,children:t.jsx(Cs,{focusKey:H,initialFilter:G})}),t.jsx("div",{ref:x.updates,children:t.jsx(zr,{})})]})]})})]}):t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(te,{variant:"warning",className:"w-full max-w-xl",children:"Your settings could not be loaded."})})};export{sl as SettingsPage};
|
|
291
|
+
*/const Sr=[["path",{d:"M12.8 19.6A2 2 0 1 0 14 16H2",key:"148xed"}],["path",{d:"M17.5 8a2.5 2.5 0 1 1 2 4H2",key:"1u4tom"}],["path",{d:"M9.8 4.4A2 2 0 1 1 11 8H2",key:"75valh"}]],Cr=b("wind",Sr),Mr=({appVersion:e=null,slowWaitHintMs:n})=>{const s="https://local-operator.com/download",[a,o]=i.useState(!1),r=gn(a,n??Ts),[d,u]=i.useState(!1),[c,m]=i.useState(null),[y,j]=i.useState("info"),[w,h]=i.useState(null),[v,R]=i.useState(null),C=e?.trim()?e.trim():null,V=i.useRef(!1),_=lt(L=>L.openDetail),H=i.useRef(!1),$=i.useRef(0),M=i.useRef(!1),S=i.useCallback((L,D)=>{H.current=!1,m(L),j(D),u(!0)},[]),W=i.useCallback(L=>{H.current=!0,m(L),j("success"),u(!0)},[]),q=i.useCallback(()=>{H.current&&(H.current=!1,u(!1),m(null))},[]),{clearDeferredUpdate:Z}=Un();i.useEffect(()=>{const L=window.api.updater.onUpdateError(p=>{V.current&&p.includes("manually")&&(h({message:"The server is installed outside the app, so use the tool you installed it with - uv, pipx or pip.",command:""}),H.current=!1,m(null),j("warning"),u(!0))}),D=window.api.updater.onBackendUpdateDevMode(p=>{V.current&&S(p,"info")}),O=()=>{M.current=!0,q()},z=window.api.updater.onUpdateAvailable(O),K=window.api.updater.onUpdateNpxAvailable(O),se=window.api.updater.onBackendUpdateAvailable(O);return()=>{L(),D(),z(),K(),se()}},[q,S]),i.useEffect(()=>{let L=!1;const D=()=>{window.api.updater.getLastInstallAttempt().then(z=>{L||R(z)}).catch(()=>{})};D();const O=window.api.updater.onUpdateInstallFailed(()=>D());return()=>{L=!0,O()}},[]);const T=async()=>{const L=++$.current;q(),M.current=!1;try{o(!0),V.current=!0,Z(ge.UI),Z(ge.BACKEND);const D=await window.api.updater.checkForAllUpdates({manual:!0});if(L!==$.current)return;D.app==="available"&&_(ge.UI),D.server==="available"&&_(ge.BACKEND),D?.affirmation&&!M.current?W(D.affirmation):q()}catch(D){if(L!==$.current)return;console.warn(`Update check failed; the app-level alert owns the report: ${Es(D)}`)}finally{L===$.current&&o(!1),setTimeout(()=>{V.current=!1},2e3)}},ee=()=>{H.current=!1,u(!1),m(null)};return t.jsxs(t.Fragment,{children:[v&&t.jsxs("div",{className:"mb-3 rounded-sm bg-sunken p-3",children:[t.jsxs("p",{className:"text-body-sm text-ink",children:["The last update to version ",v.targetVersion," didn't finish",v.attempts>1?` (${v.attempts} attempts)`:"",".",C?` Version ${C} is running.`:null]}),t.jsxs("p",{className:"mt-1 text-meta text-ink-dim",children:["Detected"," ",v.detectedAt?new Date(v.detectedAt).toLocaleString():"at an unknown time",". ",v.detail]}),t.jsx(P,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>void window.api.openExternal(s),children:"Download a fresh copy"})]}),t.jsxs(P,{variant:"outline",onClick:()=>void T(),disabled:a,children:[a?t.jsx(re,{size:"sm"}):null,a?"Checking...":"Check for updates"]}),r&&t.jsx("p",{className:"mt-2 text-meta text-ink-muted",children:"Still checking. A slow or stalled connection can hold this for about a minute and a half - the app stops waiting on its own."}),w&&t.jsxs(Tt,{open:d,autoHideDuration:1e4,onClose:ee,variant:"warning",children:[t.jsx("p",{className:"text-body-sm",children:w.message}),w.command&&t.jsx("code",{className:"mt-2 block rounded-sm bg-sunken p-2 text-mono-sm text-ink",children:w.command})]}),c&&y!=="danger"&&t.jsx(Tt,{open:d,autoHideDuration:6e3,onClose:ee,variant:y,children:c})]})},qe=["system-prompt"],Ar=()=>{const{shouldEnableQuery:e}=Pn();return ke({enabled:e({bypassInternetCheck:!0}),queryKey:qe,queryFn:async()=>{try{const s=await tn(vt.baseUrl).config.getSystemPrompt();if(s===null)return null;if(s.status>=400)throw new Error(s.message||"Failed to fetch system prompt");return s.result}catch(n){const s=n instanceof Error?n.message:"An unknown error occurred while fetching system prompt";throw nn(s),n}},refetchOnWindowFocus:!1,staleTime:5e3})},Rr=()=>{const e=sn(),n=tn(vt.baseUrl);return zn({mutationFn:async s=>{try{const a=await n.config.updateSystemPrompt(s);if(a.status>=400)throw new Error(a.message||"Failed to update system prompt");return a.result}catch(a){const o=a instanceof Error?a.message:"An unknown error occurred while updating system prompt";throw nn(o),a}},onSuccess:async s=>{await e.invalidateQueries({queryKey:qe,refetchType:"none"}),e.setQueryData(qe,a=>a&&{...a,...s}),await e.refetchQueries({queryKey:qe,type:"all"}),Kn("System prompt updated")},onError:s=>{console.error("Error updating system prompt:",s)}})},Tr=({value:e,label:n,description:s,onChange:a,icon:o,isSaving:r=!1})=>{const[d,u]=i.useState(e),c=i.useId(),m=`${c}-label`,y=`${c}-description`,j=async w=>{if(!r){u(w);try{await a(w)}catch(h){u(!w),console.error("Error toggling setting:",h)}}};return t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("span",{id:m,className:"flex min-h-6 items-center gap-2 text-body text-ink",children:[o&&t.jsx(o,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-dim"}),n]}),s&&t.jsx("p",{id:y,className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:s})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:r?t.jsx(re,{size:"md",label:`Saving ${n}`}):t.jsx(Qs,{checked:d,onCheckedChange:j,"aria-labelledby":m,"aria-describedby":s?y:void 0})})]})};function Pt(e,n){const s=ka(e,n?.in);if(!ya(s))throw new RangeError("Invalid time value");const a=Ne(s.getDate(),2),o=Ne(s.getMonth()+1,2),r=s.getFullYear(),d=Ne(s.getHours(),2),u=Ne(s.getMinutes(),2),c=Ne(s.getSeconds(),2);let m="",y="";const j=s.getTimezoneOffset();if(j!==0){const w=Math.abs(j),h=Ne(Math.trunc(w/60),2),v=Ne(w%60,2);y=`${j<0?"+":"-"}${h}:${v}`}else y="Z";return`${r}-${o}-${a}T${d}:${u}:${c}${m}${y}`}function Er(e,n,s){return ga(e,-30,s)}var Ir=Hn({chartName:"LineChart",GraphicalChild:an,axisComponents:[{axisType:"xAxis",AxisComp:Bn},{axisType:"yAxis",AxisComp:Vn}],formatAxisMap:Gn});const Lr=["radient","creditBalance"],Or=e=>{const{user:n,isAuthenticated:s}=bt(),a=n?.account?.tenant_id,o=s&&!!a&&e?.enabled;return ke({queryKey:[Lr,a],queryFn:async()=>{if(!a)throw new Error("Tenant ID not available");const r=await on({operation:"credits",tenantId:a});if(!r||typeof r.balance!="number")throw new Error("Invalid credit balance response format");return r},enabled:o,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},Fr=["radient","usageRollup"],Dr=(e,n)=>{const{user:s,isAuthenticated:a}=bt(),o=s?.account?.tenant_id,r=a&&!!o&&n?.enabled;return ke({queryKey:[...Fr,o,e],queryFn:async()=>{if(!o)throw new Error("Tenant ID not available");const d={};for(const[c,m]of Object.entries(e))m!=null&&(d[c]=String(m));const u=await on({operation:"usage",tenantId:o,query:d});if(!u)throw new Error("Invalid usage rollup response format");return u},enabled:r,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},zt={[ge.UI]:"Application updates",[ge.BACKEND]:"Server updates"},Kt=({type:e})=>{const n=lt(a=>a.followed[e]),s=lt(a=>a.setFollowedSegment);return t.jsxs("div",{className:"flex flex-col gap-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-6",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-body-sm text-ink",children:zt[e]}),t.jsx("div",{className:"mt-0.5 text-meta text-ink-muted",children:He[n].description})]}),t.jsxs(Zs,{value:n,onValueChange:a=>s(e,a),children:[t.jsx(Js,{"aria-label":`${zt[e]}: ${He[n].label}`,className:"w-full sm:w-56","data-followed-segment":e,children:t.jsx(Xs,{})}),t.jsx(ea,{children:qn.map(a=>t.jsx(ta,{value:a,title:He[a].description,children:He[a].label},a))})]})]})},$r=()=>t.jsxs("div",{className:ce("flex flex-col gap-3"),children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-heading text-ink",children:"Update notifications"}),t.jsx("p",{className:"mt-1 text-meta text-ink-muted",children:"How much of a version change shows the update notice at the bottom of the window. A check you run yourself always reports what it finds."})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(Kt,{type:ge.UI}),t.jsx(Kt,{type:ge.BACKEND})]})]}),Ur=({appVersion:e})=>t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx($r,{}),t.jsx(Mr,{appVersion:e})]}),Pr=e=>{if(!e)return null;try{return new URL(e).host}catch{return null}},zr=()=>{const[e,n]=i.useState(null),[s,a]=i.useState({value:"Loading...",detail:null,degraded:!1}),[o,r]=i.useState({platform:"Loading...",arch:"...",nodeVersion:"Loading...",electronVersion:"Loading...",chromeVersion:"Loading..."});i.useEffect(()=>{let u=!0;const c=h=>{if(!u)return;const v=Pr(h.url);if(h.state==="connecting"){a({value:"Loading...",detail:null,degraded:!1});return}if(h.state==="detached"){a({value:"Not connected",detail:h.detail||null,degraded:!1});return}if(h.state==="wedged"){a({value:"Not attached",detail:h.detail||null,degraded:!1});return}const R=h.version||"Version unknown";a({value:v?`${R} · ${v}`:R,detail:h.detail||null,degraded:h.state==="degraded"})};let m=!1;const y=window.api?.backend?.onStatusChange(h=>{m=!0,c(h)}),j=async()=>{try{const[h,v]=await Promise.all([window.api.systemInfo.getAppVersion(),window.api.systemInfo.getPlatformInfo()]);u&&(n(h),r(v))}catch(h){console.error("Error fetching app information:",h)}},w=async()=>{try{const h=window.api?.backend;if(h){const C=await h.getStatus();m||c(C);return}const v=await Et.healthCheck(vt.baseUrl),R=Et.getServerVersion(v);u&&a({value:R,detail:null,degraded:!1})}catch(h){console.error("Error fetching server version:",h),u&&a({value:"Unavailable",detail:null,degraded:!1})}};return j(),w(),()=>{u=!1,y?.()}},[]);const d=(u,c,m,y={})=>t.jsx(oe,{label:t.jsx($e,{content:m,children:t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(Qe,{size:12,className:"shrink-0"}),u]})}),valueClassName:y.valueClassName,value:t.jsxs(t.Fragment,{children:[y.valueTooltip?t.jsx($e,{content:y.valueTooltip,children:t.jsx("span",{"data-backend-version":y.valueHoverTarget?"":void 0,children:c})}):c,y.statusNote?t.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:y.statusNote}):null]})});return t.jsx(ne,{title:"Application updates and info",icon:Yn,description:"Check for updates and view information about your Local Operator installation.",dataTourTag:"settings-app-updates-section",children:t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs(Ze,{children:[d("Application version",e??"Loading...","The version of the Local Operator user interface application."),d("Server version",s.value,"The version of the Local Operator API server backend, and the address of the daemon it was read from.",{valueTooltip:s.detail,valueHoverTarget:!0,statusNote:s.degraded?"Not answering":void 0,valueClassName:s.degraded?"text-ink-muted":void 0}),d("Platform",`${o.platform} (${o.arch})`,"The operating system and architecture your application is running on."),d("Node.js version",o.nodeVersion,"The JavaScript runtime environment version."),d("Electron version",o.electronVersion,"The framework version enabling this desktop application.")]}),t.jsx(Ur,{appVersion:e})]})})},Kr=[[[".claude.json"],"Claude Code"],[[".claude",".mcp.json"],"Claude Code"],[[".cursor","mcp.json"],"Cursor"],[[".vscode","mcp.json"],"VS Code"],[[".codex","config.toml"],"Codex CLI"]];function vn(e){if(!e)return null;const n=e.split("\\").join("/").split("/").filter(Boolean);for(const[s,a]of Kr)if(!(n.length<s.length)&&n.slice(-s.length).join("/")===s.join("/"))return a;return null}const Ye=e=>`${e} ${e===1?"tool":"tools"}`,Hr=e=>`${e} ${e===1?"integration":"integrations"}`,Br=["connected","needs_sign_in","not_started","connecting","error"],bn=e=>Br.includes(e),Re=(e,n)=>[...n].filter(s=>s.name===e&&s.status==="running").sort((s,a)=>a.created_at-s.created_at)[0]??null,Vr={connectedAt:null,connectedToolCount:null,settledGroup:null,pinnedGroup:null,pinnedOperationId:null,needsKey:!1,needsSignIn:!1,disconnectedAt:null,holdUntil:null,lastDecisive:null},Gr=1e12,qr=1e9,Yr=60*60*1e3,jn=(e,n=Date.now())=>{if(typeof e!="number"||!Number.isFinite(e))return null;const s=e>=Gr?e:e<qr?null:e*1e3;return s===null||s>n+Yr?null:Math.min(s,n)},Se=(e,n)=>e?.[n]??Vr,Pe=(e,n,s)=>Zr(e,n)??s?.lastDecisive??null,Wr=e=>({id:e.id,name:e.name,action:e.action,status:e.status,created_at:e.created_at,credential_removed:e.credential_removed,...e.message?{message:e.message}:{}}),wt=(e,n)=>e.status==="not_started"&&typeof e.tool_count=="number"&&(n.connectedAt!==null||e.status_basis==="stored"&&e.tool_count_basis==="last_seen"),Qr=(e,n)=>[...n].filter(s=>s.name===e).sort((s,a)=>a.created_at-s.created_at)[0]??null,Zr=(e,n)=>Qr(e,n.filter(s=>s.status!=="cancelled")),Je=e=>e.actions.includes("set_key")||e.actions.includes("add_key");function Jr(e,n){const s=Math.max(0,Math.round((e-n)/1e3));if(s<60)return"just now";const a=Math.round(s/60);if(a<60)return`${a} min ago`;const o=Math.round(a/60);return o<24?`${o} h ago`:`${Math.round(o/24)} d ago`}function ot(e){if(!e)return null;const n=e.trim();if(!n||/^\/\w/.test(n)||/\/mcp\s+\w+/.test(n))return null;let s=n;for(let a=0;a<3;a+=1){const o=s.replace(/^(?:connection (?:closed|error|refused)|error|closed|failed)\s*:\s*/i,"").trim();if(o===s)break;s=o}return s=s.replace(/\s*\(\s*\d{3}\s*\)/g,"").replace(/\s+([.,;])/g,"$1").replace(/\s{2,}/g," ").trim(),s||null}function Xr(e,n=[],s,a=Date.now()){const o=Se(s,e.name),r=Re(e.name,n);if(r){if(r.action==="login"||r.action==="reauth")return{label:"Signing in…",tone:"info",detail:null,busy:!0};if(r.action==="logout")return{label:"Signing out…",tone:"info",detail:null,busy:!0}}if(!bn(e.status))return{label:"Status unavailable",tone:"neutral",detail:null,busy:!1};const d=Pe(e.name,n,o),u=Xe(d)&&e.status!=="connected",c=wt(e,o),m=St(d)&&e.status!=="connected",y=(d?.action==="login"||d?.action==="reauth")&&d.status==="failed";if(o.disconnectedAt!==null)return{label:"Not connected",tone:"neutral",detail:null,busy:!1};switch(e.status){case"connected":return{label:typeof e.tool_count=="number"?`Connected · ${Ye(e.tool_count)}`:"Connected",tone:"success",detail:null,busy:!1};case"connecting":return{label:"Connecting…",tone:"info",detail:null,busy:!0};case"needs_sign_in":return{label:e.auth.kind==="api_key"||De(e,n,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:ot(e.status_reason),busy:!1};case"error":return{label:"Couldn't start",tone:"danger",detail:ot(e.status_reason)??"No reason was given.",busy:!1};default:if(u)return{label:"Signed out",tone:"warning",detail:null,busy:!1};if(m)return{label:"Sign-out didn't finish",tone:"warning",detail:"The sign-in is still saved.",busy:!1};if(De(e,n,o))return{label:"Needs a key",tone:"warning",detail:null,busy:!1};if(y)return{label:"Sign-in didn't finish",tone:"warning",detail:null,busy:!1};if(o.needsSignIn)return{label:e.auth.kind==="api_key"||De(e,n,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:ot(e.status_reason),busy:!1};if(e.status_basis==="stored"&&c&&o.disconnectedAt===null){const j=o.connectedAt??jn(e.last_seen_at,a);return{label:j!==null?`Worked ${Jr(a,j)} · ${Ye(e.tool_count)}`:`Worked earlier · ${Ye(e.tool_count)}`,tone:"success",detail:null,busy:!1}}return e.status_basis==="live"?{label:"Not connected",tone:"neutral",detail:null,busy:!1}:{label:"Ready",tone:"neutral",detail:null,busy:!1}}}const wn=e=>e===1?"Replace the saved key":"Replace saved keys",ei=/[,;]?\s*(?:or|and)?\s*add (?:its|a|the) key instead\.?\s*$/i;function ti(e,n){const s=e?.trim()??"";if(!s)return null;if(n)return s;const a=s.replace(ei,"").trim();return a?/\.$/.test(a)?a:`${a}.`:s}const ni="Nothing is wrong. It starts when a chat uses it.",si="Not running in this chat.",ai=e=>e.transport==="local_command"?"Local command":"Remote URL";function _n(e){switch(e.source.kind){case"local-operator":case"project-mcp-json":return null;case"claude-code":return"Claude Code";case"cursor":return"Cursor";case"vscode":return"VS Code";case"codex":return"Codex CLI";default:return vn(e.source.path)}}function oi(e,n){const s=[ai(e)];e.status!=="connected"&&e.tool_count_basis==="last_seen"&&typeof e.tool_count=="number"&&s.push(`${Ye(e.tool_count)} when last checked`),n&&s.push(e.scope==="project"?"This project":"Global");const a=_n(e);return a?s.push(`Imported from ${a}`):e.source.editable||s.push("Imported from a project file"),s}const _t=(e,n)=>n.disconnectedAt!==null?"not_started":e.status;function Nt(e,n=[],s){const a=Se(s,e.name),o=Re(e.name,n);if(o)return o.action==="login"||o.action==="reauth"?{kind:"sign_in",label:"Continue sign-in"}:null;const r=y=>e.actions.includes(y),d=Je(e),u=De(e,n,a);if(!bn(e.status))return r("test")?{kind:"test",label:"Check again"}:null;const c=Pe(e.name,n,a),m=c?.status==="failed"&&ze(c);switch(_t(e,a)){case"connected":case"connecting":return null;case"needs_sign_in":return u?{kind:"set_key",label:"Add key"}:r("sign_in")?{kind:"sign_in",label:"Sign in"}:d?{kind:"set_key",label:"Add key"}:r("reauth")?{kind:"reauth",label:"Sign in again"}:{kind:"fix",label:"Fix"};case"error":return r("connect")?{kind:"connect",label:"Reconnect"}:r("test")?{kind:"test",label:"Retry"}:{kind:"fix",label:"Fix"};default:{if(Xe(c)&&r("sign_in"))return{kind:"sign_in",label:"Sign in"};if(St(c)&&r("sign_out"))return{kind:"sign_out",label:"Sign out again"};if(a.disconnectedAt!==null&&r("connect"))return{kind:"connect",label:"Connect"};if(a.needsSignIn){if(u&&d)return{kind:"set_key",label:"Add key"};if(r("sign_in"))return{kind:"sign_in",label:"Sign in"}}return u&&d?{kind:"set_key",label:"Add key"}:m&&r("sign_in")?{kind:"sign_in",label:"Try again"}:wt(e,a)&&!r("connect")?null:r("connect")?{kind:"connect",label:"Connect",...a.connectedAt===null&&e.status_basis!=="live"?{variant:"ghost"}:{}}:r("test")&&e.tool_count===null&&e.tool_count_basis===null?{kind:"test",label:"Test",variant:"ghost"}:null}}}const ze=e=>e.action==="login"||e.action==="reauth",Xe=e=>!!(e&&e.action==="logout"&&e.status==="complete"),St=e=>!!(e&&e.action==="logout"&&e.status!=="running"&&e.status!=="complete"),Nn=/no oauth authorization server/i;function De(e,n,s){if(!Je(e))return!1;const a=Pe(e.name,n,s);return a&&ze(a)&&a.status==="failed"&&Nn.test(a.message??"")?!0:s.needsKey}function ri(e,n=[],s){const a=Nt(e,n,s)?.kind,o=_t(e,Se(s,e.name)),r=c=>e.actions.includes(c),d=[],u=Re(e.name,n);if(u&&d.push({kind:"cancel",label:"Cancel"}),!u&&r("test")&&a!=="test"&&d.push({kind:"test",label:"Test connection"}),r("connect")&&a!=="connect"&&o!=="connected"&&d.push({kind:"connect",label:"Reconnect"}),!u&&r("sign_in")&&a!=="sign_in"&&o!=="connected"&&d.push({kind:"sign_in",label:"Sign in"}),r("reload")&&d.push({kind:"reload",label:"Reload"}),!u&&r("reauth")&&a!=="reauth"&&d.push({kind:"reauth",label:"Sign in again"}),Je(e)&&a!=="set_key"&&d.push({kind:"set_key",label:e.auth.secret_refs.length>0?"Update key":"Add key"}),r("sign_out")&&d.push({kind:"sign_out",label:"Sign out"}),r("disconnect")&&o==="connected"&&d.push({kind:"disconnect",label:"Disconnect"}),r("copy_setup")&&e.setup_prompt&&d.push({kind:"copy_setup",label:"Copy setup prompt"}),a!=="fix"&&d.push({kind:"open_config",label:"Open config file"}),r("remove"))d.push({kind:"remove",label:"Remove",destructive:!0});else if(!e.source.editable){const c=_n(e);d.push({kind:"remove_elsewhere",label:c?`Remove in ${c}`:"Remove in its own file",hint:c?`Defined in ${c}'s config. Remove it there.`:"Defined in a file this app doesn't write. Remove it there."})}return d}const ii={attention:"Needs attention",connected:"Connected",ready:"Available"};function Sn(e,n=[],s){const a=Se(s,e.name),o=Re(e.name,n),r=_t(e,a);if(o&&a.pinnedGroup&&a.pinnedOperationId===o.id)return a.pinnedGroup;if(r==="needs_sign_in"||r==="error")return"attention";const d=Pe(e.name,n,a);return Xe(d)&&r!=="connected"||St(d)&&r!=="connected"?"attention":a.disconnectedAt!==null?"ready":De(e,n,a)||a.needsSignIn&&r!=="connected"||d?.status==="failed"&&ze(d)&&r!=="connected"?"attention":r==="connected"||e.status_basis==="stored"&&wt(e,a)?"connected":o&&o.action!=="test"?"attention":"ready"}function ci(e,n=[],s){return["attention","connected","ready"].map(o=>({id:o,title:ii[o],rows:e.filter(r=>Sn(r,n,s)===o)})).filter(o=>o.rows.length>0)}function li(e,n,s=Date.now()){if(!n)return e??{};const a={};for(const o of n.servers){const r=Se(e,o.name),d=Re(o.name,n.operations),u=Pe(o.name,n.operations,r),c=Xe(u),m=o.status==="connected"&&(o.status_basis==="probe"||o.status_basis==="live"),y=r.holdUntil!==null&&s<r.holdUntil,j=!y&&!c&&r.connectedAt===null&&o.status_basis==="stored"&&o.tool_count_basis==="last_seen"?jn(o.last_seen_at,s):null,w=!c,h=u?.status==="failed"&&ze(u)&&Nn.test(u.message??""),v={connectedAt:m&&!y?s:j!==null?j:w?r.connectedAt:null,connectedToolCount:m&&!y||j!==null?o.tool_count??r.connectedToolCount:w?r.connectedToolCount:null,settledGroup:r.settledGroup,pinnedGroup:d&&r.pinnedOperationId===d.id?r.pinnedGroup:d?r.settledGroup:null,pinnedOperationId:d?d.id:null,needsKey:m?!1:r.needsKey||h,needsSignIn:m||c?!1:r.needsSignIn||o.status==="needs_sign_in",disconnectedAt:m&&!y?null:r.disconnectedAt,holdUntil:y?r.holdUntil:null,lastDecisive:u?Wr(u):null};d||(v.settledGroup=Sn(o,n.operations,{...a,[o.name]:v})),a[o.name]=v}return a}const di=(e,n)=>e!==null&&n===e,yt="local-operator.settings.integrations.row-memory",Cn=(e,n)=>`${e}#${n}`;function ui(e,n){const s={};if(!n)return s;for(const a of n.servers){const o=e[a.name];o&&(s[Cn(a.source.path,a.name)]=o)}return s}function mi(e,n,s){if(!n)return e;let a=null;for(const o of n.servers){if(Object.prototype.hasOwnProperty.call(e,o.name))continue;const r=fi(s[Cn(o.source.path,o.name)]);r&&(a=a??{...e},a[o.name]=r)}return a??e}const hi=["attention","connected","ready"],Mn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ct=e=>typeof e=="number"&&Number.isFinite(e)?e:null,Ht=e=>hi.includes(e)?e:null,rt=e=>{const n=Ct(e);return n!==null&&n>=1e12?n:null};function pi(e){if(!Mn(e)||typeof e.id!="string"||typeof e.name!="string")return null;const n=e.action,s=e.status;return n!=="login"&&n!=="logout"&&n!=="reauth"&&n!=="test"||s!=="running"&&s!=="complete"&&s!=="cancelled"&&s!=="failed"?null:{id:e.id,name:e.name,action:n,status:s,created_at:Ct(e.created_at)??0,credential_removed:e.credential_removed===!0,...typeof e.message=="string"?{message:e.message}:{}}}function fi(e){if(!Mn(e))return null;const n=rt(e.connectedAt),s=rt(e.disconnectedAt),a=e.needsKey===!0,o=e.needsSignIn===!0,r=pi(e.lastDecisive);return n===null&&s===null&&!a&&!o&&!r?null:{connectedAt:n,connectedToolCount:Ct(e.connectedToolCount),settledGroup:Ht(e.settledGroup),pinnedGroup:Ht(e.pinnedGroup),pinnedOperationId:typeof e.pinnedOperationId=="string"?e.pinnedOperationId:null,needsKey:a,needsSignIn:o,disconnectedAt:s,holdUntil:rt(e.holdUntil),lastDecisive:r}}const An=2e3,Bt=8e3;function gi(e){return e&&(e.servers.some(s=>s.status==="connecting")||e.operations.some(s=>s.status==="running"))?An:!1}const yi=/^[A-Za-z0-9_.:-]{1,100}$/,xi=/:\/\//;function ki(e,n){const s=e.trim();return s?yi.test(s)?n.includes(s)?`An integration named ${s} already exists.`:null:"Use letters, numbers, dots, dashes, underscores or colons, with no spaces.":"Give it a name."}function vi(e){const n=e.trim();if(!n)return"Enter the server's URL.";let s;try{s=new URL(n)}catch{return"Enter a full URL, like https://mcp.example.com/mcp."}return s.protocol!=="https:"&&s.protocol!=="http:"?"The URL must start with https:// or http://.":s.hostname?s.username||s.password?"Remove the username or password from the URL. Keys are added after it's saved.":s.search||s.hash?"Remove the ? or # part of the URL. Keys are added after it's saved.":xi.test(n.slice(s.protocol.length+2))?"This looks like two URLs pasted together. Enter just one.":null:"The URL needs a host name."}const bi=e=>e.split(`
|
|
292
|
+
`).map(n=>n.trim()).filter(Boolean);function xt(e,n){const s=!!e?.cold,a=(e?.servers??[]).map(o=>{const r=o.transport==="http",d=o.secret_refs??[],u=o.status==="connected"?"connected":o.status==="connecting"?"connecting":o.status==="auth-required"?"needs_sign_in":"not_started",c=[];u!=="connected"&&c.push("connect"),u==="connected"&&c.push("disconnect"),s||c.push("reload"),r&&o.transport_oauth_supported!==!1&&c.push("sign_in"),d.length>0&&c.push("set_key"),o.owned_scope&&c.push("remove"),o.setup?.text&&c.push("copy_setup");const m=vn(o.source);return{id:o.name,name:o.name,scope:o.owned_scope??"global",project_cwd:null,source:{kind:ji(o.source,m,o.owned_scope),path:o.source??"",editable:o.owned_scope!==null,owned_scope:o.owned_scope},transport:r?"remote_url":"local_command",endpoint:{command:null,url:null,endpoint_redacted:!1},status:u,status_reason:null,status_observed_at:null,last_seen_at:null,status_basis:s?"stored":"live",auth:{kind:d.length?"api_key":r?"unknown":"none",signed_in:null,secret_refs:d.map(y=>({id:y.id,state:"missing"}))},tool_count:typeof o.tool_count=="number"?o.tool_count:null,tool_count_basis:typeof o.tool_count=="number"?"live":null,actions:c,setup_prompt:o.setup?.text??null}});return{cwd:"",project_scope_available:a.some(o=>o.source.owned_scope==="project"),global_path:"",project_path:null,status_source:s?"config":"live",session_id:n,servers:a,operations:(e?.operations??[]).map(o=>({...o}))}}const ji=(e,n,s)=>n==="Claude Code"?"claude-code":n==="Cursor"?"cursor":n==="VS Code"?"vscode":n==="Codex CLI"?"codex":s?"local-operator":e?"project-mcp-json":"local-operator",Vt={invalid_config:"That configuration isn't valid. Check the command or the URL, then try again.",operation_unavailable:"That sign-in or test isn't running any more. Try again.",exists:"An integration with this name already exists. Choose another name.",not_owned:"It's defined in another tool's config, so it can't be changed here. Edit it in that file.",project_scope_unavailable:"There's no separate project config here, so it can only be added globally.",unknown_server:"It no longer exists. The list has been refreshed.",oauth_unsupported:"It doesn't use browser sign-in.",grant_running:"A sign-in or test is already running. Wait for it to finish, or cancel it.",too_many_operations:"Too many sign-ins and tests are waiting. Try again in a moment.",write_failed:"The config file couldn't be written. Check that it isn't read-only.",mcp_starting:"Integrations are still starting. Try again in a moment.",mcp_control_refused:"The server refused it, so nothing was changed."},wi="The server refused it, so nothing was changed. Try again.";function Ve(e,n,s){if(n instanceof jt&&n.status===409){const a=typeof n.code=="string"&&Object.prototype.hasOwnProperty.call(Vt,n.code)?Vt[n.code]:wi;return`${Wn[e]}. ${a}`}return Qn(e,n,s).message}const _i="New chats can use it right away. Open chats pick it up when you start a new chat or reload integrations there.",Ni="Most services give you a URL. Use Local command when their setup says npx or uvx.",Si=({existingNames:e,projectScopeAvailable:n,projectLabel:s,onSubmit:a,onCancel:o,initial:r})=>{const[d,u]=i.useState(r?.name??""),[c,m]=i.useState(r?.mode??"command"),[y,j]=i.useState(r?.command??""),[w,h]=i.useState(r?.args??""),[v,R]=i.useState(r?.url??""),[C,V]=i.useState("global"),[_,H]=i.useState(r?.touched?{name:!0,command:!0,url:!0}:{}),[$,M]=i.useState(!!r?.touched),[S,W]=i.useState(!1),[q,Z]=i.useState(null),T=i.useRef(null),ee=i.useRef(null),L=i.useRef(null);i.useEffect(()=>{T.current?.focus()},[]);const D=ki(d,e),O=c==="command"&&!y.trim()?"Enter the command to run.":null,z=c==="url"?vi(v):null,K=x=>$||_[x],se=async x=>{if(x.preventDefault(),M(!0),D||O||z){D?T.current?.focus():O?ee.current?.focus():L.current?.focus();return}W(!0),Z(null);const B=n?C:"global",G=c==="command"?{name:d.trim(),scope:B,mode:c,command:y.trim(),args:bi(w)}:{name:d.trim(),scope:B,mode:c,url:v.trim()},J=await a(G);W(!1),Z(J)},p=(x,B,G)=>B&&K(G)?t.jsx("p",{id:x,className:"text-body-sm text-danger",children:B}):null,I=x=>x.preventDefault();return t.jsxs("form",{noValidate:!0,"aria-label":"Add integration",className:"flex flex-col gap-4 rounded-lg bg-surface p-4",onSubmit:x=>void se(x),onKeyDown:x=>{x.key==="Escape"&&(x.stopPropagation(),o())},children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-name",children:"Name"}),t.jsx(Ae,{ref:T,id:"integration-add-name",value:d,placeholder:"e.g. notion",autoComplete:"off","aria-invalid":!!(D&&K("name")),"aria-describedby":D&&K("name")?"integration-add-name-error":void 0,onChange:x=>u(x.target.value),onBlur:()=>H(x=>({...x,name:!0}))}),p("integration-add-name-error",D,"name")]}),t.jsxs(ft,{value:c,onValueChange:x=>m(x==="url"?"url":"command"),className:"flex flex-col gap-1.5",children:[t.jsx("span",{id:"integration-add-transport-label",className:"font-medium text-body-sm text-ink",children:"How it runs"}),t.jsxs(gt,{"aria-labelledby":"integration-add-transport-label",children:[t.jsx(Fe,{value:"command","data-integration-transport":"command",children:"Local command"}),t.jsx(Fe,{value:"url","data-integration-transport":"url",children:"Remote URL"})]}),t.jsx("p",{className:"text-ink-dim text-meta",children:Ni}),t.jsxs($t,{value:"command",className:"mt-0 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-command",children:"Command"}),t.jsx(Ae,{ref:ee,id:"integration-add-command",value:y,placeholder:"e.g. npx",autoComplete:"off",className:"font-mono","aria-invalid":!!(O&&K("command")),"aria-describedby":O&&K("command")?"integration-add-command-error":void 0,onChange:x=>j(x.target.value),onBlur:()=>H(x=>({...x,command:!0}))}),p("integration-add-command-error",O,"command")]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs(xe,{htmlFor:"integration-add-args",children:["Arguments"," ",t.jsx("span",{className:"font-normal text-ink-dim",children:"(one per line)"})]}),t.jsx(yn,{id:"integration-add-args",value:w,rows:2,className:"font-mono",onChange:x=>h(x.target.value)})]})]}),t.jsx($t,{value:"url",className:"mt-0 flex flex-col gap-4",children:t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-add-url",children:"URL"}),t.jsx(Ae,{ref:L,id:"integration-add-url",type:"url",value:v,placeholder:"https://mcp.example.com/mcp",autoComplete:"off",className:"font-mono","aria-invalid":!!(z&&K("url")),"aria-describedby":z&&K("url")?"integration-add-url-error":"integration-add-url-help",onChange:x=>R(x.target.value),onBlur:()=>H(x=>({...x,url:!0}))}),p("integration-add-url-error",z,"url")??t.jsx("p",{id:"integration-add-url-help",className:"text-ink-dim text-meta",children:"If it needs a sign-in or a key, you'll be asked after it's added."})]})})]}),n?t.jsxs(ft,{value:C,onValueChange:x=>V(x==="project"?"project":"global"),className:"flex flex-col gap-1.5",children:[t.jsx("span",{id:"integration-add-scope-label",className:"font-medium text-body-sm text-ink",children:"Available in"}),t.jsxs(gt,{"aria-labelledby":"integration-add-scope-label",children:[t.jsx(Fe,{value:"global","data-integration-scope":"global",children:"All chats"}),t.jsx(Fe,{value:"project","data-integration-scope":"project",children:"This project"})]}),s?t.jsx("p",{className:"text-ink-dim text-meta",children:C==="project"?`Only chats working in ${s}.`:"Every chat, in any folder."}):null]}):null,q?t.jsx("p",{className:"text-body-sm text-danger",role:"alert",children:q}):null,t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsx("p",{className:ce("text-body-sm text-ink-dim"),children:_i}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(P,{type:"button",variant:"ghost",size:"md",onMouseDown:I,onClick:o,children:"Cancel"}),t.jsxs(P,{type:"submit",variant:"primary",size:"md",disabled:S,onMouseDown:I,children:[S?t.jsx(re,{size:"xs"}):null,"Add integration"]})]})]})]})},Ci=4;function Mi(e){return e.rowMoving?e.now+e.windowMs:Math.max(e.hold.until,e.lastMovingAt+e.windowMs)}function Ai(e){return e.now>e.hold.until||e.hold.reanchors>=Ci?"drop":e.hold.landedOn.isConnected&&(!e.candidate||e.candidate===e.hold.landedOn)?"settled":e.active&&e.active!==e.body&&e.active!==e.hold.landedOn?"drop":e.candidate?.isConnected?"restore":"drop"}function Ri(e){const n=Mi({hold:e.hold,now:e.now,windowMs:e.windowMs,rowMoving:e.rowMoving,lastMovingAt:e.lastMovingAt});if(e.now>n)return{hold:null,land:null};const s=e.hold.landedOn??null,a=e.candidate;if(!a)return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},land:null};if(!s)return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:a},land:a};const o=Ai({hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},candidate:a,active:e.active,body:e.body,now:e.now});if(o==="settled")return{hold:{until:n,reanchors:e.hold.reanchors,landedOn:s},land:null};if(o==="drop")return{hold:null,land:null};const r=!s.isConnected;return{hold:{until:r?e.now+e.windowMs:n,reanchors:r?e.hold.reanchors+1:e.hold.reanchors,landedOn:a},land:a}}function Ti(e){const{row:n,target:s}=e;return!n||!s||typeof s.nodeType!="number"?!1:!n.contains(s)}const Gt=250;function qt(e){return e?!e.disabled:!1}function Ei(e){return qt(e.primary)?e.primary??null:qt(e.overflow)?e.overflow??null:null}function Ii(e){return e.verdict==="finished"?null:e.watchMs}const Rn="key";function Li(e){const{name:n,keyless:s,freeName:a,names:o,values:r,replace:d,canReplace:u}=e;if(s){const c=kt(n,a);return{values:{[c]:(r[Rn]??"").trim()},confirmedReplace:d&&u?[c]:[],header:a.trim()}}return{values:Object.fromEntries(o.map(c=>[c,(r[c]??"").trim()])),confirmedReplace:d&&u?o:[],header:void 0}}function kt(e,n){const s=Yt(e),a=Yt(n);if(!a)return"";const o=[s,a].filter(Boolean).join("_"),r=/^[A-Za-z_]/.test(o)?o:`K_${o}`;if(r.length<=it)return r;const d=Oi(s),u=it-a.length-d.length-2,c=[s.slice(0,Math.max(u,0)),d,a].filter(Boolean).join("_");return c.length<=it?c:c.slice(-128)}const it=128,Yt=e=>e.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,""),Oi=e=>{let n=2166136261;for(let s=0;s<e.length;s+=1)n^=e.charCodeAt(s),n=Math.imul(n,16777619)>>>0;return n.toString(36).toUpperCase().slice(0,5)},Fi=({name:e,keyNames:n,keyless:s=!1,savedKeys:a=[],saving:o,failure:r,onSave:d,onClose:u})=>{const[c,m]=i.useState({}),[y,j]=i.useState(!1),[w,h]=i.useState(""),v=s?[kt(e,w)]:[...n],R=s?[Rn]:v,C=(s?kt(e,w).length>0:!0)&&R.every(_=>(c[_]??"").trim()),V=v.some(_=>a.includes(_));return t.jsx(rn,{open:!0,onClose:u,maxWidth:"xs",title:s||n.length===1?`Add the key for ${e}`:`Add keys for ${e}`,actions:t.jsxs(t.Fragment,{children:[t.jsx(dt,{onClick:u,children:"Cancel"}),t.jsx(ut,{disabled:!C||o,onClick:()=>{const _=Li({name:e,keyless:s,freeName:w,names:v,values:c,replace:y,canReplace:V});d(_.values,_.confirmedReplace,_.header)},children:o?"Saving…":"Save and test"})]}),children:t.jsxs("div",{className:"flex flex-col gap-3 p-1.5 text-body text-ink-muted",children:[t.jsx("p",{className:"-mx-1.5",children:s?"Keys are saved encrypted on this computer. This one is stored under a name derived from this integration, so no other server shares it.":"Keys are saved encrypted on this computer. Other integrations that use the same key name share it."}),s?t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:"integration-key-name",children:"The header this server wants the key in"}),t.jsx(Ae,{id:"integration-key-name",autoComplete:"off",placeholder:"e.g. Authorization or X-Api-Key",value:w,onChange:_=>h(_.target.value)}),t.jsx("p",{className:"-mx-1.5 text-ink-dim text-meta",children:"This server declares no key of its own, so Local Operator adds one to its config for you."})]}):null,R.filter(_=>s!==!0||_.trim().length>0).map(_=>t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(xe,{htmlFor:`integration-key-${_}`,className:"font-mono",children:s?"Key":_}),t.jsx(Ae,{id:`integration-key-${_}`,type:"password",autoComplete:"off",value:c[_]??"",onChange:H=>m($=>({...$,[_]:H.target.value}))})]},_)),V?t.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[t.jsx(na,{id:"integration-key-replace",checked:y,onCheckedChange:_=>j(_===!0)}),t.jsx(xe,{htmlFor:"integration-key-replace",className:"font-normal",children:wn(v.length)})]}):null,r?t.jsx("p",{className:"-mx-1.5 text-body-sm text-danger",role:"alert",children:r}):null]})})},Di={success:"bg-success",warning:"bg-warning",danger:"bg-danger",info:"bg-info",neutral:"bg-ink-dim"},$i={success:"text-ink-muted",warning:"text-warning",danger:"text-danger",info:"text-ink-muted",neutral:"text-ink-dim"},Wt={Ready:ni,"Not connected":si},Ui=({row:e,operations:n,memories:s,now:a,projectScopeAvailable:o,highlighted:r=!1,rowRef:d,primaryRef:u,overflowRef:c,pending:m,failure:y,confirm:j,onPrimary:w,onOverflow:h,onConfirm:v,onCancelConfirm:R})=>{const C=Xr(e,n,s,a),V=r&&C.tone==="danger"?"text-ink":$i[C.tone],_=Nt(e,n,s),H=ri(e,n,s),$=oi(e,o),M=H.findIndex(S=>S.kind==="remove"||S.kind==="remove_elsewhere");return t.jsxs("li",{ref:d,"data-integration":e.name,"data-status":e.status,className:ce("flex min-h-14 flex-col justify-center gap-1 px-4 py-2.5",r&&"bg-row-selected"),onKeyDown:S=>{!j||S.key!=="Escape"||(S.stopPropagation(),R())},children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:C.busy?t.jsx(re,{size:"xs"}):t.jsx("span",{"aria-hidden":"true","data-tone":C.tone,className:ce("size-2 rounded-full",Di[C.tone])})}),t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:"truncate font-medium text-body text-ink",title:e.name,children:e.name}),t.jsx("span",{className:"truncate text-ink-dim text-meta",children:$.map((S,W)=>t.jsxs("span",{children:[W>0?" · ":null,S.startsWith("Imported from")&&e.source.path?t.jsx($e,{content:Zn(e.source.path),children:t.jsx("span",{className:"underline decoration-dotted underline-offset-2",children:S})}):S]},S))})]}),Wt[C.label]?t.jsx($e,{content:Wt[C.label],children:t.jsx("span",{className:ce("shrink-0 text-body-sm",V),children:C.label})}):t.jsx("span",{className:ce("shrink-0 text-body-sm",V),children:C.label}),_?t.jsxs(P,{ref:u,variant:_.variant??"secondary",size:"sm","aria-label":`${_.label} ${e.name}`,disabled:m,"data-integration-action":_.kind,onClick:()=>w(_),children:[m?t.jsx(re,{size:"xs"}):null,_.label]}):null,t.jsxs(sa,{children:[t.jsx(aa,{asChild:!0,children:t.jsx(P,{ref:c,variant:"ghost",size:"icon-sm","aria-label":`More actions for ${e.name}`,disabled:m,children:t.jsx(Jn,{"aria-hidden":"true"})})}),t.jsx(oa,{align:"end",className:"min-w-48",children:H.map((S,W)=>t.jsx(Pi,{item:S,separated:W===M&&W>0,onSelect:()=>h(S)},S.kind))})]})]}),C.detail?t.jsx("p",{className:ce("pl-7 text-body-sm",C.tone==="danger"?"text-ink-muted":"text-ink-dim"),children:C.detail}):null,y?t.jsx("p",{className:ce("pl-7 text-body-sm",r?"text-ink":"text-danger"),role:"alert",children:y}):null,j?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-7",children:[t.jsx("span",{className:"text-body-sm text-ink",children:j.kind==="remove"?`Remove ${e.name}?`:`Sign out of ${e.name}?`}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:j.kind==="remove"?`Agents in every chat lose access to ${e.name}.`:e.auth.kind==="oauth"?"The saved sign-in is removed too.":"Its saved credential is removed too."}),t.jsx(P,{variant:"danger",size:"sm",onClick:v,"data-integration-confirm":j.kind,children:j.kind==="remove"?"Remove":"Sign out"}),t.jsx(P,{variant:"ghost",size:"sm",onClick:R,children:"Keep"})]}):null]})},Pi=({item:e,separated:n,onSelect:s})=>t.jsxs(t.Fragment,{children:[n?t.jsx(ra,{}):null,e.kind==="remove_elsewhere"?t.jsxs(Ut,{disabled:!0,className:"flex-col items-start gap-0.5",children:[t.jsx("span",{children:e.label}),t.jsx("span",{className:"text-meta text-ink-dim",children:e.hint})]}):t.jsx(Ut,{destructive:e.kind==="remove",onSelect:s,"data-integration-menu":e.kind,children:e.label})]});function zi(e,n,s){return!n||n.status==="running"?n?.browser_opened===!0?{message:`Your browser opened. Approve access to ${e} there, then come back here.`,tone:"progress",link:n.authorization_url??null}:n?.browser_opened===!1?{message:n.authorization_url?"Your browser didn't open. Open this link to approve access:":"Your browser didn't open, and no link was provided. Cancel and try again.",tone:"progress",link:n.authorization_url??null}:{message:`Waiting for you to approve access to ${e}…`,tone:"progress",link:n?.authorization_url??null}:n.status==="complete"?{message:`Signed in to ${e}. Agents can use it now.`,tone:"success",link:null}:n.status==="cancelled"?{message:"Sign-in cancelled.",tone:"failure",link:null,reason:null,nextStep:"Press Try again when you are ready."}:{message:"Sign-in didn't finish.",tone:"failure",link:null,reason:ti(n.message,s)??"The server didn't say why.",nextStep:Ki(n.message??null,s)}}function Ki(e,n){const s=(e??"").toLowerCase();return s.includes("redirect")?n?"This server may not accept sign-ins from Local Operator. Check the server's settings, or add a key instead.":"This server may not accept sign-ins from Local Operator. Check the server's settings, then try again.":s.includes("no oauth")||s.includes("authorization server")?n?"This server doesn't publish a browser sign-in. Add its key instead.":"This server doesn't publish a browser sign-in. Check the server's settings, then try again.":s.includes("network")||s.includes("connect")?"Check the server's URL and your network, then try again.":"Check the server's settings, then try again."}function Hi(e,n){return e.kind==="ready"?"ready":e.kind==="running"&&n&&n.tone!=="progress"?n.tone==="success"?"success":"failure":"running"}const Bi=({name:e,action:n,keyRoute:s,phase:a,onStart:o,onCancel:r,onOpenLink:d,onClose:u})=>{const c=a.kind==="running"?a.operation:null,m=a.kind==="running"?zi(e,c,s):null,y=a.kind==="starting"||a.kind==="running"&&m?.tone==="progress",j=m&&m.tone!=="progress",w=i.useRef(null),h=i.useRef(!1),v=Hi(a,m);i.useEffect(()=>{if(!h.current){h.current=!0;return}v&&w.current?.focus()},[v]);const R=()=>u(m?.tone==="success"?"signed-in":"dismissed");return t.jsx(rn,{open:!0,onClose:R,maxWidth:"xs",fullWidth:!0,title:`Sign in to ${e}`,dialogProps:{onOpenAutoFocus:C=>{C.preventDefault(),w.current?.focus()}},actions:t.jsxs(t.Fragment,{children:[y&&c?t.jsx(dt,{ref:w,onClick:()=>r(c.id),children:"Cancel sign-in"}):t.jsx(dt,{ref:a.kind==="ready"?void 0:w,onClick:R,children:m?.tone==="success"?"Done":"Close"}),a.kind==="ready"?t.jsx(ut,{ref:w,onClick:o,children:"Continue in browser"}):null,a.kind==="refused"||m?.tone==="failure"?t.jsx(ut,{ref:m?.tone==="failure"?w:void 0,onClick:o,children:"Try again"}):null]}),children:t.jsxs("div",{className:"flex flex-col gap-3 p-1.5 text-body text-ink-muted","aria-live":"polite",children:[a.kind==="ready"?t.jsxs("p",{className:"-mx-1.5",children:["Local Operator opens your browser so you can approve access to"," ",e,".",n==="reauth"?" This replaces the sign-in it has now.":""]}):null,a.kind==="starting"?t.jsxs("p",{className:"-mx-1.5 flex items-center gap-2",children:[t.jsx(re,{size:"xs"}),"Starting sign-in…"]}):null,m?t.jsxs("div",{className:"flex flex-col gap-1",role:j?"status":void 0,children:[t.jsxs("p",{className:(m.tone==="success","-mx-1.5 flex items-start gap-2 text-ink"),children:[m.tone==="progress"?t.jsx(re,{size:"xs",className:"mt-0.5"}):null,m.tone==="failure"?t.jsx(ia,{"aria-hidden":"true",className:"mt-0.5 size-4 shrink-0 text-danger"}):null,t.jsx("span",{children:m.message})]}),m.reason?t.jsx("p",{className:"-mx-1.5 text-ink-muted",children:m.reason}):null,m.nextStep?t.jsx("p",{className:"-mx-1.5 text-ink-muted",children:m.nextStep}):null]}):null,m?.link&&m.tone==="progress"?t.jsxs("div",{className:"flex flex-col items-start gap-1",children:[t.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-ink-dim text-mono-sm",title:m.link,children:m.link}),t.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"Copy the sign-in link",title:"Copy the sign-in link",onClick:()=>{navigator.clipboard.writeText(m.link??"").then(()=>mt("Sign-in link copied.")).catch(()=>{})},children:t.jsx(Xn,{"aria-hidden":"true"})})]}),t.jsx(P,{variant:"link",size:"sm",onClick:()=>d(m.link??""),children:"Open the sign-in page"})]}):null,a.kind==="refused"?t.jsx("p",{className:"text-danger",role:"alert",children:a.message}):null]})})},Vi=e=>e.reduce((n,s)=>n?(s.updated_at??0)>(n.updated_at??0)?s:n:s,null),Gi=/^[A-Za-z]:[\\/]/,We=e=>{const n=e?.trim();return n&&(n.startsWith("/")||Gi.test(n))?n:null};function qi(e){const o=e?.payload?.frontend?.snapshot?.cwd;return typeof o=="string"&&o.trim()?o:null}const Ue="local-operator.settings.integrations.last-cwd";function Yi(e,n,s=typeof localStorage>"u"?null:localStorage){const a=We(n);if(!(!e||!a||!s))try{const o=s.getItem(Ue),r=o?JSON.parse(o):{};if(r[e]===a)return;s.setItem(Ue,JSON.stringify({...r,[e]:a}))}catch{}}const Tn=()=>typeof localStorage>"u"?null:localStorage;function En(e=Tn()){if(!e)return{};try{const n=e.getItem(yt);if(!n)return{};const s=JSON.parse(n);return!s||typeof s!="object"||Array.isArray(s)?{}:s}catch{return{}}}const Qt=256;function Wi(e,n=Tn()){if(n)try{const s={...En(n),...e},a=Object.keys(s);if(a.length>Qt){const o={};for(const r of a.slice(-Qt))o[r]=s[r];n.setItem(yt,JSON.stringify(o));return}n.setItem(yt,JSON.stringify(s))}catch{}}function Zt(e,n,s){return e==="saved"?null:e==="replace_confirmation_required"?`A saved value already exists for this key. Tick “${wn(Object.keys(s).length)}” to overwrite it.`:e==="invalid_target"?"That header can't carry this key. It may already be set on the server, or belong to the transport - try a different header name. Nothing was saved.":`Not saved: ${(n.length?n:Object.keys(s)).join(", ")}. The encrypted store may be locked.`}function Qi(e,n=typeof localStorage>"u"?null:localStorage){if(!(!e||!n))try{const s=n.getItem(Ue);if(!s)return;const a=JSON.parse(s);if(!(e in a))return;const o={...a};delete o[e],n.setItem(Ue,JSON.stringify(o))}catch{}}const Zi=e=>!!(e&&typeof e=="object"&&"code"in e&&e.code==="invalid_cwd"),Ji=(e,n)=>n!==null&&e===n?null:e;function Xi(e,n=typeof localStorage>"u"?null:localStorage){if(!e||!n)return null;try{const s=n.getItem(Ue);if(!s)return null;const o=JSON.parse(s)[e];return typeof o=="string"?o:null}catch{return null}}const ec=e=>e.action==="disconnect"?"disconnected":"connected";function tc(e){switch(e.action){case"cancel":return{action:"cancel",operation_id:e.operationId};case"connect":case"disconnect":case"reload":return null;case"test":return{action:"test",name:e.name};default:return{...e,confirmed:!0}}}function nc(e){switch(e.action){case"cancel":return{action:"cancel",operation_id:e.operationId};case"test":case"connect":return{action:"connect",name:e.name};case"reload":return{action:"reload",name:e.name};case"add":return e;case"remove":return{...e,confirmed:!0};default:return{action:e.action,name:e.name,confirmed:!0}}}function sc({sessionId:e}){const n=cn(),s=It(n.data,"mcp_catalog"),a=It(n.data,"mcp"),o=s?"catalog":a?"session":null,[r,d]=i.useState(null),u=sn(),c=Ge(k=>k.sessions),m=Ge(k=>k.fetchSessions),y=Ge(k=>k.loading),j=i.useMemo(()=>c.find(k=>k.session_id===e)??null,[c,e]),w=i.useMemo(()=>o==="session"&&!e?Vi(c):null,[o,e,c]),h=o==="session"?e??w?.session_id??null:null;i.useEffect(()=>{o!=="session"||e||c.length>0||m(es)},[o,e,c.length,m]);const v=o==="catalog"?We(j?.cwd):null,R=o==="catalog"&&!!e&&v===null,C=ke({queryKey:["desktop","session-cwd",e??""],queryFn:()=>ye({op:"sessions.get",sessionId:e??""}),enabled:R,staleTime:Number.POSITIVE_INFINITY,retry:!1}),V=R&&!C.isFetched,_=v??We(qi(C.data))??(C.isFetched?We(Xi(e)):null),H=Ji(_,r),$=o==="catalog"?H:null,M=o==="catalog"?e??null:null,S=ts.catalog($,M);i.useEffect(()=>{o!=="catalog"||!e||!$||Yi(e,$)},[o,e,$]);const W=i.useRef(0),[q,Z]=i.useState(0),T=i.useRef(null),ee=i.useCallback((k,A)=>{const f=Date.now()+Bt;W.current=f,T.current={name:k,expect:A},Z(f)},[]),L=i.useCallback(k=>Date.now()<W.current?An:gi(k),[]),D=ke({queryKey:S,queryFn:()=>as($,M),enabled:o==="catalog"&&!V,staleTime:1e4,refetchInterval:k=>L(k.state.data)}),O=Zi(D.error);i.useEffect(()=>{!O||!_||r===_||(d(_),Qi(e))},[O,_,r,e]);const z=ke({queryKey:ht.list(h??""),queryFn:()=>os(h??""),enabled:o==="session"&&!!h,staleTime:1e4,refetchInterval:k=>L(k.state.data?xt(k.state.data,h??""):void 0)}),K=i.useMemo(()=>{if(o==="catalog")return D.data;if(o==="session"&&z.data&&h)return xt(z.data,h)},[o,D.data,z.data,h]),se=i.useCallback(()=>ac({queryClient:u,route:o,catalogKey:S,sessionId:h}),[o,S,u,h]);i.useEffect(()=>{if(!q)return;const k=T.current;if(!k)return;const A=K?.servers.find(F=>F.name===k.name);!A||!(k.expect==="connected"?A.status==="connected":A.status_basis==="live"&&A.status!=="connected")||(W.current=0,T.current=null,Z(0))},[K,q]);const p=i.useRef({}),[I,x]=i.useState(0),B=i.useMemo(()=>(p.current=li(mi(p.current,K,En()),K),p.current),[K,I]),G=i.useRef("");i.useEffect(()=>{const k=ui(B,K);if(!Object.keys(k).length)return;const A=JSON.stringify(k);A!==G.current&&(G.current=A,Wi(k))},[B,K]);const J=i.useCallback(k=>{const A=Se(p.current,k);A.needsKey||(p.current={...p.current,[k]:{...A,needsKey:!0}},x(f=>f+1))},[]),X=i.useCallback(k=>{if(k.action!=="disconnect"&&k.action!=="connect"&&k.action!=="reload")return;const A=Se(p.current,k.name),f=Date.now()+Bt,F=k.action==="disconnect"?{...A,connectedAt:null,disconnectedAt:Date.now(),holdUntil:f}:{...A,disconnectedAt:null,holdUntil:f};p.current={...p.current,[k.name]:F},ee(k.name,ec(k)),x(E=>E+1)},[ee]),Q=i.useCallback(async k=>{if(o==="catalog"){const A=tc(k);if(!A)return null;try{const f=await ns($,A);return u.setQueryData(S,f),X(k),f.operation?.id??null}catch(f){throw f instanceof jt&&f.status===409&&u.invalidateQueries({queryKey:S}),f}}if(o==="session"&&h){const A=await ye({op:"mcp.control",sessionId:h,control:nc(k)});X(k);const f=ht.list(h),F=A?.data;return F&&"servers"in F&&Array.isArray(F.servers)?(u.setQueryData(f,F),null):(u.invalidateQueries({queryKey:f}),F&&"id"in F&&typeof F.id=="string"?F.id:null)}return null},[o,$,S,u,h,X]),fe=i.useCallback(async k=>{if(o==="catalog"&&M&&(k.action==="connect"||k.action==="disconnect"||k.action==="reload")){try{await ye({op:"mcp.control",sessionId:M,control:{action:k.action,name:k.name,...k.action==="disconnect"?{confirmed:!0}:{}}})}catch(A){throw u.invalidateQueries({queryKey:S}),A}return X(k),await u.invalidateQueries({queryKey:S}),null}return Q(k)},[o,M,u,S,Q,X]),ve=i.useCallback(async(k,A,f,F)=>{if(o==="catalog"){const E=await ss($,k,A,f,F);if(E.catalog&&u.setQueryData(S,E.catalog),E.code!=="saved")return{saved:!1,message:Zt(E.code,E.failed_ids,A)};try{await Q({action:"test",name:k})}catch{}return{saved:!0,message:null}}if(o==="session"&&h){const E=await ye({op:"mcp.credentials.store",sessionId:h,name:k,values:A,confirmedReplace:f});if(E.data?.code!=="saved")return{saved:!1,message:Zt(E.data?.code,E.data?.failed_ids??[],A)};try{await Q({action:"connect",name:k})}catch{}return{saved:!0,message:null}}return{saved:!1,message:null}},[o,$,S,u,Q,h]),me=o==="catalog"?D:z,Ce=i.useCallback(()=>{me.refetch()},[me]);return{enabled:o!==null,route:o,sessionId:o==="catalog"?M:h,borrowed:w,noConversation:o==="session"&&!h&&!y,document:K,isLoading:n.isLoading||o==="catalog"&&(V||D.isLoading)||o==="session"&&(h?z.isLoading:y),isError:me.isError,folderUnavailable:di(r,_),refetch:Ce,readDocument:se,control:fe,storeKeys:ve,memories:B,markNeedsKey:J}}function ac(e){if(e.route==="catalog")return e.queryClient.getQueryData(e.catalogKey);if(e.route==="session"&&e.sessionId){const n=e.queryClient.getQueryData(ht.list(e.sessionId));return n?xt(n,e.sessionId):void 0}}const oc=(e,n)=>{const s=e?.trim();if(!s)return null;const a=ls(s,n);return a.kind==="auth"?{kind:"matched",name:a.name,unresolved:null}:{kind:"miss",asked:s}},rc=6,ct="Integrations",ic="Let agents use your tools and accounts, like Notion, Linear or GitHub.",cc={test:"test",connect:"reconnect",disconnect:"disconnect",reload:"reload",remove:"remove",sign_out:"disconnect",cancel:"cancel",login:"grant",reauth:"grant"},lc=({sessionId:e,sectionRef:n,highlightServer:s})=>{const a=sc({sessionId:e}),{document:o,control:r,readDocument:d}=a,u=rs(),c=o?.servers??[],m=o?.operations??[],y=o?.project_scope_available??!1,[j,w]=i.useState(!1),[h,v]=i.useState(""),[R,C]=i.useState(null),[V,_]=i.useState({}),[H,$]=i.useState(null),[M,S]=i.useState(null),[W,q]=i.useState({kind:"ready"}),[Z,T]=i.useState(null),[ee,L]=i.useState(null),[D,O]=i.useState(!1),z=i.useRef({}),K=i.useRef({}),se=i.useRef({}),p=i.useRef(0),I=i.useRef(null),x=i.useRef(null),B=i.useRef(null),[G,J]=i.useState(null),[X,Q]=i.useState(null),[fe,ve]=i.useState(null),me=i.useCallback(()=>{const l=B.current;B.current=null,S(null),T(null),window.setTimeout(()=>{l?.isConnected&&l.focus()},0)},[]),Ce=i.useCallback(l=>{const g=window.document.activeElement;B.current=g instanceof HTMLElement?g:null,S(l)},[]),k=i.useCallback((l,g)=>{Q({name:l,waitForSignIn:g==="signed-in",until:Date.now()+Le,reanchors:0}),me()},[me]),A=i.useMemo(()=>oc(s,c.map(l=>l.name)),[s,c]),f=A?.kind==="matched"?A.name:null,F=i.useRef(null),E=i.useRef(null),le=h.trim().toLowerCase(),Y=i.useMemo(()=>le?c.filter(l=>l.name.toLowerCase().includes(le)):c,[c,le]),de=i.useMemo(()=>ci(Y,m,a.memories),[Y,m,a.memories]),ie=M?.kind==="sign_in"?c.find(l=>l.name===M.name)??null:null;i.useEffect(()=>{!f||E.current===f||!h||v("")},[f,h]),i.useEffect(()=>{!f||E.current===f||Y.some(l=>l.name===f)&&(E.current=f,F.current?.scrollIntoView({block:"center",behavior:"smooth"}))},[f,Y]),i.useEffect(()=>{if(!Z)return;const l=m.find(g=>g.id===Z)??null;q({kind:"running",operation:l})},[m,Z]);const be=m.some(l=>l.status==="running"),he=l=>{const g=window.document.activeElement;g&&g!==window.document.body&&g.isConnected||Q({name:l,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})},ae=async(l,g,N)=>{C(l),_(({[l]:we,..._e})=>_e);let U=null,ue=!1;try{U=await N()}catch(we){ue=!0,_(_e=>({..._e,[l]:Ve(cc[g]??"status",we,be)}))}finally{C(null),g!=="sign_out"&&(g!=="remove"||ue)&&he(l)}return{operationId:U,failed:ue}},je=l=>c.find(g=>g.name===l),pe=l=>{l.source.path&&ds(l.source.path)},et=async(l,g)=>{q({kind:"starting"}),T(null);try{const N=await r({action:g,name:l});N?T(N):q({kind:"running",operation:null})}catch(N){N instanceof jt&&N.code==="oauth_unsupported"&&a.markNeedsKey(l),q({kind:"refused",message:Ve("grant",N,be)})}},Ke=(l,g)=>{switch(g.kind){case"sign_in":case"reauth":{const N=m.find(U=>U.name===l.name&&U.status==="running");N&&ze(N)?(q({kind:"running",operation:N}),T(N.id)):(q({kind:"ready"}),T(null)),Ce({kind:"sign_in",name:l.name,action:g.kind==="reauth"?"reauth":"login"});return}case"set_key":L(null),Ce({kind:"key",name:l.name,keyNames:l.auth.secret_refs.map(N=>N.id)});return;case"fix":pe(l);return;case"sign_out":$({name:l.name,kind:"sign_out"});return;default:{const N=g.kind;ae(l.name,N,()=>r({action:N,name:l.name}))}}},tt=(l,g)=>{switch(g.kind){case"remove":case"sign_out":$({name:l.name,kind:g.kind});return;case"sign_in":case"reauth":case"set_key":Ke(l,{kind:g.kind,label:g.label});return;case"open_config":pe(l);return;case"copy_setup":navigator.clipboard.writeText(l.setup_prompt??"").then(()=>mt("Setup steps copied. Paste them into a chat.")).catch(()=>{});return;case"cancel":{const N=m.find(U=>U.name===l.name&&U.status==="running");N&&ae(l.name,"cancel",()=>r({action:"cancel",operationId:N.id}));return}case"test":case"connect":case"disconnect":case"reload":{const N=g.kind;ae(l.name,N,()=>r({action:N,name:l.name}));return}default:return}},nt=(l,g)=>{if($(null),g==="remove"){const N=l.source.owned_scope;if(!N)return;const U=Y.findIndex(ue=>ue.name===l.name);ae(l.name,"remove",()=>r({action:"remove",name:l.name,scope:N})).then(({operationId:ue,failed:we})=>{we||ue!==null||(mt(`Removed ${l.name}.`),U>=0&&ve({index:U}))});return}ae(l.name,"sign_out",()=>r({action:"logout",name:l.name})).then(()=>{Q({name:l.name,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})})},Mt=async l=>{try{return await r({action:"add",name:l.name,scope:l.scope,...l.mode==="command"?{command:l.command,args:l.args}:{url:l.url}}),w(!1),J(l.name),null}catch(g){return Ve("add",g,!1)}},Te=t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"text-heading text-ink",children:ct}),t.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:ic})]}),a.enabled&&c.length>0&&!j?t.jsxs(P,{ref:I,variant:"secondary",size:"sm",onClick:()=>w(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(Ot,{"aria-hidden":"true"}),"Add integration"]}):null]});if(!a.enabled&&!a.isLoading)return t.jsx(ne,{title:ct,titleComponent:Te,sectionRef:n,children:t.jsx(te,{variant:"warning",children:"Integrations need a newer Local Operator backend. Update it and restart the app to manage them here."})});const Ee=t.jsx(Si,{existingNames:c.map(l=>l.name),projectScopeAvailable:y,projectLabel:o?.cwd?uc(o.cwd):null,onSubmit:Mt,onCancel:()=>{w(!1),window.setTimeout(()=>I.current?.focus(),0)}}),At=M?je(M.name):void 0,On=Object.entries(V).filter(([l])=>!c.some(g=>g.name===l)),Fn=l=>_(({[l]:g,...N})=>N);i.useEffect(()=>{if(!G)return;const l=z.current[G];if(!l){c.some(g=>g.name===G)&&(K.current[G]?.focus(),J(null));return}l.focus(),J(null)},[G,c]),i.useEffect(()=>{if(!fe)return;const g=Y[Math.min(fe.index,Y.length-1)]??Y.at(-1);if(g){const N=z.current[g.name]??K.current[g.name];if(!N)return;N.focus()}else I.current?.focus();ve(null)},[fe,Y]);const st=i.useCallback((l,g)=>{const N=d()??o,U=N?.servers.find(Dn=>Dn.name===l.name),ue=N?.operations??[],we=U?U.status==="connecting"||Re(U.name,ue)!==null:!1;we&&U&&(p.current=g);const _e=U?Nt(U,ue,a.memories):null;if(U&&l.waitForSignIn&&(_e?.kind==="sign_in"||_e?.kind==="reauth"))return"kept";const Me=Ri({hold:l,now:g,windowMs:Le,rowMoving:we,lastMovingAt:p.current,candidate:U?Ei({primary:_e?z.current[U.name]:null,overflow:K.current[U.name]}):void 0,active:window.document.activeElement,body:window.document.body});if(!Me.hold)return Q(null),"finished";if(!Me.land)return"kept";Q({name:l.name,waitForSignIn:!1,until:Me.hold.until,landedOn:Me.land,reanchors:Me.hold.reanchors});const Rt=Me.land;return window.setTimeout(()=>{Rt.isConnected&&Rt.focus()},0),"landed"},[d,o,a.memories]);return i.useEffect(()=>{if(!X)return;st(X,Date.now());let l=0,g=!1;const N=()=>{if(g)return;const U=Ii({verdict:st(X,Date.now()),watchMs:Gt});U!==null&&(l=window.setTimeout(N,U))};return l=window.setTimeout(N,Gt),()=>{g=!0,window.clearTimeout(l)}},[X,st]),i.useEffect(()=>{if(!X)return;const l=g=>{Ti({target:g.target,row:se.current[X.name]})&&Q(null)};return window.document.addEventListener("pointerdown",l,!0),()=>{window.document.removeEventListener("pointerdown",l,!0)}},[X]),t.jsxs(ne,{title:ct,titleComponent:Te,sectionRef:n,children:[t.jsxs("div",{className:"flex flex-col gap-4",children:[a.route==="session"&&a.borrowed?t.jsxs("p",{className:"text-body-sm text-ink-muted",children:["Showing the integrations for"," ",a.borrowed.title?.trim()||a.borrowed.session_id.slice(0,6),", your most recent chat."]}):null,a.noConversation?t.jsxs("div",{className:"flex flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"Integrations can be managed here once a chat has started."}),t.jsx(P,{variant:"primary",size:"sm",onClick:()=>u("/chat"),children:"Start a chat"}),t.jsx("p",{className:"text-ink-dim text-meta",children:"Updating Local Operator removes this step."})]}):null,a.isLoading?t.jsx("div",{className:"flex h-24 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading integrations"})}):null,a.folderUnavailable?t.jsx(te,{variant:"warning",children:t.jsx("span",{children:"This chat's folder no longer exists, so only global integrations are shown."})}):null,a.isError?t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:"Integrations couldn't be loaded."}),t.jsx(P,{variant:"secondary",size:"sm",onClick:a.refetch,children:"Retry"})]})}):null,On.map(([l,g])=>t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:g}),t.jsx(P,{variant:"ghost",size:"sm",onClick:()=>Fn(l),children:"Dismiss"})]})},l)),j&&c.length>0?Ee:null,c.length>=rc?t.jsxs("div",{className:"relative",children:[t.jsx(is,{"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-dim"}),t.jsx(Ae,{ref:x,value:h,onChange:l=>v(l.target.value),onKeyDown:l=>{l.key!=="Escape"||!h||(l.preventDefault(),v(""))},placeholder:`Search ${Hr(c.length)}`,"aria-label":"Search integrations",className:"pl-9"})]}):null,A?.kind==="miss"&&c.length>0?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`No integration matches "${A.asked}".`}):null,A?.kind==="matched"&&A.unresolved?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`Showing "${A.name}" — "${A.unresolved}" is not one of your integrations.`}):null,o&&c.length===0&&!a.isLoading?j?Ee:t.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-lg bg-surface p-6",children:[t.jsx(ln,{"aria-hidden":"true",className:"size-5 text-ink-muted"}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"text-heading text-ink",children:"No integrations yet"}),t.jsx("p",{className:"max-w-xl text-body-sm text-ink-muted",children:"Integrations let agents read and act in your other tools, like Notion or Linear. Add one with a command that runs on this computer, or a server's URL."})]}),t.jsxs(P,{variant:"primary",size:"md",onClick:()=>w(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(Ot,{"aria-hidden":"true"}),"Add integration"]})]}):null,c.length>0&&Y.length===0?t.jsxs("div",{className:"flex flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"No integrations match this search."}),t.jsx(P,{variant:"secondary",size:"sm",onClick:()=>{v(""),window.setTimeout(()=>{(x.current??I.current)?.focus()},0)},children:"Clear search"})]}):null,de.map(l=>t.jsxs("section",{"aria-labelledby":`integrations-group-${l.id}`,className:"flex flex-col gap-1.5",children:[t.jsxs("h3",{id:`integrations-group-${l.id}`,className:"px-1 text-ink-dim text-meta",children:[l.title," · ",l.rows.length]}),t.jsx("ul",{className:"flex flex-col divide-y divide-hairline overflow-hidden rounded-lg bg-surface",children:l.rows.map(g=>t.jsx(Ui,{row:g,operations:m,memories:a.memories,projectScopeAvailable:y,highlighted:g.name===f,rowRef:N=>{se.current[g.name]=N,g.name===f&&(F.current=N)},primaryRef:N=>{z.current[g.name]=N},overflowRef:N=>{K.current[g.name]=N},pending:R===g.name,failure:V[g.name]??null,confirm:H?.name===g.name?{kind:H.kind}:null,onPrimary:N=>Ke(g,N),onOverflow:N=>tt(g,N),onConfirm:()=>H&&nt(g,H.kind),onCancelConfirm:()=>{$(null),window.setTimeout(()=>{K.current[g.name]?.focus()},0)}},g.id))})]},l.id))]}),M?.kind==="sign_in"?t.jsx(Bi,{name:M.name,action:M.action,keyRoute:ie?Je(ie):!1,phase:W,onStart:()=>void et(M.name,M.action),onCancel:l=>void r({action:"cancel",operationId:l}).catch(()=>{}),onOpenLink:l=>void cs(l),onClose:l=>k(M.name,l)}):null,M?.kind==="key"?t.jsx(Fi,{name:M.name,keyNames:M.keyNames.length?M.keyNames:At?.auth.secret_refs.map(l=>l.id)??[],keyless:M.keyNames.length===0,savedKeys:At?.auth.secret_refs.filter(l=>l.state==="encrypted").map(l=>l.id),saving:D,failure:ee,onClose:me,onSave:(l,g,N)=>{O(!0),L(null),a.storeKeys(M.name,l,g,N).then(U=>{if(!U.saved){L(U.message);return}S(null),Q({name:M.name,waitForSignIn:!1,until:Date.now()+Le,reanchors:0})}).catch(U=>L(Ve("key",U,!1))).finally(()=>O(!1))}}):null]})},Le=4e3,dc=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,uc=e=>e.replace(dc,"~"),mc=e=>typeof e!="number"||!Number.isFinite(e)?"your free credits":`$${e.toFixed(2)} in free credits`,hc="https://console.radienthq.com/dashboard/verification",pc=(e,n)=>e==="pending"?{sentence:`Verify your email to claim ${n}. Check your inbox for the link Radient sent.`,action:"Open verification page"}:e==="expired"?{sentence:`The link to claim ${n} has expired. Request a new one from the verification page.`,action:"Request a new link"}:{sentence:"No signup grant is attached to this account. Open the verification page to check the account.",action:"Open verification page"},fc=({verification:e})=>{const{prices:n}=Ls(),s=e.grant_amount??n?.default_new_credits,{sentence:a,action:o}=pc(e.signup_grant,mc(s)),r=e.claim_url||hc;return t.jsxs("div",{className:"mt-8 flex items-start gap-3 rounded-sm border border-hairline bg-surface p-3",children:[t.jsx(Qe,{className:"mt-0.5 size-4 shrink-0 text-ink-muted","aria-hidden":"true"}),t.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-2",children:[t.jsx("p",{className:"text-body-sm text-ink",children:a}),t.jsx(P,{variant:"secondary",size:"sm",onClick:()=>{window.api?.openExternal?window.api.openExternal(r):window.open(r,"_blank")},children:o})]})]})},gc=({onAfterCredentialUpdate:e})=>{const{isAuthenticated:n,user:s,isLoading:a,accountRead:o,signOut:r}=us(),d=dn(j=>j.isSigningOut),u=i.useCallback(async()=>{try{await r()}catch(j){console.error("Error signing out:",j)}},[r]),c=i.useMemo(()=>{if(!n||!s?.radientUser)return null;const{account:j,identity:w,verification:h}=s.radientUser,v=h!=null&&!h.email_verified&&h.signup_grant!=="claimed";return t.jsxs(t.Fragment,{children:[t.jsxs(Ze,{children:[t.jsx(oe,{label:"Status",value:t.jsxs("span",{className:"inline-flex items-center gap-2",children:["Connected",t.jsx(ca,{variant:"success",className:"capitalize",children:j.status})]})}),t.jsx(oe,{label:"Name",value:j.name||"Not provided"}),t.jsx(oe,{label:"Email",value:j.email}),t.jsx(oe,{label:"Account ID",value:t.jsx("span",{className:"text-mono-sm",children:j.id})}),t.jsx(oe,{label:"Tenant ID",value:t.jsx("span",{className:"text-mono-sm",children:j.tenant_id})}),t.jsx(oe,{label:"Provider",value:t.jsx("span",{className:"capitalize",children:w.provider})}),t.jsx(oe,{label:"Created",value:un(j.created_at)})]}),v&&h?t.jsx(fc,{verification:h}):null,t.jsxs("div",{className:"mt-8",children:[t.jsx("p",{className:"text-body-sm text-ink-muted",children:"Need to sign out or switch accounts?"}),t.jsxs(P,{variant:"danger",className:"mt-3",onClick:u,children:[t.jsx(Is,{}),"Sign out from Radient"]})]})]})},[n,s?.radientUser,u]),m=i.useMemo(()=>o==="refused"?"Radient refused the sign-in this app is holding, so your account details could not be read. Signing in again below replaces it.":mn(o)?"Your Radient account could not be read, so this app cannot show your account details.":"You are not currently signed in to Radient.",[o]),y=i.useMemo(()=>n&&s?null:t.jsxs("div",{children:[t.jsxs("p",{className:"text-body-sm text-ink-muted",children:[m," Sign in to access your account details or sign up to get free credits and unified access to models, tools, and more with Radient Pass. Radient's automatic model router will automatically select the best model for your agents to balance cost and performance. It is often cheaper to use Radient Pass than to use single AI providers due to automatic cost optimization."]}),t.jsx("div",{className:"mt-6",children:t.jsx(pa,{titleText:"",onAfterCredentialUpdate:e,descriptionText:"",onSignInSuccess:()=>{}})})]}),[n,s,m,e]);return a||d?t.jsxs("div",{className:"flex min-h-36 flex-col items-center justify-center gap-3",children:[t.jsx(re,{size:"lg",label:"Loading account"}),!d&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Loading your Radient account details…"})]}):n&&s?.radientUser?c:t.jsx("div",{className:"flex flex-col gap-4",children:y})};function yc({metric:e,data:n}){return t.jsx(ms,{title:"",heightClassName:"h-62",yAxisWidth:48,unit:e==="credits"?"credits":"tokens",srSummary:`${e==="credits"?"Credits consumed":"Tokens used"} over the last 30 days, plotted per day across ${n.length} days.`,xTickFormatter:s=>s,yTickFormatter:s=>e==="credits"?`$${s.toFixed(2)}`:hs(s),children:t.jsx(Ir,{data:n,children:t.jsx(an,{type:"monotone",dataKey:"value",strokeWidth:2,dot:!1,activeDot:{r:4,strokeWidth:0},name:e==="credits"?"Credits consumed":"Tokens used"})})})}const xc={all:["desktop","tts-path-resolution"]};function kc(e){return ke({queryKey:xc.all,queryFn:()=>ye({op:"tts.paths"}),enabled:e,staleTime:Number.POSITIVE_INFINITY,refetchOnWindowFocus:!1,refetchOnReconnect:!1,retry:ps})}const vc=["speech.voice.gender","speech.voice.tone","speech.voice.expressiveness","speech.voice.pace","speech.voice.language","speech.voice.accent","speech.voice.instructions"];function Jt(e){const n=new Map(e.map(o=>[o.key,o])),s=[],a=[];for(const o of vc){const r=n.get(o);r?s.push(r):a.push(o)}return{rows:s,missing:a}}const bc=["provider_tts_radient","provider_tts_elevenlabs","provider_tts_openai","none"];function Xt(e){return typeof e=="string"&&bc.includes(e)}function jc(e){if(e===null||typeof e!="object")return null;const n=e;if(!Xt(n.path)||typeof n.reason!="string"||typeof n.servable!="boolean"||!Array.isArray(n.rungs))return null;const s=[];for(const a of n.rungs){if(a===null||typeof a!="object")return null;const o=a;if(!Xt(o.path)||typeof o.available!="boolean"||typeof o.reason!="string")return null;s.push({path:o.path,available:o.available,reason:o.reason})}return{path:n.path,reason:n.reason,servable:n.servable,rungs:s}}const wc={provider_tts_radient:"Radient Pass",provider_tts_elevenlabs:"ElevenLabs",provider_tts_openai:"OpenAI",none:"No provider"};function In(e){return wc[e]}function _c(e){return{servable:e.servable,serving:e.path==="none"?null:e.path,reason:e.reason,rungs:e.rungs.map(n=>({path:n.path,name:In(n.path),available:n.available,reason:n.reason}))}}const Nc="This backend does not serve the voicing surface. Update the backend to tune how the assistant sounds.",Ln="Speech availability could not be read.",Sc=({resetErrorBoundary:e})=>t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("span",{children:Ln}),t.jsxs(P,{variant:"secondary",onClick:e,children:[t.jsx(da,{"aria-hidden":"true"}),"Try again"]})]})});function Cc(e){return e==="enabled"?"ready":e==="below-version"?"older":"pairing"}const Mc=({sectionRef:e})=>{const n=cn(),s=hn(),a=fs(n.data,"tts"),o=Cc(a),r=ke({queryKey:vs.all,queryFn:()=>ye({op:"settings.list"}),enabled:o==="ready",staleTime:1e4}),d=kc(o==="ready"),{hasRadientApiKey:u,hasRadientSession:c,speechBlock:m}=gs(),y=`${c}:${u}`,j=i.useRef(y),w=d.refetch;i.useEffect(()=>{j.current!==y&&(j.current=y,w())},[y,w]);const h=r.data,v=i.useMemo(()=>Jt(h?.settings??[]),[h]),[R,C]=i.useState({}),[V,_]=i.useState({}),[H,$]=i.useState({});i.useEffect(()=>{h&&C(p=>{let I=!1;const x={...p};for(const B of Jt(h.settings).rows){const G=p[B.key];if(G&&G.value!==Ie(B).value)continue;const J=Ie(B);G&&G.value===J.value&&G.cascadeBase===J.cascadeBase||(x[B.key]=J,I=!0)}return I?x:p})},[h]);const M=(p,I)=>_(x=>({...x,[p]:I})),S=(p,I)=>$(x=>({...x,[p]:I})),W=async p=>{const I=R[p.key];if(!I)return;const x=ks(p,I);if(!x.ok){S(p.key,x.error);return}M(p.key,!0),S(p.key,null);try{await ye(x.request),M(p.key,!1);const G=(await r.refetch()).data?.settings.find(J=>J.key===p.key);G&&C(J=>{const X=J[p.key];return X&&X.value===I.value&&X.cascadeBase===I.cascadeBase?{...J,[p.key]:Ie(G)}:J})}catch(B){M(p.key,!1),S(p.key,B instanceof Error?B.message:"The setting could not be saved.")}},q=async p=>{M(p.key,!0),S(p.key,null);try{await ye({op:"settings.reset",key:p.key}),C(I=>({...I,[p.key]:Ie({...p,value:p.default,is_default:!0})})),M(p.key,!1),await r.refetch()}catch(I){M(p.key,!1),S(p.key,I instanceof Error?I.message:"The setting could not be reset.")}},Z=i.useMemo(()=>jc(d.data),[d.data]),T=Z?_c(Z):null,ee=d.isSuccess&&Z===null,L=(n.data?null:n.error)??null,D=r.error,O="Speech voicing",z="How the assistant sounds when it speaks aloud.";if(o==="pairing"){const{sentence:p}=pt(s??null,"Speech settings could not be loaded.",L);return t.jsx(ne,{title:O,icon:Be,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:p})})}if(o==="older")return t.jsx(ne,{title:O,icon:Be,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:Nc})});if(D||!h){const{sentence:p,remedy:I}=pt(s??null,"Speech settings could not be loaded.",D);return t.jsx(ne,{title:O,icon:Be,description:z,sectionRef:e,children:t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:p}),I&&t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>{r.refetch()},children:"Retry"})]})})})}const K=T?!T.servable:m==="offline",se=T?T.rungs.find(p=>p.path===T.serving)??null:null;return t.jsx(ne,{title:O,icon:Be,description:z,sectionRef:e,children:t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs("section",{className:"flex flex-col gap-3",children:[d.isPending&&t.jsxs("p",{className:"flex items-center gap-2 text-body-sm text-ink-muted",children:[t.jsx(re,{}),Lt("checking")]}),(d.isError||ee)&&!T&&m!=="offline"&&t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("span",{children:[Ln," ",d.error instanceof Error?d.error.message:""]}),t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>{d.refetch()},children:"Retry"})]})}),t.jsx(la,{fallbackRender:Sc,resetKeys:[d.dataUpdatedAt],children:T&&t.jsxs(t.Fragment,{children:[t.jsxs(Ze,{children:[t.jsx(oe,{label:"Speaks through",value:T.serving?In(T.serving):"Nothing yet"}),t.jsx(oe,{label:"Availability",value:T.servable?"Ready":"No provider"})]}),T.reason&&T.reason!==se?.reason&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:T.reason}),t.jsx("ul",{className:"flex flex-col gap-1",children:T.rungs.map(p=>t.jsxs("li",{className:"flex flex-col gap-0.5 text-body-sm",children:[t.jsxs("span",{className:p.path===T.serving?"text-ink":"text-ink-muted",children:[p.name,t.jsxs("span",{className:p.path===T.serving?"text-ink-muted":"text-ink-dim",children:[" ",p.available?"(available)":"(not available)"]})]}),t.jsx("span",{className:"text-meta text-ink-dim",children:p.reason})]},p.path))})]})})]}),K&&t.jsx(te,{variant:"warning",children:Lt(m)}),t.jsx("div",{className:"flex flex-col gap-1",children:v.rows.map(p=>t.jsx(ys,{setting:p,draft:R[p.key]??Ie(p),tier:xs(p),saving:!!V[p.key],error:H[p.key]??null,onDraftChange:I=>C(x=>({...x,[p.key]:I})),onSave:()=>{W(p)},onReset:()=>{q(p)}},p.key))}),v.missing.length>0&&t.jsxs("p",{className:"text-meta text-ink-dim",children:["This backend does not register ",v.missing.join(", ")," yet, so those rows are not shown."]})]})})},Ac=()=>{const{data:e,isLoading:n,error:s,refetch:a}=Ar(),o=Rr(),[r,d]=i.useState(""),[u,c]=i.useState(!1);i.useEffect(()=>{d(e?.content??""),c(!1)},[e]);const m=v=>{const R=v.target.value;d(R),c(R!==(e?.content??""))},y=async()=>{if(!(!u||o.isPending))try{const v={content:r};await o.mutateAsync(v),await a(),c(!1)}catch(v){console.error("Error updating system prompt:",v)}},j=()=>{d(e?.content??""),c(!1)},w=o.isPending,h=()=>t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(xe,{htmlFor:"app-system-prompt",children:"Instructions"}),t.jsx(yn,{id:"app-system-prompt",name:"systemPrompt",value:r,onChange:m,placeholder:"Enter instructions for how all agents should behave and respond to your requests...",className:"min-h-50"})]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs(P,{variant:"primary",onClick:y,disabled:!u||w,children:[w?t.jsx(re,{size:"sm"}):t.jsx(Os,{}),w?"Saving...":"Save changes"]}),t.jsx(P,{onClick:j,disabled:!u||w,children:"Cancel"})]}),e?.last_modified&&t.jsxs("p",{className:"text-ink-dim text-meta",children:["Last modified:"," ",t.jsx("span",{className:"font-mono text-mono-sm",children:pn(e.last_modified)})]})]});return t.jsx(ne,{title:"System prompt",icon:ha,description:"Every Local Operator agent receives this prompt in addition to its own instructions, so it is the place for baseline expectations and for details you want every agent to know about you, such as your name, location, or preferences. It is sent to your selected hosting provider.",children:n?t.jsx("div",{className:"flex min-h-50 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading system prompt"})}):s?t.jsxs(te,{variant:"danger",children:["Failed to load system prompt:"," ",s instanceof Error?s.message:"Unknown error"]}):h()})},Rc=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"],Tc=e=>Rc.includes(e),Ec=e=>{const n=[];let s=0;for(const a of e){const o=Math.max(0,Math.floor(a.count)),r=Math.max(1,Math.floor(a.columns));for(let d=0;d<o;d+=r)n.push({start:s+d,count:Math.min(r,o-d)});s+=o}return n},Ic=({index:e,key:n,groups:s})=>{const a=Ec(s),o=a.reduce((r,d)=>r+d.count,0);if(!Number.isInteger(e)||e<0||e>=o)return e;switch(n){case"Home":return 0;case"End":return o-1;case"ArrowLeft":return Math.max(0,e-1);case"ArrowRight":return Math.min(o-1,e+1);case"ArrowUp":case"ArrowDown":{const r=a.findIndex(c=>e>=c.start&&e<c.start+c.count),d=a[r+(n==="ArrowDown"?1:-1)];if(!d)return e;const u=e-a[r].start;return d.start+Math.min(u,d.count-1)}default:return e}},Lc={localOperatorDark:Uo,localOperatorLight:or,dracula:Zo,dune:ho,sage:To,monokai:$s,tokyoNight:Ho,iceberg:Xo,radient:No,neon:bs,obsidian:kn,synth:Na,catppuccinMocha:Za,catppuccinLatte:Oo,tokyoNightStorm:Ha,gruvbox:Ia,nord:Cr,oneDark:wa,solarizedDark:sr,rosePine:yo,rosePineMoon:Do,rosePineDawn:Wa,alucard:ko,gruvboxLight:ao,tokyoNightDay:zo,oneLight:Io,catppuccinFrappe:no,catppuccinMacchiato:Co,palenight:Ds,everforest:kr,everforestLight:yr,kanagawaWave:wr,kanagawaLotus:fo,ayuDark:ro,ayuMirage:co,ayuLight:qo,nightfox:Va,duskfox:lr,synthwave:Vo,matrix:Ca,tron:za,cyberpunk:Fs,vaporwave:fr,outrun:Ta,neonNoir:br,arcade:Ao,forest:hr,ocean:uo,desert:ur,autumn:Nr,lavender:tr,arctic:qa,rosewood:wo,solarizedLight:ir,githubLight:bo,paper:fa,linen:Wo,highContrastLight:ba,mintLight:Aa},en="bg-[color-mix(in_srgb,var(--color-accent)_8%,var(--color-accent-wash))]",Oc=({id:e})=>t.jsxs("div",{"data-theme":e,"aria-hidden":"true",className:"flex h-full bg-canvas",children:[t.jsxs("div",{className:"flex w-1/4 flex-col gap-1 bg-sunken p-1",children:[t.jsx("span",{className:"flex h-2.5 items-center rounded-xs bg-accent-wash px-1",children:t.jsx("span",{className:"h-1 w-full rounded-xs bg-accent"})}),t.jsx("span",{className:"mx-1 h-1 w-2/3 rounded-xs bg-ink-dim"}),t.jsx("span",{className:"mx-1 h-1 w-1/2 rounded-xs bg-ink-dim"})]}),t.jsxs("div",{className:"flex flex-1 flex-col justify-between p-1",children:[t.jsxs("div",{className:"flex flex-col gap-1 rounded-xs bg-surface p-1",children:[t.jsx("span",{className:"h-1 w-3/5 rounded-xs bg-ink"}),t.jsx("span",{className:"h-1 w-full rounded-xs bg-ink-dim"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"h-2.5 w-6 rounded-xs bg-elevated"}),t.jsx("span",{className:"h-2.5 w-5 rounded-xs bg-accent"}),t.jsx("span",{className:"h-2.5 w-4 rounded-xs bg-accent-alt"}),t.jsx("span",{className:"h-2.5 w-4 rounded-xs border border-control"})]})]})]}),Fc=({id:e,name:n,description:s,isSelected:a,isTabStop:o,onSelect:r,onFocusTile:d})=>{const u=Lc[e];return t.jsx($e,{side:"bottom",align:"start",content:s,children:t.jsxs("button",{type:"button","data-theme-tile":e,"aria-pressed":a,tabIndex:o?0:-1,onFocus:d,onClick:r,className:ce("relative flex flex-col gap-1.5 rounded-md p-1 text-left transition-colors duration-fast ease-out-quart",a?en:"hover:bg-surface"),children:[t.jsxs("span",{className:ce("relative block h-10 overflow-hidden rounded-sm border transition-colors duration-fast ease-out-quart",a?"border-accent":"border-hairline"),children:[t.jsx(Oc,{id:e}),a&&t.jsx("span",{className:ce("pointer-events-none absolute top-0.5 right-0.5 flex h-4 w-4 items-center justify-center rounded-full",en),children:t.jsx(ma,{size:12,className:"text-accent","aria-hidden":"true"})})]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(u,{size:12,className:"shrink-0 text-ink-dim","aria-hidden":"true"}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink",children:n})]})]})})},Dc=e=>[...e.querySelectorAll("[data-theme-grid]")].map(n=>{const s=[...n.querySelectorAll("[data-theme-tile]")],a=s[0]?.getBoundingClientRect().top??0;return{count:s.length,columns:Math.max(1,s.filter(o=>Math.abs(o.getBoundingClientRect().top-a)<1).length)}}),$c=()=>{const{themeName:e,setTheme:n}=Oe(),s=i.useMemo(()=>{const u=Object.values($n);return[{label:"Dark",items:u.filter(c=>c.theme.palette.mode==="dark")},{label:"Light",items:u.filter(c=>c.theme.palette.mode==="light")}].filter(c=>c.items.length>0)},[]),[a,o]=i.useState(null),r=i.useMemo(()=>{const u=s.flatMap(c=>c.items.map(m=>m.id));return a&&u.includes(a)?a:u.includes(e)?e:u[0]},[s,a,e]),d=u=>{if(!Tc(u.key))return;const c=[...u.currentTarget.querySelectorAll("[data-theme-tile]")],m=c.indexOf(u.target);if(m<0)return;u.preventDefault();const y=Ic({index:m,key:u.key,groups:Dc(u.currentTarget)});y!==m&&c[y]?.focus()};return t.jsx(ua,{children:t.jsx("div",{onKeyDown:d,className:"flex flex-col gap-6",children:s.map(u=>t.jsxs("div",{children:[t.jsx("h3",{className:"px-1 pb-2 text-meta text-ink-dim",children:u.label}),t.jsx("div",{"data-theme-grid":u.label,className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-2",children:u.items.map(({id:c,name:m,description:y})=>t.jsx(Fc,{id:c,name:m,description:y,isSelected:c===e,isTabStop:c===r,onSelect:()=>n(c),onFocusTile:()=>o(c)},c))})]},u.label))})})},Uc=({value:e,onChange:n})=>{const s=i.useId();return t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{id:s,className:"flex min-h-6 items-center text-body text-ink",children:"Transcript display"}),t.jsx("p",{className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:"By turn condenses each turn to its answer. By response keeps every settled response on screen, with the turn's final answer still marked."})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:t.jsx(ft,{value:e,onValueChange:a=>n(fn(a)),children:t.jsx(gt,{"aria-labelledby":s,children:Rs.map(a=>t.jsx(Fe,{value:a.value,children:a.label},a.value))})})})]})},Pc=()=>{const{data:e,isLoading:n,error:s}=Or({enabled:!0});return t.jsxs("div",{children:[t.jsxs("h3",{className:"mb-3 flex items-center gap-2 text-heading text-ink",children:[t.jsx(eo,{size:16,className:"shrink-0 text-ink-dim"}),"Radient Pass"]}),n&&t.jsx(xn,{className:"h-6 w-36"}),s&&t.jsxs(te,{variant:"warning",children:["Could not load your credit balance. ",s.message]}),e&&!n&&!s&&t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[t.jsxs("p",{className:"flex-1 text-body-sm text-ink-muted",children:["Available credits"," ",t.jsx("span",{className:"font-medium text-ink",children:e.balance.toFixed(2)})]}),t.jsx(P,{variant:"secondary",size:"sm",asChild:!0,children:t.jsxs("a",{href:"https://console.radienthq.com/dashboard/billing",target:"_blank",rel:"noopener noreferrer",children:[t.jsx(Ua,{}),"Add credits"]})})]})]})},zc=[{id:"credits",label:"Credits"},{id:"tokens",label:"Tokens"}],Kc=()=>{const[e,n]=i.useState("credits"),s=i.useMemo(()=>{const u=new Date,c=Er(u);return{start_date:Pt(c),end_date:Pt(u),rollup:"daily"}},[]),{data:a,isLoading:o,error:r}=Dr(s,{enabled:!0}),d=i.useMemo(()=>a?.data_points?[...a.data_points].sort((c,m)=>at(c.timestamp).getTime()-at(m.timestamp).getTime()).map(c=>({bucket:Ms(xa(at(c.timestamp),"yyyy-MM-dd")),value:e==="credits"?Number.parseFloat(c.total_cost.toFixed(2)):c.total_tokens})):[],[a,e]);return t.jsxs("div",{children:[t.jsxs("div",{className:"mb-5 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("h3",{className:"flex items-center gap-2 text-heading text-ink",children:[t.jsx(Oa,{size:16,className:"shrink-0 text-ink-dim"}),"Usage (last 30 days)"]}),t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:"Usage metric"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:zc.map(({id:u,label:c})=>t.jsx(P,{variant:"ghost",size:"sm","aria-pressed":e===u,onClick:()=>n(u),className:ce(e===u&&"bg-surface text-ink hover:bg-surface"),children:c},u))})]})]}),o&&t.jsx(xn,{className:"h-62 w-full"}),r&&t.jsxs(te,{variant:"warning",children:["Could not load your usage data. ",r.message]}),!o&&!r&&a&&d.length>0&&t.jsx(yc,{metric:e,data:d}),!o&&!r&&(!a||d.length===0)&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:"No usage recorded in the last 30 days."})]})},Hc=()=>t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[t.jsx(Ys,{size:16,className:"shrink-0 text-ink-dim"}),"Radient account"]}),t.jsx(P,{variant:"secondary",size:"sm",className:"self-start sm:self-center",asChild:!0,children:t.jsxs("a",{href:"https://console.radienthq.com",target:"_blank",rel:"noopener noreferrer",children:["Go to Radient console",t.jsx(As,{})]})})]}),sl=()=>{const e=js("surface"),n=Oe(f=>f.showAgentReasoning),s=Oe(f=>f.setShowAgentReasoning),a=Oe(f=>f.transcriptDisplayMode),o=Oe(f=>f.setTranscriptDisplayMode),{data:r,isLoading:d,isFetching:u,error:c,refetch:m}=ws(),y=hn(),{sentence:j,remedy:w}=pt(y??null,"Your settings could not be loaded.",c),h=Us(),[v,R]=i.useState(null),C=dn(),{isAuthenticated:V,accountRead:_,isFetching:H,isRefreshing:$,refreshUser:M}=bt(),S=Ge(f=>f.activeSessionId),[W,q]=i.useState("general"),[Z,T]=i.useState(!1),ee=i.useRef(null),L=i.useRef(null),{startTour:D}=Ps(),O=_s(),{data:z,refetch:K}=Ns(),{refreshModels:se}=Ss(),p=i.useMemo(()=>z?.keys?[...z.keys].sort():[],[z?.keys]),I=i.useRef({keys:"",hosting:void 0});i.useEffect(()=>{const f=p.join(","),F=r?.values?.hosting;(I.current.keys!==f||I.current.hosting!==F)&&(I.current={keys:f,hosting:F},se().catch(E=>{console.error("Failed to refresh models after credentials or hosting change:",E)}))},[p,r?.values?.hosting,se]);const x=i.useRef({general:i.useRef(null),radient:i.useRef(null),integrations:i.useRef(null),appearance:i.useRef(null),speech:i.useRef(null),providers:i.useRef(null),backend:i.useRef(null),updates:i.useRef(null)}).current,B=i.useMemo(()=>new URLSearchParams(O.search).get("setting"),[O.search]),G=i.useMemo(()=>new URLSearchParams(O.search).get("filter")??"",[O.search]),J=i.useMemo(()=>new URLSearchParams(O.search).get("mcp")??void 0,[O.search]),X=i.useMemo(()=>new URLSearchParams(O.search).get("provider"),[O.search]),Q=i.useCallback(f=>{q(f),T(!0);const F=x[f],E=L.current;if(F?.current&&E){const Y=F.current.getBoundingClientRect().top-E.getBoundingClientRect().top;E.scrollHeight>E.clientHeight?E.scrollTo({top:Math.max(0,E.scrollTop+Y-80),behavior:"smooth"}):window.scrollTo({top:Math.max(0,F.current.getBoundingClientRect().top+window.scrollY-80),behavior:"smooth"}),clearTimeout(ee.current??void 0),ee.current=setTimeout(()=>{T(!1),ee.current=null},800)}else T(!1)},[x]);i.useEffect(()=>{const f=setTimeout(()=>{const F=L.current;if(!F)return;const E=()=>{if(Z)return;const le=F.getBoundingClientRect(),Y=le.height;let de="",ie=0;for(const[be,he]of Object.entries(x))if(he.current){const ae=he.current.getBoundingClientRect(),je=le.top,pe=ae.top-je,et=ae.bottom-je,Ke=ae.height,tt=Math.max(0,pe),nt=Math.min(Y,et),Te=Math.max(0,nt-tt)/Ke,Ee=Te+(pe<Y*.3?.1:0);Ee>ie&&Te>.1&&(ie=Ee,de=be)}de&&de!==W&&q(de)};return E(),F.addEventListener("scroll",E,{passive:!0}),()=>{F.removeEventListener("scroll",E),clearTimeout(ee.current??void 0)}},100);return()=>clearTimeout(f)},[x,W,Z]),i.useEffect(()=>{const f=new URLSearchParams(O.search),F=f.get("section"),E=f.get("setting")?"backend":F,le=E?x[E]:void 0;if(!E||!le)return;let Y=!1,de=Number.NaN,ie=0;const be=window.setTimeout(()=>{Y||(Y=!0,ae.disconnect(),Q(E))},2e3),he=()=>{if(Y)return;const je=le.current;if(!je){ie=requestAnimationFrame(he);return}const pe=Math.round(je.getBoundingClientRect().top+window.scrollY);if(pe===de&&pe>0){Y=!0,ae.disconnect(),window.clearTimeout(be),Q(E);return}de=pe,ie=requestAnimationFrame(he)},ae=new ResizeObserver(()=>{Y||(cancelAnimationFrame(ie),ie=requestAnimationFrame(he))});return L.current&&ae.observe(L.current),ie=requestAnimationFrame(he),()=>{Y=!0,cancelAnimationFrame(ie),ae.disconnect(),window.clearTimeout(be)}},[O.search,x,Q]);const fe=async(f,F)=>{R(f);try{await h.mutateAsync({[f]:F}),await m()}catch(E){console.error(`Error updating ${f}:`,E)}finally{R(null)}},ve=d,me=_==="checking",Ce=mn(_),k=_==="ready"||_==="checking"||H,A=gn(ve,4e3);return c?t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(te,{variant:"warning",className:"w-full max-w-xl",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:j}),w&&t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>void m(),disabled:u,children:u?"Retrying":"Retry"})]})})}):ve?t.jsxs("div",{role:"status",className:"flex h-full w-full flex-col items-center justify-center gap-3 bg-canvas",children:[t.jsx(re,{size:"lg",label:A?void 0:"Loading settings"}),A&&t.jsx("p",{className:"max-w-sm text-center text-body-sm text-ink-muted",children:"The Local Operator server is taking longer than usual to answer. If it does not respond, you will be able to retry from here."})]}):r?t.jsxs("div",{className:"flex h-full w-full overflow-hidden bg-canvas",children:[t.jsx("div",{ref:e,className:"w-12 shrink-0 overflow-y-auto min-[1040px]:w-55",children:t.jsx(zs,{activeSection:W,onSelectSection:Q,sections:Ks})}),t.jsx("div",{ref:L,"data-settings-content":!0,"data-tour-tag":"settings-general-section",className:"flex-1 overflow-y-auto overflow-x-hidden p-4 sm:p-6 md:p-8",children:t.jsxs("div",{className:"mx-auto flex w-full max-w-4xl flex-col gap-8 pb-8",children:[t.jsx(Ws,{title:"Settings",icon:Ft}),t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsxs("div",{ref:x.general,className:"flex flex-col gap-8",children:[t.jsxs(ne,{title:"User profile",icon:Hs,description:`Your user profile information displayed in the application. This information is not provided to the agents. ${V?"These details are provided through your Radient account.":""}`,children:[me&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Checking your Radient account…"}),Ce&&t.jsx(te,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("span",{children:["Your Radient account could not be read, so the name and email below are placeholders rather than your account details.",_==="refused"?" Retry, or sign in to Radient again.":" Retry."]}),t.jsx(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>M(),disabled:$,children:$?"Retrying":"Retry"})]})}),t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Dt,{value:C.profile.name,label:"Display name",placeholder:"Enter your name...",isSaving:v==="user_name",onSave:async f=>{R("user_name");try{C.updateName(f)}finally{R(null)}},readOnly:k}),t.jsx(Dt,{value:C.profile.email,label:"Email address",placeholder:"Enter your email...",isSaving:v==="user_email",onSave:async f=>{R("user_email");try{C.updateEmail(f)}finally{R(null)}},readOnly:k})]})]}),t.jsx(ne,{title:"Application tour",description:"Missed the application onboarding tour or want a refresher? Start it again here.",children:t.jsxs(P,{variant:"secondary",onClick:()=>{D({forceModalCompleted:!0})},children:[t.jsx(Da,{}),"Take the tour"]})}),t.jsx(ne,{id:"model-settings",title:"Model settings",icon:Bs,description:"Configure the default AI model and hosting providers used for generating responses. This will be used for all agents that don't have a specific model or hosting provider configured. You can override these settings for individual agents in the agent settings.",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Vs,{value:r.values.hosting,isSaving:v==="hosting",onSave:f=>fe("hosting",f),filterByCredentials:!0,allowCustom:!0,allowDefault:!1,emptyHelperText:"No hosting providers available. Sign in to a provider, or add a provider's API key below, under Providers."}),t.jsx(Gs,{value:r.values.model_name,hostingId:r.values.hosting,isSaving:v==="model_name",onSave:f=>fe("model_name",f),allowCustom:!0,allowDefault:!1}),t.jsx(te,{variant:"neutral",icon:t.jsx(Qe,{className:"size-4","aria-hidden":"true"}),children:"You need a Radient account or your own API keys to reach cloud providers. If you don't see more hosting providers and models here, sign in to Radient, or add a provider's API key below, under Providers."})]})}),t.jsx(Ac,{}),t.jsx(ne,{title:"Configuration information",icon:Qe,description:"System information about the current configuration.",children:t.jsxs(Ze,{children:[t.jsx(oe,{label:"Version",value:t.jsx("span",{className:"text-mono-sm",children:r.version})}),t.jsx(oe,{label:"Created",value:un(r.metadata.created_at)}),t.jsx(oe,{label:"Last modified",value:pn(r.metadata.last_modified)}),t.jsx(oe,{label:"Description",value:r.metadata.description||"No description available"})]})})]}),t.jsx(ne,{title:"Appearance",icon:kn,description:"Customize the look and feel of Local Operator",sectionRef:x.appearance,dataTourTag:"settings-appearance-section",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx($c,{}),t.jsx(Tr,{value:n,label:"Show agent reasoning",description:"Adds the agent's Reasoning and Thinking rows to conversations. They stay closed until you open one. Reasoning only: narration the agent writes as prose mid-turn is transcript content, not reasoning — never removed by either display mode (by turn folds it behind the turn's bars, by response keeps it on screen).",onChange:async f=>s(f)}),t.jsx(Uc,{value:fn(a),onChange:f=>o(f)})]})}),t.jsx(Mc,{sectionRef:x.speech}),t.jsx(ne,{title:"Model providers",icon:ln,description:"Sign in to the services your agents think with. New chats use your default model.",sectionRef:x.providers,children:t.jsx(qs,{initialProviderId:X,onChangeModel:()=>Q("general")})}),t.jsx(lc,{sessionId:S??void 0,sectionRef:x.integrations,highlightServer:J}),t.jsx(ne,{title:"Radient account",titleComponent:t.jsx(Hc,{}),description:"Your Radient account, Radient Pass details and credits. To use Radient models, sign in under Model providers.",sectionRef:x.radient,dataTourTag:"settings-radient-account-section",children:t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsx(gc,{onAfterCredentialUpdate:()=>{se(),K()}}),V&&t.jsxs(t.Fragment,{children:[t.jsx(Pc,{}),t.jsx(Kc,{})]})]})}),t.jsx(ne,{title:"Backend settings",icon:Ft,description:"Every setting the backend registry owns, searchable, with typed editors and scopes.",sectionRef:x.backend,children:t.jsx(Cs,{focusKey:B,initialFilter:G})}),t.jsx("div",{ref:x.updates,children:t.jsx(zr,{})})]})]})})]}):t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(te,{variant:"warning",className:"w-full max-w-xl",children:"Your settings could not be loaded."})})};export{sl as SettingsPage};
|