local-operator-ui 0.31.31 → 0.31.32
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 +60 -10
- package/out/renderer/assets/{_basePickBy-Bf87kbLT.js → _basePickBy-BzFdg-GF.js} +1 -1
- package/out/renderer/assets/{_baseUniq-BH5GsGmP.js → _baseUniq-Bm2KnnbI.js} +1 -1
- package/out/renderer/assets/{agent-details-page-C3T3KXVe.js → agent-details-page-BMiohCvb.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-C9i0FC1M.js → agent-hub-page-CAJMRlDU.js} +1 -1
- package/out/renderer/assets/{agents-page-iwyAy2dH.js → agents-page-GLKOnCr6.js} +3 -3
- package/out/renderer/assets/{arc-D5SGXb2R.js → arc-CcekKWMM.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-DU9QzL8S.js → architectureDiagram-IEHRJDOE-8foMClj9.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-DcKApfM_.js → blockDiagram-JOT3LUYC-DhfZvGTr.js} +1 -1
- package/out/renderer/assets/{book-open-s9VDPEq5.js → book-open-CueO0nwZ.js} +1 -1
- package/out/renderer/assets/browser-page-MbQ-dd2e.js +1 -0
- package/out/renderer/assets/{browser-webauthn-prompt-2pudGCfZ.js → browser-webauthn-prompt-DrMpnMBW.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-Bzfgk0Sn.js → c4Diagram-VJAJSXHY-BtAFjDFO.js} +1 -1
- package/out/renderer/assets/channel-er9Isqc8.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-dKcCv0u5.js → chunk-4BMEZGHF-hEpjTUlR.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-BsCiqyno.js → chunk-A2AXSNBT-BQE33qQV.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-1r_2Mv4Z.js → chunk-AEK57VVT-Bfv-VOfu.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-DYkeE8Xz.js → chunk-D6G4REZN-CDEQDet7.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-CPFwl8UM.js → chunk-RZ5BOZE2-BHPvStD5.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-D2UnATG-.js → chunk-XZIHB7SX-DOAEvfwX.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-CiL29Sc-.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-CiL29Sc-.js +1 -0
- package/out/renderer/assets/clone-Bsk4HvnO.js +1 -0
- package/out/renderer/assets/{console-mirror-DM2NwKgG.js → console-mirror-CiDuCMfE.js} +1 -1
- package/out/renderer/assets/{consoleCapture-Dz6t0BLj.js → consoleCapture-PlJxiaGX.js} +1 -1
- package/out/renderer/assets/{conversation-input-sync-D5WTijVw.js → conversation-input-sync-zDEtF-9C.js} +225 -225
- package/out/renderer/assets/{dagre-OKDRZEBW-CC7ZHJGZ.js → dagre-OKDRZEBW-DY30NVKc.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-BIgXD6N3.js → diagram-SSKATNLV-Cj6GWkPW.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-DSb-jidW.js → diagram-VNBRO52H-B1BnbNGr.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-BVsfO34u.js → erDiagram-Q7BY3M3F-Dt2TZzKY.js} +1 -1
- package/out/renderer/assets/{error-boundary-Bz59nB-q.js → error-boundary-BCN3_4Dn.js} +2 -2
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-BeLsb93D.js → flowDiagram-4HSFHLVR-B0y5c9qz.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-BYW2a9Z4.js → ganttDiagram-APWFNJXF-twBGRDsR.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-CmL3lNpb.js → gitGraphDiagram-7IBYFJ6S-vi21DxCt.js} +1 -1
- package/out/renderer/assets/{graph-BghwrGcW.js → graph-BVnn4QNL.js} +1 -1
- package/out/renderer/assets/index-B4ItTI5Q.css +1 -0
- package/out/renderer/assets/{index-DlJX13aK.js → index-D94pB35A.js} +1 -1
- package/out/renderer/assets/{index-BQpze3Xm.js → index-Dwxu7UOq.js} +1 -1
- package/out/renderer/assets/{index-D9eEHYnY.js → index-QVureTEn.js} +191 -191
- package/out/renderer/assets/{infoDiagram-PH2N3AL5-Dlc4HRnT.js → infoDiagram-PH2N3AL5-B-Ch65yi.js} +1 -1
- package/out/renderer/assets/{installer-ChFDulNf.js → installer-DovMkJto.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-D9GIHKf8.js → journeyDiagram-U35MCT3I-Bp6eVPe6.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-GbHp25E6.js → kanban-definition-NDS4AKOZ-D6I-GN7U.js} +1 -1
- package/out/renderer/assets/{layout-D5NC6G2z.js → layout-DFC3HVFP.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-BHwGeOra.js → legacy-agents-page-Dfrz_ZCe.js} +3 -3
- package/out/renderer/assets/{mermaid.core-CPX3HUNW.js → mermaid.core-DKfPxzKU.js} +5 -5
- package/out/renderer/assets/mesh-page-DoKTWh-X.js +1 -0
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-yAjncoir.js → mindmap-definition-ALO5MXBD-kM4s__rt.js} +1 -1
- package/out/renderer/assets/{mini-CskWqoCm.js → mini-D0On64Oc.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-DmIzbHBX.js → org-surface-gate-DArMk6ID.js} +1 -1
- package/out/renderer/assets/{page-header-C73htBLU.js → page-header-ouA0fPx9.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-BTv_vjGw.js → pieDiagram-IB7DONF6-DM1JhBgg.js} +1 -1
- package/out/renderer/assets/{projects-page-CoJRWpnW.js → projects-page-Bb200mtz.js} +5 -5
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-E-Z7fgK4.js → quadrantDiagram-7GDLP6J5-B8T16HnV.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-LRPaWbT7.js → radar-MK3ICKWK-DnM_Vl89.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-CkIa2gnI.js → radient-auth-buttons-Doso02jc.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-D41oCTsq.js → requirementDiagram-KVF5MWMF-M7JjuiAa.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-Dj68j1bd.js → sankeyDiagram-QLVOVGJD-pZ0w_k-t.js} +1 -1
- package/out/renderer/assets/{schedules-page-DEn7fbmP.js → schedules-page-OVNdDci6.js} +10 -10
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-CuT8-UJl.js → sequenceDiagram-X6HHIX6F-B7YWpV3i.js} +1 -1
- package/out/renderer/assets/{settings-page-BUPgMvuh.js → settings-page-CrOBuOHy.js} +6 -6
- package/out/renderer/assets/{settings-section-hVWmfyYL.js → settings-section-8d2ITQC3.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-CtoVTWw4.js → stateDiagram-DGXRK772-DwDArxIb.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-CEqnEMuN.js +1 -0
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-B4S43lWT.js → timeline-definition-BDJGKUSR-COfMTtoJ.js} +1 -1
- package/out/renderer/assets/{ui-preferences-store-Ch3sXoS6.js → ui-preferences-store-BaXpFsZf.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-CPCwxFuX.js → use-download-agent-mutation-fP7MSQui.js} +1 -1
- package/out/renderer/assets/{use-memberships-query-Cq1pVuOg.js → use-memberships-query-B_qwJ7_k.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-PmR4I0xI.js → xychartDiagram-VJFVF3MP-COiK9nJs.js} +1 -1
- package/out/renderer/console-capture.html +5 -5
- package/out/renderer/index.html +7 -7
- package/out/renderer/installer.html +4 -4
- package/out/renderer/mini.html +6 -6
- package/package.json +8 -3
- package/out/renderer/assets/browser-page-ufPL_LU7.js +0 -1
- package/out/renderer/assets/channel-DIn96Ghl.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-OB18Wa5z.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-OB18Wa5z.js +0 -1
- package/out/renderer/assets/clone-DZKGcLf4.js +0 -1
- package/out/renderer/assets/index-BUbxCOmE.css +0 -1
- package/out/renderer/assets/mesh-page-DW4V6mDF.js +0 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-CASDd-AK.js +0 -1
- /package/out/renderer/assets/{index-h1qa1pbA.js → index-DvjcW_EJ.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as i,j as t,c as oe,t as Cn}from"./index-
|
|
1
|
+
import{r as i,j as t,c as oe,t as Cn}from"./index-DvjcW_EJ.js";import{co as st,cp as Mn,cq as St,cr as he,bJ as An,aF as Ne,a7 as Wt,a8 as mt,aw as Zt,u as Qt,aM as Rn,aN as Tn,cs as Ln,ct as En,cu as In,cv as On,cw as Jt,cx as ht,a5 as Xt,cy as $e,cz as Fn,aR as Dn,cA as Ct,S as ft,cB as $n,cC as Un,av as en,aT as at,aU as ot,cD as zn,aX as Pn,cE as Kn,c3 as rt,a as Hn,d as Mt,ag as Ke,cF as Bn,cG as Vn,cH as Gn,X as Ue,cI as it,cJ as qn,cK as Yn,cL as Wn,aP as Zn,bb as Qn,cM as tn,cN as Jn,cO as Xn,cP as es,aL as ts,cQ as nn,aS as sn,cR as an,cS as ns,cT as ss,cU as on,cV as as,b4 as os,bM as rs,bg as is,cW as cs,bL as ls,cX as ds,cY as us,cZ as ms,c_ as hs,c$ as fs}from"./conversation-input-sync-zDEtF-9C.js";import{a_ as rn,a$ as ps,b0 as gs,ap as At,b1 as ys,b2 as xs,S as ks,aL as vs,b3 as bs,b4 as ws,b5 as js,b6 as _s,b7 as Ns,b8 as Ss,aB as Rt,aw as Cs,aI as Tt,b9 as Ms,aJ as As,aK as Rs,ba as Ts,bb as Ls}from"./index-QVureTEn.js";import{P as Es}from"./page-header-ouA0fPx9.js";import{c as y,B as D,S as re,x as Is,s as Os,t as Fs,u as Ds,v as $s,w as Us,f as Re,J as Ge,L as fe,I as Se,z as Lt,F as Et,G as ze,_ as It,T as cn,O as zs,D as Ps,l as Ks,m as Hs,o as Bs,p as Ot,k as Vs,A as le,j as Gs,Q as qs,C as Ys,e as ln}from"./error-boundary-BCN3_4Dn.js";import{u as ct}from"./ui-preferences-store-BaXpFsZf.js";import{S as se,I as pt,a as ae,N as Ws}from"./settings-section-8d2ITQC3.js";import{R as Zs}from"./radient-auth-buttons-Doso02jc.js";import{B as Qs}from"./book-open-CueO0nwZ.js";import{a as Js,p as Je}from"./parseISO-CZfAC2_J.js";import{i as Xs,a as ve,f as ea}from"./format-CZUObkkr.js";import{t as ta}from"./en-US-BcB1DWxG.js";import"./console-mirror-CiDuCMfE.js";/**
|
|
2
2
|
* @license lucide-react v0.507.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -123,12 +123,12 @@ import{r as i,j as t,c as oe,t as Cn}from"./index-h1qa1pbA.js";import{co as st,c
|
|
|
123
123
|
*
|
|
124
124
|
* This source code is licensed under the ISC license.
|
|
125
125
|
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const Wa=[["path",{d:"M12 5a3 3 0 1 1 3 3m-3-3a3 3 0 1 0-3 3m3-3v1M9 8a3 3 0 1 0 3 3M9 8h1m5 0a3 3 0 1 1-3 3m3-3h-1m-2 3v-1",key:"3pnvol"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["path",{d:"M12 10v12",key:"6ubwww"}],["path",{d:"M12 22c4.2 0 7-1.667 7-5-4.2 0-7 1.667-7 5Z",key:"9hd38g"}],["path",{d:"M12 22c-4.2 0-7-1.667-7-5 4.2 0 7 1.667 7 5Z",key:"ufn41s"}]],
|
|
126
|
+
*/const Wa=[["path",{d:"M12 5a3 3 0 1 1 3 3m-3-3a3 3 0 1 0-3 3m3-3v1M9 8a3 3 0 1 0 3 3M9 8h1m5 0a3 3 0 1 1-3 3m3-3h-1m-2 3v-1",key:"3pnvol"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["path",{d:"M12 10v12",key:"6ubwww"}],["path",{d:"M12 22c4.2 0 7-1.667 7-5-4.2 0-7 1.667-7 5Z",key:"9hd38g"}],["path",{d:"M12 22c-4.2 0-7-1.667-7-5 4.2 0 7 1.667 7 5Z",key:"ufn41s"}]],Za=y("flower-2",Wa);/**
|
|
127
127
|
* @license lucide-react v0.507.0 - ISC
|
|
128
128
|
*
|
|
129
129
|
* This source code is licensed under the ISC license.
|
|
130
130
|
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const
|
|
131
|
+
*/const Qa=[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"M12 16.5A4.5 4.5 0 1 1 7.5 12 4.5 4.5 0 1 1 12 7.5a4.5 4.5 0 1 1 4.5 4.5 4.5 4.5 0 1 1-4.5 4.5",key:"14wa3c"}],["path",{d:"M12 7.5V9",key:"1oy5b0"}],["path",{d:"M7.5 12H9",key:"eltsq1"}],["path",{d:"M16.5 12H15",key:"vk5kw4"}],["path",{d:"M12 16.5V15",key:"k7eayi"}],["path",{d:"m8 8 1.88 1.88",key:"nxy4qf"}],["path",{d:"M14.12 9.88 16 8",key:"1lst6k"}],["path",{d:"m8 16 1.88-1.88",key:"h2eex1"}],["path",{d:"M14.12 14.12 16 16",key:"uqkrx3"}]],Ja=y("flower",Qa);/**
|
|
132
132
|
* @license lucide-react v0.507.0 - ISC
|
|
133
133
|
*
|
|
134
134
|
* This source code is licensed under the ISC license.
|
|
@@ -258,7 +258,7 @@ import{r as i,j as t,c as oe,t as Cn}from"./index-h1qa1pbA.js";import{co as st,c
|
|
|
258
258
|
*
|
|
259
259
|
* This source code is licensed under the ISC license.
|
|
260
260
|
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
-
*/const
|
|
261
|
+
*/const Zo=[["path",{d:"M13 8c0-2.76-2.46-5-5.5-5S2 5.24 2 8h2l1-1 1 1h4",key:"foxbe7"}],["path",{d:"M13 7.14A5.82 5.82 0 0 1 16.5 6c3.04 0 5.5 2.24 5.5 5h-3l-1-1-1 1h-3",key:"18arnh"}],["path",{d:"M5.89 9.71c-2.15 2.15-2.3 5.47-.35 7.43l4.24-4.25.7-.7.71-.71 2.12-2.12c-1.95-1.96-5.27-1.8-7.42.35",key:"ywahnh"}],["path",{d:"M11 15.5c.5 2.5-.17 4.5-1 6.5h4c2-5.5-.5-12-1-14",key:"ft0feo"}]],Qo=y("tree-palm",Zo);/**
|
|
262
262
|
* @license lucide-react v0.507.0 - ISC
|
|
263
263
|
*
|
|
264
264
|
* This source code is licensed under the ISC license.
|
|
@@ -288,5 +288,5 @@ import{r as i,j as t,c as oe,t as Cn}from"./index-h1qa1pbA.js";import{co as st,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 cr=[["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"}]],lr=y("wind",cr),dr=({appVersion:e=null,slowWaitHintMs:s})=>{const n="https://local-operator.com/download",[a,o]=i.useState(!1),r=rn(a,s??ps),[u,d]=i.useState(!1),[c,m]=i.useState(null),[g,b]=i.useState("info"),[k,f]=i.useState(null),[x,E]=i.useState(null),S=e?.trim()?e.trim():null,H=i.useRef(!1),_=st(A=>A.openDetail),$=i.useRef(!1),I=i.useRef(0),M=i.useRef(!1),N=i.useCallback((A,T)=>{$.current=!1,m(A),b(T),d(!0)},[]),G=i.useCallback(A=>{$.current=!0,m(A),b("success"),d(!0)},[]),P=i.useCallback(()=>{$.current&&($.current=!1,d(!1),m(null))},[]),{clearDeferredUpdate:q}=Mn();i.useEffect(()=>{const A=window.api.updater.onUpdateError(R=>{H.current&&R.includes("manually")&&(f({message:"The server is installed outside the app, so use the tool you installed it with - uv, pipx or pip.",command:""}),$.current=!1,m(null),b("warning"),d(!0))}),T=window.api.updater.onBackendUpdateDevMode(R=>{H.current&&N(R,"info")}),V=()=>{M.current=!0,P()},z=window.api.updater.onUpdateAvailable(V),O=window.api.updater.onUpdateNpxAvailable(V),ee=window.api.updater.onBackendUpdateAvailable(V);return()=>{A(),T(),z(),O(),ee()}},[P,N]),i.useEffect(()=>{let A=!1;const T=()=>{window.api.updater.getLastInstallAttempt().then(z=>{A||E(z)}).catch(()=>{})};T();const V=window.api.updater.onUpdateInstallFailed(()=>T());return()=>{A=!0,V()}},[]);const K=async()=>{const A=++I.current;P(),M.current=!1;try{o(!0),H.current=!0,q(he.UI),q(he.BACKEND);const T=await window.api.updater.checkForAllUpdates({manual:!0});if(A!==I.current)return;T.app==="available"&&_(he.UI),T.server==="available"&&_(he.BACKEND),T?.affirmation&&!M.current?G(T.affirmation):P()}catch(T){if(A!==I.current)return;console.warn(`Update check failed; the app-level alert owns the report: ${gs(T)}`)}finally{A===I.current&&o(!1),setTimeout(()=>{H.current=!1},2e3)}},X=()=>{$.current=!1,d(!1),m(null)};return t.jsxs(t.Fragment,{children:[x&&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 ",x.targetVersion," didn't finish",x.attempts>1?` (${x.attempts} attempts)`:"",".",S?` Version ${S} is running.`:null]}),t.jsxs("p",{className:"mt-1 text-meta text-ink-dim",children:["Detected"," ",x.detectedAt?new Date(x.detectedAt).toLocaleString():"at an unknown time",". ",x.detail]}),t.jsx(D,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>void window.api.openExternal(n),children:"Download a fresh copy"})]}),t.jsxs(D,{variant:"outline",onClick:()=>void K(),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."}),k&&t.jsxs(St,{open:u,autoHideDuration:1e4,onClose:X,variant:"warning",children:[t.jsx("p",{className:"text-body-sm",children:k.message}),k.command&&t.jsx("code",{className:"mt-2 block rounded-sm bg-sunken p-2 text-mono-sm text-ink",children:k.command})]}),c&&g!=="danger"&&t.jsx(St,{open:u,autoHideDuration:6e3,onClose:X,variant:g,children:c})]})},He=["system-prompt"],ur=()=>{const{shouldEnableQuery:e}=An();return Ne({enabled:e({bypassInternetCheck:!0}),queryKey:He,queryFn:async()=>{try{const n=await Wt(mt.baseUrl).config.getSystemPrompt();if(n===null)return null;if(n.status>=400)throw new Error(n.message||"Failed to fetch system prompt");return n.result}catch(s){const n=s instanceof Error?s.message:"An unknown error occurred while fetching system prompt";throw Qt(n),s}},refetchOnWindowFocus:!1,staleTime:5e3})},mr=()=>{const e=Zt(),s=Wt(mt.baseUrl);return Rn({mutationFn:async n=>{try{const a=await s.config.updateSystemPrompt(n);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 Qt(o),a}},onSuccess:async n=>{await e.invalidateQueries({queryKey:He,refetchType:"none"}),e.setQueryData(He,a=>a&&{...a,...n}),await e.refetchQueries({queryKey:He,type:"all"}),Tn("System prompt updated")},onError:n=>{console.error("Error updating system prompt:",n)}})},hr=({value:e,label:s,description:n,onChange:a,icon:o,isSaving:r=!1})=>{const[u,d]=i.useState(e),c=i.useId(),m=`${c}-label`,g=`${c}-description`,b=async k=>{if(!r){d(k);try{await a(k)}catch(f){d(!k),console.error("Error toggling setting:",f)}}};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"}),s]}),n&&t.jsx("p",{id:g,className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:n})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:r?t.jsx(re,{size:"md",label:`Saving ${s}`}):t.jsx(Is,{checked:u,onCheckedChange:b,"aria-labelledby":m,"aria-describedby":n?g:void 0})})]})};function Ft(e,s){const n=ta(e,s?.in);if(!Xs(n))throw new RangeError("Invalid time value");const a=ve(n.getDate(),2),o=ve(n.getMonth()+1,2),r=n.getFullYear(),u=ve(n.getHours(),2),d=ve(n.getMinutes(),2),c=ve(n.getSeconds(),2);let m="",g="";const b=n.getTimezoneOffset();if(b!==0){const k=Math.abs(b),f=ve(Math.trunc(k/60),2),x=ve(k%60,2);g=`${b<0?"+":"-"}${f}:${x}`}else g="Z";return`${r}-${o}-${a}T${u}:${d}:${c}${m}${g}`}function fr(e,s,n){return Js(e,-30,n)}var pr=Ln({chartName:"LineChart",GraphicalChild:Jt,axisComponents:[{axisType:"xAxis",AxisComp:En},{axisType:"yAxis",AxisComp:In}],formatAxisMap:On});const gr=["radient","creditBalance"],yr=e=>{const{user:s,isAuthenticated:n}=ht(),a=s?.account?.tenant_id,o=n&&!!a&&e?.enabled;return Ne({queryKey:[gr,a],queryFn:async()=>{if(!a)throw new Error("Tenant ID not available");const r=await Xt({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})},xr=["radient","usageRollup"],kr=(e,s)=>{const{user:n,isAuthenticated:a}=ht(),o=n?.account?.tenant_id,r=a&&!!o&&s?.enabled;return Ne({queryKey:[...xr,o,e],queryFn:async()=>{if(!o)throw new Error("Tenant ID not available");const u={};for(const[c,m]of Object.entries(e))m!=null&&(u[c]=String(m));const d=await Xt({operation:"usage",tenantId:o,query:u});if(!d)throw new Error("Invalid usage rollup response format");return d},enabled:r,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},Dt={[he.UI]:"Application updates",[he.BACKEND]:"Server updates"},$t=({type:e})=>{const s=st(a=>a.followed[e]),n=st(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:Dt[e]}),t.jsx("div",{className:"mt-0.5 text-meta text-ink-muted",children:$e[s].description})]}),t.jsxs(Os,{value:s,onValueChange:a=>n(e,a),children:[t.jsx(Fs,{"aria-label":`${Dt[e]}: ${$e[s].label}`,className:"w-full sm:w-56","data-followed-segment":e,children:t.jsx(Ds,{})}),t.jsx($s,{children:Fn.map(a=>t.jsx(Us,{value:a,title:$e[a].description,children:$e[a].label},a))})]})]})},vr=()=>t.jsxs("div",{className:oe("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($t,{type:he.UI}),t.jsx($t,{type:he.BACKEND})]})]}),br=({appVersion:e})=>t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx(vr,{}),t.jsx(dr,{appVersion:e})]}),wr=e=>{if(!e)return null;try{return new URL(e).host}catch{return null}},jr=()=>{const[e,s]=i.useState(null),[n,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 d=!0;const c=f=>{if(!d)return;const x=wr(f.url);if(f.state==="connecting"){a({value:"Loading...",detail:null,degraded:!1});return}if(f.state==="detached"){a({value:"Not connected",detail:f.detail||null,degraded:!1});return}if(f.state==="wedged"){a({value:"Not attached",detail:f.detail||null,degraded:!1});return}const E=f.version||"Version unknown";a({value:x?`${E} · ${x}`:E,detail:f.detail||null,degraded:f.state==="degraded"})};let m=!1;const g=window.api?.backend?.onStatusChange(f=>{m=!0,c(f)}),b=async()=>{try{const[f,x]=await Promise.all([window.api.systemInfo.getAppVersion(),window.api.systemInfo.getPlatformInfo()]);d&&(s(f),r(x))}catch(f){console.error("Error fetching app information:",f)}},k=async()=>{try{const f=window.api?.backend;if(f){const S=await f.getStatus();m||c(S);return}const x=await Ct.healthCheck(mt.baseUrl),E=Ct.getServerVersion(x);d&&a({value:E,detail:null,degraded:!1})}catch(f){console.error("Error fetching server version:",f),d&&a({value:"Unavailable",detail:null,degraded:!1})}};return b(),k(),()=>{d=!1,g?.()}},[]);const u=(d,c,m,g={})=>t.jsx(ae,{label:t.jsx(Re,{content:m,children:t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(Ge,{size:12,className:"shrink-0"}),d]})}),valueClassName:g.valueClassName,value:t.jsxs(t.Fragment,{children:[g.valueTooltip?t.jsx(Re,{content:g.valueTooltip,children:t.jsx("span",{"data-backend-version":g.valueHoverTarget?"":void 0,children:c})}):c,g.statusNote?t.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:g.statusNote}):null]})});return t.jsx(se,{title:"Application updates and info",icon:Dn,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(pt,{children:[u("Application version",e??"Loading...","The version of the Local Operator user interface application."),u("Server version",n.value,"The version of the Local Operator API server backend, and the address of the daemon it was read from.",{valueTooltip:n.detail,valueHoverTarget:!0,statusNote:n.degraded?"Not answering":void 0,valueClassName:n.degraded?"text-ink-muted":void 0}),u("Platform",`${o.platform} (${o.arch})`,"The operating system and architecture your application is running on."),u("Node.js version",o.nodeVersion,"The JavaScript runtime environment version."),u("Electron version",o.electronVersion,"The framework version enabling this desktop application.")]}),t.jsx(br,{appVersion:e})]})})},_r=[[[".claude.json"],"Claude Code"],[[".claude",".mcp.json"],"Claude Code"],[[".cursor","mcp.json"],"Cursor"],[[".vscode","mcp.json"],"VS Code"],[[".codex","config.toml"],"Codex CLI"]];function un(e){if(!e)return null;const s=e.split("\\").join("/").split("/").filter(Boolean);for(const[n,a]of _r)if(!(s.length<n.length)&&s.slice(-n.length).join("/")===n.join("/"))return a;return null}const Be=e=>`${e} ${e===1?"tool":"tools"}`,Nr=e=>`${e} ${e===1?"integration":"integrations"}`,Sr=["connected","needs_sign_in","not_started","connecting","error"],mn=e=>Sr.includes(e),Ce=(e,s)=>[...s].filter(n=>n.name===e&&n.status==="running").sort((n,a)=>a.created_at-n.created_at)[0]??null,Cr={connectedAt:null,connectedToolCount:null,settledGroup:null,pinnedGroup:null,pinnedOperationId:null,needsKey:!1,needsSignIn:!1,disconnectedAt:null,holdUntil:null,lastDecisive:null},Mr=1e12,Ar=1e9,Rr=60*60*1e3,hn=(e,s=Date.now())=>{if(typeof e!="number"||!Number.isFinite(e))return null;const n=e>=Mr?e:e<Ar?null:e*1e3;return n===null||n>s+Rr?null:Math.min(n,s)},be=(e,s)=>e?.[s]??Cr,Le=(e,s,n)=>Er(e,s)??n?.lastDecisive??null,Tr=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}:{}}),gt=(e,s)=>e.status==="not_started"&&typeof e.tool_count=="number"&&(s.connectedAt!==null||e.status_basis==="stored"&&e.tool_count_basis==="last_seen"),Lr=(e,s)=>[...s].filter(n=>n.name===e).sort((n,a)=>a.created_at-n.created_at)[0]??null,Er=(e,s)=>Lr(e,s.filter(n=>n.status!=="cancelled")),qe=e=>e.actions.includes("set_key")||e.actions.includes("add_key");function Ir(e,s){const n=Math.max(0,Math.round((e-s)/1e3));if(n<60)return"just now";const a=Math.round(n/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 Xe(e){if(!e)return null;const s=e.trim();if(!s||/^\/\w/.test(s)||/\/mcp\s+\w+/.test(s))return null;let n=s;for(let a=0;a<3;a+=1){const o=n.replace(/^(?:connection (?:closed|error|refused)|error|closed|failed)\s*:\s*/i,"").trim();if(o===n)break;n=o}return n=n.replace(/\s*\(\s*\d{3}\s*\)/g,"").replace(/\s+([.,;])/g,"$1").replace(/\s{2,}/g," ").trim(),n||null}function Or(e,s=[],n,a=Date.now()){const o=be(n,e.name),r=Ce(e.name,s);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(!mn(e.status))return{label:"Status unavailable",tone:"neutral",detail:null,busy:!1};const u=Le(e.name,s,o),d=Ye(u)&&e.status!=="connected",c=gt(e,o),m=kt(u)&&e.status!=="connected",g=(u?.action==="login"||u?.action==="reauth")&&u.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 · ${Be(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"||Ae(e,s,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:Xe(e.status_reason),busy:!1};case"error":return{label:"Couldn't start",tone:"danger",detail:Xe(e.status_reason)??"No reason was given.",busy:!1};default:if(d)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(Ae(e,s,o))return{label:"Needs a key",tone:"warning",detail:null,busy:!1};if(g)return{label:"Sign-in didn't finish",tone:"warning",detail:null,busy:!1};if(o.needsSignIn)return{label:e.auth.kind==="api_key"||Ae(e,s,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:Xe(e.status_reason),busy:!1};if(e.status_basis==="stored"&&c&&o.disconnectedAt===null){const b=o.connectedAt??hn(e.last_seen_at,a);return{label:b!==null?`Worked ${Ir(a,b)} · ${Be(e.tool_count)}`:`Worked earlier · ${Be(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 fn=e=>e===1?"Replace the saved key":"Replace saved keys",Fr=/[,;]?\s*(?:or|and)?\s*add (?:its|a|the) key instead\.?\s*$/i;function Dr(e,s){const n=e?.trim()??"";if(!n)return null;if(s)return n;const a=n.replace(Fr,"").trim();return a?/\.$/.test(a)?a:`${a}.`:n}const $r="Nothing is wrong. It starts when a chat uses it.",Ur="Not running in this chat.",zr=e=>e.transport==="local_command"?"Local command":"Remote URL";function pn(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 un(e.source.path)}}function Pr(e,s){const n=[zr(e)];e.status!=="connected"&&e.tool_count_basis==="last_seen"&&typeof e.tool_count=="number"&&n.push(`${Be(e.tool_count)} when last checked`),s&&n.push(e.scope==="project"?"This project":"Global");const a=pn(e);return a?n.push(`Imported from ${a}`):e.source.editable||n.push("Imported from a project file"),n}const yt=(e,s)=>s.disconnectedAt!==null?"not_started":e.status;function xt(e,s=[],n){const a=be(n,e.name),o=Ce(e.name,s);if(o)return o.action==="login"||o.action==="reauth"?{kind:"sign_in",label:"Continue sign-in"}:null;const r=g=>e.actions.includes(g),u=qe(e),d=Ae(e,s,a);if(!mn(e.status))return r("test")?{kind:"test",label:"Check again"}:null;const c=Le(e.name,s,a),m=c?.status==="failed"&&Ee(c);switch(yt(e,a)){case"connected":case"connecting":return null;case"needs_sign_in":return d?{kind:"set_key",label:"Add key"}:r("sign_in")?{kind:"sign_in",label:"Sign in"}:u?{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(Ye(c)&&r("sign_in"))return{kind:"sign_in",label:"Sign in"};if(kt(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(d&&u)return{kind:"set_key",label:"Add key"};if(r("sign_in"))return{kind:"sign_in",label:"Sign in"}}return d&&u?{kind:"set_key",label:"Add key"}:m&&r("sign_in")?{kind:"sign_in",label:"Try again"}:gt(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 Ee=e=>e.action==="login"||e.action==="reauth",Ye=e=>!!(e&&e.action==="logout"&&e.status==="complete"),kt=e=>!!(e&&e.action==="logout"&&e.status!=="running"&&e.status!=="complete"),gn=/no oauth authorization server/i;function Ae(e,s,n){if(!qe(e))return!1;const a=Le(e.name,s,n);return a&&Ee(a)&&a.status==="failed"&&gn.test(a.message??"")?!0:n.needsKey}function Kr(e,s=[],n){const a=xt(e,s,n)?.kind,o=yt(e,be(n,e.name)),r=c=>e.actions.includes(c),u=[],d=Ce(e.name,s);if(d&&u.push({kind:"cancel",label:"Cancel"}),!d&&r("test")&&a!=="test"&&u.push({kind:"test",label:"Test connection"}),r("connect")&&a!=="connect"&&o!=="connected"&&u.push({kind:"connect",label:"Reconnect"}),!d&&r("sign_in")&&a!=="sign_in"&&o!=="connected"&&u.push({kind:"sign_in",label:"Sign in"}),r("reload")&&u.push({kind:"reload",label:"Reload"}),!d&&r("reauth")&&a!=="reauth"&&u.push({kind:"reauth",label:"Sign in again"}),qe(e)&&a!=="set_key"&&u.push({kind:"set_key",label:e.auth.secret_refs.length>0?"Update key":"Add key"}),r("sign_out")&&u.push({kind:"sign_out",label:"Sign out"}),r("disconnect")&&o==="connected"&&u.push({kind:"disconnect",label:"Disconnect"}),r("copy_setup")&&e.setup_prompt&&u.push({kind:"copy_setup",label:"Copy setup prompt"}),a!=="fix"&&u.push({kind:"open_config",label:"Open config file"}),r("remove"))u.push({kind:"remove",label:"Remove",destructive:!0});else if(!e.source.editable){const c=pn(e);u.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 u}const Hr={attention:"Needs attention",connected:"Connected",ready:"Available"};function yn(e,s=[],n){const a=be(n,e.name),o=Ce(e.name,s),r=yt(e,a);if(o&&a.pinnedGroup&&a.pinnedOperationId===o.id)return a.pinnedGroup;if(r==="needs_sign_in"||r==="error")return"attention";const u=Le(e.name,s,a);return Ye(u)&&r!=="connected"||kt(u)&&r!=="connected"?"attention":a.disconnectedAt!==null?"ready":Ae(e,s,a)||a.needsSignIn&&r!=="connected"||u?.status==="failed"&&Ee(u)&&r!=="connected"?"attention":r==="connected"||e.status_basis==="stored"&>(e,a)?"connected":o&&o.action!=="test"?"attention":"ready"}function Br(e,s=[],n){return["attention","connected","ready"].map(o=>({id:o,title:Hr[o],rows:e.filter(r=>yn(r,s,n)===o)})).filter(o=>o.rows.length>0)}function Vr(e,s,n=Date.now()){if(!s)return e??{};const a={};for(const o of s.servers){const r=be(e,o.name),u=Ce(o.name,s.operations),d=Le(o.name,s.operations,r),c=Ye(d),m=o.status==="connected"&&(o.status_basis==="probe"||o.status_basis==="live"),g=r.holdUntil!==null&&n<r.holdUntil,b=!g&&!c&&r.connectedAt===null&&o.status_basis==="stored"&&o.tool_count_basis==="last_seen"?hn(o.last_seen_at,n):null,k=!c,f=d?.status==="failed"&&Ee(d)&&gn.test(d.message??""),x={connectedAt:m&&!g?n:b!==null?b:k?r.connectedAt:null,connectedToolCount:m&&!g||b!==null?o.tool_count??r.connectedToolCount:k?r.connectedToolCount:null,settledGroup:r.settledGroup,pinnedGroup:u&&r.pinnedOperationId===u.id?r.pinnedGroup:u?r.settledGroup:null,pinnedOperationId:u?u.id:null,needsKey:m?!1:r.needsKey||f,needsSignIn:m||c?!1:r.needsSignIn||o.status==="needs_sign_in",disconnectedAt:m&&!g?null:r.disconnectedAt,holdUntil:g?r.holdUntil:null,lastDecisive:d?Tr(d):null};u||(x.settledGroup=yn(o,s.operations,{...a,[o.name]:x})),a[o.name]=x}return a}const Gr=(e,s)=>e!==null&&s===e,lt="local-operator.settings.integrations.row-memory",xn=(e,s)=>`${e}#${s}`;function qr(e,s){const n={};if(!s)return n;for(const a of s.servers){const o=e[a.name];o&&(n[xn(a.source.path,a.name)]=o)}return n}function Yr(e,s,n){if(!s)return e;let a=null;for(const o of s.servers){if(Object.prototype.hasOwnProperty.call(e,o.name))continue;const r=Zr(n[xn(o.source.path,o.name)]);r&&(a=a??{...e},a[o.name]=r)}return a??e}const Wr=["attention","connected","ready"],kn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),vt=e=>typeof e=="number"&&Number.isFinite(e)?e:null,Ut=e=>Wr.includes(e)?e:null,et=e=>{const s=vt(e);return s!==null&&s>=1e12?s:null};function Qr(e){if(!kn(e)||typeof e.id!="string"||typeof e.name!="string")return null;const s=e.action,n=e.status;return s!=="login"&&s!=="logout"&&s!=="reauth"&&s!=="test"||n!=="running"&&n!=="complete"&&n!=="cancelled"&&n!=="failed"?null:{id:e.id,name:e.name,action:s,status:n,created_at:vt(e.created_at)??0,credential_removed:e.credential_removed===!0,...typeof e.message=="string"?{message:e.message}:{}}}function Zr(e){if(!kn(e))return null;const s=et(e.connectedAt),n=et(e.disconnectedAt),a=e.needsKey===!0,o=e.needsSignIn===!0,r=Qr(e.lastDecisive);return s===null&&n===null&&!a&&!o&&!r?null:{connectedAt:s,connectedToolCount:vt(e.connectedToolCount),settledGroup:Ut(e.settledGroup),pinnedGroup:Ut(e.pinnedGroup),pinnedOperationId:typeof e.pinnedOperationId=="string"?e.pinnedOperationId:null,needsKey:a,needsSignIn:o,disconnectedAt:n,holdUntil:et(e.holdUntil),lastDecisive:r}}const vn=2e3,zt=8e3;function Jr(e){return e&&(e.servers.some(n=>n.status==="connecting")||e.operations.some(n=>n.status==="running"))?vn:!1}const Xr=/^[A-Za-z0-9_.:-]{1,100}$/,ei=/:\/\//;function ti(e,s){const n=e.trim();return n?Xr.test(n)?s.includes(n)?`An integration named ${n} already exists.`:null:"Use letters, numbers, dots, dashes, underscores or colons, with no spaces.":"Give it a name."}function ni(e){const s=e.trim();if(!s)return"Enter the server's URL.";let n;try{n=new URL(s)}catch{return"Enter a full URL, like https://mcp.example.com/mcp."}return n.protocol!=="https:"&&n.protocol!=="http:"?"The URL must start with https:// or http://.":n.hostname?n.username||n.password?"Remove the username or password from the URL. Keys are added after it's saved.":n.search||n.hash?"Remove the ? or # part of the URL. Keys are added after it's saved.":ei.test(s.slice(n.protocol.length+2))?"This looks like two URLs pasted together. Enter just one.":null:"The URL needs a host name."}const si=e=>e.split(`
|
|
292
|
-
`).map(s=>s.trim()).filter(Boolean);function dt(e,s){const n=!!e?.cold,a=(e?.servers??[]).map(o=>{const r=o.transport==="http",u=o.secret_refs??[],d=o.status==="connected"?"connected":o.status==="connecting"?"connecting":o.status==="auth-required"?"needs_sign_in":"not_started",c=[];d!=="connected"&&c.push("connect"),d==="connected"&&c.push("disconnect"),n||c.push("reload"),r&&o.transport_oauth_supported!==!1&&c.push("sign_in"),u.length>0&&c.push("set_key"),o.owned_scope&&c.push("remove"),o.setup?.text&&c.push("copy_setup");const m=un(o.source);return{id:o.name,name:o.name,scope:o.owned_scope??"global",project_cwd:null,source:{kind:ai(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:d,status_reason:null,status_observed_at:null,last_seen_at:null,status_basis:n?"stored":"live",auth:{kind:u.length?"api_key":r?"unknown":"none",signed_in:null,secret_refs:u.map(g=>({id:g.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:n?"config":"live",session_id:s,servers:a,operations:(e?.operations??[]).map(o=>({...o}))}}const ai=(e,s,n)=>s==="Claude Code"?"claude-code":s==="Cursor"?"cursor":s==="VS Code"?"vscode":s==="Codex CLI"?"codex":n?"local-operator":e?"project-mcp-json":"local-operator",Pt={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."},oi="The server refused it, so nothing was changed. Try again.";function Pe(e,s,n){if(s instanceof ft&&s.status===409){const a=typeof s.code=="string"&&Object.prototype.hasOwnProperty.call(Pt,s.code)?Pt[s.code]:oi;return`${$n[e]}. ${a}`}return Un(e,s,n).message}const ri="New chats can use it right away. Open chats pick it up when you start a new chat or reload integrations there.",ii="Most services give you a URL. Use Local command when their setup says npx or uvx.",ci=({existingNames:e,projectScopeAvailable:s,projectLabel:n,onSubmit:a,onCancel:o,initial:r})=>{const[u,d]=i.useState(r?.name??""),[c,m]=i.useState(r?.mode??"command"),[g,b]=i.useState(r?.command??""),[k,f]=i.useState(r?.args??""),[x,E]=i.useState(r?.url??""),[S,H]=i.useState("global"),[_,$]=i.useState(r?.touched?{name:!0,command:!0,url:!0}:{}),[I,M]=i.useState(!!r?.touched),[N,G]=i.useState(!1),[P,q]=i.useState(null),K=i.useRef(null),X=i.useRef(null),A=i.useRef(null);i.useEffect(()=>{K.current?.focus()},[]);const T=ti(u,e),V=c==="command"&&!g.trim()?"Enter the command to run.":null,z=c==="url"?ni(x):null,O=C=>I||_[C],ee=async C=>{if(C.preventDefault(),M(!0),T||V||z){T?K.current?.focus():V?X.current?.focus():A.current?.focus();return}G(!0),q(null);const Q=s?S:"global",Z=c==="command"?{name:u.trim(),scope:Q,mode:c,command:g.trim(),args:si(k)}:{name:u.trim(),scope:Q,mode:c,url:x.trim()},J=await a(Z);G(!1),q(J)},R=(C,Q,Z)=>Q&&O(Z)?t.jsx("p",{id:C,className:"text-body-sm text-danger",children:Q}):null,ie=C=>C.preventDefault();return t.jsxs("form",{noValidate:!0,"aria-label":"Add integration",className:"flex flex-col gap-4 rounded-lg bg-surface p-4",onSubmit:C=>void ee(C),onKeyDown:C=>{C.key==="Escape"&&(C.stopPropagation(),o())},children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-name",children:"Name"}),t.jsx(Se,{ref:K,id:"integration-add-name",value:u,placeholder:"e.g. notion",autoComplete:"off","aria-invalid":!!(T&&O("name")),"aria-describedby":T&&O("name")?"integration-add-name-error":void 0,onChange:C=>d(C.target.value),onBlur:()=>$(C=>({...C,name:!0}))}),R("integration-add-name-error",T,"name")]}),t.jsxs(Lt,{value:c,onValueChange:C=>m(C==="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(Et,{"aria-labelledby":"integration-add-transport-label",children:[t.jsx(ze,{value:"command","data-integration-transport":"command",children:"Local command"}),t.jsx(ze,{value:"url","data-integration-transport":"url",children:"Remote URL"})]}),t.jsx("p",{className:"text-ink-dim text-meta",children:ii}),t.jsxs(It,{value:"command",className:"mt-0 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-command",children:"Command"}),t.jsx(Se,{ref:X,id:"integration-add-command",value:g,placeholder:"e.g. npx",autoComplete:"off",className:"font-mono","aria-invalid":!!(V&&O("command")),"aria-describedby":V&&O("command")?"integration-add-command-error":void 0,onChange:C=>b(C.target.value),onBlur:()=>$(C=>({...C,command:!0}))}),R("integration-add-command-error",V,"command")]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs(fe,{htmlFor:"integration-add-args",children:["Arguments"," ",t.jsx("span",{className:"font-normal text-ink-dim",children:"(one per line)"})]}),t.jsx(cn,{id:"integration-add-args",value:k,rows:2,className:"font-mono",onChange:C=>f(C.target.value)})]})]}),t.jsx(It,{value:"url",className:"mt-0 flex flex-col gap-4",children:t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-url",children:"URL"}),t.jsx(Se,{ref:A,id:"integration-add-url",type:"url",value:x,placeholder:"https://mcp.example.com/mcp",autoComplete:"off",className:"font-mono","aria-invalid":!!(z&&O("url")),"aria-describedby":z&&O("url")?"integration-add-url-error":"integration-add-url-help",onChange:C=>E(C.target.value),onBlur:()=>$(C=>({...C,url:!0}))}),R("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."})]})})]}),s?t.jsxs(Lt,{value:S,onValueChange:C=>H(C==="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(Et,{"aria-labelledby":"integration-add-scope-label",children:[t.jsx(ze,{value:"global","data-integration-scope":"global",children:"All chats"}),t.jsx(ze,{value:"project","data-integration-scope":"project",children:"This project"})]}),n?t.jsx("p",{className:"text-ink-dim text-meta",children:S==="project"?`Only chats working in ${n}.`:"Every chat, in any folder."}):null]}):null,P?t.jsx("p",{className:"text-body-sm text-danger",role:"alert",children:P}):null,t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsx("p",{className:oe("text-body-sm text-ink-dim"),children:ri}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(D,{type:"button",variant:"ghost",size:"md",onMouseDown:ie,onClick:o,children:"Cancel"}),t.jsxs(D,{type:"submit",variant:"primary",size:"md",disabled:N,onMouseDown:ie,children:[N?t.jsx(re,{size:"xs"}):null,"Add integration"]})]})]})]})},li=4;function di(e){return e.rowMoving?e.now+e.windowMs:Math.max(e.hold.until,e.lastMovingAt+e.windowMs)}function ui(e){return e.now>e.hold.until||e.hold.reanchors>=li?"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 mi(e){const s=di({hold:e.hold,now:e.now,windowMs:e.windowMs,rowMoving:e.rowMoving,lastMovingAt:e.lastMovingAt});if(e.now>s)return{hold:null,land:null};const n=e.hold.landedOn??null,a=e.candidate;if(!a)return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},land:null};if(!n)return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:a},land:a};const o=ui({hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},candidate:a,active:e.active,body:e.body,now:e.now});if(o==="settled")return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},land:null};if(o==="drop")return{hold:null,land:null};const r=!n.isConnected;return{hold:{until:r?e.now+e.windowMs:s,reanchors:r?e.hold.reanchors+1:e.hold.reanchors,landedOn:a},land:a}}function hi(e){const{row:s,target:n}=e;return!s||!n||typeof n.nodeType!="number"?!1:!s.contains(n)}const Kt=250;function Ht(e){return e?!e.disabled:!1}function fi(e){return Ht(e.primary)?e.primary??null:Ht(e.overflow)?e.overflow??null:null}function pi(e){return e.verdict==="finished"?null:e.watchMs}const bn="key";function gi(e){const{name:s,keyless:n,freeName:a,names:o,values:r,replace:u,canReplace:d}=e;if(n){const c=ut(s,a);return{values:{[c]:(r[bn]??"").trim()},confirmedReplace:u&&d?[c]:[],header:a.trim()}}return{values:Object.fromEntries(o.map(c=>[c,(r[c]??"").trim()])),confirmedReplace:u&&d?o:[],header:void 0}}function ut(e,s){const n=Bt(e),a=Bt(s);if(!a)return"";const o=[n,a].filter(Boolean).join("_"),r=/^[A-Za-z_]/.test(o)?o:`K_${o}`;if(r.length<=tt)return r;const u=yi(n),d=tt-a.length-u.length-2,c=[n.slice(0,Math.max(d,0)),u,a].filter(Boolean).join("_");return c.length<=tt?c:c.slice(-128)}const tt=128,Bt=e=>e.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,""),yi=e=>{let s=2166136261;for(let n=0;n<e.length;n+=1)s^=e.charCodeAt(n),s=Math.imul(s,16777619)>>>0;return s.toString(36).toUpperCase().slice(0,5)},xi=({name:e,keyNames:s,keyless:n=!1,savedKeys:a=[],saving:o,failure:r,onSave:u,onClose:d})=>{const[c,m]=i.useState({}),[g,b]=i.useState(!1),[k,f]=i.useState(""),x=n?[ut(e,k)]:[...s],E=n?[bn]:x,S=(n?ut(e,k).length>0:!0)&&E.every(_=>(c[_]??"").trim()),H=x.some(_=>a.includes(_));return t.jsx(en,{open:!0,onClose:d,maxWidth:"xs",title:n||s.length===1?`Add the key for ${e}`:`Add keys for ${e}`,actions:t.jsxs(t.Fragment,{children:[t.jsx(at,{onClick:d,children:"Cancel"}),t.jsx(ot,{disabled:!S||o,onClick:()=>{const _=gi({name:e,keyless:n,freeName:k,names:x,values:c,replace:g,canReplace:H});u(_.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:n?"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."}),n?t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-key-name",children:"The header this server wants the key in"}),t.jsx(Se,{id:"integration-key-name",autoComplete:"off",placeholder:"e.g. Authorization or X-Api-Key",value:k,onChange:_=>f(_.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,E.filter(_=>n!==!0||_.trim().length>0).map(_=>t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:`integration-key-${_}`,className:"font-mono",children:n?"Key":_}),t.jsx(Se,{id:`integration-key-${_}`,type:"password",autoComplete:"off",value:c[_]??"",onChange:$=>m(I=>({...I,[_]:$.target.value}))})]},_)),H?t.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[t.jsx(zs,{id:"integration-key-replace",checked:g,onCheckedChange:_=>b(_===!0)}),t.jsx(fe,{htmlFor:"integration-key-replace",className:"font-normal",children:fn(x.length)})]}):null,r?t.jsx("p",{className:"-mx-1.5 text-body-sm text-danger",role:"alert",children:r}):null]})})},ki={success:"bg-success",warning:"bg-warning",danger:"bg-danger",info:"bg-info",neutral:"bg-ink-dim"},vi={success:"text-ink-muted",warning:"text-warning",danger:"text-danger",info:"text-ink-muted",neutral:"text-ink-dim"},Vt={Ready:$r,"Not connected":Ur},bi=({row:e,operations:s,memories:n,now:a,projectScopeAvailable:o,highlighted:r=!1,rowRef:u,primaryRef:d,overflowRef:c,pending:m,failure:g,confirm:b,onPrimary:k,onOverflow:f,onConfirm:x,onCancelConfirm:E})=>{const S=Or(e,s,n,a),H=r&&S.tone==="danger"?"text-ink":vi[S.tone],_=xt(e,s,n),$=Kr(e,s,n),I=Pr(e,o),M=$.findIndex(N=>N.kind==="remove"||N.kind==="remove_elsewhere");return t.jsxs("li",{ref:u,"data-integration":e.name,"data-status":e.status,className:oe("flex min-h-14 flex-col justify-center gap-1 px-4 py-2.5",r&&"bg-row-selected"),onKeyDown:N=>{!b||N.key!=="Escape"||(N.stopPropagation(),E())},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:S.busy?t.jsx(re,{size:"xs"}):t.jsx("span",{"aria-hidden":"true","data-tone":S.tone,className:oe("size-2 rounded-full",ki[S.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:I.map((N,G)=>t.jsxs("span",{children:[G>0?" · ":null,N.startsWith("Imported from")&&e.source.path?t.jsx(Re,{content:zn(e.source.path),children:t.jsx("span",{className:"underline decoration-dotted underline-offset-2",children:N})}):N]},N))})]}),Vt[S.label]?t.jsx(Re,{content:Vt[S.label],children:t.jsx("span",{className:oe("shrink-0 text-body-sm",H),children:S.label})}):t.jsx("span",{className:oe("shrink-0 text-body-sm",H),children:S.label}),_?t.jsxs(D,{ref:d,variant:_.variant??"secondary",size:"sm","aria-label":`${_.label} ${e.name}`,disabled:m,"data-integration-action":_.kind,onClick:()=>k(_),children:[m?t.jsx(re,{size:"xs"}):null,_.label]}):null,t.jsxs(Ps,{children:[t.jsx(Ks,{asChild:!0,children:t.jsx(D,{ref:c,variant:"ghost",size:"icon-sm","aria-label":`More actions for ${e.name}`,disabled:m,children:t.jsx(Pn,{"aria-hidden":"true"})})}),t.jsx(Hs,{align:"end",className:"min-w-48",children:$.map((N,G)=>t.jsx(wi,{item:N,separated:G===M&&G>0,onSelect:()=>f(N)},N.kind))})]})]}),S.detail?t.jsx("p",{className:oe("pl-7 text-body-sm",S.tone==="danger"?"text-ink-muted":"text-ink-dim"),children:S.detail}):null,g?t.jsx("p",{className:oe("pl-7 text-body-sm",r?"text-ink":"text-danger"),role:"alert",children:g}):null,b?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-7",children:[t.jsx("span",{className:"text-body-sm text-ink",children:b.kind==="remove"?`Remove ${e.name}?`:`Sign out of ${e.name}?`}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:b.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(D,{variant:"danger",size:"sm",onClick:x,"data-integration-confirm":b.kind,children:b.kind==="remove"?"Remove":"Sign out"}),t.jsx(D,{variant:"ghost",size:"sm",onClick:E,children:"Keep"})]}):null]})},wi=({item:e,separated:s,onSelect:n})=>t.jsxs(t.Fragment,{children:[s?t.jsx(Bs,{}):null,e.kind==="remove_elsewhere"?t.jsxs(Ot,{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(Ot,{destructive:e.kind==="remove",onSelect:n,"data-integration-menu":e.kind,children:e.label})]});function ji(e,s,n){return!s||s.status==="running"?s?.browser_opened===!0?{message:`Your browser opened. Approve access to ${e} there, then come back here.`,tone:"progress",link:s.authorization_url??null}:s?.browser_opened===!1?{message:s.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:s.authorization_url??null}:{message:`Waiting for you to approve access to ${e}…`,tone:"progress",link:s?.authorization_url??null}:s.status==="complete"?{message:`Signed in to ${e}. Agents can use it now.`,tone:"success",link:null}:s.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:Dr(s.message,n)??"The server didn't say why.",nextStep:_i(s.message??null,n)}}function _i(e,s){const n=(e??"").toLowerCase();return n.includes("redirect")?s?"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.":n.includes("no oauth")||n.includes("authorization server")?s?"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.":n.includes("network")||n.includes("connect")?"Check the server's URL and your network, then try again.":"Check the server's settings, then try again."}function Ni(e,s){return e.kind==="ready"?"ready":e.kind==="running"&&s&&s.tone!=="progress"?s.tone==="success"?"success":"failure":"running"}const Si=({name:e,action:s,keyRoute:n,phase:a,onStart:o,onCancel:r,onOpenLink:u,onClose:d})=>{const c=a.kind==="running"?a.operation:null,m=a.kind==="running"?ji(e,c,n):null,g=a.kind==="starting"||a.kind==="running"&&m?.tone==="progress",b=m&&m.tone!=="progress",k=i.useRef(null),f=i.useRef(!1),x=Ni(a,m);i.useEffect(()=>{if(!f.current){f.current=!0;return}x&&k.current?.focus()},[x]);const E=()=>d(m?.tone==="success"?"signed-in":"dismissed");return t.jsx(en,{open:!0,onClose:E,maxWidth:"xs",fullWidth:!0,title:`Sign in to ${e}`,dialogProps:{onOpenAutoFocus:S=>{S.preventDefault(),k.current?.focus()}},actions:t.jsxs(t.Fragment,{children:[g&&c?t.jsx(at,{ref:k,onClick:()=>r(c.id),children:"Cancel sign-in"}):t.jsx(at,{ref:a.kind==="ready"?void 0:k,onClick:E,children:m?.tone==="success"?"Done":"Close"}),a.kind==="ready"?t.jsx(ot,{ref:k,onClick:o,children:"Continue in browser"}):null,a.kind==="refused"||m?.tone==="failure"?t.jsx(ot,{ref:m?.tone==="failure"?k: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,".",s==="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:b?"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(Vs,{"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(D,{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(()=>rt("Sign-in link copied.")).catch(()=>{})},children:t.jsx(Kn,{"aria-hidden":"true"})})]}),t.jsx(D,{variant:"link",size:"sm",onClick:()=>u(m.link??""),children:"Open the sign-in page"})]}):null,a.kind==="refused"?t.jsx("p",{className:"text-danger",role:"alert",children:a.message}):null]})})},Ci=e=>e.reduce((s,n)=>s?(n.updated_at??0)>(s.updated_at??0)?n:s:n,null),Mi=/^[A-Za-z]:[\\/]/,Ve=e=>{const s=e?.trim();return s&&(s.startsWith("/")||Mi.test(s))?s:null};function Ai(e){const o=e?.payload?.frontend?.snapshot?.cwd;return typeof o=="string"&&o.trim()?o:null}const Te="local-operator.settings.integrations.last-cwd";function Ri(e,s,n=typeof localStorage>"u"?null:localStorage){const a=Ve(s);if(!(!e||!a||!n))try{const o=n.getItem(Te),r=o?JSON.parse(o):{};if(r[e]===a)return;n.setItem(Te,JSON.stringify({...r,[e]:a}))}catch{}}const wn=()=>typeof localStorage>"u"?null:localStorage;function jn(e=wn()){if(!e)return{};try{const s=e.getItem(lt);if(!s)return{};const n=JSON.parse(s);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}const Gt=256;function Ti(e,s=wn()){if(s)try{const n={...jn(s),...e},a=Object.keys(n);if(a.length>Gt){const o={};for(const r of a.slice(-Gt))o[r]=n[r];s.setItem(lt,JSON.stringify(o));return}s.setItem(lt,JSON.stringify(n))}catch{}}function qt(e,s,n){return e==="saved"?null:e==="replace_confirmation_required"?`A saved value already exists for this key. Tick “${fn(Object.keys(n).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: ${(s.length?s:Object.keys(n)).join(", ")}. The encrypted store may be locked.`}function Li(e,s=typeof localStorage>"u"?null:localStorage){if(!(!e||!s))try{const n=s.getItem(Te);if(!n)return;const a=JSON.parse(n);if(!(e in a))return;const o={...a};delete o[e],s.setItem(Te,JSON.stringify(o))}catch{}}const Ei=e=>!!(e&&typeof e=="object"&&"code"in e&&e.code==="invalid_cwd"),Ii=(e,s)=>s!==null&&e===s?null:e;function Oi(e,s=typeof localStorage>"u"?null:localStorage){if(!e||!s)return null;try{const n=s.getItem(Te);if(!n)return null;const o=JSON.parse(n)[e];return typeof o=="string"?o:null}catch{return null}}const Fi=e=>e.action==="disconnect"?"disconnected":"connected";function Di(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 $i(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 Ui({sessionId:e}){const s=Hn(),n=Mt(s.data,"mcp_catalog"),a=Mt(s.data,"mcp"),o=n?"catalog":a?"session":null,[r,u]=i.useState(null),d=Zt(),c=Ke(h=>h.sessions),m=Ke(h=>h.fetchSessions),g=Ke(h=>h.loading),b=i.useMemo(()=>c.find(h=>h.session_id===e)??null,[c,e]),k=i.useMemo(()=>o==="session"&&!e?Ci(c):null,[o,e,c]),f=o==="session"?e??k?.session_id??null:null;i.useEffect(()=>{o!=="session"||e||c.length>0||m(Bn)},[o,e,c.length,m]);const x=o==="catalog"?Ve(b?.cwd):null,E=o==="catalog"&&!!e&&x===null,S=Ne({queryKey:["desktop","session-cwd",e??""],queryFn:()=>Ue({op:"sessions.get",sessionId:e??""}),enabled:E,staleTime:Number.POSITIVE_INFINITY,retry:!1}),H=E&&!S.isFetched,_=x??Ve(Ai(S.data))??(S.isFetched?Ve(Oi(e)):null),$=Ii(_,r),I=o==="catalog"?$:null,M=o==="catalog"?e??null:null,N=Vn.catalog(I,M);i.useEffect(()=>{o!=="catalog"||!e||!I||Ri(e,I)},[o,e,I]);const G=i.useRef(0),[P,q]=i.useState(0),K=i.useRef(null),X=i.useCallback((h,w)=>{const v=Date.now()+zt;G.current=v,K.current={name:h,expect:w},q(v)},[]),A=i.useCallback(h=>Date.now()<G.current?vn:Jr(h),[]),T=Ne({queryKey:N,queryFn:()=>Yn(I,M),enabled:o==="catalog"&&!H,staleTime:1e4,refetchInterval:h=>A(h.state.data)}),V=Ei(T.error);i.useEffect(()=>{!V||!_||r===_||(u(_),Li(e))},[V,_,r,e]);const z=Ne({queryKey:it.list(f??""),queryFn:()=>Wn(f??""),enabled:o==="session"&&!!f,staleTime:1e4,refetchInterval:h=>A(h.state.data?dt(h.state.data,f??""):void 0)}),O=i.useMemo(()=>{if(o==="catalog")return T.data;if(o==="session"&&z.data&&f)return dt(z.data,f)},[o,T.data,z.data,f]),ee=i.useCallback(()=>zi({queryClient:d,route:o,catalogKey:N,sessionId:f}),[o,N,d,f]);i.useEffect(()=>{if(!P)return;const h=K.current;if(!h)return;const w=O?.servers.find(U=>U.name===h.name);!w||!(h.expect==="connected"?w.status==="connected":w.status_basis==="live"&&w.status!=="connected")||(G.current=0,K.current=null,q(0))},[O,P]);const R=i.useRef({}),[ie,C]=i.useState(0),Q=i.useMemo(()=>(R.current=Vr(Yr(R.current,O,jn()),O),R.current),[O,ie]),Z=i.useRef("");i.useEffect(()=>{const h=qr(Q,O);if(!Object.keys(h).length)return;const w=JSON.stringify(h);w!==Z.current&&(Z.current=w,Ti(h))},[Q,O]);const J=i.useCallback(h=>{const w=be(R.current,h);w.needsKey||(R.current={...R.current,[h]:{...w,needsKey:!0}},C(v=>v+1))},[]),Y=i.useCallback(h=>{if(h.action!=="disconnect"&&h.action!=="connect"&&h.action!=="reload")return;const w=be(R.current,h.name),v=Date.now()+zt,U=h.action==="disconnect"?{...w,connectedAt:null,disconnectedAt:Date.now(),holdUntil:v}:{...w,disconnectedAt:null,holdUntil:v};R.current={...R.current,[h.name]:U},X(h.name,Fi(h)),C(F=>F+1)},[X]),W=i.useCallback(async h=>{if(o==="catalog"){const w=Di(h);if(!w)return null;try{const v=await Gn(I,w);return d.setQueryData(N,v),Y(h),v.operation?.id??null}catch(v){throw v instanceof ft&&v.status===409&&d.invalidateQueries({queryKey:N}),v}}if(o==="session"&&f){const w=await Ue({op:"mcp.control",sessionId:f,control:$i(h)});Y(h);const v=it.list(f),U=w?.data;return U&&"servers"in U&&Array.isArray(U.servers)?(d.setQueryData(v,U),null):(d.invalidateQueries({queryKey:v}),U&&"id"in U&&typeof U.id=="string"?U.id:null)}return null},[o,I,N,d,f,Y]),pe=i.useCallback(async h=>{if(o==="catalog"&&M&&(h.action==="connect"||h.action==="disconnect"||h.action==="reload")){try{await Ue({op:"mcp.control",sessionId:M,control:{action:h.action,name:h.name,...h.action==="disconnect"?{confirmed:!0}:{}}})}catch(w){throw d.invalidateQueries({queryKey:N}),w}return Y(h),await d.invalidateQueries({queryKey:N}),null}return W(h)},[o,M,d,N,W,Y]),we=i.useCallback(async(h,w,v,U)=>{if(o==="catalog"){const F=await qn(I,h,w,v,U);if(F.catalog&&d.setQueryData(N,F.catalog),F.code!=="saved")return{saved:!1,message:qt(F.code,F.failed_ids,w)};try{await W({action:"test",name:h})}catch{}return{saved:!0,message:null}}if(o==="session"&&f){const F=await Ue({op:"mcp.credentials.store",sessionId:f,name:h,values:w,confirmedReplace:v});if(F.data?.code!=="saved")return{saved:!1,message:qt(F.data?.code,F.data?.failed_ids??[],w)};try{await W({action:"connect",name:h})}catch{}return{saved:!0,message:null}}return{saved:!1,message:null}},[o,I,N,d,W,f]),de=o==="catalog"?T:z,ge=i.useCallback(()=>{de.refetch()},[de]);return{enabled:o!==null,route:o,sessionId:o==="catalog"?M:f,borrowed:k,noConversation:o==="session"&&!f&&!g,document:O,isLoading:s.isLoading||o==="catalog"&&(H||T.isLoading)||o==="session"&&(f?z.isLoading:g),isError:de.isError,folderUnavailable:Gr(r,_),refetch:ge,readDocument:ee,control:pe,storeKeys:we,memories:Q,markNeedsKey:J}}function zi(e){if(e.route==="catalog")return e.queryClient.getQueryData(e.catalogKey);if(e.route==="session"&&e.sessionId){const s=e.queryClient.getQueryData(it.list(e.sessionId));return s?dt(s,e.sessionId):void 0}}const Pi=(e,s)=>{const n=e?.trim();if(!n)return null;const a=Xn(n,s);return a.kind==="auth"?{kind:"matched",name:a.name,unresolved:null}:{kind:"miss",asked:n}},Ki=6,nt="Integrations",Hi="Let agents use your tools and accounts, like Notion, Linear or GitHub.",Bi={test:"test",connect:"reconnect",disconnect:"disconnect",reload:"reload",remove:"remove",sign_out:"disconnect",cancel:"cancel",login:"grant",reauth:"grant"},Vi=({sessionId:e,sectionRef:s,highlightServer:n})=>{const a=Ui({sessionId:e}),{document:o,control:r,readDocument:u}=a,d=Qn(),c=o?.servers??[],m=o?.operations??[],g=o?.project_scope_available??!1,[b,k]=i.useState(!1),[f,x]=i.useState(""),[E,S]=i.useState(null),[H,_]=i.useState({}),[$,I]=i.useState(null),[M,N]=i.useState(null),[G,P]=i.useState({kind:"ready"}),[q,K]=i.useState(null),[X,A]=i.useState(null),[T,V]=i.useState(!1),z=i.useRef({}),O=i.useRef({}),ee=i.useRef({}),R=i.useRef(0),ie=i.useRef(null),C=i.useRef(null),Q=i.useRef(null),[Z,J]=i.useState(null),[Y,W]=i.useState(null),[pe,we]=i.useState(null),de=i.useCallback(()=>{const l=Q.current;Q.current=null,N(null),K(null),window.setTimeout(()=>{l?.isConnected&&l.focus()},0)},[]),ge=i.useCallback(l=>{const p=window.document.activeElement;Q.current=p instanceof HTMLElement?p:null,N(l)},[]),h=i.useCallback((l,p)=>{W({name:l,waitForSignIn:p==="signed-in",until:Date.now()+Me,reanchors:0}),de()},[de]),w=i.useMemo(()=>Pi(n,c.map(l=>l.name)),[n,c]),v=w?.kind==="matched"?w.name:null,U=i.useRef(null),F=i.useRef(null),te=f.trim().toLowerCase(),B=i.useMemo(()=>te?c.filter(l=>l.name.toLowerCase().includes(te)):c,[c,te]),je=i.useMemo(()=>Br(B,m,a.memories),[B,m,a.memories]),ue=M?.kind==="sign_in"?c.find(l=>l.name===M.name)??null:null;i.useEffect(()=>{!v||F.current===v||!f||x("")},[v,f]),i.useEffect(()=>{!v||F.current===v||B.some(l=>l.name===v)&&(F.current=v,U.current?.scrollIntoView({block:"center",behavior:"smooth"}))},[v,B]),i.useEffect(()=>{if(!q)return;const l=m.find(p=>p.id===q)??null;P({kind:"running",operation:l})},[m,q]);const ce=m.some(l=>l.status==="running"),ye=l=>{const p=window.document.activeElement;p&&p!==window.document.body&&p.isConnected||W({name:l,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})},ne=async(l,p,j)=>{S(l),_(({[l]:xe,...ke})=>ke);let L=null,me=!1;try{L=await j()}catch(xe){me=!0,_(ke=>({...ke,[l]:Pe(Bi[p]??"status",xe,ce)}))}finally{S(null),p!=="sign_out"&&(p!=="remove"||me)&&ye(l)}return{operationId:L,failed:me}},We=l=>c.find(p=>p.name===l),Ie=l=>{l.source.path&&es(l.source.path)},Qe=async(l,p)=>{P({kind:"starting"}),K(null);try{const j=await r({action:p,name:l});j?K(j):P({kind:"running",operation:null})}catch(j){j instanceof ft&&j.code==="oauth_unsupported"&&a.markNeedsKey(l),P({kind:"refused",message:Pe("grant",j,ce)})}},Oe=(l,p)=>{switch(p.kind){case"sign_in":case"reauth":{const j=m.find(L=>L.name===l.name&&L.status==="running");j&&Ee(j)?(P({kind:"running",operation:j}),K(j.id)):(P({kind:"ready"}),K(null)),ge({kind:"sign_in",name:l.name,action:p.kind==="reauth"?"reauth":"login"});return}case"set_key":A(null),ge({kind:"key",name:l.name,keyNames:l.auth.secret_refs.map(j=>j.id)});return;case"fix":Ie(l);return;case"sign_out":I({name:l.name,kind:"sign_out"});return;default:{const j=p.kind;ne(l.name,j,()=>r({action:j,name:l.name}))}}},bt=(l,p)=>{switch(p.kind){case"remove":case"sign_out":I({name:l.name,kind:p.kind});return;case"sign_in":case"reauth":case"set_key":Oe(l,{kind:p.kind,label:p.label});return;case"open_config":Ie(l);return;case"copy_setup":navigator.clipboard.writeText(l.setup_prompt??"").then(()=>rt("Setup steps copied. Paste them into a chat.")).catch(()=>{});return;case"cancel":{const j=m.find(L=>L.name===l.name&&L.status==="running");j&&ne(l.name,"cancel",()=>r({action:"cancel",operationId:j.id}));return}case"test":case"connect":case"disconnect":case"reload":{const j=p.kind;ne(l.name,j,()=>r({action:j,name:l.name}));return}default:return}},Fe=(l,p)=>{if(I(null),p==="remove"){const j=l.source.owned_scope;if(!j)return;const L=B.findIndex(me=>me.name===l.name);ne(l.name,"remove",()=>r({action:"remove",name:l.name,scope:j})).then(({operationId:me,failed:xe})=>{xe||me!==null||(rt(`Removed ${l.name}.`),L>=0&&we({index:L}))});return}ne(l.name,"sign_out",()=>r({action:"logout",name:l.name})).then(()=>{W({name:l.name,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})})},De=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}}),k(!1),J(l.name),null}catch(p){return Pe("add",p,!1)}},wt=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:nt}),t.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:Hi})]}),a.enabled&&c.length>0&&!b?t.jsxs(D,{ref:ie,variant:"secondary",size:"sm",onClick:()=>k(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(At,{"aria-hidden":"true"}),"Add integration"]}):null]});if(!a.enabled&&!a.isLoading)return t.jsx(se,{title:nt,titleComponent:wt,sectionRef:s,children:t.jsx(le,{variant:"warning",children:"Integrations need a newer Local Operator backend. Update it and restart the app to manage them here."})});const jt=t.jsx(ci,{existingNames:c.map(l=>l.name),projectScopeAvailable:g,projectLabel:o?.cwd?qi(o.cwd):null,onSubmit:De,onCancel:()=>{k(!1),window.setTimeout(()=>ie.current?.focus(),0)}}),_t=M?We(M.name):void 0,_n=Object.entries(H).filter(([l])=>!c.some(p=>p.name===l)),Nn=l=>_(({[l]:p,...j})=>j);i.useEffect(()=>{if(!Z)return;const l=z.current[Z];if(!l){c.some(p=>p.name===Z)&&(O.current[Z]?.focus(),J(null));return}l.focus(),J(null)},[Z,c]),i.useEffect(()=>{if(!pe)return;const p=B[Math.min(pe.index,B.length-1)]??B.at(-1);if(p){const j=z.current[p.name]??O.current[p.name];if(!j)return;j.focus()}else ie.current?.focus();we(null)},[pe,B]);const Ze=i.useCallback((l,p)=>{const j=u()??o,L=j?.servers.find(Sn=>Sn.name===l.name),me=j?.operations??[],xe=L?L.status==="connecting"||Ce(L.name,me)!==null:!1;xe&&L&&(R.current=p);const ke=L?xt(L,me,a.memories):null;if(L&&l.waitForSignIn&&(ke?.kind==="sign_in"||ke?.kind==="reauth"))return"kept";const _e=mi({hold:l,now:p,windowMs:Me,rowMoving:xe,lastMovingAt:R.current,candidate:L?fi({primary:ke?z.current[L.name]:null,overflow:O.current[L.name]}):void 0,active:window.document.activeElement,body:window.document.body});if(!_e.hold)return W(null),"finished";if(!_e.land)return"kept";W({name:l.name,waitForSignIn:!1,until:_e.hold.until,landedOn:_e.land,reanchors:_e.hold.reanchors});const Nt=_e.land;return window.setTimeout(()=>{Nt.isConnected&&Nt.focus()},0),"landed"},[u,o,a.memories]);return i.useEffect(()=>{if(!Y)return;Ze(Y,Date.now());let l=0,p=!1;const j=()=>{if(p)return;const L=pi({verdict:Ze(Y,Date.now()),watchMs:Kt});L!==null&&(l=window.setTimeout(j,L))};return l=window.setTimeout(j,Kt),()=>{p=!0,window.clearTimeout(l)}},[Y,Ze]),i.useEffect(()=>{if(!Y)return;const l=p=>{hi({target:p.target,row:ee.current[Y.name]})&&W(null)};return window.document.addEventListener("pointerdown",l,!0),()=>{window.document.removeEventListener("pointerdown",l,!0)}},[Y]),t.jsxs(se,{title:nt,titleComponent:wt,sectionRef:s,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(D,{variant:"primary",size:"sm",onClick:()=>d("/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(le,{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(le,{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(D,{variant:"secondary",size:"sm",onClick:a.refetch,children:"Retry"})]})}):null,_n.map(([l,p])=>t.jsx(le,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:p}),t.jsx(D,{variant:"ghost",size:"sm",onClick:()=>Nn(l),children:"Dismiss"})]})},l)),b&&c.length>0?jt:null,c.length>=Ki?t.jsxs("div",{className:"relative",children:[t.jsx(Zn,{"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-dim"}),t.jsx(Se,{ref:C,value:f,onChange:l=>x(l.target.value),onKeyDown:l=>{l.key!=="Escape"||!f||(l.preventDefault(),x(""))},placeholder:`Search ${Nr(c.length)}`,"aria-label":"Search integrations",className:"pl-9"})]}):null,w?.kind==="miss"&&c.length>0?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`No integration matches "${w.asked}".`}):null,w?.kind==="matched"&&w.unresolved?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`Showing "${w.name}" — "${w.unresolved}" is not one of your integrations.`}):null,o&&c.length===0&&!a.isLoading?b?jt:t.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-lg bg-surface p-6",children:[t.jsx(tn,{"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(D,{variant:"primary",size:"md",onClick:()=>k(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(At,{"aria-hidden":"true"}),"Add integration"]})]}):null,c.length>0&&B.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(D,{variant:"secondary",size:"sm",onClick:()=>{x(""),window.setTimeout(()=>{(C.current??ie.current)?.focus()},0)},children:"Clear search"})]}):null,je.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(p=>t.jsx(bi,{row:p,operations:m,memories:a.memories,projectScopeAvailable:g,highlighted:p.name===v,rowRef:j=>{ee.current[p.name]=j,p.name===v&&(U.current=j)},primaryRef:j=>{z.current[p.name]=j},overflowRef:j=>{O.current[p.name]=j},pending:E===p.name,failure:H[p.name]??null,confirm:$?.name===p.name?{kind:$.kind}:null,onPrimary:j=>Oe(p,j),onOverflow:j=>bt(p,j),onConfirm:()=>$&&Fe(p,$.kind),onCancelConfirm:()=>{I(null),window.setTimeout(()=>{O.current[p.name]?.focus()},0)}},p.id))})]},l.id))]}),M?.kind==="sign_in"?t.jsx(Si,{name:M.name,action:M.action,keyRoute:ue?qe(ue):!1,phase:G,onStart:()=>void Qe(M.name,M.action),onCancel:l=>void r({action:"cancel",operationId:l}).catch(()=>{}),onOpenLink:l=>void Jn(l),onClose:l=>h(M.name,l)}):null,M?.kind==="key"?t.jsx(xi,{name:M.name,keyNames:M.keyNames.length?M.keyNames:_t?.auth.secret_refs.map(l=>l.id)??[],keyless:M.keyNames.length===0,savedKeys:_t?.auth.secret_refs.filter(l=>l.state==="encrypted").map(l=>l.id),saving:T,failure:X,onClose:de,onSave:(l,p,j)=>{V(!0),A(null),a.storeKeys(M.name,l,p,j).then(L=>{if(!L.saved){A(L.message);return}N(null),W({name:M.name,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})}).catch(L=>A(Pe("key",L,!1))).finally(()=>V(!1))}}):null]})},Me=4e3,Gi=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,qi=e=>e.replace(Gi,"~"),Yi=e=>typeof e!="number"||!Number.isFinite(e)?"your free credits":`$${e.toFixed(2)} in free credits`,Wi="https://console.radienthq.com/dashboard/verification",Qi=(e,s)=>e==="pending"?{sentence:`Verify your email to claim ${s}. Check your inbox for the link Radient sent.`,action:"Open verification page"}:e==="expired"?{sentence:`The link to claim ${s} 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"},Zi=({verification:e})=>{const{prices:s}=xs(),n=e.grant_amount??s?.default_new_credits,{sentence:a,action:o}=Qi(e.signup_grant,Yi(n)),r=e.claim_url||Wi;return t.jsxs("div",{className:"mt-8 flex items-start gap-3 rounded-sm border border-hairline bg-surface p-3",children:[t.jsx(Ge,{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(D,{variant:"secondary",size:"sm",onClick:()=>{window.api?.openExternal?window.api.openExternal(r):window.open(r,"_blank")},children:o})]})]})},Ji=({onAfterCredentialUpdate:e})=>{const{isAuthenticated:s,user:n,isLoading:a,accountRead:o,signOut:r}=ts(),u=nn(b=>b.isSigningOut),d=i.useCallback(async()=>{try{await r()}catch(b){console.error("Error signing out:",b)}},[r]),c=i.useMemo(()=>{if(!s||!n?.radientUser)return null;const{account:b,identity:k,verification:f}=n.radientUser,x=f!=null&&!f.email_verified&&f.signup_grant!=="claimed";return t.jsxs(t.Fragment,{children:[t.jsxs(pt,{children:[t.jsx(ae,{label:"Status",value:t.jsxs("span",{className:"inline-flex items-center gap-2",children:["Connected",t.jsx(Gs,{variant:"success",className:"capitalize",children:b.status})]})}),t.jsx(ae,{label:"Name",value:b.name||"Not provided"}),t.jsx(ae,{label:"Email",value:b.email}),t.jsx(ae,{label:"Account ID",value:t.jsx("span",{className:"text-mono-sm",children:b.id})}),t.jsx(ae,{label:"Tenant ID",value:t.jsx("span",{className:"text-mono-sm",children:b.tenant_id})}),t.jsx(ae,{label:"Provider",value:t.jsx("span",{className:"capitalize",children:k.provider})}),t.jsx(ae,{label:"Created",value:sn(b.created_at)})]}),x&&f?t.jsx(Zi,{verification:f}):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(D,{variant:"danger",className:"mt-3",onClick:d,children:[t.jsx(ys,{}),"Sign out from Radient"]})]})]})},[s,n?.radientUser,d]),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.":an(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]),g=i.useMemo(()=>s&&n?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(Qs,{titleText:"",onAfterCredentialUpdate:e,descriptionText:"",onSignInSuccess:()=>{}})})]}),[s,n,m,e]);return a||u?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"}),!u&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Loading your Radient account details…"})]}):s&&n?.radientUser?c:t.jsx("div",{className:"flex flex-col gap-4",children:g})};function Xi({metric:e,data:s}){return t.jsx(ns,{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 ${s.length} days.`,xTickFormatter:n=>n,yTickFormatter:n=>e==="credits"?`$${n.toFixed(2)}`:ss(n),children:t.jsx(pr,{data:s,children:t.jsx(Jt,{type:"monotone",dataKey:"value",strokeWidth:2,dot:!1,activeDot:{r:4,strokeWidth:0},name:e==="credits"?"Credits consumed":"Tokens used"})})})}const ec=()=>{const{data:e,isLoading:s,error:n,refetch:a}=ur(),o=mr(),[r,u]=i.useState(""),[d,c]=i.useState(!1);i.useEffect(()=>{u(e?.content??""),c(!1)},[e]);const m=x=>{const E=x.target.value;u(E),c(E!==(e?.content??""))},g=async()=>{if(!(!d||o.isPending))try{const x={content:r};await o.mutateAsync(x),await a(),c(!1)}catch(x){console.error("Error updating system prompt:",x)}},b=()=>{u(e?.content??""),c(!1)},k=o.isPending,f=()=>t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(fe,{htmlFor:"app-system-prompt",children:"Instructions"}),t.jsx(cn,{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(D,{variant:"primary",onClick:g,disabled:!d||k,children:[k?t.jsx(re,{size:"sm"}):t.jsx(ks,{}),k?"Saving...":"Save changes"]}),t.jsx(D,{onClick:b,disabled:!d||k,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:on(e.last_modified)})]})]});return t.jsx(se,{title:"System prompt",icon:Ws,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:s?t.jsx("div",{className:"flex min-h-50 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading system prompt"})}):n?t.jsxs(le,{variant:"danger",children:["Failed to load system prompt:"," ",n instanceof Error?n.message:"Unknown error"]}):f()})},tc=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"],nc=e=>tc.includes(e),sc=e=>{const s=[];let n=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 u=0;u<o;u+=r)s.push({start:n+u,count:Math.min(r,o-u)});n+=o}return s},ac=({index:e,key:s,groups:n})=>{const a=sc(n),o=a.reduce((r,u)=>r+u.count,0);if(!Number.isInteger(e)||e<0||e>=o)return e;switch(s){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),u=a[r+(s==="ArrowDown"?1:-1)];if(!u)return e;const d=e-a[r].start;return u.start+Math.min(d,u.count-1)}default:return e}},oc={localOperatorDark:bo,localOperatorLight:Po,dracula:Eo,dune:Ya,sage:ho,monokai:ws,tokyoNight:No,iceberg:Oo,radient:ro,neon:as,obsidian:dn,synth:ia,catppuccinMocha:Ea,catppuccinLatte:yo,tokyoNightStorm:Na,gruvbox:pa,nord:lr,oneDark:oa,solarizedDark:Uo,rosePine:Ja,rosePineMoon:ko,rosePineDawn:Ta,alucard:eo,gruvboxLight:za,tokyoNightDay:jo,oneLight:po,catppuccinFrappe:$a,catppuccinMacchiato:co,palenight:bs,everforest:tr,everforestLight:Xo,kanagawaWave:or,kanagawaLotus:Qa,ayuDark:Ka,ayuMirage:Ba,ayuLight:Ao,nightfox:Ca,duskfox:Vo,synthwave:Co,matrix:la,tron:ja,cyberpunk:vs,vaporwave:Zo,outrun:ha,neonNoir:sr,arcade:uo,forest:Wo,ocean:Ga,desert:qo,autumn:ir,lavender:Do,arctic:Aa,rosewood:ao,solarizedLight:Ho,githubLight:no,paper:Zs,linen:To,highContrastLight:sa,mintLight:ua},Yt="bg-[color-mix(in_srgb,var(--color-accent)_8%,var(--color-accent-wash))]",rc=({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"})]})]})]}),ic=({id:e,name:s,description:n,isSelected:a,isTabStop:o,onSelect:r,onFocusTile:u})=>{const d=oc[e];return t.jsx(Re,{side:"bottom",align:"start",content:n,children:t.jsxs("button",{type:"button","data-theme-tile":e,"aria-pressed":a,tabIndex:o?0:-1,onFocus:u,onClick:r,className:oe("relative flex flex-col gap-1.5 rounded-md p-1 text-left transition-colors duration-fast ease-out-quart",a?Yt:"hover:bg-surface"),children:[t.jsxs("span",{className:oe("relative block h-10 overflow-hidden rounded-sm border transition-colors duration-fast ease-out-quart",a?"border-accent":"border-hairline"),children:[t.jsx(rc,{id:e}),a&&t.jsx("span",{className:oe("pointer-events-none absolute top-0.5 right-0.5 flex h-4 w-4 items-center justify-center rounded-full",Yt),children:t.jsx(Ys,{size:12,className:"text-accent","aria-hidden":"true"})})]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(d,{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:s})]})]})})},cc=e=>[...e.querySelectorAll("[data-theme-grid]")].map(s=>{const n=[...s.querySelectorAll("[data-theme-tile]")],a=n[0]?.getBoundingClientRect().top??0;return{count:n.length,columns:Math.max(1,n.filter(o=>Math.abs(o.getBoundingClientRect().top-a)<1).length)}}),lc=()=>{const{themeName:e,setTheme:s}=ct(),n=i.useMemo(()=>{const d=Object.values(Cn);return[{label:"Dark",items:d.filter(c=>c.theme.palette.mode==="dark")},{label:"Light",items:d.filter(c=>c.theme.palette.mode==="light")}].filter(c=>c.items.length>0)},[]),[a,o]=i.useState(null),r=i.useMemo(()=>{const d=n.flatMap(c=>c.items.map(m=>m.id));return a&&d.includes(a)?a:d.includes(e)?e:d[0]},[n,a,e]),u=d=>{if(!nc(d.key))return;const c=[...d.currentTarget.querySelectorAll("[data-theme-tile]")],m=c.indexOf(d.target);if(m<0)return;d.preventDefault();const g=ac({index:m,key:d.key,groups:cc(d.currentTarget)});g!==m&&c[g]?.focus()};return t.jsx(qs,{children:t.jsx("div",{onKeyDown:u,className:"flex flex-col gap-6",children:n.map(d=>t.jsxs("div",{children:[t.jsx("h3",{className:"px-1 pb-2 text-meta text-ink-dim",children:d.label}),t.jsx("div",{"data-theme-grid":d.label,className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-2",children:d.items.map(({id:c,name:m,description:g})=>t.jsx(ic,{id:c,name:m,description:g,isSelected:c===e,isTabStop:c===r,onSelect:()=>s(c),onFocusTile:()=>o(c)},c))})]},d.label))})})},dc=()=>{const{data:e,isLoading:s,error:n}=yr({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(Fa,{size:16,className:"shrink-0 text-ink-dim"}),"Radient Pass"]}),s&&t.jsx(ln,{className:"h-6 w-36"}),n&&t.jsxs(le,{variant:"warning",children:["Could not load your credit balance. ",n.message]}),e&&!s&&!n&&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(D,{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(ba,{}),"Add credits"]})})]})]})},uc=[{id:"credits",label:"Credits"},{id:"tokens",label:"Tokens"}],mc=()=>{const[e,s]=i.useState("credits"),n=i.useMemo(()=>{const d=new Date,c=fr(d);return{start_date:Ft(c),end_date:Ft(d),rollup:"daily"}},[]),{data:a,isLoading:o,error:r}=kr(n,{enabled:!0}),u=i.useMemo(()=>a?.data_points?[...a.data_points].sort((c,m)=>Je(c.timestamp).getTime()-Je(m.timestamp).getTime()).map(c=>({bucket:hs(ea(Je(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(ya,{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:uc.map(({id:d,label:c})=>t.jsx(D,{variant:"ghost",size:"sm","aria-pressed":e===d,onClick:()=>s(d),className:oe(e===d&&"bg-surface text-ink hover:bg-surface"),children:c},d))})]})]}),o&&t.jsx(ln,{className:"h-62 w-full"}),r&&t.jsxs(le,{variant:"warning",children:["Could not load your usage data. ",r.message]}),!o&&!r&&a&&u.length>0&&t.jsx(Xi,{metric:e,data:u}),!o&&!r&&(!a||u.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(Ls,{size:16,className:"shrink-0 text-ink-dim"}),"Radient account"]}),t.jsx(D,{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(fs,{})]})})]}),Cc=()=>{const e=os("surface"),s=ct(h=>h.showAgentReasoning),n=ct(h=>h.setShowAgentReasoning),{data:a,isLoading:o,isFetching:r,error:u,refetch:d}=rs(),c=is(),{sentence:m,remedy:g}=cs(c??null,"Your settings could not be loaded.",u),b=js(),[k,f]=i.useState(null),x=nn(),{isAuthenticated:E,accountRead:S,isFetching:H,isRefreshing:_,refreshUser:$}=ht(),I=Ke(h=>h.activeSessionId),[M,N]=i.useState("general"),[G,P]=i.useState(!1),q=i.useRef(null),K=i.useRef(null),{startTour:X}=_s(),A=ls(),{data:T,refetch:V}=ds(),{refreshModels:z}=us(),O=i.useMemo(()=>T?.keys?[...T.keys].sort():[],[T?.keys]),ee=i.useRef({keys:"",hosting:void 0});i.useEffect(()=>{const h=O.join(","),w=a?.values?.hosting;(ee.current.keys!==h||ee.current.hosting!==w)&&(ee.current={keys:h,hosting:w},z().catch(v=>{console.error("Failed to refresh models after credentials or hosting change:",v)}))},[O,a?.values?.hosting,z]);const R=i.useRef({general:i.useRef(null),radient:i.useRef(null),integrations:i.useRef(null),appearance:i.useRef(null),providers:i.useRef(null),backend:i.useRef(null),updates:i.useRef(null)}).current,ie=i.useMemo(()=>new URLSearchParams(A.search).get("setting"),[A.search]),C=i.useMemo(()=>new URLSearchParams(A.search).get("filter")??"",[A.search]),Q=i.useMemo(()=>new URLSearchParams(A.search).get("mcp")??void 0,[A.search]),Z=i.useMemo(()=>new URLSearchParams(A.search).get("provider"),[A.search]),J=i.useCallback(h=>{N(h),P(!0);const w=R[h],v=K.current;if(w?.current&&v){const F=w.current.getBoundingClientRect().top-v.getBoundingClientRect().top;v.scrollHeight>v.clientHeight?v.scrollTo({top:Math.max(0,v.scrollTop+F-80),behavior:"smooth"}):window.scrollTo({top:Math.max(0,w.current.getBoundingClientRect().top+window.scrollY-80),behavior:"smooth"}),clearTimeout(q.current??void 0),q.current=setTimeout(()=>{P(!1),q.current=null},800)}else P(!1)},[R]);i.useEffect(()=>{const h=setTimeout(()=>{const w=K.current;if(!w)return;const v=()=>{if(G)return;const U=w.getBoundingClientRect(),F=U.height;let te="",B=0;for(const[je,ue]of Object.entries(R))if(ue.current){const ce=ue.current.getBoundingClientRect(),ye=U.top,ne=ce.top-ye,We=ce.bottom-ye,Ie=ce.height,Qe=Math.max(0,ne),Oe=Math.min(F,We),Fe=Math.max(0,Oe-Qe)/Ie,De=Fe+(ne<F*.3?.1:0);De>B&&Fe>.1&&(B=De,te=je)}te&&te!==M&&N(te)};return v(),w.addEventListener("scroll",v,{passive:!0}),()=>{w.removeEventListener("scroll",v),clearTimeout(q.current??void 0)}},100);return()=>clearTimeout(h)},[R,M,G]),i.useEffect(()=>{const h=new URLSearchParams(A.search),w=h.get("section"),v=h.get("setting")?"backend":w,U=v?R[v]:void 0;if(!v||!U)return;let F=!1,te=Number.NaN,B=0;const je=window.setTimeout(()=>{F||(F=!0,ce.disconnect(),J(v))},2e3),ue=()=>{if(F)return;const ye=U.current;if(!ye){B=requestAnimationFrame(ue);return}const ne=Math.round(ye.getBoundingClientRect().top+window.scrollY);if(ne===te&&ne>0){F=!0,ce.disconnect(),window.clearTimeout(je),J(v);return}te=ne,B=requestAnimationFrame(ue)},ce=new ResizeObserver(()=>{F||(cancelAnimationFrame(B),B=requestAnimationFrame(ue))});return K.current&&ce.observe(K.current),B=requestAnimationFrame(ue),()=>{F=!0,cancelAnimationFrame(B),ce.disconnect(),window.clearTimeout(je)}},[A.search,R,J]);const Y=async(h,w)=>{f(h);try{await b.mutateAsync({[h]:w}),await d()}catch(v){console.error(`Error updating ${h}:`,v)}finally{f(null)}},W=o,pe=S==="checking",we=an(S),de=S==="ready"||S==="checking"||H,ge=rn(W,4e3);return u?t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(le,{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:m}),g&&t.jsx(D,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>void d(),disabled:r,children:r?"Retrying":"Retry"})]})})}):W?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:ge?void 0:"Loading settings"}),ge&&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."})]}):a?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(Ns,{activeSection:M,onSelectSection:J,sections:Ss})}),t.jsx("div",{ref:K,"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(Es,{title:"Settings",icon:Rt}),t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsxs("div",{ref:R.general,className:"flex flex-col gap-8",children:[t.jsxs(se,{title:"User profile",icon:Cs,description:`Your user profile information displayed in the application. This information is not provided to the agents. ${E?"These details are provided through your Radient account.":""}`,children:[pe&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Checking your Radient account…"}),we&&t.jsx(le,{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.",S==="refused"?" Retry, or sign in to Radient again.":" Retry."]}),t.jsx(D,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>$(),disabled:_,children:_?"Retrying":"Retry"})]})}),t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Tt,{value:x.profile.name,label:"Display name",placeholder:"Enter your name...",isSaving:k==="user_name",onSave:async h=>{f("user_name");try{x.updateName(h)}finally{f(null)}},readOnly:de}),t.jsx(Tt,{value:x.profile.email,label:"Email address",placeholder:"Enter your email...",isSaving:k==="user_email",onSave:async h=>{f("user_email");try{x.updateEmail(h)}finally{f(null)}},readOnly:de})]})]}),t.jsx(se,{title:"Application tour",description:"Missed the application onboarding tour or want a refresher? Start it again here.",children:t.jsxs(D,{variant:"secondary",onClick:()=>{X({forceModalCompleted:!0})},children:[t.jsx(ka,{}),"Take the tour"]})}),t.jsx(se,{id:"model-settings",title:"Model settings",icon:Ms,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(As,{value:a.values.hosting,isSaving:k==="hosting",onSave:h=>Y("hosting",h),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(Rs,{value:a.values.model_name,hostingId:a.values.hosting,isSaving:k==="model_name",onSave:h=>Y("model_name",h),allowCustom:!0,allowDefault:!1}),t.jsx(le,{variant:"neutral",icon:t.jsx(Ge,{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(ec,{}),t.jsx(se,{title:"Configuration information",icon:Ge,description:"System information about the current configuration.",children:t.jsxs(pt,{children:[t.jsx(ae,{label:"Version",value:t.jsx("span",{className:"text-mono-sm",children:a.version})}),t.jsx(ae,{label:"Created",value:sn(a.metadata.created_at)}),t.jsx(ae,{label:"Last modified",value:on(a.metadata.last_modified)}),t.jsx(ae,{label:"Description",value:a.metadata.description||"No description available"})]})})]}),t.jsx(se,{title:"Appearance",icon:dn,description:"Customize the look and feel of Local Operator",sectionRef:R.appearance,dataTourTag:"settings-appearance-section",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(lc,{}),t.jsx(hr,{value:s,label:"Show agent reasoning",description:"Adds the agent's Reasoning and Thinking rows to conversations. They stay closed until you open one.",onChange:async h=>n(h)})]})}),t.jsx(se,{title:"Model providers",icon:tn,description:"Sign in to the services your agents think with. New chats use your default model.",sectionRef:R.providers,children:t.jsx(Ts,{initialProviderId:Z,onChangeModel:()=>J("general")})}),t.jsx(Vi,{sessionId:I??void 0,sectionRef:R.integrations,highlightServer:Q}),t.jsx(se,{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:R.radient,dataTourTag:"settings-radient-account-section",children:t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsx(Ji,{onAfterCredentialUpdate:()=>{z(),V()}}),E&&t.jsxs(t.Fragment,{children:[t.jsx(dc,{}),t.jsx(mc,{})]})]})}),t.jsx(se,{title:"Backend settings",icon:Rt,description:"Every setting the backend registry owns, searchable, with typed editors and scopes.",sectionRef:R.backend,children:t.jsx(ms,{focusKey:ie,initialFilter:C})}),t.jsx("div",{ref:R.updates,children:t.jsx(jr,{})})]})]})})]}):t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(le,{variant:"warning",className:"w-full max-w-xl",children:"Your settings could not be loaded."})})};export{Cc as SettingsPage};
|
|
291
|
+
*/const cr=[["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"}]],lr=y("wind",cr),dr=({appVersion:e=null,slowWaitHintMs:s})=>{const n="https://local-operator.com/download",[a,o]=i.useState(!1),r=rn(a,s??ps),[u,d]=i.useState(!1),[c,m]=i.useState(null),[g,b]=i.useState("info"),[k,f]=i.useState(null),[x,E]=i.useState(null),S=e?.trim()?e.trim():null,H=i.useRef(!1),_=st(A=>A.openDetail),$=i.useRef(!1),I=i.useRef(0),M=i.useRef(!1),N=i.useCallback((A,T)=>{$.current=!1,m(A),b(T),d(!0)},[]),G=i.useCallback(A=>{$.current=!0,m(A),b("success"),d(!0)},[]),P=i.useCallback(()=>{$.current&&($.current=!1,d(!1),m(null))},[]),{clearDeferredUpdate:q}=Mn();i.useEffect(()=>{const A=window.api.updater.onUpdateError(R=>{H.current&&R.includes("manually")&&(f({message:"The server is installed outside the app, so use the tool you installed it with - uv, pipx or pip.",command:""}),$.current=!1,m(null),b("warning"),d(!0))}),T=window.api.updater.onBackendUpdateDevMode(R=>{H.current&&N(R,"info")}),V=()=>{M.current=!0,P()},z=window.api.updater.onUpdateAvailable(V),O=window.api.updater.onUpdateNpxAvailable(V),ee=window.api.updater.onBackendUpdateAvailable(V);return()=>{A(),T(),z(),O(),ee()}},[P,N]),i.useEffect(()=>{let A=!1;const T=()=>{window.api.updater.getLastInstallAttempt().then(z=>{A||E(z)}).catch(()=>{})};T();const V=window.api.updater.onUpdateInstallFailed(()=>T());return()=>{A=!0,V()}},[]);const K=async()=>{const A=++I.current;P(),M.current=!1;try{o(!0),H.current=!0,q(he.UI),q(he.BACKEND);const T=await window.api.updater.checkForAllUpdates({manual:!0});if(A!==I.current)return;T.app==="available"&&_(he.UI),T.server==="available"&&_(he.BACKEND),T?.affirmation&&!M.current?G(T.affirmation):P()}catch(T){if(A!==I.current)return;console.warn(`Update check failed; the app-level alert owns the report: ${gs(T)}`)}finally{A===I.current&&o(!1),setTimeout(()=>{H.current=!1},2e3)}},X=()=>{$.current=!1,d(!1),m(null)};return t.jsxs(t.Fragment,{children:[x&&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 ",x.targetVersion," didn't finish",x.attempts>1?` (${x.attempts} attempts)`:"",".",S?` Version ${S} is running.`:null]}),t.jsxs("p",{className:"mt-1 text-meta text-ink-dim",children:["Detected"," ",x.detectedAt?new Date(x.detectedAt).toLocaleString():"at an unknown time",". ",x.detail]}),t.jsx(D,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>void window.api.openExternal(n),children:"Download a fresh copy"})]}),t.jsxs(D,{variant:"outline",onClick:()=>void K(),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."}),k&&t.jsxs(St,{open:u,autoHideDuration:1e4,onClose:X,variant:"warning",children:[t.jsx("p",{className:"text-body-sm",children:k.message}),k.command&&t.jsx("code",{className:"mt-2 block rounded-sm bg-sunken p-2 text-mono-sm text-ink",children:k.command})]}),c&&g!=="danger"&&t.jsx(St,{open:u,autoHideDuration:6e3,onClose:X,variant:g,children:c})]})},He=["system-prompt"],ur=()=>{const{shouldEnableQuery:e}=An();return Ne({enabled:e({bypassInternetCheck:!0}),queryKey:He,queryFn:async()=>{try{const n=await Wt(mt.baseUrl).config.getSystemPrompt();if(n===null)return null;if(n.status>=400)throw new Error(n.message||"Failed to fetch system prompt");return n.result}catch(s){const n=s instanceof Error?s.message:"An unknown error occurred while fetching system prompt";throw Zt(n),s}},refetchOnWindowFocus:!1,staleTime:5e3})},mr=()=>{const e=Qt(),s=Wt(mt.baseUrl);return Rn({mutationFn:async n=>{try{const a=await s.config.updateSystemPrompt(n);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 Zt(o),a}},onSuccess:async n=>{await e.invalidateQueries({queryKey:He,refetchType:"none"}),e.setQueryData(He,a=>a&&{...a,...n}),await e.refetchQueries({queryKey:He,type:"all"}),Tn("System prompt updated")},onError:n=>{console.error("Error updating system prompt:",n)}})},hr=({value:e,label:s,description:n,onChange:a,icon:o,isSaving:r=!1})=>{const[u,d]=i.useState(e),c=i.useId(),m=`${c}-label`,g=`${c}-description`,b=async k=>{if(!r){d(k);try{await a(k)}catch(f){d(!k),console.error("Error toggling setting:",f)}}};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"}),s]}),n&&t.jsx("p",{id:g,className:"mt-0.5 max-w-2xl text-body-sm text-ink-muted",children:n})]}),t.jsx("div",{className:"flex h-6 shrink-0 items-center",children:r?t.jsx(re,{size:"md",label:`Saving ${s}`}):t.jsx(Is,{checked:u,onCheckedChange:b,"aria-labelledby":m,"aria-describedby":n?g:void 0})})]})};function Ft(e,s){const n=ta(e,s?.in);if(!Xs(n))throw new RangeError("Invalid time value");const a=ve(n.getDate(),2),o=ve(n.getMonth()+1,2),r=n.getFullYear(),u=ve(n.getHours(),2),d=ve(n.getMinutes(),2),c=ve(n.getSeconds(),2);let m="",g="";const b=n.getTimezoneOffset();if(b!==0){const k=Math.abs(b),f=ve(Math.trunc(k/60),2),x=ve(k%60,2);g=`${b<0?"+":"-"}${f}:${x}`}else g="Z";return`${r}-${o}-${a}T${u}:${d}:${c}${m}${g}`}function fr(e,s,n){return Js(e,-30,n)}var pr=Ln({chartName:"LineChart",GraphicalChild:Jt,axisComponents:[{axisType:"xAxis",AxisComp:En},{axisType:"yAxis",AxisComp:In}],formatAxisMap:On});const gr=["radient","creditBalance"],yr=e=>{const{user:s,isAuthenticated:n}=ht(),a=s?.account?.tenant_id,o=n&&!!a&&e?.enabled;return Ne({queryKey:[gr,a],queryFn:async()=>{if(!a)throw new Error("Tenant ID not available");const r=await Xt({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})},xr=["radient","usageRollup"],kr=(e,s)=>{const{user:n,isAuthenticated:a}=ht(),o=n?.account?.tenant_id,r=a&&!!o&&s?.enabled;return Ne({queryKey:[...xr,o,e],queryFn:async()=>{if(!o)throw new Error("Tenant ID not available");const u={};for(const[c,m]of Object.entries(e))m!=null&&(u[c]=String(m));const d=await Xt({operation:"usage",tenantId:o,query:u});if(!d)throw new Error("Invalid usage rollup response format");return d},enabled:r,staleTime:5*60*1e3,refetchOnWindowFocus:!0})},Dt={[he.UI]:"Application updates",[he.BACKEND]:"Server updates"},$t=({type:e})=>{const s=st(a=>a.followed[e]),n=st(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:Dt[e]}),t.jsx("div",{className:"mt-0.5 text-meta text-ink-muted",children:$e[s].description})]}),t.jsxs(Os,{value:s,onValueChange:a=>n(e,a),children:[t.jsx(Fs,{"aria-label":`${Dt[e]}: ${$e[s].label}`,className:"w-full sm:w-56","data-followed-segment":e,children:t.jsx(Ds,{})}),t.jsx($s,{children:Fn.map(a=>t.jsx(Us,{value:a,title:$e[a].description,children:$e[a].label},a))})]})]})},vr=()=>t.jsxs("div",{className:oe("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($t,{type:he.UI}),t.jsx($t,{type:he.BACKEND})]})]}),br=({appVersion:e})=>t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx(vr,{}),t.jsx(dr,{appVersion:e})]}),wr=e=>{if(!e)return null;try{return new URL(e).host}catch{return null}},jr=()=>{const[e,s]=i.useState(null),[n,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 d=!0;const c=f=>{if(!d)return;const x=wr(f.url);if(f.state==="connecting"){a({value:"Loading...",detail:null,degraded:!1});return}if(f.state==="detached"){a({value:"Not connected",detail:f.detail||null,degraded:!1});return}if(f.state==="wedged"){a({value:"Not attached",detail:f.detail||null,degraded:!1});return}const E=f.version||"Version unknown";a({value:x?`${E} · ${x}`:E,detail:f.detail||null,degraded:f.state==="degraded"})};let m=!1;const g=window.api?.backend?.onStatusChange(f=>{m=!0,c(f)}),b=async()=>{try{const[f,x]=await Promise.all([window.api.systemInfo.getAppVersion(),window.api.systemInfo.getPlatformInfo()]);d&&(s(f),r(x))}catch(f){console.error("Error fetching app information:",f)}},k=async()=>{try{const f=window.api?.backend;if(f){const S=await f.getStatus();m||c(S);return}const x=await Ct.healthCheck(mt.baseUrl),E=Ct.getServerVersion(x);d&&a({value:E,detail:null,degraded:!1})}catch(f){console.error("Error fetching server version:",f),d&&a({value:"Unavailable",detail:null,degraded:!1})}};return b(),k(),()=>{d=!1,g?.()}},[]);const u=(d,c,m,g={})=>t.jsx(ae,{label:t.jsx(Re,{content:m,children:t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(Ge,{size:12,className:"shrink-0"}),d]})}),valueClassName:g.valueClassName,value:t.jsxs(t.Fragment,{children:[g.valueTooltip?t.jsx(Re,{content:g.valueTooltip,children:t.jsx("span",{"data-backend-version":g.valueHoverTarget?"":void 0,children:c})}):c,g.statusNote?t.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:g.statusNote}):null]})});return t.jsx(se,{title:"Application updates and info",icon:Dn,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(pt,{children:[u("Application version",e??"Loading...","The version of the Local Operator user interface application."),u("Server version",n.value,"The version of the Local Operator API server backend, and the address of the daemon it was read from.",{valueTooltip:n.detail,valueHoverTarget:!0,statusNote:n.degraded?"Not answering":void 0,valueClassName:n.degraded?"text-ink-muted":void 0}),u("Platform",`${o.platform} (${o.arch})`,"The operating system and architecture your application is running on."),u("Node.js version",o.nodeVersion,"The JavaScript runtime environment version."),u("Electron version",o.electronVersion,"The framework version enabling this desktop application.")]}),t.jsx(br,{appVersion:e})]})})},_r=[[[".claude.json"],"Claude Code"],[[".claude",".mcp.json"],"Claude Code"],[[".cursor","mcp.json"],"Cursor"],[[".vscode","mcp.json"],"VS Code"],[[".codex","config.toml"],"Codex CLI"]];function un(e){if(!e)return null;const s=e.split("\\").join("/").split("/").filter(Boolean);for(const[n,a]of _r)if(!(s.length<n.length)&&s.slice(-n.length).join("/")===n.join("/"))return a;return null}const Be=e=>`${e} ${e===1?"tool":"tools"}`,Nr=e=>`${e} ${e===1?"integration":"integrations"}`,Sr=["connected","needs_sign_in","not_started","connecting","error"],mn=e=>Sr.includes(e),Ce=(e,s)=>[...s].filter(n=>n.name===e&&n.status==="running").sort((n,a)=>a.created_at-n.created_at)[0]??null,Cr={connectedAt:null,connectedToolCount:null,settledGroup:null,pinnedGroup:null,pinnedOperationId:null,needsKey:!1,needsSignIn:!1,disconnectedAt:null,holdUntil:null,lastDecisive:null},Mr=1e12,Ar=1e9,Rr=60*60*1e3,hn=(e,s=Date.now())=>{if(typeof e!="number"||!Number.isFinite(e))return null;const n=e>=Mr?e:e<Ar?null:e*1e3;return n===null||n>s+Rr?null:Math.min(n,s)},be=(e,s)=>e?.[s]??Cr,Le=(e,s,n)=>Er(e,s)??n?.lastDecisive??null,Tr=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}:{}}),gt=(e,s)=>e.status==="not_started"&&typeof e.tool_count=="number"&&(s.connectedAt!==null||e.status_basis==="stored"&&e.tool_count_basis==="last_seen"),Lr=(e,s)=>[...s].filter(n=>n.name===e).sort((n,a)=>a.created_at-n.created_at)[0]??null,Er=(e,s)=>Lr(e,s.filter(n=>n.status!=="cancelled")),qe=e=>e.actions.includes("set_key")||e.actions.includes("add_key");function Ir(e,s){const n=Math.max(0,Math.round((e-s)/1e3));if(n<60)return"just now";const a=Math.round(n/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 Xe(e){if(!e)return null;const s=e.trim();if(!s||/^\/\w/.test(s)||/\/mcp\s+\w+/.test(s))return null;let n=s;for(let a=0;a<3;a+=1){const o=n.replace(/^(?:connection (?:closed|error|refused)|error|closed|failed)\s*:\s*/i,"").trim();if(o===n)break;n=o}return n=n.replace(/\s*\(\s*\d{3}\s*\)/g,"").replace(/\s+([.,;])/g,"$1").replace(/\s{2,}/g," ").trim(),n||null}function Or(e,s=[],n,a=Date.now()){const o=be(n,e.name),r=Ce(e.name,s);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(!mn(e.status))return{label:"Status unavailable",tone:"neutral",detail:null,busy:!1};const u=Le(e.name,s,o),d=Ye(u)&&e.status!=="connected",c=gt(e,o),m=kt(u)&&e.status!=="connected",g=(u?.action==="login"||u?.action==="reauth")&&u.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 · ${Be(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"||Ae(e,s,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:Xe(e.status_reason),busy:!1};case"error":return{label:"Couldn't start",tone:"danger",detail:Xe(e.status_reason)??"No reason was given.",busy:!1};default:if(d)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(Ae(e,s,o))return{label:"Needs a key",tone:"warning",detail:null,busy:!1};if(g)return{label:"Sign-in didn't finish",tone:"warning",detail:null,busy:!1};if(o.needsSignIn)return{label:e.auth.kind==="api_key"||Ae(e,s,o)?"Needs a key":"Needs sign-in",tone:"warning",detail:Xe(e.status_reason),busy:!1};if(e.status_basis==="stored"&&c&&o.disconnectedAt===null){const b=o.connectedAt??hn(e.last_seen_at,a);return{label:b!==null?`Worked ${Ir(a,b)} · ${Be(e.tool_count)}`:`Worked earlier · ${Be(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 fn=e=>e===1?"Replace the saved key":"Replace saved keys",Fr=/[,;]?\s*(?:or|and)?\s*add (?:its|a|the) key instead\.?\s*$/i;function Dr(e,s){const n=e?.trim()??"";if(!n)return null;if(s)return n;const a=n.replace(Fr,"").trim();return a?/\.$/.test(a)?a:`${a}.`:n}const $r="Nothing is wrong. It starts when a chat uses it.",Ur="Not running in this chat.",zr=e=>e.transport==="local_command"?"Local command":"Remote URL";function pn(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 un(e.source.path)}}function Pr(e,s){const n=[zr(e)];e.status!=="connected"&&e.tool_count_basis==="last_seen"&&typeof e.tool_count=="number"&&n.push(`${Be(e.tool_count)} when last checked`),s&&n.push(e.scope==="project"?"This project":"Global");const a=pn(e);return a?n.push(`Imported from ${a}`):e.source.editable||n.push("Imported from a project file"),n}const yt=(e,s)=>s.disconnectedAt!==null?"not_started":e.status;function xt(e,s=[],n){const a=be(n,e.name),o=Ce(e.name,s);if(o)return o.action==="login"||o.action==="reauth"?{kind:"sign_in",label:"Continue sign-in"}:null;const r=g=>e.actions.includes(g),u=qe(e),d=Ae(e,s,a);if(!mn(e.status))return r("test")?{kind:"test",label:"Check again"}:null;const c=Le(e.name,s,a),m=c?.status==="failed"&&Ee(c);switch(yt(e,a)){case"connected":case"connecting":return null;case"needs_sign_in":return d?{kind:"set_key",label:"Add key"}:r("sign_in")?{kind:"sign_in",label:"Sign in"}:u?{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(Ye(c)&&r("sign_in"))return{kind:"sign_in",label:"Sign in"};if(kt(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(d&&u)return{kind:"set_key",label:"Add key"};if(r("sign_in"))return{kind:"sign_in",label:"Sign in"}}return d&&u?{kind:"set_key",label:"Add key"}:m&&r("sign_in")?{kind:"sign_in",label:"Try again"}:gt(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 Ee=e=>e.action==="login"||e.action==="reauth",Ye=e=>!!(e&&e.action==="logout"&&e.status==="complete"),kt=e=>!!(e&&e.action==="logout"&&e.status!=="running"&&e.status!=="complete"),gn=/no oauth authorization server/i;function Ae(e,s,n){if(!qe(e))return!1;const a=Le(e.name,s,n);return a&&Ee(a)&&a.status==="failed"&&gn.test(a.message??"")?!0:n.needsKey}function Kr(e,s=[],n){const a=xt(e,s,n)?.kind,o=yt(e,be(n,e.name)),r=c=>e.actions.includes(c),u=[],d=Ce(e.name,s);if(d&&u.push({kind:"cancel",label:"Cancel"}),!d&&r("test")&&a!=="test"&&u.push({kind:"test",label:"Test connection"}),r("connect")&&a!=="connect"&&o!=="connected"&&u.push({kind:"connect",label:"Reconnect"}),!d&&r("sign_in")&&a!=="sign_in"&&o!=="connected"&&u.push({kind:"sign_in",label:"Sign in"}),r("reload")&&u.push({kind:"reload",label:"Reload"}),!d&&r("reauth")&&a!=="reauth"&&u.push({kind:"reauth",label:"Sign in again"}),qe(e)&&a!=="set_key"&&u.push({kind:"set_key",label:e.auth.secret_refs.length>0?"Update key":"Add key"}),r("sign_out")&&u.push({kind:"sign_out",label:"Sign out"}),r("disconnect")&&o==="connected"&&u.push({kind:"disconnect",label:"Disconnect"}),r("copy_setup")&&e.setup_prompt&&u.push({kind:"copy_setup",label:"Copy setup prompt"}),a!=="fix"&&u.push({kind:"open_config",label:"Open config file"}),r("remove"))u.push({kind:"remove",label:"Remove",destructive:!0});else if(!e.source.editable){const c=pn(e);u.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 u}const Hr={attention:"Needs attention",connected:"Connected",ready:"Available"};function yn(e,s=[],n){const a=be(n,e.name),o=Ce(e.name,s),r=yt(e,a);if(o&&a.pinnedGroup&&a.pinnedOperationId===o.id)return a.pinnedGroup;if(r==="needs_sign_in"||r==="error")return"attention";const u=Le(e.name,s,a);return Ye(u)&&r!=="connected"||kt(u)&&r!=="connected"?"attention":a.disconnectedAt!==null?"ready":Ae(e,s,a)||a.needsSignIn&&r!=="connected"||u?.status==="failed"&&Ee(u)&&r!=="connected"?"attention":r==="connected"||e.status_basis==="stored"&>(e,a)?"connected":o&&o.action!=="test"?"attention":"ready"}function Br(e,s=[],n){return["attention","connected","ready"].map(o=>({id:o,title:Hr[o],rows:e.filter(r=>yn(r,s,n)===o)})).filter(o=>o.rows.length>0)}function Vr(e,s,n=Date.now()){if(!s)return e??{};const a={};for(const o of s.servers){const r=be(e,o.name),u=Ce(o.name,s.operations),d=Le(o.name,s.operations,r),c=Ye(d),m=o.status==="connected"&&(o.status_basis==="probe"||o.status_basis==="live"),g=r.holdUntil!==null&&n<r.holdUntil,b=!g&&!c&&r.connectedAt===null&&o.status_basis==="stored"&&o.tool_count_basis==="last_seen"?hn(o.last_seen_at,n):null,k=!c,f=d?.status==="failed"&&Ee(d)&&gn.test(d.message??""),x={connectedAt:m&&!g?n:b!==null?b:k?r.connectedAt:null,connectedToolCount:m&&!g||b!==null?o.tool_count??r.connectedToolCount:k?r.connectedToolCount:null,settledGroup:r.settledGroup,pinnedGroup:u&&r.pinnedOperationId===u.id?r.pinnedGroup:u?r.settledGroup:null,pinnedOperationId:u?u.id:null,needsKey:m?!1:r.needsKey||f,needsSignIn:m||c?!1:r.needsSignIn||o.status==="needs_sign_in",disconnectedAt:m&&!g?null:r.disconnectedAt,holdUntil:g?r.holdUntil:null,lastDecisive:d?Tr(d):null};u||(x.settledGroup=yn(o,s.operations,{...a,[o.name]:x})),a[o.name]=x}return a}const Gr=(e,s)=>e!==null&&s===e,lt="local-operator.settings.integrations.row-memory",xn=(e,s)=>`${e}#${s}`;function qr(e,s){const n={};if(!s)return n;for(const a of s.servers){const o=e[a.name];o&&(n[xn(a.source.path,a.name)]=o)}return n}function Yr(e,s,n){if(!s)return e;let a=null;for(const o of s.servers){if(Object.prototype.hasOwnProperty.call(e,o.name))continue;const r=Qr(n[xn(o.source.path,o.name)]);r&&(a=a??{...e},a[o.name]=r)}return a??e}const Wr=["attention","connected","ready"],kn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),vt=e=>typeof e=="number"&&Number.isFinite(e)?e:null,Ut=e=>Wr.includes(e)?e:null,et=e=>{const s=vt(e);return s!==null&&s>=1e12?s:null};function Zr(e){if(!kn(e)||typeof e.id!="string"||typeof e.name!="string")return null;const s=e.action,n=e.status;return s!=="login"&&s!=="logout"&&s!=="reauth"&&s!=="test"||n!=="running"&&n!=="complete"&&n!=="cancelled"&&n!=="failed"?null:{id:e.id,name:e.name,action:s,status:n,created_at:vt(e.created_at)??0,credential_removed:e.credential_removed===!0,...typeof e.message=="string"?{message:e.message}:{}}}function Qr(e){if(!kn(e))return null;const s=et(e.connectedAt),n=et(e.disconnectedAt),a=e.needsKey===!0,o=e.needsSignIn===!0,r=Zr(e.lastDecisive);return s===null&&n===null&&!a&&!o&&!r?null:{connectedAt:s,connectedToolCount:vt(e.connectedToolCount),settledGroup:Ut(e.settledGroup),pinnedGroup:Ut(e.pinnedGroup),pinnedOperationId:typeof e.pinnedOperationId=="string"?e.pinnedOperationId:null,needsKey:a,needsSignIn:o,disconnectedAt:n,holdUntil:et(e.holdUntil),lastDecisive:r}}const vn=2e3,zt=8e3;function Jr(e){return e&&(e.servers.some(n=>n.status==="connecting")||e.operations.some(n=>n.status==="running"))?vn:!1}const Xr=/^[A-Za-z0-9_.:-]{1,100}$/,ei=/:\/\//;function ti(e,s){const n=e.trim();return n?Xr.test(n)?s.includes(n)?`An integration named ${n} already exists.`:null:"Use letters, numbers, dots, dashes, underscores or colons, with no spaces.":"Give it a name."}function ni(e){const s=e.trim();if(!s)return"Enter the server's URL.";let n;try{n=new URL(s)}catch{return"Enter a full URL, like https://mcp.example.com/mcp."}return n.protocol!=="https:"&&n.protocol!=="http:"?"The URL must start with https:// or http://.":n.hostname?n.username||n.password?"Remove the username or password from the URL. Keys are added after it's saved.":n.search||n.hash?"Remove the ? or # part of the URL. Keys are added after it's saved.":ei.test(s.slice(n.protocol.length+2))?"This looks like two URLs pasted together. Enter just one.":null:"The URL needs a host name."}const si=e=>e.split(`
|
|
292
|
+
`).map(s=>s.trim()).filter(Boolean);function dt(e,s){const n=!!e?.cold,a=(e?.servers??[]).map(o=>{const r=o.transport==="http",u=o.secret_refs??[],d=o.status==="connected"?"connected":o.status==="connecting"?"connecting":o.status==="auth-required"?"needs_sign_in":"not_started",c=[];d!=="connected"&&c.push("connect"),d==="connected"&&c.push("disconnect"),n||c.push("reload"),r&&o.transport_oauth_supported!==!1&&c.push("sign_in"),u.length>0&&c.push("set_key"),o.owned_scope&&c.push("remove"),o.setup?.text&&c.push("copy_setup");const m=un(o.source);return{id:o.name,name:o.name,scope:o.owned_scope??"global",project_cwd:null,source:{kind:ai(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:d,status_reason:null,status_observed_at:null,last_seen_at:null,status_basis:n?"stored":"live",auth:{kind:u.length?"api_key":r?"unknown":"none",signed_in:null,secret_refs:u.map(g=>({id:g.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:n?"config":"live",session_id:s,servers:a,operations:(e?.operations??[]).map(o=>({...o}))}}const ai=(e,s,n)=>s==="Claude Code"?"claude-code":s==="Cursor"?"cursor":s==="VS Code"?"vscode":s==="Codex CLI"?"codex":n?"local-operator":e?"project-mcp-json":"local-operator",Pt={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."},oi="The server refused it, so nothing was changed. Try again.";function Pe(e,s,n){if(s instanceof ft&&s.status===409){const a=typeof s.code=="string"&&Object.prototype.hasOwnProperty.call(Pt,s.code)?Pt[s.code]:oi;return`${$n[e]}. ${a}`}return Un(e,s,n).message}const ri="New chats can use it right away. Open chats pick it up when you start a new chat or reload integrations there.",ii="Most services give you a URL. Use Local command when their setup says npx or uvx.",ci=({existingNames:e,projectScopeAvailable:s,projectLabel:n,onSubmit:a,onCancel:o,initial:r})=>{const[u,d]=i.useState(r?.name??""),[c,m]=i.useState(r?.mode??"command"),[g,b]=i.useState(r?.command??""),[k,f]=i.useState(r?.args??""),[x,E]=i.useState(r?.url??""),[S,H]=i.useState("global"),[_,$]=i.useState(r?.touched?{name:!0,command:!0,url:!0}:{}),[I,M]=i.useState(!!r?.touched),[N,G]=i.useState(!1),[P,q]=i.useState(null),K=i.useRef(null),X=i.useRef(null),A=i.useRef(null);i.useEffect(()=>{K.current?.focus()},[]);const T=ti(u,e),V=c==="command"&&!g.trim()?"Enter the command to run.":null,z=c==="url"?ni(x):null,O=C=>I||_[C],ee=async C=>{if(C.preventDefault(),M(!0),T||V||z){T?K.current?.focus():V?X.current?.focus():A.current?.focus();return}G(!0),q(null);const Z=s?S:"global",Q=c==="command"?{name:u.trim(),scope:Z,mode:c,command:g.trim(),args:si(k)}:{name:u.trim(),scope:Z,mode:c,url:x.trim()},J=await a(Q);G(!1),q(J)},R=(C,Z,Q)=>Z&&O(Q)?t.jsx("p",{id:C,className:"text-body-sm text-danger",children:Z}):null,ie=C=>C.preventDefault();return t.jsxs("form",{noValidate:!0,"aria-label":"Add integration",className:"flex flex-col gap-4 rounded-lg bg-surface p-4",onSubmit:C=>void ee(C),onKeyDown:C=>{C.key==="Escape"&&(C.stopPropagation(),o())},children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-name",children:"Name"}),t.jsx(Se,{ref:K,id:"integration-add-name",value:u,placeholder:"e.g. notion",autoComplete:"off","aria-invalid":!!(T&&O("name")),"aria-describedby":T&&O("name")?"integration-add-name-error":void 0,onChange:C=>d(C.target.value),onBlur:()=>$(C=>({...C,name:!0}))}),R("integration-add-name-error",T,"name")]}),t.jsxs(Lt,{value:c,onValueChange:C=>m(C==="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(Et,{"aria-labelledby":"integration-add-transport-label",children:[t.jsx(ze,{value:"command","data-integration-transport":"command",children:"Local command"}),t.jsx(ze,{value:"url","data-integration-transport":"url",children:"Remote URL"})]}),t.jsx("p",{className:"text-ink-dim text-meta",children:ii}),t.jsxs(It,{value:"command",className:"mt-0 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-command",children:"Command"}),t.jsx(Se,{ref:X,id:"integration-add-command",value:g,placeholder:"e.g. npx",autoComplete:"off",className:"font-mono","aria-invalid":!!(V&&O("command")),"aria-describedby":V&&O("command")?"integration-add-command-error":void 0,onChange:C=>b(C.target.value),onBlur:()=>$(C=>({...C,command:!0}))}),R("integration-add-command-error",V,"command")]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs(fe,{htmlFor:"integration-add-args",children:["Arguments"," ",t.jsx("span",{className:"font-normal text-ink-dim",children:"(one per line)"})]}),t.jsx(cn,{id:"integration-add-args",value:k,rows:2,className:"font-mono",onChange:C=>f(C.target.value)})]})]}),t.jsx(It,{value:"url",className:"mt-0 flex flex-col gap-4",children:t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-add-url",children:"URL"}),t.jsx(Se,{ref:A,id:"integration-add-url",type:"url",value:x,placeholder:"https://mcp.example.com/mcp",autoComplete:"off",className:"font-mono","aria-invalid":!!(z&&O("url")),"aria-describedby":z&&O("url")?"integration-add-url-error":"integration-add-url-help",onChange:C=>E(C.target.value),onBlur:()=>$(C=>({...C,url:!0}))}),R("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."})]})})]}),s?t.jsxs(Lt,{value:S,onValueChange:C=>H(C==="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(Et,{"aria-labelledby":"integration-add-scope-label",children:[t.jsx(ze,{value:"global","data-integration-scope":"global",children:"All chats"}),t.jsx(ze,{value:"project","data-integration-scope":"project",children:"This project"})]}),n?t.jsx("p",{className:"text-ink-dim text-meta",children:S==="project"?`Only chats working in ${n}.`:"Every chat, in any folder."}):null]}):null,P?t.jsx("p",{className:"text-body-sm text-danger",role:"alert",children:P}):null,t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsx("p",{className:oe("text-body-sm text-ink-dim"),children:ri}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(D,{type:"button",variant:"ghost",size:"md",onMouseDown:ie,onClick:o,children:"Cancel"}),t.jsxs(D,{type:"submit",variant:"primary",size:"md",disabled:N,onMouseDown:ie,children:[N?t.jsx(re,{size:"xs"}):null,"Add integration"]})]})]})]})},li=4;function di(e){return e.rowMoving?e.now+e.windowMs:Math.max(e.hold.until,e.lastMovingAt+e.windowMs)}function ui(e){return e.now>e.hold.until||e.hold.reanchors>=li?"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 mi(e){const s=di({hold:e.hold,now:e.now,windowMs:e.windowMs,rowMoving:e.rowMoving,lastMovingAt:e.lastMovingAt});if(e.now>s)return{hold:null,land:null};const n=e.hold.landedOn??null,a=e.candidate;if(!a)return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},land:null};if(!n)return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:a},land:a};const o=ui({hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},candidate:a,active:e.active,body:e.body,now:e.now});if(o==="settled")return{hold:{until:s,reanchors:e.hold.reanchors,landedOn:n},land:null};if(o==="drop")return{hold:null,land:null};const r=!n.isConnected;return{hold:{until:r?e.now+e.windowMs:s,reanchors:r?e.hold.reanchors+1:e.hold.reanchors,landedOn:a},land:a}}function hi(e){const{row:s,target:n}=e;return!s||!n||typeof n.nodeType!="number"?!1:!s.contains(n)}const Kt=250;function Ht(e){return e?!e.disabled:!1}function fi(e){return Ht(e.primary)?e.primary??null:Ht(e.overflow)?e.overflow??null:null}function pi(e){return e.verdict==="finished"?null:e.watchMs}const bn="key";function gi(e){const{name:s,keyless:n,freeName:a,names:o,values:r,replace:u,canReplace:d}=e;if(n){const c=ut(s,a);return{values:{[c]:(r[bn]??"").trim()},confirmedReplace:u&&d?[c]:[],header:a.trim()}}return{values:Object.fromEntries(o.map(c=>[c,(r[c]??"").trim()])),confirmedReplace:u&&d?o:[],header:void 0}}function ut(e,s){const n=Bt(e),a=Bt(s);if(!a)return"";const o=[n,a].filter(Boolean).join("_"),r=/^[A-Za-z_]/.test(o)?o:`K_${o}`;if(r.length<=tt)return r;const u=yi(n),d=tt-a.length-u.length-2,c=[n.slice(0,Math.max(d,0)),u,a].filter(Boolean).join("_");return c.length<=tt?c:c.slice(-128)}const tt=128,Bt=e=>e.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_").replace(/^_+|_+$/g,""),yi=e=>{let s=2166136261;for(let n=0;n<e.length;n+=1)s^=e.charCodeAt(n),s=Math.imul(s,16777619)>>>0;return s.toString(36).toUpperCase().slice(0,5)},xi=({name:e,keyNames:s,keyless:n=!1,savedKeys:a=[],saving:o,failure:r,onSave:u,onClose:d})=>{const[c,m]=i.useState({}),[g,b]=i.useState(!1),[k,f]=i.useState(""),x=n?[ut(e,k)]:[...s],E=n?[bn]:x,S=(n?ut(e,k).length>0:!0)&&E.every(_=>(c[_]??"").trim()),H=x.some(_=>a.includes(_));return t.jsx(en,{open:!0,onClose:d,maxWidth:"xs",title:n||s.length===1?`Add the key for ${e}`:`Add keys for ${e}`,actions:t.jsxs(t.Fragment,{children:[t.jsx(at,{onClick:d,children:"Cancel"}),t.jsx(ot,{disabled:!S||o,onClick:()=>{const _=gi({name:e,keyless:n,freeName:k,names:x,values:c,replace:g,canReplace:H});u(_.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:n?"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."}),n?t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:"integration-key-name",children:"The header this server wants the key in"}),t.jsx(Se,{id:"integration-key-name",autoComplete:"off",placeholder:"e.g. Authorization or X-Api-Key",value:k,onChange:_=>f(_.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,E.filter(_=>n!==!0||_.trim().length>0).map(_=>t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx(fe,{htmlFor:`integration-key-${_}`,className:"font-mono",children:n?"Key":_}),t.jsx(Se,{id:`integration-key-${_}`,type:"password",autoComplete:"off",value:c[_]??"",onChange:$=>m(I=>({...I,[_]:$.target.value}))})]},_)),H?t.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[t.jsx(zs,{id:"integration-key-replace",checked:g,onCheckedChange:_=>b(_===!0)}),t.jsx(fe,{htmlFor:"integration-key-replace",className:"font-normal",children:fn(x.length)})]}):null,r?t.jsx("p",{className:"-mx-1.5 text-body-sm text-danger",role:"alert",children:r}):null]})})},ki={success:"bg-success",warning:"bg-warning",danger:"bg-danger",info:"bg-info",neutral:"bg-ink-dim"},vi={success:"text-ink-muted",warning:"text-warning",danger:"text-danger",info:"text-ink-muted",neutral:"text-ink-dim"},Vt={Ready:$r,"Not connected":Ur},bi=({row:e,operations:s,memories:n,now:a,projectScopeAvailable:o,highlighted:r=!1,rowRef:u,primaryRef:d,overflowRef:c,pending:m,failure:g,confirm:b,onPrimary:k,onOverflow:f,onConfirm:x,onCancelConfirm:E})=>{const S=Or(e,s,n,a),H=r&&S.tone==="danger"?"text-ink":vi[S.tone],_=xt(e,s,n),$=Kr(e,s,n),I=Pr(e,o),M=$.findIndex(N=>N.kind==="remove"||N.kind==="remove_elsewhere");return t.jsxs("li",{ref:u,"data-integration":e.name,"data-status":e.status,className:oe("flex min-h-14 flex-col justify-center gap-1 px-4 py-2.5",r&&"bg-row-selected"),onKeyDown:N=>{!b||N.key!=="Escape"||(N.stopPropagation(),E())},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:S.busy?t.jsx(re,{size:"xs"}):t.jsx("span",{"aria-hidden":"true","data-tone":S.tone,className:oe("size-2 rounded-full",ki[S.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:I.map((N,G)=>t.jsxs("span",{children:[G>0?" · ":null,N.startsWith("Imported from")&&e.source.path?t.jsx(Re,{content:zn(e.source.path),children:t.jsx("span",{className:"underline decoration-dotted underline-offset-2",children:N})}):N]},N))})]}),Vt[S.label]?t.jsx(Re,{content:Vt[S.label],children:t.jsx("span",{className:oe("shrink-0 text-body-sm",H),children:S.label})}):t.jsx("span",{className:oe("shrink-0 text-body-sm",H),children:S.label}),_?t.jsxs(D,{ref:d,variant:_.variant??"secondary",size:"sm","aria-label":`${_.label} ${e.name}`,disabled:m,"data-integration-action":_.kind,onClick:()=>k(_),children:[m?t.jsx(re,{size:"xs"}):null,_.label]}):null,t.jsxs(Ps,{children:[t.jsx(Ks,{asChild:!0,children:t.jsx(D,{ref:c,variant:"ghost",size:"icon-sm","aria-label":`More actions for ${e.name}`,disabled:m,children:t.jsx(Pn,{"aria-hidden":"true"})})}),t.jsx(Hs,{align:"end",className:"min-w-48",children:$.map((N,G)=>t.jsx(wi,{item:N,separated:G===M&&G>0,onSelect:()=>f(N)},N.kind))})]})]}),S.detail?t.jsx("p",{className:oe("pl-7 text-body-sm",S.tone==="danger"?"text-ink-muted":"text-ink-dim"),children:S.detail}):null,g?t.jsx("p",{className:oe("pl-7 text-body-sm",r?"text-ink":"text-danger"),role:"alert",children:g}):null,b?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-7",children:[t.jsx("span",{className:"text-body-sm text-ink",children:b.kind==="remove"?`Remove ${e.name}?`:`Sign out of ${e.name}?`}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:b.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(D,{variant:"danger",size:"sm",onClick:x,"data-integration-confirm":b.kind,children:b.kind==="remove"?"Remove":"Sign out"}),t.jsx(D,{variant:"ghost",size:"sm",onClick:E,children:"Keep"})]}):null]})},wi=({item:e,separated:s,onSelect:n})=>t.jsxs(t.Fragment,{children:[s?t.jsx(Bs,{}):null,e.kind==="remove_elsewhere"?t.jsxs(Ot,{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(Ot,{destructive:e.kind==="remove",onSelect:n,"data-integration-menu":e.kind,children:e.label})]});function ji(e,s,n){return!s||s.status==="running"?s?.browser_opened===!0?{message:`Your browser opened. Approve access to ${e} there, then come back here.`,tone:"progress",link:s.authorization_url??null}:s?.browser_opened===!1?{message:s.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:s.authorization_url??null}:{message:`Waiting for you to approve access to ${e}…`,tone:"progress",link:s?.authorization_url??null}:s.status==="complete"?{message:`Signed in to ${e}. Agents can use it now.`,tone:"success",link:null}:s.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:Dr(s.message,n)??"The server didn't say why.",nextStep:_i(s.message??null,n)}}function _i(e,s){const n=(e??"").toLowerCase();return n.includes("redirect")?s?"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.":n.includes("no oauth")||n.includes("authorization server")?s?"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.":n.includes("network")||n.includes("connect")?"Check the server's URL and your network, then try again.":"Check the server's settings, then try again."}function Ni(e,s){return e.kind==="ready"?"ready":e.kind==="running"&&s&&s.tone!=="progress"?s.tone==="success"?"success":"failure":"running"}const Si=({name:e,action:s,keyRoute:n,phase:a,onStart:o,onCancel:r,onOpenLink:u,onClose:d})=>{const c=a.kind==="running"?a.operation:null,m=a.kind==="running"?ji(e,c,n):null,g=a.kind==="starting"||a.kind==="running"&&m?.tone==="progress",b=m&&m.tone!=="progress",k=i.useRef(null),f=i.useRef(!1),x=Ni(a,m);i.useEffect(()=>{if(!f.current){f.current=!0;return}x&&k.current?.focus()},[x]);const E=()=>d(m?.tone==="success"?"signed-in":"dismissed");return t.jsx(en,{open:!0,onClose:E,maxWidth:"xs",fullWidth:!0,title:`Sign in to ${e}`,dialogProps:{onOpenAutoFocus:S=>{S.preventDefault(),k.current?.focus()}},actions:t.jsxs(t.Fragment,{children:[g&&c?t.jsx(at,{ref:k,onClick:()=>r(c.id),children:"Cancel sign-in"}):t.jsx(at,{ref:a.kind==="ready"?void 0:k,onClick:E,children:m?.tone==="success"?"Done":"Close"}),a.kind==="ready"?t.jsx(ot,{ref:k,onClick:o,children:"Continue in browser"}):null,a.kind==="refused"||m?.tone==="failure"?t.jsx(ot,{ref:m?.tone==="failure"?k: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,".",s==="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:b?"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(Vs,{"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(D,{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(()=>rt("Sign-in link copied.")).catch(()=>{})},children:t.jsx(Kn,{"aria-hidden":"true"})})]}),t.jsx(D,{variant:"link",size:"sm",onClick:()=>u(m.link??""),children:"Open the sign-in page"})]}):null,a.kind==="refused"?t.jsx("p",{className:"text-danger",role:"alert",children:a.message}):null]})})},Ci=e=>e.reduce((s,n)=>s?(n.updated_at??0)>(s.updated_at??0)?n:s:n,null),Mi=/^[A-Za-z]:[\\/]/,Ve=e=>{const s=e?.trim();return s&&(s.startsWith("/")||Mi.test(s))?s:null};function Ai(e){const o=e?.payload?.frontend?.snapshot?.cwd;return typeof o=="string"&&o.trim()?o:null}const Te="local-operator.settings.integrations.last-cwd";function Ri(e,s,n=typeof localStorage>"u"?null:localStorage){const a=Ve(s);if(!(!e||!a||!n))try{const o=n.getItem(Te),r=o?JSON.parse(o):{};if(r[e]===a)return;n.setItem(Te,JSON.stringify({...r,[e]:a}))}catch{}}const wn=()=>typeof localStorage>"u"?null:localStorage;function jn(e=wn()){if(!e)return{};try{const s=e.getItem(lt);if(!s)return{};const n=JSON.parse(s);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}const Gt=256;function Ti(e,s=wn()){if(s)try{const n={...jn(s),...e},a=Object.keys(n);if(a.length>Gt){const o={};for(const r of a.slice(-Gt))o[r]=n[r];s.setItem(lt,JSON.stringify(o));return}s.setItem(lt,JSON.stringify(n))}catch{}}function qt(e,s,n){return e==="saved"?null:e==="replace_confirmation_required"?`A saved value already exists for this key. Tick “${fn(Object.keys(n).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: ${(s.length?s:Object.keys(n)).join(", ")}. The encrypted store may be locked.`}function Li(e,s=typeof localStorage>"u"?null:localStorage){if(!(!e||!s))try{const n=s.getItem(Te);if(!n)return;const a=JSON.parse(n);if(!(e in a))return;const o={...a};delete o[e],s.setItem(Te,JSON.stringify(o))}catch{}}const Ei=e=>!!(e&&typeof e=="object"&&"code"in e&&e.code==="invalid_cwd"),Ii=(e,s)=>s!==null&&e===s?null:e;function Oi(e,s=typeof localStorage>"u"?null:localStorage){if(!e||!s)return null;try{const n=s.getItem(Te);if(!n)return null;const o=JSON.parse(n)[e];return typeof o=="string"?o:null}catch{return null}}const Fi=e=>e.action==="disconnect"?"disconnected":"connected";function Di(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 $i(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 Ui({sessionId:e}){const s=Hn(),n=Mt(s.data,"mcp_catalog"),a=Mt(s.data,"mcp"),o=n?"catalog":a?"session":null,[r,u]=i.useState(null),d=Qt(),c=Ke(h=>h.sessions),m=Ke(h=>h.fetchSessions),g=Ke(h=>h.loading),b=i.useMemo(()=>c.find(h=>h.session_id===e)??null,[c,e]),k=i.useMemo(()=>o==="session"&&!e?Ci(c):null,[o,e,c]),f=o==="session"?e??k?.session_id??null:null;i.useEffect(()=>{o!=="session"||e||c.length>0||m(Bn)},[o,e,c.length,m]);const x=o==="catalog"?Ve(b?.cwd):null,E=o==="catalog"&&!!e&&x===null,S=Ne({queryKey:["desktop","session-cwd",e??""],queryFn:()=>Ue({op:"sessions.get",sessionId:e??""}),enabled:E,staleTime:Number.POSITIVE_INFINITY,retry:!1}),H=E&&!S.isFetched,_=x??Ve(Ai(S.data))??(S.isFetched?Ve(Oi(e)):null),$=Ii(_,r),I=o==="catalog"?$:null,M=o==="catalog"?e??null:null,N=Vn.catalog(I,M);i.useEffect(()=>{o!=="catalog"||!e||!I||Ri(e,I)},[o,e,I]);const G=i.useRef(0),[P,q]=i.useState(0),K=i.useRef(null),X=i.useCallback((h,w)=>{const v=Date.now()+zt;G.current=v,K.current={name:h,expect:w},q(v)},[]),A=i.useCallback(h=>Date.now()<G.current?vn:Jr(h),[]),T=Ne({queryKey:N,queryFn:()=>Yn(I,M),enabled:o==="catalog"&&!H,staleTime:1e4,refetchInterval:h=>A(h.state.data)}),V=Ei(T.error);i.useEffect(()=>{!V||!_||r===_||(u(_),Li(e))},[V,_,r,e]);const z=Ne({queryKey:it.list(f??""),queryFn:()=>Wn(f??""),enabled:o==="session"&&!!f,staleTime:1e4,refetchInterval:h=>A(h.state.data?dt(h.state.data,f??""):void 0)}),O=i.useMemo(()=>{if(o==="catalog")return T.data;if(o==="session"&&z.data&&f)return dt(z.data,f)},[o,T.data,z.data,f]),ee=i.useCallback(()=>zi({queryClient:d,route:o,catalogKey:N,sessionId:f}),[o,N,d,f]);i.useEffect(()=>{if(!P)return;const h=K.current;if(!h)return;const w=O?.servers.find(U=>U.name===h.name);!w||!(h.expect==="connected"?w.status==="connected":w.status_basis==="live"&&w.status!=="connected")||(G.current=0,K.current=null,q(0))},[O,P]);const R=i.useRef({}),[ie,C]=i.useState(0),Z=i.useMemo(()=>(R.current=Vr(Yr(R.current,O,jn()),O),R.current),[O,ie]),Q=i.useRef("");i.useEffect(()=>{const h=qr(Z,O);if(!Object.keys(h).length)return;const w=JSON.stringify(h);w!==Q.current&&(Q.current=w,Ti(h))},[Z,O]);const J=i.useCallback(h=>{const w=be(R.current,h);w.needsKey||(R.current={...R.current,[h]:{...w,needsKey:!0}},C(v=>v+1))},[]),Y=i.useCallback(h=>{if(h.action!=="disconnect"&&h.action!=="connect"&&h.action!=="reload")return;const w=be(R.current,h.name),v=Date.now()+zt,U=h.action==="disconnect"?{...w,connectedAt:null,disconnectedAt:Date.now(),holdUntil:v}:{...w,disconnectedAt:null,holdUntil:v};R.current={...R.current,[h.name]:U},X(h.name,Fi(h)),C(F=>F+1)},[X]),W=i.useCallback(async h=>{if(o==="catalog"){const w=Di(h);if(!w)return null;try{const v=await Gn(I,w);return d.setQueryData(N,v),Y(h),v.operation?.id??null}catch(v){throw v instanceof ft&&v.status===409&&d.invalidateQueries({queryKey:N}),v}}if(o==="session"&&f){const w=await Ue({op:"mcp.control",sessionId:f,control:$i(h)});Y(h);const v=it.list(f),U=w?.data;return U&&"servers"in U&&Array.isArray(U.servers)?(d.setQueryData(v,U),null):(d.invalidateQueries({queryKey:v}),U&&"id"in U&&typeof U.id=="string"?U.id:null)}return null},[o,I,N,d,f,Y]),pe=i.useCallback(async h=>{if(o==="catalog"&&M&&(h.action==="connect"||h.action==="disconnect"||h.action==="reload")){try{await Ue({op:"mcp.control",sessionId:M,control:{action:h.action,name:h.name,...h.action==="disconnect"?{confirmed:!0}:{}}})}catch(w){throw d.invalidateQueries({queryKey:N}),w}return Y(h),await d.invalidateQueries({queryKey:N}),null}return W(h)},[o,M,d,N,W,Y]),we=i.useCallback(async(h,w,v,U)=>{if(o==="catalog"){const F=await qn(I,h,w,v,U);if(F.catalog&&d.setQueryData(N,F.catalog),F.code!=="saved")return{saved:!1,message:qt(F.code,F.failed_ids,w)};try{await W({action:"test",name:h})}catch{}return{saved:!0,message:null}}if(o==="session"&&f){const F=await Ue({op:"mcp.credentials.store",sessionId:f,name:h,values:w,confirmedReplace:v});if(F.data?.code!=="saved")return{saved:!1,message:qt(F.data?.code,F.data?.failed_ids??[],w)};try{await W({action:"connect",name:h})}catch{}return{saved:!0,message:null}}return{saved:!1,message:null}},[o,I,N,d,W,f]),de=o==="catalog"?T:z,ge=i.useCallback(()=>{de.refetch()},[de]);return{enabled:o!==null,route:o,sessionId:o==="catalog"?M:f,borrowed:k,noConversation:o==="session"&&!f&&!g,document:O,isLoading:s.isLoading||o==="catalog"&&(H||T.isLoading)||o==="session"&&(f?z.isLoading:g),isError:de.isError,folderUnavailable:Gr(r,_),refetch:ge,readDocument:ee,control:pe,storeKeys:we,memories:Z,markNeedsKey:J}}function zi(e){if(e.route==="catalog")return e.queryClient.getQueryData(e.catalogKey);if(e.route==="session"&&e.sessionId){const s=e.queryClient.getQueryData(it.list(e.sessionId));return s?dt(s,e.sessionId):void 0}}const Pi=(e,s)=>{const n=e?.trim();if(!n)return null;const a=Xn(n,s);return a.kind==="auth"?{kind:"matched",name:a.name,unresolved:null}:{kind:"miss",asked:n}},Ki=6,nt="Integrations",Hi="Let agents use your tools and accounts, like Notion, Linear or GitHub.",Bi={test:"test",connect:"reconnect",disconnect:"disconnect",reload:"reload",remove:"remove",sign_out:"disconnect",cancel:"cancel",login:"grant",reauth:"grant"},Vi=({sessionId:e,sectionRef:s,highlightServer:n})=>{const a=Ui({sessionId:e}),{document:o,control:r,readDocument:u}=a,d=Zn(),c=o?.servers??[],m=o?.operations??[],g=o?.project_scope_available??!1,[b,k]=i.useState(!1),[f,x]=i.useState(""),[E,S]=i.useState(null),[H,_]=i.useState({}),[$,I]=i.useState(null),[M,N]=i.useState(null),[G,P]=i.useState({kind:"ready"}),[q,K]=i.useState(null),[X,A]=i.useState(null),[T,V]=i.useState(!1),z=i.useRef({}),O=i.useRef({}),ee=i.useRef({}),R=i.useRef(0),ie=i.useRef(null),C=i.useRef(null),Z=i.useRef(null),[Q,J]=i.useState(null),[Y,W]=i.useState(null),[pe,we]=i.useState(null),de=i.useCallback(()=>{const l=Z.current;Z.current=null,N(null),K(null),window.setTimeout(()=>{l?.isConnected&&l.focus()},0)},[]),ge=i.useCallback(l=>{const p=window.document.activeElement;Z.current=p instanceof HTMLElement?p:null,N(l)},[]),h=i.useCallback((l,p)=>{W({name:l,waitForSignIn:p==="signed-in",until:Date.now()+Me,reanchors:0}),de()},[de]),w=i.useMemo(()=>Pi(n,c.map(l=>l.name)),[n,c]),v=w?.kind==="matched"?w.name:null,U=i.useRef(null),F=i.useRef(null),te=f.trim().toLowerCase(),B=i.useMemo(()=>te?c.filter(l=>l.name.toLowerCase().includes(te)):c,[c,te]),je=i.useMemo(()=>Br(B,m,a.memories),[B,m,a.memories]),ue=M?.kind==="sign_in"?c.find(l=>l.name===M.name)??null:null;i.useEffect(()=>{!v||F.current===v||!f||x("")},[v,f]),i.useEffect(()=>{!v||F.current===v||B.some(l=>l.name===v)&&(F.current=v,U.current?.scrollIntoView({block:"center",behavior:"smooth"}))},[v,B]),i.useEffect(()=>{if(!q)return;const l=m.find(p=>p.id===q)??null;P({kind:"running",operation:l})},[m,q]);const ce=m.some(l=>l.status==="running"),ye=l=>{const p=window.document.activeElement;p&&p!==window.document.body&&p.isConnected||W({name:l,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})},ne=async(l,p,j)=>{S(l),_(({[l]:xe,...ke})=>ke);let L=null,me=!1;try{L=await j()}catch(xe){me=!0,_(ke=>({...ke,[l]:Pe(Bi[p]??"status",xe,ce)}))}finally{S(null),p!=="sign_out"&&(p!=="remove"||me)&&ye(l)}return{operationId:L,failed:me}},We=l=>c.find(p=>p.name===l),Ie=l=>{l.source.path&&es(l.source.path)},Ze=async(l,p)=>{P({kind:"starting"}),K(null);try{const j=await r({action:p,name:l});j?K(j):P({kind:"running",operation:null})}catch(j){j instanceof ft&&j.code==="oauth_unsupported"&&a.markNeedsKey(l),P({kind:"refused",message:Pe("grant",j,ce)})}},Oe=(l,p)=>{switch(p.kind){case"sign_in":case"reauth":{const j=m.find(L=>L.name===l.name&&L.status==="running");j&&Ee(j)?(P({kind:"running",operation:j}),K(j.id)):(P({kind:"ready"}),K(null)),ge({kind:"sign_in",name:l.name,action:p.kind==="reauth"?"reauth":"login"});return}case"set_key":A(null),ge({kind:"key",name:l.name,keyNames:l.auth.secret_refs.map(j=>j.id)});return;case"fix":Ie(l);return;case"sign_out":I({name:l.name,kind:"sign_out"});return;default:{const j=p.kind;ne(l.name,j,()=>r({action:j,name:l.name}))}}},bt=(l,p)=>{switch(p.kind){case"remove":case"sign_out":I({name:l.name,kind:p.kind});return;case"sign_in":case"reauth":case"set_key":Oe(l,{kind:p.kind,label:p.label});return;case"open_config":Ie(l);return;case"copy_setup":navigator.clipboard.writeText(l.setup_prompt??"").then(()=>rt("Setup steps copied. Paste them into a chat.")).catch(()=>{});return;case"cancel":{const j=m.find(L=>L.name===l.name&&L.status==="running");j&&ne(l.name,"cancel",()=>r({action:"cancel",operationId:j.id}));return}case"test":case"connect":case"disconnect":case"reload":{const j=p.kind;ne(l.name,j,()=>r({action:j,name:l.name}));return}default:return}},Fe=(l,p)=>{if(I(null),p==="remove"){const j=l.source.owned_scope;if(!j)return;const L=B.findIndex(me=>me.name===l.name);ne(l.name,"remove",()=>r({action:"remove",name:l.name,scope:j})).then(({operationId:me,failed:xe})=>{xe||me!==null||(rt(`Removed ${l.name}.`),L>=0&&we({index:L}))});return}ne(l.name,"sign_out",()=>r({action:"logout",name:l.name})).then(()=>{W({name:l.name,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})})},De=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}}),k(!1),J(l.name),null}catch(p){return Pe("add",p,!1)}},wt=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:nt}),t.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:Hi})]}),a.enabled&&c.length>0&&!b?t.jsxs(D,{ref:ie,variant:"secondary",size:"sm",onClick:()=>k(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(At,{"aria-hidden":"true"}),"Add integration"]}):null]});if(!a.enabled&&!a.isLoading)return t.jsx(se,{title:nt,titleComponent:wt,sectionRef:s,children:t.jsx(le,{variant:"warning",children:"Integrations need a newer Local Operator backend. Update it and restart the app to manage them here."})});const jt=t.jsx(ci,{existingNames:c.map(l=>l.name),projectScopeAvailable:g,projectLabel:o?.cwd?qi(o.cwd):null,onSubmit:De,onCancel:()=>{k(!1),window.setTimeout(()=>ie.current?.focus(),0)}}),_t=M?We(M.name):void 0,_n=Object.entries(H).filter(([l])=>!c.some(p=>p.name===l)),Nn=l=>_(({[l]:p,...j})=>j);i.useEffect(()=>{if(!Q)return;const l=z.current[Q];if(!l){c.some(p=>p.name===Q)&&(O.current[Q]?.focus(),J(null));return}l.focus(),J(null)},[Q,c]),i.useEffect(()=>{if(!pe)return;const p=B[Math.min(pe.index,B.length-1)]??B.at(-1);if(p){const j=z.current[p.name]??O.current[p.name];if(!j)return;j.focus()}else ie.current?.focus();we(null)},[pe,B]);const Qe=i.useCallback((l,p)=>{const j=u()??o,L=j?.servers.find(Sn=>Sn.name===l.name),me=j?.operations??[],xe=L?L.status==="connecting"||Ce(L.name,me)!==null:!1;xe&&L&&(R.current=p);const ke=L?xt(L,me,a.memories):null;if(L&&l.waitForSignIn&&(ke?.kind==="sign_in"||ke?.kind==="reauth"))return"kept";const _e=mi({hold:l,now:p,windowMs:Me,rowMoving:xe,lastMovingAt:R.current,candidate:L?fi({primary:ke?z.current[L.name]:null,overflow:O.current[L.name]}):void 0,active:window.document.activeElement,body:window.document.body});if(!_e.hold)return W(null),"finished";if(!_e.land)return"kept";W({name:l.name,waitForSignIn:!1,until:_e.hold.until,landedOn:_e.land,reanchors:_e.hold.reanchors});const Nt=_e.land;return window.setTimeout(()=>{Nt.isConnected&&Nt.focus()},0),"landed"},[u,o,a.memories]);return i.useEffect(()=>{if(!Y)return;Qe(Y,Date.now());let l=0,p=!1;const j=()=>{if(p)return;const L=pi({verdict:Qe(Y,Date.now()),watchMs:Kt});L!==null&&(l=window.setTimeout(j,L))};return l=window.setTimeout(j,Kt),()=>{p=!0,window.clearTimeout(l)}},[Y,Qe]),i.useEffect(()=>{if(!Y)return;const l=p=>{hi({target:p.target,row:ee.current[Y.name]})&&W(null)};return window.document.addEventListener("pointerdown",l,!0),()=>{window.document.removeEventListener("pointerdown",l,!0)}},[Y]),t.jsxs(se,{title:nt,titleComponent:wt,sectionRef:s,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(D,{variant:"primary",size:"sm",onClick:()=>d("/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(le,{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(le,{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(D,{variant:"secondary",size:"sm",onClick:a.refetch,children:"Retry"})]})}):null,_n.map(([l,p])=>t.jsx(le,{variant:"warning",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{children:p}),t.jsx(D,{variant:"ghost",size:"sm",onClick:()=>Nn(l),children:"Dismiss"})]})},l)),b&&c.length>0?jt:null,c.length>=Ki?t.jsxs("div",{className:"relative",children:[t.jsx(Qn,{"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-dim"}),t.jsx(Se,{ref:C,value:f,onChange:l=>x(l.target.value),onKeyDown:l=>{l.key!=="Escape"||!f||(l.preventDefault(),x(""))},placeholder:`Search ${Nr(c.length)}`,"aria-label":"Search integrations",className:"pl-9"})]}):null,w?.kind==="miss"&&c.length>0?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`No integration matches "${w.asked}".`}):null,w?.kind==="matched"&&w.unresolved?t.jsx("p",{className:"text-body-sm text-ink-muted",children:`Showing "${w.name}" — "${w.unresolved}" is not one of your integrations.`}):null,o&&c.length===0&&!a.isLoading?b?jt:t.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-lg bg-surface p-6",children:[t.jsx(tn,{"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(D,{variant:"primary",size:"md",onClick:()=>k(!0),"data-tour-tag":"mcp-add-server",children:[t.jsx(At,{"aria-hidden":"true"}),"Add integration"]})]}):null,c.length>0&&B.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(D,{variant:"secondary",size:"sm",onClick:()=>{x(""),window.setTimeout(()=>{(C.current??ie.current)?.focus()},0)},children:"Clear search"})]}):null,je.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(p=>t.jsx(bi,{row:p,operations:m,memories:a.memories,projectScopeAvailable:g,highlighted:p.name===v,rowRef:j=>{ee.current[p.name]=j,p.name===v&&(U.current=j)},primaryRef:j=>{z.current[p.name]=j},overflowRef:j=>{O.current[p.name]=j},pending:E===p.name,failure:H[p.name]??null,confirm:$?.name===p.name?{kind:$.kind}:null,onPrimary:j=>Oe(p,j),onOverflow:j=>bt(p,j),onConfirm:()=>$&&Fe(p,$.kind),onCancelConfirm:()=>{I(null),window.setTimeout(()=>{O.current[p.name]?.focus()},0)}},p.id))})]},l.id))]}),M?.kind==="sign_in"?t.jsx(Si,{name:M.name,action:M.action,keyRoute:ue?qe(ue):!1,phase:G,onStart:()=>void Ze(M.name,M.action),onCancel:l=>void r({action:"cancel",operationId:l}).catch(()=>{}),onOpenLink:l=>void Jn(l),onClose:l=>h(M.name,l)}):null,M?.kind==="key"?t.jsx(xi,{name:M.name,keyNames:M.keyNames.length?M.keyNames:_t?.auth.secret_refs.map(l=>l.id)??[],keyless:M.keyNames.length===0,savedKeys:_t?.auth.secret_refs.filter(l=>l.state==="encrypted").map(l=>l.id),saving:T,failure:X,onClose:de,onSave:(l,p,j)=>{V(!0),A(null),a.storeKeys(M.name,l,p,j).then(L=>{if(!L.saved){A(L.message);return}N(null),W({name:M.name,waitForSignIn:!1,until:Date.now()+Me,reanchors:0})}).catch(L=>A(Pe("key",L,!1))).finally(()=>V(!1))}}):null]})},Me=4e3,Gi=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,qi=e=>e.replace(Gi,"~"),Yi=e=>typeof e!="number"||!Number.isFinite(e)?"your free credits":`$${e.toFixed(2)} in free credits`,Wi="https://console.radienthq.com/dashboard/verification",Zi=(e,s)=>e==="pending"?{sentence:`Verify your email to claim ${s}. Check your inbox for the link Radient sent.`,action:"Open verification page"}:e==="expired"?{sentence:`The link to claim ${s} 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"},Qi=({verification:e})=>{const{prices:s}=xs(),n=e.grant_amount??s?.default_new_credits,{sentence:a,action:o}=Zi(e.signup_grant,Yi(n)),r=e.claim_url||Wi;return t.jsxs("div",{className:"mt-8 flex items-start gap-3 rounded-sm border border-hairline bg-surface p-3",children:[t.jsx(Ge,{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(D,{variant:"secondary",size:"sm",onClick:()=>{window.api?.openExternal?window.api.openExternal(r):window.open(r,"_blank")},children:o})]})]})},Ji=({onAfterCredentialUpdate:e})=>{const{isAuthenticated:s,user:n,isLoading:a,accountRead:o,signOut:r}=ts(),u=nn(b=>b.isSigningOut),d=i.useCallback(async()=>{try{await r()}catch(b){console.error("Error signing out:",b)}},[r]),c=i.useMemo(()=>{if(!s||!n?.radientUser)return null;const{account:b,identity:k,verification:f}=n.radientUser,x=f!=null&&!f.email_verified&&f.signup_grant!=="claimed";return t.jsxs(t.Fragment,{children:[t.jsxs(pt,{children:[t.jsx(ae,{label:"Status",value:t.jsxs("span",{className:"inline-flex items-center gap-2",children:["Connected",t.jsx(Gs,{variant:"success",className:"capitalize",children:b.status})]})}),t.jsx(ae,{label:"Name",value:b.name||"Not provided"}),t.jsx(ae,{label:"Email",value:b.email}),t.jsx(ae,{label:"Account ID",value:t.jsx("span",{className:"text-mono-sm",children:b.id})}),t.jsx(ae,{label:"Tenant ID",value:t.jsx("span",{className:"text-mono-sm",children:b.tenant_id})}),t.jsx(ae,{label:"Provider",value:t.jsx("span",{className:"capitalize",children:k.provider})}),t.jsx(ae,{label:"Created",value:sn(b.created_at)})]}),x&&f?t.jsx(Qi,{verification:f}):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(D,{variant:"danger",className:"mt-3",onClick:d,children:[t.jsx(ys,{}),"Sign out from Radient"]})]})]})},[s,n?.radientUser,d]),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.":an(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]),g=i.useMemo(()=>s&&n?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(Zs,{titleText:"",onAfterCredentialUpdate:e,descriptionText:"",onSignInSuccess:()=>{}})})]}),[s,n,m,e]);return a||u?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"}),!u&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Loading your Radient account details…"})]}):s&&n?.radientUser?c:t.jsx("div",{className:"flex flex-col gap-4",children:g})};function Xi({metric:e,data:s}){return t.jsx(ns,{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 ${s.length} days.`,xTickFormatter:n=>n,yTickFormatter:n=>e==="credits"?`$${n.toFixed(2)}`:ss(n),children:t.jsx(pr,{data:s,children:t.jsx(Jt,{type:"monotone",dataKey:"value",strokeWidth:2,dot:!1,activeDot:{r:4,strokeWidth:0},name:e==="credits"?"Credits consumed":"Tokens used"})})})}const ec=()=>{const{data:e,isLoading:s,error:n,refetch:a}=ur(),o=mr(),[r,u]=i.useState(""),[d,c]=i.useState(!1);i.useEffect(()=>{u(e?.content??""),c(!1)},[e]);const m=x=>{const E=x.target.value;u(E),c(E!==(e?.content??""))},g=async()=>{if(!(!d||o.isPending))try{const x={content:r};await o.mutateAsync(x),await a(),c(!1)}catch(x){console.error("Error updating system prompt:",x)}},b=()=>{u(e?.content??""),c(!1)},k=o.isPending,f=()=>t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(fe,{htmlFor:"app-system-prompt",children:"Instructions"}),t.jsx(cn,{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(D,{variant:"primary",onClick:g,disabled:!d||k,children:[k?t.jsx(re,{size:"sm"}):t.jsx(ks,{}),k?"Saving...":"Save changes"]}),t.jsx(D,{onClick:b,disabled:!d||k,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:on(e.last_modified)})]})]});return t.jsx(se,{title:"System prompt",icon:Ws,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:s?t.jsx("div",{className:"flex min-h-50 items-center justify-center",children:t.jsx(re,{size:"lg",label:"Loading system prompt"})}):n?t.jsxs(le,{variant:"danger",children:["Failed to load system prompt:"," ",n instanceof Error?n.message:"Unknown error"]}):f()})},tc=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"],nc=e=>tc.includes(e),sc=e=>{const s=[];let n=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 u=0;u<o;u+=r)s.push({start:n+u,count:Math.min(r,o-u)});n+=o}return s},ac=({index:e,key:s,groups:n})=>{const a=sc(n),o=a.reduce((r,u)=>r+u.count,0);if(!Number.isInteger(e)||e<0||e>=o)return e;switch(s){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),u=a[r+(s==="ArrowDown"?1:-1)];if(!u)return e;const d=e-a[r].start;return u.start+Math.min(d,u.count-1)}default:return e}},oc={localOperatorDark:bo,localOperatorLight:Po,dracula:Eo,dune:Ya,sage:ho,monokai:ws,tokyoNight:No,iceberg:Oo,radient:ro,neon:as,obsidian:dn,synth:ia,catppuccinMocha:Ea,catppuccinLatte:yo,tokyoNightStorm:Na,gruvbox:pa,nord:lr,oneDark:oa,solarizedDark:Uo,rosePine:Ja,rosePineMoon:ko,rosePineDawn:Ta,alucard:eo,gruvboxLight:za,tokyoNightDay:jo,oneLight:po,catppuccinFrappe:$a,catppuccinMacchiato:co,palenight:bs,everforest:tr,everforestLight:Xo,kanagawaWave:or,kanagawaLotus:Za,ayuDark:Ka,ayuMirage:Ba,ayuLight:Ao,nightfox:Ca,duskfox:Vo,synthwave:Co,matrix:la,tron:ja,cyberpunk:vs,vaporwave:Qo,outrun:ha,neonNoir:sr,arcade:uo,forest:Wo,ocean:Ga,desert:qo,autumn:ir,lavender:Do,arctic:Aa,rosewood:ao,solarizedLight:Ho,githubLight:no,paper:Qs,linen:To,highContrastLight:sa,mintLight:ua},Yt="bg-[color-mix(in_srgb,var(--color-accent)_8%,var(--color-accent-wash))]",rc=({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"})]})]})]}),ic=({id:e,name:s,description:n,isSelected:a,isTabStop:o,onSelect:r,onFocusTile:u})=>{const d=oc[e];return t.jsx(Re,{side:"bottom",align:"start",content:n,children:t.jsxs("button",{type:"button","data-theme-tile":e,"aria-pressed":a,tabIndex:o?0:-1,onFocus:u,onClick:r,className:oe("relative flex flex-col gap-1.5 rounded-md p-1 text-left transition-colors duration-fast ease-out-quart",a?Yt:"hover:bg-surface"),children:[t.jsxs("span",{className:oe("relative block h-10 overflow-hidden rounded-sm border transition-colors duration-fast ease-out-quart",a?"border-accent":"border-hairline"),children:[t.jsx(rc,{id:e}),a&&t.jsx("span",{className:oe("pointer-events-none absolute top-0.5 right-0.5 flex h-4 w-4 items-center justify-center rounded-full",Yt),children:t.jsx(Ys,{size:12,className:"text-accent","aria-hidden":"true"})})]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(d,{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:s})]})]})})},cc=e=>[...e.querySelectorAll("[data-theme-grid]")].map(s=>{const n=[...s.querySelectorAll("[data-theme-tile]")],a=n[0]?.getBoundingClientRect().top??0;return{count:n.length,columns:Math.max(1,n.filter(o=>Math.abs(o.getBoundingClientRect().top-a)<1).length)}}),lc=()=>{const{themeName:e,setTheme:s}=ct(),n=i.useMemo(()=>{const d=Object.values(Cn);return[{label:"Dark",items:d.filter(c=>c.theme.palette.mode==="dark")},{label:"Light",items:d.filter(c=>c.theme.palette.mode==="light")}].filter(c=>c.items.length>0)},[]),[a,o]=i.useState(null),r=i.useMemo(()=>{const d=n.flatMap(c=>c.items.map(m=>m.id));return a&&d.includes(a)?a:d.includes(e)?e:d[0]},[n,a,e]),u=d=>{if(!nc(d.key))return;const c=[...d.currentTarget.querySelectorAll("[data-theme-tile]")],m=c.indexOf(d.target);if(m<0)return;d.preventDefault();const g=ac({index:m,key:d.key,groups:cc(d.currentTarget)});g!==m&&c[g]?.focus()};return t.jsx(qs,{children:t.jsx("div",{onKeyDown:u,className:"flex flex-col gap-6",children:n.map(d=>t.jsxs("div",{children:[t.jsx("h3",{className:"px-1 pb-2 text-meta text-ink-dim",children:d.label}),t.jsx("div",{"data-theme-grid":d.label,className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-2",children:d.items.map(({id:c,name:m,description:g})=>t.jsx(ic,{id:c,name:m,description:g,isSelected:c===e,isTabStop:c===r,onSelect:()=>s(c),onFocusTile:()=>o(c)},c))})]},d.label))})})},dc=()=>{const{data:e,isLoading:s,error:n}=yr({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(Fa,{size:16,className:"shrink-0 text-ink-dim"}),"Radient Pass"]}),s&&t.jsx(ln,{className:"h-6 w-36"}),n&&t.jsxs(le,{variant:"warning",children:["Could not load your credit balance. ",n.message]}),e&&!s&&!n&&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(D,{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(ba,{}),"Add credits"]})})]})]})},uc=[{id:"credits",label:"Credits"},{id:"tokens",label:"Tokens"}],mc=()=>{const[e,s]=i.useState("credits"),n=i.useMemo(()=>{const d=new Date,c=fr(d);return{start_date:Ft(c),end_date:Ft(d),rollup:"daily"}},[]),{data:a,isLoading:o,error:r}=kr(n,{enabled:!0}),u=i.useMemo(()=>a?.data_points?[...a.data_points].sort((c,m)=>Je(c.timestamp).getTime()-Je(m.timestamp).getTime()).map(c=>({bucket:hs(ea(Je(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(ya,{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:uc.map(({id:d,label:c})=>t.jsx(D,{variant:"ghost",size:"sm","aria-pressed":e===d,onClick:()=>s(d),className:oe(e===d&&"bg-surface text-ink hover:bg-surface"),children:c},d))})]})]}),o&&t.jsx(ln,{className:"h-62 w-full"}),r&&t.jsxs(le,{variant:"warning",children:["Could not load your usage data. ",r.message]}),!o&&!r&&a&&u.length>0&&t.jsx(Xi,{metric:e,data:u}),!o&&!r&&(!a||u.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(Ls,{size:16,className:"shrink-0 text-ink-dim"}),"Radient account"]}),t.jsx(D,{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(fs,{})]})})]}),Cc=()=>{const e=os("surface"),s=ct(h=>h.showAgentReasoning),n=ct(h=>h.setShowAgentReasoning),{data:a,isLoading:o,isFetching:r,error:u,refetch:d}=rs(),c=is(),{sentence:m,remedy:g}=cs(c??null,"Your settings could not be loaded.",u),b=js(),[k,f]=i.useState(null),x=nn(),{isAuthenticated:E,accountRead:S,isFetching:H,isRefreshing:_,refreshUser:$}=ht(),I=Ke(h=>h.activeSessionId),[M,N]=i.useState("general"),[G,P]=i.useState(!1),q=i.useRef(null),K=i.useRef(null),{startTour:X}=_s(),A=ls(),{data:T,refetch:V}=ds(),{refreshModels:z}=us(),O=i.useMemo(()=>T?.keys?[...T.keys].sort():[],[T?.keys]),ee=i.useRef({keys:"",hosting:void 0});i.useEffect(()=>{const h=O.join(","),w=a?.values?.hosting;(ee.current.keys!==h||ee.current.hosting!==w)&&(ee.current={keys:h,hosting:w},z().catch(v=>{console.error("Failed to refresh models after credentials or hosting change:",v)}))},[O,a?.values?.hosting,z]);const R=i.useRef({general:i.useRef(null),radient:i.useRef(null),integrations:i.useRef(null),appearance:i.useRef(null),providers:i.useRef(null),backend:i.useRef(null),updates:i.useRef(null)}).current,ie=i.useMemo(()=>new URLSearchParams(A.search).get("setting"),[A.search]),C=i.useMemo(()=>new URLSearchParams(A.search).get("filter")??"",[A.search]),Z=i.useMemo(()=>new URLSearchParams(A.search).get("mcp")??void 0,[A.search]),Q=i.useMemo(()=>new URLSearchParams(A.search).get("provider"),[A.search]),J=i.useCallback(h=>{N(h),P(!0);const w=R[h],v=K.current;if(w?.current&&v){const F=w.current.getBoundingClientRect().top-v.getBoundingClientRect().top;v.scrollHeight>v.clientHeight?v.scrollTo({top:Math.max(0,v.scrollTop+F-80),behavior:"smooth"}):window.scrollTo({top:Math.max(0,w.current.getBoundingClientRect().top+window.scrollY-80),behavior:"smooth"}),clearTimeout(q.current??void 0),q.current=setTimeout(()=>{P(!1),q.current=null},800)}else P(!1)},[R]);i.useEffect(()=>{const h=setTimeout(()=>{const w=K.current;if(!w)return;const v=()=>{if(G)return;const U=w.getBoundingClientRect(),F=U.height;let te="",B=0;for(const[je,ue]of Object.entries(R))if(ue.current){const ce=ue.current.getBoundingClientRect(),ye=U.top,ne=ce.top-ye,We=ce.bottom-ye,Ie=ce.height,Ze=Math.max(0,ne),Oe=Math.min(F,We),Fe=Math.max(0,Oe-Ze)/Ie,De=Fe+(ne<F*.3?.1:0);De>B&&Fe>.1&&(B=De,te=je)}te&&te!==M&&N(te)};return v(),w.addEventListener("scroll",v,{passive:!0}),()=>{w.removeEventListener("scroll",v),clearTimeout(q.current??void 0)}},100);return()=>clearTimeout(h)},[R,M,G]),i.useEffect(()=>{const h=new URLSearchParams(A.search),w=h.get("section"),v=h.get("setting")?"backend":w,U=v?R[v]:void 0;if(!v||!U)return;let F=!1,te=Number.NaN,B=0;const je=window.setTimeout(()=>{F||(F=!0,ce.disconnect(),J(v))},2e3),ue=()=>{if(F)return;const ye=U.current;if(!ye){B=requestAnimationFrame(ue);return}const ne=Math.round(ye.getBoundingClientRect().top+window.scrollY);if(ne===te&&ne>0){F=!0,ce.disconnect(),window.clearTimeout(je),J(v);return}te=ne,B=requestAnimationFrame(ue)},ce=new ResizeObserver(()=>{F||(cancelAnimationFrame(B),B=requestAnimationFrame(ue))});return K.current&&ce.observe(K.current),B=requestAnimationFrame(ue),()=>{F=!0,cancelAnimationFrame(B),ce.disconnect(),window.clearTimeout(je)}},[A.search,R,J]);const Y=async(h,w)=>{f(h);try{await b.mutateAsync({[h]:w}),await d()}catch(v){console.error(`Error updating ${h}:`,v)}finally{f(null)}},W=o,pe=S==="checking",we=an(S),de=S==="ready"||S==="checking"||H,ge=rn(W,4e3);return u?t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(le,{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:m}),g&&t.jsx(D,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>void d(),disabled:r,children:r?"Retrying":"Retry"})]})})}):W?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:ge?void 0:"Loading settings"}),ge&&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."})]}):a?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(Ns,{activeSection:M,onSelectSection:J,sections:Ss})}),t.jsx("div",{ref:K,"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(Es,{title:"Settings",icon:Rt}),t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsxs("div",{ref:R.general,className:"flex flex-col gap-8",children:[t.jsxs(se,{title:"User profile",icon:Cs,description:`Your user profile information displayed in the application. This information is not provided to the agents. ${E?"These details are provided through your Radient account.":""}`,children:[pe&&t.jsx("p",{className:"text-meta text-ink-dim",children:"Checking your Radient account…"}),we&&t.jsx(le,{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.",S==="refused"?" Retry, or sign in to Radient again.":" Retry."]}),t.jsx(D,{variant:"secondary",size:"sm",className:"shrink-0",onClick:()=>$(),disabled:_,children:_?"Retrying":"Retry"})]})}),t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Tt,{value:x.profile.name,label:"Display name",placeholder:"Enter your name...",isSaving:k==="user_name",onSave:async h=>{f("user_name");try{x.updateName(h)}finally{f(null)}},readOnly:de}),t.jsx(Tt,{value:x.profile.email,label:"Email address",placeholder:"Enter your email...",isSaving:k==="user_email",onSave:async h=>{f("user_email");try{x.updateEmail(h)}finally{f(null)}},readOnly:de})]})]}),t.jsx(se,{title:"Application tour",description:"Missed the application onboarding tour or want a refresher? Start it again here.",children:t.jsxs(D,{variant:"secondary",onClick:()=>{X({forceModalCompleted:!0})},children:[t.jsx(ka,{}),"Take the tour"]})}),t.jsx(se,{id:"model-settings",title:"Model settings",icon:Ms,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(As,{value:a.values.hosting,isSaving:k==="hosting",onSave:h=>Y("hosting",h),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(Rs,{value:a.values.model_name,hostingId:a.values.hosting,isSaving:k==="model_name",onSave:h=>Y("model_name",h),allowCustom:!0,allowDefault:!1}),t.jsx(le,{variant:"neutral",icon:t.jsx(Ge,{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(ec,{}),t.jsx(se,{title:"Configuration information",icon:Ge,description:"System information about the current configuration.",children:t.jsxs(pt,{children:[t.jsx(ae,{label:"Version",value:t.jsx("span",{className:"text-mono-sm",children:a.version})}),t.jsx(ae,{label:"Created",value:sn(a.metadata.created_at)}),t.jsx(ae,{label:"Last modified",value:on(a.metadata.last_modified)}),t.jsx(ae,{label:"Description",value:a.metadata.description||"No description available"})]})})]}),t.jsx(se,{title:"Appearance",icon:dn,description:"Customize the look and feel of Local Operator",sectionRef:R.appearance,dataTourTag:"settings-appearance-section",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(lc,{}),t.jsx(hr,{value:s,label:"Show agent reasoning",description:"Adds the agent's Reasoning and Thinking rows to conversations. They stay closed until you open one.",onChange:async h=>n(h)})]})}),t.jsx(se,{title:"Model providers",icon:tn,description:"Sign in to the services your agents think with. New chats use your default model.",sectionRef:R.providers,children:t.jsx(Ts,{initialProviderId:Q,onChangeModel:()=>J("general")})}),t.jsx(Vi,{sessionId:I??void 0,sectionRef:R.integrations,highlightServer:Z}),t.jsx(se,{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:R.radient,dataTourTag:"settings-radient-account-section",children:t.jsxs("div",{className:"flex flex-col gap-8",children:[t.jsx(Ji,{onAfterCredentialUpdate:()=>{z(),V()}}),E&&t.jsxs(t.Fragment,{children:[t.jsx(dc,{}),t.jsx(mc,{})]})]})}),t.jsx(se,{title:"Backend settings",icon:Rt,description:"Every setting the backend registry owns, searchable, with typed editors and scopes.",sectionRef:R.backend,children:t.jsx(ms,{focusKey:ie,initialFilter:C})}),t.jsx("div",{ref:R.updates,children:t.jsx(jr,{})})]})]})})]}):t.jsx("div",{className:"flex h-full w-full items-center justify-center bg-canvas p-6",children:t.jsx(le,{variant:"warning",className:"w-full max-w-xl",children:"Your settings could not be loaded."})})};export{Cc as SettingsPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as r}from"./error-boundary-
|
|
1
|
+
import{c as r}from"./error-boundary-BCN3_4Dn.js";import{j as e,c as i}from"./index-DvjcW_EJ.js";/**
|
|
2
2
|
* @license lucide-react v0.507.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|