@cuongtran001/kanna 1.100.2 → 1.100.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{BoardsPage-BTQTmG7S.js → BoardsPage-BUPJYGXZ.js} +1 -1
- package/dist/client/assets/{BoardsRoutePage-BS1woWdU.js → BoardsRoutePage-M4-5IDST.js} +1 -1
- package/dist/client/assets/{ChatPage-BGs_JRJN.js → ChatPage-CYb-8oYP.js} +28 -28
- package/dist/client/assets/{CronJobsPage-BhpAKXqw.js → CronJobsPage-_LHw6EoX.js} +1 -1
- package/dist/client/assets/{FilePreviewSheet-DzTQZ1zH.js → FilePreviewSheet-CF_nyCEA.js} +1 -1
- package/dist/client/assets/{FlowSurface-CUDnfByl.js → FlowSurface-tDdRNhCp.js} +1 -1
- package/dist/client/assets/{GenUIBlock-cGO14f57.js → GenUIBlock-CKYrP7Gn.js} +2 -2
- package/dist/client/assets/{InboundHandlerFields-D4vXxv2W.js → InboundHandlerFields-DLPkDYQo.js} +1 -1
- package/dist/client/assets/InboxPage-DlVjljTn.js +1 -0
- package/dist/client/assets/{LocalProjectsPage-DswpB-es.js → LocalProjectsPage-C_ymeVRd.js} +1 -1
- package/dist/client/assets/{SettingsPage-JErsd_bl.js → SettingsPage-CjHY9VXq.js} +5 -5
- package/dist/client/assets/{StackBoardsRoutePage-Bhc_4-Mc.js → StackBoardsRoutePage-C2jc-rX0.js} +1 -1
- package/dist/client/assets/{ToolCallMessage-BoQpY4uk.js → ToolCallMessage-XRB0Rzoo.js} +1 -1
- package/dist/client/assets/{VChartSurface-BZ3Z9Aeg.js → VChartSurface-ZvVT39mD.js} +1 -1
- package/dist/client/assets/{WebhooksPage-rVb3gBYJ.js → WebhooksPage-Dt23R5y_.js} +2 -2
- package/dist/client/assets/{WorkflowsPage-D4Z6wU-Z.js → WorkflowsPage-iRJH1vDk.js} +1 -1
- package/dist/client/assets/{arrow-left-PqpvLsJO.js → arrow-left-C3oicQUh.js} +1 -1
- package/dist/client/assets/{beacon-alias-CBKMiHBx.js → beacon-alias-Y46OkdpU.js} +3 -3
- package/dist/client/assets/{code-xml-BTLQlLBu.js → code-xml-AZ1ZQL4-.js} +1 -1
- package/dist/client/assets/{commandFeedback-zY8fLBrX.js → commandFeedback-Lzlzc1iV.js} +1 -1
- package/dist/client/assets/{contextWindow-CWsXmf9J.js → contextWindow-BqXKSvM3.js} +1 -1
- package/dist/client/assets/{copyFeedbackStore-BETKMVH6.js → copyFeedbackStore-DRdRTPSB.js} +1 -1
- package/dist/client/assets/{createScopedStore-C7JKS8Pq.js → createScopedStore-AXBUXRGN.js} +1 -1
- package/dist/client/assets/cronJobsStore-CoLQONrs.js +1 -0
- package/dist/client/assets/{file-plus-corner-XIytIEn1.js → file-plus-corner-BbV6zKJx.js} +1 -1
- package/dist/client/assets/{inboxAutonomy-BdptfbA-.js → inboxAutonomy-CpkWYpCU.js} +1 -1
- package/dist/client/assets/index-BlL72nKf.js +85 -0
- package/dist/client/assets/{info-7GIVJy4i.js → info-xjfw_aIo.js} +1 -1
- package/dist/client/assets/{input-BuAZHNjZ.js → input-CzZyMS39.js} +1 -1
- package/dist/client/assets/{keybindings-CVq5EVn-.js → keybindings-D6ojTUcm.js} +1 -1
- package/dist/client/assets/{log-BgLAkl7p.js → log-BtILyPXN.js} +1 -1
- package/dist/client/assets/minus-BIy09qGb.js +1 -0
- package/dist/client/assets/{monitor-C5_rmdWJ.js → monitor-CJu2dBY2.js} +1 -1
- package/dist/client/assets/{pencil-CHhLL3VF.js → pencil-D74A5m1N.js} +1 -1
- package/dist/client/assets/{pendingActionsStore-HJFCK0_5.js → pendingActionsStore-tyIM7H15.js} +1 -1
- package/dist/client/assets/{plus-D1MM3e7O.js → plus-1J-y2SUN.js} +1 -1
- package/dist/client/assets/{refresh-cw-D4CAFsVR.js → refresh-cw-DQ0n_x3I.js} +1 -1
- package/dist/client/assets/runDetached-C-tqrG01.js +1 -0
- package/dist/client/assets/{search-wiiiEcYQ.js → search-WzAKqjaJ.js} +1 -1
- package/dist/client/assets/{searchable-select-DS4cEiyn.js → searchable-select-Bs6L7YOH.js} +1 -1
- package/dist/client/assets/{segmented-control-BSXUcxmo.js → segmented-control-DmiIJJuE.js} +1 -1
- package/dist/client/assets/{select-BmTzDh2-.js → select-qh2tsZ5U.js} +1 -1
- package/dist/client/assets/{settings-header-button-DExFFZeo.js → settings-header-button-BkWj0d5-.js} +1 -1
- package/dist/client/assets/{state-mark-B2sAgvfs.js → state-mark-CZuog43J.js} +1 -1
- package/dist/client/assets/{terminal-D-Ysl-xN.js → terminal-BGVWbkIW.js} +1 -1
- package/dist/client/assets/{timer.adapter-QFPap342.js → timer.adapter-CAyQ03SG.js} +1 -1
- package/dist/client/assets/{tool-call-types-Di5d_Vp8.js → tool-call-types-BPhjPQVt.js} +1 -1
- package/dist/client/assets/{tools-GD8cfNMa.js → tools-_rQtgAeZ.js} +1 -1
- package/dist/client/assets/{triangle-alert-bgjlUeHe.js → triangle-alert-AJmFik1Z.js} +1 -1
- package/dist/client/assets/{types-YkWzOG1Y.js → types-Bzcas-On.js} +1 -1
- package/dist/client/assets/{useAppGlobalState-DmV_hsYm.js → useAppGlobalState-BZY419Te.js} +1 -1
- package/dist/client/assets/{useProviderCatalog-Bn9BPxoK.js → useProviderCatalog-CrJ_JTAN.js} +1 -1
- package/dist/client/assets/{useTheme-DyHqkMEA.js → useTheme-CoKiTydH.js} +1 -1
- package/dist/client/index.html +32 -32
- package/package.json +1 -1
- package/src/server/chat-ops-diff.test.ts +87 -1
- package/src/server/chat-ops-diff.ts +54 -4
- package/src/server/chat-ops-parity.test.ts +126 -55
- package/src/server/event-store-subagent.test.ts +1 -0
- package/src/server/event-store-subagent.ts +33 -10
- package/src/server/event-store.ts +3 -2
- package/src/server/history-paging.ts +2 -1
- package/src/server/import-subagent-drill.e2e.test.ts +1 -1
- package/src/server/read-models.test.ts +5 -4
- package/src/server/read-models.ts +1 -1
- package/src/server/remote-mcp/remote-mcp-tools-observability.ts +1 -1
- package/src/server/ws-router-observability.test.ts +52 -12
- package/src/server/ws-router-observability.ts +2 -2
- package/src/shared/chat-ops.test.ts +90 -1
- package/src/shared/chat-ops.ts +57 -17
- package/src/shared/commands/chat.ts +10 -3
- package/src/shared/loop-progress.test.ts +1 -0
- package/src/shared/subagent-types.ts +4 -1
- package/dist/client/assets/InboxPage-bzjr1WVF.js +0 -1
- package/dist/client/assets/cronJobsStore-C4q2VUIh.js +0 -1
- package/dist/client/assets/index-CckUE5c3.js +0 -85
- package/dist/client/assets/minus-CrsToRyy.js +0 -1
- package/dist/client/assets/runDetached-w36rRAeq.js +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./react-BWPDF9mI.js";import{l as n,u as r}from"./chunk-6KYCQHYJ-C0N1h4Su.js";import{t as i}from"./jsx-runtime-BB9-612F.js";import{A as a,E as o,N as s,P as c,St as l,T as u,U as d,_ as f,a as p,bt as m,c as h,d as g,g as _,h as v,j as y,l as b,m as x,n as S,o as ee,s as te,u as C,vt as w,xt as ne}from"./useAppGlobalState-DmV_hsYm.js";import{a as re,d as T,f as E,h as D,i as ie,l as O,m as k,n as A,o as ae,r as j,t as M,u as oe}from"./pendingActionsStore-HJFCK0_5.js";import{a as se,l as ce,n as le,o as ue}from"./beacon-alias-CBKMiHBx.js";import{a as de,i as fe,n as pe,o as me,t as he}from"./copyFeedbackStore-BETKMVH6.js";import{a as ge,i as N,n as P,o as _e,r as F,t as ve}from"./select-BmTzDh2-.js";import{t as ye}from"./info-7GIVJy4i.js";import{c as be,r as xe,s as Se}from"./contextWindow-CWsXmf9J.js";import{t as Ce}from"./monitor-C5_rmdWJ.js";import{t as we}from"./pencil-CHhLL3VF.js";import{t as Te}from"./plus-D1MM3e7O.js";import{t as Ee}from"./refresh-cw-D4CAFsVR.js";import{t as De}from"./search-wiiiEcYQ.js";import{T as Oe,a as ke,c as Ae,i as je,o as Me,r as Ne,s as Pe,t as Fe}from"./useProviderCatalog-Bn9BPxoK.js";import{g as Ie,i as Le,n as Re,o as ze,r as Be,t as Ve,u as He}from"./timer.adapter-QFPap342.js";import{a as Ue,c as We,o as Ge,s as Ke,t as I}from"./segmented-control-BSXUcxmo.js";import{d as qe,f as L,i as Je,n as Ye,r as Xe,s as Ze}from"./log-BgLAkl7p.js";import{t as R}from"./input-BuAZHNjZ.js";import{f as Qe,i as $e,o as et,u as tt}from"./core-types-Ds7PFmZN.js";import{$ as nt,A as rt,C as it,D as at,E as ot,G as st,H as ct,J as lt,K as ut,L as dt,M as ft,N as pt,O as mt,U as ht,V as gt,W as _t,X as vt,Y as yt,Z as bt,_ as xt,a as St,at as Ct,b as wt,c as Tt,ct as Et,d as Dt,et as Ot,f as kt,g as At,h as jt,i as Mt,it as Nt,j as Pt,k as Ft,l as It,m as Lt,n as Rt,nt as zt,o as Bt,p as Vt,q as Ht,r as Ut,rt as Wt,s as Gt,u as Kt,ut as qt,v as z,w as Jt}from"./tool-call-types-Di5d_Vp8.js";import{M as Yt,N as Xt,iu as Zt,j as Qt,r as $t,ru as en}from"./useTheme-DyHqkMEA.js";import{t as tn}from"./runDetached-w36rRAeq.js";import{t as nn}from"./dom.adapter-C26vNdMA.js";import{_ as rn,a as B,b as an,g as on,r as sn,v as cn}from"./commandFeedback-zY8fLBrX.js";import{d as ln,f as un,l as dn,t as fn}from"./keybindings-CVq5EVn-.js";import{a as pn,n as mn}from"./state-mark-B2sAgvfs.js";import{_ as hn,a as gn,c as _n,d as vn,f as yn,g as bn,h as xn,i as Sn,n as Cn,o as wn,p as Tn,r as En,t as Dn,u as On,v as kn,x as An,y as jn}from"./types-YkWzOG1Y.js";import{n as Mn,t as Nn}from"./formatDuration-BbWTR_M_.js";import{bn as Pn,bt as Fn,gn as In,it as Ln,tn as Rn,xt as zn,yt as Bn}from"./index-CckUE5c3.js";import{S as Vn,_ as Hn,b as Un,c as Wn,f as Gn,l as Kn,s as qn,u as Jn,v as Yn,y as Xn}from"./ChatPage-BGs_JRJN.js";import{a as Zn,c as Qn,d as $n,f as er,i as tr,l as nr,o as rr,p as ir,s as ar,t as or,u as sr}from"./searchable-select-DS4cEiyn.js";import{f as cr,l as lr,t as ur,u as dr}from"./inboxAutonomy-BdptfbA-.js";import{t as fr}from"./settings-header-button-DExFFZeo.js";import{t as pr}from"./InboundHandlerFields-D4vXxv2W.js";var mr={name:`antenna`,size:24,node:[[`path`,{d:`M2 12 7 2`,key:`117k30`}],[`path`,{d:`m7 12 5-10`,key:`1tvx22`}],[`path`,{d:`m12 12 5-10`,key:`ev1o1a`}],[`path`,{d:`m17 12 5-10`,key:`1e4ti3`}],[`path`,{d:`M4.5 7h15`,key:`vlsxkz`}],[`path`,{d:`M12 16v6`,key:`c8a4gj`}]]};mr.node;var hr=D(mr),gr={name:`book-text`,size:24,node:[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]};gr.node;var _r=D(gr),vr={name:`circle-alert`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`]};vr.node;var yr=D(vr),br={name:`circle-arrow-up`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]],aliases:[`arrow-up-circle`]};br.node;var xr=D(br),Sr={name:`cloud-download`,size:24,node:[[`path`,{d:`M12 13v8l-4-4`,key:`1f5nwf`}],[`path`,{d:`m12 21 4-4`,key:`1lfcce`}],[`path`,{d:`M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284`,key:`ui1hmy`}]],aliases:[`download-cloud`]};Sr.node;var Cr=D(Sr),wr={name:`command`,size:24,node:[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]};wr.node;var Tr=D(wr),Er={name:`cpu`,size:24,node:[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]};Er.node;var Dr=D(Er),Or={name:`flask-conical`,size:24,node:[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]};Or.node;var kr=D(Or),Ar={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};Ar.node;var jr=D(Ar),Mr={name:`message-square-quote`,size:24,node:[[`path`,{d:`M14 14a2 2 0 0 0 2-2V8h-2`,key:`1r06pg`}],[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M8 14a2 2 0 0 0 2-2V8H8`,key:`1jzu5j`}]]};Mr.node;var Nr=D(Mr),Pr={name:`moon`,size:24,node:[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]};Pr.node;var Fr=D(Pr),Ir={name:`network`,size:24,node:[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]};Ir.node;var Lr=D(Ir),Rr={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};Rr.node;var zr=D(Rr),Br={name:`power-off`,size:24,node:[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};Br.node;var Vr=D(Br),Hr={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};Hr.node;var Ur=D(Hr),Wr={name:`sun`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]};Wr.node;var Gr=D(Wr),Kr={name:`type`,size:24,node:[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]};Kr.node;var qr=D(Kr),Jr={name:`waypoints`,size:24,node:[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]};Jr.node;var Yr=D(Jr),Xr={enabled:!1,cloudflaredPath:`cloudflared`,mode:`always-ask`},V=e(t(),1),H=e(i(),1);function Zr(e){let t=e.trim();if(t.startsWith(`https://`))try{let e=new URL(t);if(e.protocol!==`https:`)return!1;let n=e.hostname.toLowerCase();return!(n===`localhost`||!n.includes(`.`)||n.startsWith(`.`)||n.endsWith(`.`))}catch{return!1}if(t.startsWith(`mailto:`)){let e=t.slice(7),n=/^[^\s@]+@([^\s@]+)$/.exec(e);if(!n)return!1;let r=n[1].toLowerCase();return!(r===`localhost`||!r.includes(`.`)||r.startsWith(`.`)||r.endsWith(`.`))}return!1}var Qr={maxFileSizeMb:2048},$r={path:`uploads.maxFileSizeMb`,min:1,max:51200,integer:!1},ei=L()(e=>({authEnabled:!1,setAuthEnabled:t=>e({authEnabled:t})}));function U({title:e,description:t,children:n,bordered:r=!0,alignStart:i=!1}){return(0,H.jsx)(`div`,{className:r?`border-t border-border`:void 0,children:(0,H.jsxs)(`div`,{className:E(`flex flex-col gap-4 py-5 md:flex-row md:justify-between md:gap-8`,i?`md:items-start`:`md:items-center`),children:[(0,H.jsxs)(`div`,{className:`min-w-0 max-w-xl`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e}),(0,H.jsx)(`div`,{className:`mt-1 text-13 text-muted-foreground`,children:t})]}),(0,H.jsx)(`div`,{className:`flex items-center justify-start md:shrink-0 md:justify-end`,children:n})]})})}function ti({icon:e,message:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-md border border-dashed px-6 py-10 text-center`,children:[(0,H.jsx)(e,{className:`mb-3 h-8 w-8 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function ni({children:e}){return(0,H.jsx)(`ul`,{className:`flex flex-col divide-y rounded-md border`,children:e})}function ri({label:e,onEdit:t,onDelete:n,deletePending:r=!1}){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:t,"aria-label":`Edit ${e}`,children:(0,H.jsx)(we,{className:`h-4 w-4`})}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:n,pending:r,"aria-label":`Delete ${e}`,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})}var ii=new Set([`checking`,`downloading`,`installing`,`restarting`]);function ai(e){return e!==null&&ii.has(e.state)}function oi(e){switch(e.state){case`checking`:return`Checking ${e.version}…`;case`downloading`:return`Downloading ${e.version}…`;case`installing`:return`Installing ${e.version}…`;case`restarting`:return`Restarting…`;case`current`:return`Up to date`;case`failed`:return e.message===void 0?`Update failed`:`Update failed: ${e.message}`}}function si(e){switch(e.state){case`failed`:return`destructive`;case`current`:return`muted`;case`checking`:case`downloading`:case`installing`:case`restarting`:return`active`}}var ci={},li={},ui={},di={};function fi(e,t){return`${e}:${t}`}function pi(e,t,n){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e!==t));return Object.keys(r).length>0?r:n}var W=L()(e=>({pairing:null,expandedId:null,drafts:ci,updateErrors:li,aliasErrors:ui,openExplanations:di,setPairing:t=>e({pairing:t}),toggleExpanded:t=>e(e=>({expandedId:e.expandedId===t?null:t})),setDraft:(t,n)=>e(e=>({drafts:{...e.drafts,[t]:n}})),clearDraft:t=>e(e=>({drafts:pi(e.drafts,t,ci)})),setUpdateError:(t,n)=>e(e=>n===null?{updateErrors:pi(e.updateErrors,t,li)}:{updateErrors:{...e.updateErrors,[t]:n}}),beginAliasEdit:(t,n)=>e(e=>({drafts:{...e.drafts,[fi(t,`alias`)]:n}})),endAliasEdit:t=>e(e=>({drafts:pi(e.drafts,fi(t,`alias`),ci),aliasErrors:pi(e.aliasErrors,t,ui)})),setAliasError:(t,n)=>e(e=>n===null?{aliasErrors:pi(e.aliasErrors,t,ui)}:{aliasErrors:{...e.aliasErrors,[t]:n}}),toggleExplanation:t=>e(e=>({openExplanations:t in e.openExplanations?pi(e.openExplanations,t,di):{...e.openExplanations,[t]:!0}}))})),mi=`kanna-beacon`,hi=`ABCDEFGHJKLMNPQRSTUVWXYZ23456789`,gi=`https://github.com/cuongtranba/kanna/releases/latest`;RegExp(`^[${hi}]{8}$`);function _i(e){return`${mi}://pair?url=${encodeURIComponent(e.kannaUrl)}&code=${encodeURIComponent(e.code)}`}function vi(e){return`kanna-beacon pair ${e.kannaUrl} ${e.code}`}function yi(e){return e.replace(/^v/,``).split(`-`)[0].split(`.`).map(e=>Number.parseInt(e,10))}function bi(e,t){if(e===t)return!1;let n=yi(e),r=yi(t),i=Math.max(n.length,r.length);for(let a=0;a<i;a+=1){let i=n[a]??0,o=r[a]??0;if(Number.isNaN(i)||Number.isNaN(o))return e<t;if(i!==o)return i<o}return!1}var xi={outdated:`border-warning/40 text-warning-text bg-warning/10`,partial:`border-warning/40 text-warning-text bg-warning/10`,unknown:`border-border text-muted-foreground bg-muted/40`};function Si({beaconId:e,alias:t,displayName:n}){let r=W(e=>e.beginAliasEdit),i=(0,V.useCallback)(()=>{r(e,t??``)},[t,e,r]);return(0,H.jsx)(rn,{label:`Set a short name`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:i,"aria-label":`Set a short name for ${n}`,children:(0,H.jsx)(we,{className:`h-3.5 w-3.5`})})})}function Ci({beaconId:e,alias:t,displayName:n,onSetAlias:r}){let i=fi(e,`alias`),a=W(e=>e.drafts[i]),o=W(t=>t.aliasErrors[e]??null),s=W(e=>e.setDraft),c=W(e=>e.setAliasError),l=W(e=>e.endAliasEdit),u=M(`beacons.setAlias`,e),d=j(u),f=a??``,p=f.length===0?null:se(f),m=f.length>0&&p===null&&f!==t,h=p??o,g=(0,V.useCallback)(t=>{s(i,t.target.value.toLowerCase()),c(e,null)},[e,i,c,s]),_=(0,V.useCallback)(t=>{A(u,async()=>{try{await r(e,t),l(e)}catch(t){c(e,Ye(t))}})},[e,l,r,u,c]),v=(0,V.useCallback)(()=>{_(f)},[_,f]),y=(0,V.useCallback)(()=>{_(null)},[_]),b=(0,V.useCallback)(()=>{l(e)},[e,l]);return a===void 0?null:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(R,{value:f,onChange:g,placeholder:`office-mac`,disabled:d,"aria-label":`Short name for ${n}`,"aria-invalid":h!==null||void 0,className:`w-48`}),(0,H.jsx)(O,{size:`sm`,onClick:v,pending:d,disabled:!m,children:`Save`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:b,disabled:d,children:`Cancel`}),t!==null&&(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:y,disabled:d,children:`Clear alias`})]}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Type `,(0,H.jsxs)(`span`,{className:`font-mono`,children:[`@beacon/`,f.length>0?f:`name`]}),` in a message to refer to this machine.`]}),h!==null&&(0,H.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive-text`,children:h})]})}var wi=`Lets the agent run commands and scripts on this machine. Off means every command and script is refused, and the agent can only read and copy files inside the folders below. When on, each command still waits for your approval unless it is on the always-run list or you switch on running without asking.`,Ti=`Skips the approval prompt. Reads and writes inside the folders below, and every command and script, run immediately. Leave it off to review each action before it runs on this machine.`,Ei=`The agent can list, search, read and copy files off this machine only inside these folders and their subfolders. Anything outside is refused. With none listed it cannot read from this machine at all. Each read waits for your approval unless running without asking is on.`,Di=`The agent can copy files onto this machine only inside these folders and their subfolders. Leave empty and it cannot write to this machine at all. Each write waits for your approval unless running without asking is on.`,Oi=`Command names, such as git, that run immediately once running commands is allowed. Matching uses the command name only, so git covers every git subcommand. Anything not listed asks you first.`;function ki(e){return`beacon-explain-${e}`}function Ai({explanationKey:e,subject:t}){let n=W(t=>e in t.openExplanations),r=W(e=>e.toggleExplanation),i=(0,V.useCallback)(()=>{r(e)},[e,r]);return(0,H.jsx)(rn,{label:`What does this do?`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:i,"aria-expanded":n,"aria-controls":ki(e),"aria-label":`What does "${t}" do?`,children:(0,H.jsx)(ye,{className:`h-4 w-4`})})})}function ji({explanationKey:e,text:t}){let n=W(t=>e in t.openExplanations);return(0,H.jsx)(`p`,{id:ki(e),hidden:!n,className:`text-13 text-muted-foreground`,children:t})}function Mi({beaconId:e,scope:t,onSetScope:n}){let r=M(`beacons.setScope`,e),i=j(r),a=(0,V.useCallback)(t=>{A(r,()=>n(e,t))},[e,n,r]),o=(0,V.useCallback)(e=>{a({...t,exec:e.target.checked})},[a,t]),s=(0,V.useCallback)(e=>{a({...t,autoRunScripts:e.target.checked})},[a,t]),c=(0,V.useCallback)(e=>{a({...t,readRoots:e})},[a,t]),l=(0,V.useCallback)(e=>{a({...t,writeRoots:e})},[a,t]),u=(0,V.useCallback)(e=>{a({...t,execAllowlist:e})},[a,t]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border bg-muted/40 px-4 py-4`,"aria-busy":i||void 0,children:[(0,H.jsx)(Ni,{explanationKey:fi(e,`exec`),checked:t.exec,disabled:i,onChange:o,title:`Allow running commands`,explanation:wi}),(0,H.jsx)(Ni,{explanationKey:fi(e,`autoRunScripts`),checked:t.autoRunScripts,disabled:i,onChange:s,title:`Run commands and scripts from this chat without asking each time`,explanation:Ti}),(0,H.jsx)(Pi,{label:`Folders the agent may read`,explanation:Ei,placeholder:`/Users/me/projects`,draftKey:fi(e,`readRoots`),items:t.readRoots,disabled:i,onChange:c}),(0,H.jsx)(Pi,{label:`Folders the agent may write to`,explanation:Di,placeholder:`/Users/me/inbox`,draftKey:fi(e,`writeRoots`),items:t.writeRoots,disabled:i,onChange:l}),(0,H.jsx)(Pi,{label:`Commands that always run without asking`,explanation:Oi,placeholder:`git`,draftKey:fi(e,`execAllowlist`),items:t.execAllowlist,disabled:i,onChange:u})]})}function Ni({explanationKey:e,checked:t,disabled:n,onChange:r,title:i,explanation:a}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsxs)(`label`,{className:`flex min-w-0 cursor-pointer items-center gap-3`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:t,disabled:n,onChange:r}),(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i})]}),(0,H.jsx)(Ai,{explanationKey:e,subject:i})]}),(0,H.jsx)(`div`,{className:`pl-7`,children:(0,H.jsx)(ji,{explanationKey:e,text:a})})]})}function Pi({label:e,explanation:t,placeholder:n,draftKey:r,items:i,disabled:a,onChange:o}){let s=W(e=>e.drafts[r]??``),c=W(e=>e.setDraft),l=W(e=>e.clearDraft),u=s.trim(),d=u.length>0&&!i.includes(u),f=(0,V.useCallback)(e=>{c(r,e.target.value)},[r,c]),p=(0,V.useCallback)(()=>{o([...i,u]),l(r)},[l,r,i,o,u]),m=(0,V.useCallback)(e=>{o(i.filter(t=>t!==e))},[i,o]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e}),(0,H.jsx)(Ai,{explanationKey:r,subject:e})]}),(0,H.jsx)(ji,{explanationKey:r,text:t}),i.length===0?(0,H.jsx)(`span`,{className:`text-13 text-muted-foreground`,children:`None`}):(0,H.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.map(e=>(0,H.jsx)(Fi,{item:e,disabled:a,onRemove:m},e))}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{value:s,onChange:f,placeholder:n,disabled:a,"aria-label":e}),(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:p,disabled:a||!d,children:`Add`})]})]})}function Fi({item:e,disabled:t,onRemove:n}){let r=(0,V.useCallback)(()=>{n(e)},[e,n]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`code`,{className:`min-w-0 flex-1 break-all rounded-md border border-border bg-muted px-2 py-1 font-mono text-13`,children:e}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:r,disabled:t,"aria-label":`Remove ${e}`,children:(0,H.jsx)(Ie,{className:`h-4 w-4`})})]})}var Ii=M(`beacons.mintPairingCode`);function Li(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return{id:e.id,label:e.label,alias:e.alias??null,os:e.os,enabled:e.enabled,online:t?.online??!1,lastSeenAt:t?.lastSeenAt??null,beaconVersion:t?.beaconVersion??null,canSelfUpdate:t?.canSelfUpdate??!1,update:t?.update??null}})}function Ri({rows:e,configs:t,handlers:n,serverVersion:r,dom:i=nn,clipboard:a=fe,timer:o=Ve}){let s=Ln(1e3),c=(0,V.useMemo)(()=>Li(e,t),[e,t]),l=(0,V.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(zi,{now:s,handlers:n,dom:i,clipboard:a,timer:o}),c.length===0?(0,H.jsx)(ti,{icon:Xn,message:`No machines paired yet. Pair a machine to let the agent read files and run approved commands there.`}):(0,H.jsx)(ni,{children:c.map(e=>(0,H.jsx)(Gi,{row:e,scope:l.get(e.id)?.scope??null,now:s,serverVersion:r,handlers:n,dom:i},e.id))})]})}function zi({now:e,handlers:t,dom:n,clipboard:r,timer:i}){let a=W(e=>e.pairing),o=W(e=>e.setPairing),s=j(Ii),c=(0,V.useCallback)(()=>{A(Ii,async()=>{o(await t.onMint())})},[t,o]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-border bg-card p-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Beacons`}),(0,H.jsx)(`p`,{className:`mt-1 text-13 text-muted-foreground`,children:`A beacon is a small program on your own machine. Once paired, the agent can read files and run commands there, only within the scope you grant below.`})]}),(0,H.jsxs)(O,{size:`sm`,variant:a?.ok===!0?`secondary`:`default`,onClick:c,pending:s,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Pair a machine`]})]}),a?.ok===!1&&(0,H.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive-text`,children:a.error}),a?.ok===!0&&(0,H.jsx)(Bi,{code:a.code,expiresAt:a.expiresAt,now:e,dom:n,clipboard:r,timer:i})]})}function Bi({code:e,expiresAt:t,now:n,dom:r,clipboard:i,timer:a}){let o=t-n,s=r.getOrigin(),c=vi({kannaUrl:s,code:e}),l=_i({kannaUrl:s,code:e}),u=M(`beacons.copyPairCommand`,e),d=j(u),f=pe(u),p=(0,V.useCallback)(()=>{A(u,()=>he(u,()=>i.writeText(c),a))},[i,c,u,a]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border pt-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,H.jsx)(`span`,{className:`font-mono text-2xl font-medium tabular-nums tracking-widest`,children:e}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:o>0?`Expires in ${Mn(o)}`:`Expired. Pair again for a new code.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,H.jsxs)(`a`,{href:l,className:oe({size:`sm`}),children:[(0,H.jsx)(In,{className:`mr-1 h-4 w-4`}),`Open in Kanna Beacon`]}),(0,H.jsx)(`a`,{href:gi,target:`_blank`,rel:`noreferrer`,className:`text-13 text-muted-foreground underline underline-offset-2 hover:text-foreground`,children:`Download Kanna Beacon`})]}),(0,H.jsx)(`p`,{className:`text-13 text-muted-foreground`,children:`Or run this on the machine you want to pair:`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`code`,{className:`min-w-0 flex-1 break-all rounded-md border border-border bg-muted px-3 py-2 font-mono text-13`,children:c}),(0,H.jsx)(rn,{label:f?`Copied`:`Copy command`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon`,onClick:p,pending:d,"aria-label":f?`Copied`:`Copy pairing command`,children:f?(0,H.jsx)(me,{className:`h-4 w-4 text-success-text`}):(0,H.jsx)(de,{className:`h-4 w-4`})})})]})]})}function Vi(e,t){return e.lastSeenAt===null?`Never connected`:`Last seen ${Nn(t-e.lastSeenAt)} ago`}var Hi=`This beacon is too old to update itself. Reinstall it once from the download page; after that, updates are one click.`;function Ui({canSelfUpdate:e}){let t=E(`rounded-full border px-2 py-0.5 text-xs`,xi.outdated);return e?(0,H.jsx)(`span`,{className:t,children:`Update available`}):(0,H.jsx)(rn,{label:Hi,children:(0,H.jsx)(`a`,{href:gi,target:`_blank`,rel:`noreferrer`,className:t,children:`Update available`})})}function Wi({row:e,updateAvailable:t,handlers:n}){let r=M(`beacons.update`,e.id),i=j(r),a=W(t=>t.updateErrors[e.id]??null),o=W(e=>e.setUpdateError),s=t&&e.online&&e.canSelfUpdate&&!ai(e.update),c=(0,V.useCallback)(()=>{A(r,async()=>{let t=await n.onUpdate(e.id);o(e.id,t.ok?null:t.error)})},[n,e.id,o,r]);return(0,H.jsxs)(H.Fragment,{children:[e.update!==null&&(0,H.jsx)(mn,{tone:si(e.update),label:oi(e.update)}),s&&(0,H.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:c,pending:i,"aria-label":`Update ${le(e)} now`,children:[(0,H.jsx)(xr,{className:`mr-1 h-4 w-4`}),`Update now`]}),a!==null&&(0,H.jsx)(`span`,{role:`alert`,className:`text-destructive-text`,children:a})]})}function Gi({row:e,scope:t,now:n,serverVersion:r,handlers:i,dom:a}){let o=W(t=>t.expandedId===e.id),s=W(e=>e.toggleExpanded),c=M(`beacons.setEnabled`,e.id),l=j(c),u=M(`beacons.delete`,e.id),d=j(u),f=le(e),p=e.beaconVersion!==null&&r!==void 0&&bi(e.beaconVersion,r),m=(0,V.useCallback)(t=>{let n=t.target.checked;A(c,()=>i.onSetEnabled(e.id,n))},[c,i,e.id]),h=(0,V.useCallback)(()=>{a.confirmDialog(`Revoke "${f}"? The agent will lose access to this machine until you pair it again.`)&&A(u,()=>i.onDelete(e.id))},[u,f,a,i,e.id]),g=(0,V.useCallback)(()=>{s(e.id)},[e.id,s]);return(0,H.jsxs)(`li`,{className:`flex flex-col`,"aria-busy":d||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,H.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`truncate font-medium`,children:f}),(0,H.jsx)(Si,{beaconId:e.id,alias:e.alias,displayName:f})]}),e.alias!==null&&(0,H.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`font-mono`,children:e.label}),(0,H.jsxs)(`span`,{className:`font-mono`,children:[`@beacon/`,e.alias]})]}),(0,H.jsx)(Ci,{beaconId:e.id,alias:e.alias,displayName:f,onSetAlias:i.onSetAlias}),(0,H.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,H.jsx)(mn,{tone:e.online?`active`:`muted`,label:e.online?`Online`:`Offline`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:Vi(e,n)}),e.beaconVersion!==null&&(0,H.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[`v`,e.beaconVersion]}),p&&(0,H.jsx)(Ui,{canSelfUpdate:e.canSelfUpdate}),(0,H.jsx)(Wi,{row:e,updateAvailable:p,handlers:i}),(0,H.jsx)(`span`,{children:e.os})]})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[l?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:l,"aria-busy":l||void 0,onChange:m,"aria-label":`Enable ${f}`}),(0,H.jsx)(`span`,{children:e.enabled?`Enabled`:`Disabled`})]}),t!==null&&(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:g,"aria-expanded":o,children:[`Scope`,(0,H.jsx)(Pn,{className:E(`ml-1 h-4 w-4 transition-transform`,o&&`rotate-180`)})]}),(0,H.jsx)(rn,{label:`Revoke this machine`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon`,onClick:h,pending:d,"aria-label":`Revoke ${f}`,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})})]})]}),o&&t!==null&&(0,H.jsx)(Mi,{beaconId:e.id,scope:t,onSetScope:i.onSetScope})]})}function Ki(e){let t=c(s),n=z(Mt),{handleWriteAppSettings:r,handleMintBeaconPairingCode:i,handleUpdateBeacon:a}=e.state,o=(0,V.useMemo)(()=>({onMint:i,onSetEnabled:async(e,t)=>{await r({customBeacons:{setEnabled:{id:e,enabled:t}}})},onSetScope:async(e,t)=>{await r({customBeacons:{setScope:{id:e,scope:t}}})},onSetAlias:async(e,t)=>{await r({customBeacons:{update:{id:e,patch:{alias:t}}}})},onDelete:async e=>{await r({customBeacons:{delete:{id:e}}})},onUpdate:a}),[r,i,a]);return(0,H.jsx)(Ri,{rows:t,configs:n,handlers:o,serverVersion:Ze})}var qi=3e5,Ji=null;function Yi(e=Date.now){return Ji?e()>=Ji.expiresAt?(Ji=null,null):Ji.releases:null}function Xi(e,t=Date.now){Ji={releases:e,expiresAt:t()+qi}}async function Zi(e,t){let n=t?.now??Date.now,r=t?.force?null:Yi(n);if(r)return r;let i=await e();return Xi(i,n),i}function Qi(e){return e.trim().replace(/^v/i,``)}function $i(e,t){let n=e=>Qi(e).split(`-`)[0].split(`.`).map(e=>Number.parseInt(e,10)).filter(e=>Number.isFinite(e)),r=n(e),i=n(t),a=Math.max(r.length,i.length);for(let e=0;e<a;e+=1){let t=r[e]??0,n=i[e]??0;if(t!==n)return t<n?-1:1}return 0}function ea(e,t,n){return Qi(e)===Qi(n)?{actionLabel:`Update`,pendingLabel:`Updating…`}:$i(e,t)<0?{actionLabel:`Rollback`,pendingLabel:`Rolling back…`}:{actionLabel:`Install`,pendingLabel:`Installing…`}}function ta(e){if(!e)return`Unpublished`;let t=new Date(e);return Number.isNaN(t.getTime())?`Unknown date`:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(t)}function na({status:e,releases:t,error:n,onRetry:r,updateSnapshot:i,currentVersion:a,onInstallUpdate:o,onCheckForUpdates:s,onForceReload:c}){let l=j(`update.check`),u=re(`update.install`),d=j(`update.redeploy`),f=ie(e=>e.inFlight),p=u||d,m=i?.latestVersion??t[0]?.tag_name??`Unknown`,h=i?.currentVersion??a,g=i?.status===`checking`||l,_=i?.status===`updating`||i?.status===`restart_pending`,v=_||p,y=i?.updateAvailable===!0,b=Qi(m),x=Qi(h),S=(0,V.useCallback)(async e=>{await o(e)},[o]),ee=(0,V.useCallback)(async()=>{await c()},[c]),te=d||_;return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[e===`loading`||e===`idle`?(0,H.jsx)(`div`,{className:`flex min-h-[180px] items-center justify-center rounded-2xl border border-border bg-card/40 px-6 py-8 text-sm text-muted-foreground`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(k,{className:`h-4 w-4 animate-spin`}),(0,H.jsx)(`span`,{children:`Loading release notes…`})]})}):null,e===`error`?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-6 py-5`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Could not load changelog`}),(0,H.jsx)(`div`,{className:`mt-1 text-sm text-muted-foreground`,children:n??`Unable to load changelog.`})]}),(0,H.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted`,children:`Retry`})]})}):null,e===`success`&&t.length===0?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 px-6 py-8`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No releases yet`}),(0,H.jsx)(`div`,{className:`mt-2 text-sm text-muted-foreground`,children:`GitHub did not return any published releases for this repository.`})]}):null,e===`success`?(0,H.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,H.jsx)(fr,{variant:`outline`,onClick:()=>A(`update.redeploy`,ee),disabled:v,children:te?(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Re-deploying…`]}):`Re-deploy`}),(0,H.jsx)(fr,{variant:`outline`,onClick:()=>A(`update.check`,s),disabled:g||v,children:g?(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Checking…`]}):`Check for updates`})]}):null,e===`success`&&t.length>0?t.map(e=>{let t=Qi(e.tag_name),n=t===b,r=t===x;return(0,H.jsxs)(`article`,{className:E(`rounded-xl border bg-card/30 pl-6 pr-4 py-4`,n?`border-border bg-muted`:`border-border`),children:[(0,H.jsxs)(`div`,{className:`flex flex-row items-center min-w-0 flex-1 gap-3 `,children:[(0,H.jsxs)(`div`,{className:`flex flex-row items-center min-w-0 flex-1 gap-2 `,children:[(0,H.jsx)(`div`,{className:`text-lg font-semibold tracking-[-0.2px] text-foreground`,children:e.name?.trim()||e.tag_name}),(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:ta(e.published_at)}),e.prerelease?(0,H.jsx)(`span`,{className:`rounded-full border border-border px-2.5 py-1 tracking-wide`,children:`Prerelease`}):null]})]}),(0,H.jsxs)(`div`,{className:`flex flex-row items-center justify-end min-w-0 flex-1 gap-2 `,children:[(0,H.jsx)(`a`,{href:e.html_url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`View release on GitHub`,className:E(oe({variant:`ghost`,size:`icon-sm`}),`h-11 w-11 md:h-8 md:w-8 shrink-0 rounded-md hover:!bg-transparent hover:border-border/0`),children:(0,H.jsx)(ra,{className:`h-4 w-4`})}),r?(0,H.jsx)(`span`,{className:E(`bg-transparent border border-border text-secondary-foreground`,`h-9 rounded-full px-3 text-sm`,`h-auto gap-1.5 px-3 py-1.5`),children:`Current`}):null,n&&y||!n&&!r?(()=>{let t=f[M(`update.install`,e.tag_name)]===!0||_&&!p,{actionLabel:n,pendingLabel:r}=ea(e.tag_name,h,m);return(0,H.jsx)(fr,{variant:`default`,className:``,onClick:()=>A(M(`update.install`,e.tag_name),()=>S(e.tag_name)),disabled:v,children:(0,H.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2`,children:[t?(0,H.jsx)(k,{className:`size-4 animate-spin`}):(0,H.jsx)(Cr,{className:`size-4`}),t?r:n]})})})():null]})]}),e.body?.trim()?(0,H.jsx)(`div`,{className:`prose prose-sm mt-5 max-w-none text-foreground dark:prose-invert`,children:ce(e.body)}):(0,H.jsx)(`div`,{className:`mt-5 text-sm text-muted-foreground`,children:`No release notes were provided.`})]},e.id)}):null]})}function ra({className:e}){return(0,H.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,className:e,children:(0,H.jsx)(`path`,{d:`M12 .5C5.649.5.5 5.649.5 12A11.5 11.5 0 0 0 8.36 22.04c.575.106.785-.25.785-.556 0-.274-.01-1-.015-1.962-3.181.691-3.853-1.532-3.853-1.532-.52-1.322-1.27-1.674-1.27-1.674-1.038-.71.08-.695.08-.695 1.148.08 1.752 1.178 1.752 1.178 1.02 1.748 2.676 1.243 3.328.95.103-.738.399-1.243.725-1.53-2.54-.289-5.211-1.27-5.211-5.65 0-1.248.446-2.27 1.177-3.07-.118-.288-.51-1.45.112-3.024 0 0 .96-.307 3.145 1.173A10.91 10.91 0 0 1 12 6.03c.973.004 1.954.132 2.87.387 2.182-1.48 3.14-1.173 3.14-1.173.625 1.573.233 2.736.115 3.024.734.8 1.175 1.822 1.175 3.07 0 4.39-2.676 5.358-5.224 5.642.41.353.776 1.05.776 2.117 0 1.528-.014 2.761-.014 3.136 0 .309.207.668.79.555A11.502 11.502 0 0 0 23.5 12C23.5 5.649 18.351.5 12 .5Z`})})}var ia=[],aa=L()(e=>({status:`idle`,releases:ia,error:null,loadStarted:()=>e({status:`loading`,error:null}),loaded:t=>e({releases:t,status:`success`}),loadFailed:t=>e({error:t,status:`error`})}));function oa(e){let t=aa(e=>e.status),n=aa(e=>e.releases),r=aa(e=>e.error),i=aa(e=>e.loadStarted),a=aa(e=>e.loaded),o=aa(e=>e.loadFailed),s=(0,V.useCallback)(async(t,n)=>{i();try{let r=await Zi(e,{force:t});n()||a(r)}catch(e){n()||o(Ye(e))}},[e,i,a,o]);return(0,V.useEffect)(()=>{let e=!1;return tn(`changelog.load`,s(!1,()=>e)),()=>{e=!0}},[s]),{status:t,releases:n,error:r,retry:(0,V.useCallback)(()=>{tn(`changelog.retry`,s(!0,()=>!1))},[s])}}function sa({state:e}){let{socket:t}=e,n=oa((0,V.useCallback)(()=>t.command({type:`settings.getChangelog`}),[t]));return(0,H.jsx)(na,{status:n.status,releases:n.releases,error:n.error,onRetry:n.retry,updateSnapshot:e.updateSnapshot,currentVersion:Ze,onInstallUpdate:t=>e.handleInstallUpdate(t),onCheckForUpdates:()=>e.handleCheckForUpdates({force:!0}),onForceReload:()=>e.handleForceReload()})}var G=L()(e=>({drafts:{scrollback:``,minColumnWidth:``,tabMinWidth:``,uploadMaxFileSize:``,editorCommand:``,cloudflaredPath:``,shareDefaultTtl:``},appSettingsError:null,tunnelError:null,analyticsDialogOpen:!1,patchDrafts:t=>e(e=>({drafts:{...e.drafts,...t}})),setAppSettingsError:t=>e({appSettingsError:t}),setTunnelError:t=>e({tunnelError:t}),setAnalyticsDialogOpen:t=>e({analyticsDialogOpen:t})}));function ca(e,t){e.key===`Enter`&&(t(),e.currentTarget.blur())}function la(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}var ua=$e.map(e=>({value:e,label:la(e)})),da=L()(e=>({chatSoundPreference:ct,chatSoundId:gt,setChatSoundPreference:t=>e({chatSoundPreference:_t(t)}),setChatSoundId:t=>e({chatSoundId:ht(t)})}));function fa(e){let t=G(e=>e.setAppSettingsError),{handleWriteAppSettings:n}=e,r=(0,V.useCallback)(e=>t(e.message),[t]);return{write:(0,V.useCallback)(e=>{n(e).catch(Je(r))},[n,r]),writeAsync:(0,V.useCallback)(e=>n(e).catch(Je(r)),[n,r])}}var pa=[{value:`light`,label:`Light`,icon:Gr},{value:`dark`,label:`Dark`,icon:Fr},{value:`system`,label:`System`,icon:Ce}],ma=[{value:`sm`,label:`Small`},{value:`md`,label:`Default`},{value:`lg`,label:`Large`},{value:`xl`,label:`Extra Large`},{value:`xxl`,label:`XX-Large`}],ha=[{value:`never`,label:`Never`},{value:`unfocused`,label:`When Unfocused`},{value:`always`,label:`Always`}],ga=`settings.chatSoundPreference`,_a=`settings.chatSoundId`;function va(e,t){return e!==t}function ya(e){return e?.status===`checking`?`Checking for updates…`:e?.status===`updating`?`Installing update…`:e?.status===`restart_pending`?`Restarting Kanna…`:e?.status===`available`?`Update available${e.latestVersion?`: ${e.latestVersion}`:``}`:e?.status===`up_to_date`?`Up to date`:e?.status===`error`?`Update check failed`:`Not checked yet`}function ba({updateSnapshot:e}){return(0,H.jsx)(U,{title:`Application Update`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[ya(e),`.`]}),e?.lastCheckedAt?(0,H.jsxs)(`span`,{children:[` Last checked `,new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(e.lastCheckedAt),`.`]}):null,e?.error?(0,H.jsxs)(`span`,{children:[` `,e.error]}):null]}),bordered:!1,children:(0,H.jsxs)(`div`,{className:`text-right text-sm text-foreground`,children:[(0,H.jsxs)(`div`,{children:[`Current: `,e?.currentVersion??Ze]}),(0,H.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Latest: `,e?.latestVersion??`Unknown`]})]})})}function xa({state:e}){let{writeAsync:t}=fa(e),n=z(Ut),r=z(Rt),i=da(e=>e.setChatSoundPreference),a=da(e=>e.setChatSoundId),o=j(ga),s=j(_a);function c(e){va(n,e)&&(i(e),A(ga,()=>t({chatSoundPreference:e})),tn(`chat sound preview`,Rn(r,1)))}function l(e){va(r,e)&&(a(e),A(_a,()=>t({chatSoundId:e})),tn(`chat sound preview`,Rn(e,1)))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Chat Sounds`,description:`Play a pop when a chat starts waiting on you or the unread chat count increases`,children:(0,H.jsxs)(ve,{disabled:o,value:n,onValueChange:e=>{Ot(e)&&c(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ha.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]})}),(0,H.jsx)(U,{title:`Chat Sound`,description:`The bundled sound used for chat notification playback and previews`,children:(0,H.jsxs)(ve,{disabled:s,value:r,onValueChange:e=>{nt(e)&&l(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ua.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]})})]})}function Sa({state:e}){let{write:t}=fa(e),n=z(It),r=z(Tt),i=y(e=>e.setEditorPreset),a=y(e=>e.setEditorCommandTemplate),o=G(e=>e.drafts.editorCommand),s=G(e=>e.patchDrafts);(0,V.useEffect)(()=>{s({editorCommand:r})},[r,s]);function c(){a(o),t({editor:{commandTemplate:o}})}function l(e){i(e);let n=e===`custom`?r:dt(e);t({editor:{preset:e,commandTemplate:n}})}let u=o.replaceAll(`{path}`,`/Users/jake/Projects/kanna/src/client/app/App.tsx`).replaceAll(`{line}`,`12`).replaceAll(`{column}`,`1`);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Default Editor`,description:`Used when opening transcript links or files from the git diff menu`,alignStart:!0,children:(0,H.jsxs)(ve,{value:n,onValueChange:e=>{zt(e)&&l(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:qn.map(e=>(0,H.jsx)(N,{value:e.value,children:(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Wn,{preset:e.value,className:`h-4 w-4 shrink-0`}),(0,H.jsx)(`span`,{children:e.label})]})},e.value))})})]})}),n===`custom`?(0,H.jsx)(`div`,{className:`border-t border-border`,children:(0,H.jsxs)(`div`,{className:`flex justify-between gap-8 py-5 pl-6`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 max-w-xl`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Command Template`}),(0,H.jsxs)(`div`,{className:`mt-1 text-13 text-muted-foreground`,children:[`Include `,`{path}`,` and optionally `,`{line}`,` and `,`{column}`,` in your command.`]})]}),(0,H.jsxs)(`div`,{className:`flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2`,children:[(0,H.jsx)(R,{type:`text`,value:o,onChange:e=>s({editorCommand:e.target.value}),onBlur:c,onKeyDown:e=>ca(e,c),className:`font-mono`}),(0,H.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Preview: `,(0,H.jsx)(`span`,{className:`font-mono`,children:u})]})]})]})}):null]})}function Ca({state:e}){let{write:t}=fa(e),{theme:n,setTheme:r}=$t(),i=o(e=>e.typographyOverride),a=o(e=>e.clearTypographyOverride),s=z(e=>e.settings?.typography.scale),c=Ct(i,s);function l(e){r(e),t({theme:e})}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(ba,{updateSnapshot:e.updateSnapshot}),(0,H.jsx)(U,{title:`Theme`,description:`Choose between light, dark, or system appearance`,children:(0,H.jsx)(I,{value:n,onValueChange:l,options:pa,size:`sm`})}),(0,H.jsx)(U,{title:`Typography Scale`,description:i?`This device uses its own text size instead of the account default.`:`Choose how large text and UI elements appear across the app.`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsxs)(ve,{value:c,onValueChange:e=>{Nt(e)&&t({typography:{scale:e}})},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ma.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]}),i?(0,H.jsx)(O,{type:`button`,variant:`link`,size:`sm`,onClick:a,children:`Use account default`}):null]})}),(0,H.jsx)(xa,{state:e}),(0,H.jsx)(Sa,{state:e})]})}var wa=[`app_launch`,`project_opened`,`project_created`,`project_removed`,`project_deleted`,`chat_created`,`chat_deleted`,`message_sent`,`update_checked`,`update_installed`,`update_failed`,`analytics_enabled`,`analytics_disabled`],Ta=[`current_version`,`environment`,`latest_version`,`custom_port_enabled`,`no_open_enabled`,`password_enabled`,`strict_port_enabled`,`remote_enabled`,`host_enabled`,`share_quick_enabled`,`share_token_enabled`],Ea=L()(e=>({permissionState:`unsupported`,deviceId:null,error:null,contactSubjectDraft:``,detected:(t,n)=>e({permissionState:t,deviceId:n}),setPermissionState:t=>e({permissionState:t}),setDeviceId:t=>e({deviceId:t}),setError:t=>e({error:t}),setContactSubjectDraft:t=>e({contactSubjectDraft:t})})),Da=`inline-flex items-center justify-center rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium text-foreground transition-colors hover:bg-muted`,Oa=`inline-flex items-center justify-center rounded-lg bg-foreground px-3 py-1.5 text-sm font-medium text-background transition-colors hover:bg-foreground/90`,ka=`rounded bg-muted px-1 py-0.5 font-mono text-12 text-foreground`,Aa=`text-xs font-medium tracking-wide text-muted-foreground`,ja=`gap-1.5 disabled:cursor-default disabled:opacity-60`,Ma=`push.enable`,Na=`push.test`,Pa=`push.disable`,Fa=`push.contactSubject`;async function Ia(e){try{await e(),Ea.getState().setError(null)}catch(e){Ea.getState().setError(Ye(e))}}function La(e,t){A(e,()=>Ia(t))}function Ra(){let e=Ea(e=>e.error);return e?(0,H.jsx)(`p`,{role:`alert`,className:`rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive-text`,children:e}):null}function za({pendingKey:e,onRun:t,className:n,label:r,children:i}){let a=j(e);return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>La(e,t),disabled:a,"aria-busy":a||void 0,"aria-label":r,className:E(n,ja),children:[a?(0,H.jsx)(T,{}):null,i]})}function Ba({localPath:e,muted:t,onMuteToggle:n}){let r=M(`push.setProjectMute`,e),i=j(r);return(0,H.jsxs)(`label`,{"aria-busy":i||void 0,className:`flex cursor-pointer items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/50`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:!t,disabled:i,onChange:t=>La(r,()=>n(e,!t.target.checked)),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsx)(cn,{inline:!0,className:`min-w-0 flex-1 font-mono text-12 text-foreground`,tooltip:e,children:e}),i?(0,H.jsx)(T,{className:`text-muted-foreground`}):null]})}function Va(e){let{permissionState:t}=e,n=j(Fa);if(t===`unsupported`)return(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Push notifications are not supported in this browser.`});if(t===`insecure-context`)return(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Push requires HTTPS. Run `,(0,H.jsx)(`code`,{className:ka,children:`kanna --share`}),` or open Kanna over a tunnel, then enable on this device.`]});if(t===`denied`)return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You blocked notifications for this site. Re-enable them in your browser settings, then reload.`}),(0,H.jsx)(Ra,{})]});if(!(t===`granted`&&e.config.devices.some(t=>t.id===e.currentDeviceId)))return(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col items-start gap-2 md:w-[440px]`,children:[(0,H.jsx)(za,{pendingKey:Ma,onRun:e.onEnable,className:Oa,children:`Enable on this device`}),(0,H.jsx)(Ra,{})]});let r=new Set(e.config.preferences.mutedProjectPaths),i=e.contactSubjectDraft.trim(),a=Zr(i),o=i!==e.contactSubject,s=()=>{a&&o&&La(Fa,()=>e.onContactSubjectSave(i))};return(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-5 md:w-[440px]`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full border border-border bg-card/40 px-3 py-1 text-xs font-medium text-foreground`,children:[(0,H.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500`,"aria-hidden":!0}),`Enabled on this device`]}),(0,H.jsx)(za,{pendingKey:Na,onRun:e.onTest,className:Da,children:`Send test`}),(0,H.jsx)(za,{pendingKey:Pa,onRun:e.onDisable,className:Da,children:`Disable`})]}),(0,H.jsx)(Ra,{}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:E(Aa,`flex items-center gap-1.5`),children:[`Contact for delivery`,n?(0,H.jsx)(T,{}):null]}),(0,H.jsx)(R,{type:`text`,inputMode:`email`,spellCheck:!1,autoCapitalize:`none`,value:e.contactSubjectDraft,readOnly:n,"aria-busy":n||void 0,onChange:t=>e.onContactSubjectDraftChange(t.target.value),onBlur:s,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s())},placeholder:`mailto:you@example.com`,"aria-label":`Push contact subject`,"aria-invalid":i!==``&&!a,className:E(`font-mono`,i!==``&&!a&&`border-destructive`)}),i!==``&&!a?(0,H.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Must be a `,(0,H.jsx)(`code`,{className:ka,children:`mailto:`}),` address or`,` `,(0,H.jsx)(`code`,{className:ka,children:`https:`}),` URL with a routable domain (not localhost).`]}):(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Push services require a contact `,(0,H.jsx)(`code`,{className:ka,children:`mailto:`}),` or`,` `,(0,H.jsx)(`code`,{className:ka,children:`https:`}),` URL to sign notifications. Set your own so delivery isn’t rejected.`]})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:Aa,children:`Devices`}),(0,H.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.config.devices.map(t=>(0,H.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-border bg-card/40 px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.label}),(0,H.jsx)(`span`,{className:`line-clamp-2 break-all text-xs leading-snug text-muted-foreground`,children:t.userAgent})]}),!t.isCurrentDevice&&(0,H.jsx)(za,{pendingKey:M(`push.unsubscribe`,t.id),onRun:()=>e.onRemoveDevice(t.id),label:`Remove ${t.label}`,className:`inline-flex shrink-0 items-center rounded-md border border-border bg-background px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:`Remove`})]},t.id))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:Aa,children:`Per-project`}),(0,H.jsx)(`ul`,{className:`flex flex-col`,children:e.projects.map(t=>(0,H.jsx)(`li`,{children:(0,H.jsx)(Ba,{localPath:t.localPath,muted:r.has(t.localPath),onMuteToggle:e.onMuteToggle})},t.localPath))})]}),(0,H.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[`Phone setup: this page must be reachable over HTTPS. Run`,` `,(0,H.jsx)(`code`,{className:ka,children:`kanna --share`}),` or open Kanna over your tunnel on the phone, then enable on that device.`]})]})}function Ha(e){return e.map(e=>({...e,disabled:!0}))}function Ua({pendingKey:e,value:t,onValueChange:n,options:r,size:i}){let a=j(e);return(0,H.jsxs)(`div`,{className:`inline-flex items-center gap-2`,"aria-busy":a||void 0,children:[a?(0,H.jsx)(T,{className:`text-muted-foreground`}):null,(0,H.jsx)(I,{value:t,onValueChange:t=>A(e,()=>n(t)),options:a?Ha(r):r,size:i})]})}function Wa(e){let{pushConfig:t,socket:n}=e,r=Ea(e=>e.deviceId),i=Ea(e=>e.setDeviceId),a=Ea(e=>e.setPermissionState);return{handleEnablePush:(0,V.useCallback)(async()=>{if(t)try{let e=await b({vapidPublicKey:t.vapidPublicKey,sendToServer:async e=>{let t=await n.command({type:`push.subscribe`,subscription:e.subscription,label:e.label,userAgent:e.userAgent});return h(t.id),{id:t.id}}});i(e)}finally{a(ee().state)}},[t,n,i,a]),handleDisablePush:(0,V.useCallback)(async()=>{r&&(await C({pushDeviceId:r,sendToServer:async e=>{await n.command({type:`push.unsubscribe`,pushDeviceId:e})}}),p(),i(null))},[r,n,i])}}var Ga=[{value:`disabled`,label:`Off`},{value:`enabled`,label:`On`}],Ka=`~/.kanna/data/settings.json`;function qa({state:e,dom:t}){let n=z(e=>e.settings),r=Ea(e=>e.permissionState),i=Ea(e=>e.deviceId),a=Ea(e=>e.contactSubjectDraft),o=Ea(e=>e.setContactSubjectDraft),s=Ea(e=>e.detected),c=Ea(e=>e.setPermissionState),{handleEnablePush:l,handleDisablePush:u}=Wa(e),{pushConfig:d,socket:f}=e,p=n?.push.contactSubject;return(0,V.useLayoutEffect)(()=>{s(ee().state,te())},[s]),(0,V.useEffect)(()=>t.addWindowListener(`focus`,()=>c(ee().state)),[t,c]),(0,V.useEffect)(()=>{p!==void 0&&o(p)},[p,o]),d?(0,H.jsx)(U,{title:`Push notifications`,description:`Get notified when a chat is waiting for you, finishes, or fails. Works on iPhone (after Add to Home Screen), Android, and desktop browsers.`,bordered:!1,alignStart:!0,children:(0,H.jsx)(Va,{permissionState:r,config:d,projects:e.localProjects?.projects??[],currentDeviceId:i,contactSubject:p??``,contactSubjectDraft:a,onContactSubjectDraftChange:o,onContactSubjectSave:t=>e.handleWriteAppSettings({push:{contactSubject:t}}),onEnable:l,onDisable:u,onTest:async()=>{await f.command({type:`push.test`})},onMuteToggle:async(e,t)=>{await f.command({type:`push.setProjectMute`,localPath:e,muted:t})},onRemoveDevice:async e=>{await f.command({type:`push.unsubscribe`,pushDeviceId:e})}})}):null}function Ja({state:e}){let t=z(e=>e.settings),n=G(e=>e.setAppSettingsError),r=G(e=>e.setAnalyticsDialogOpen),i=t?.analyticsEnabled===!1?`disabled`:`enabled`,a=t?.telemetry?.enabled===!1?`disabled`:`enabled`;async function o(t){await B(n,()=>e.handleWriteAppSettings(t))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Anonymous Analytics`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Help improve Kanna with anonymous product analytics. Kanna sends tracked event names plus a small set of event properties like current version, environment, update version info, and launch flags. No message content, prompts, file paths, or provider credentials are sent.`}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Stored in `,t?.filePathDisplay??Ka,`.`,` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`underline underline-offset-2 text-foreground hover:text-foreground/80`,children:`View tracked events`})]}),t?.warning?(0,H.jsx)(`span`,{className:`mt-1 block`,children:t.warning}):null]}),children:(0,H.jsx)(Ua,{pendingKey:`settings.analytics`,value:i,onValueChange:e=>o({analyticsEnabled:e===`enabled`}),options:Ga,size:`sm`})}),(0,H.jsx)(U,{title:`Telemetry Tracing`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Export OpenTelemetry traces and metrics (turn timings, subagent runs, process memory) to Kanna's observability collector so each install can be monitored. This machine reports under its computer name. Turning it off stops the export immediately.`}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Collector: `,t?.telemetry?.endpoint??`not configured`,`. Stored in `,t?.filePathDisplay??Ka,`.`]})]}),children:(0,H.jsx)(Ua,{pendingKey:`settings.telemetry`,value:a,onValueChange:e=>o({telemetry:{enabled:e===`enabled`}}),options:Ga,size:`sm`})})]})}function Ya(){let e=G(e=>e.analyticsDialogOpen),t=G(e=>e.setAnalyticsDialogOpen);return(0,H.jsx)(Re,{open:e,onOpenChange:t,children:(0,H.jsxs)(Le,{size:`lg`,children:[(0,H.jsxs)(Be,{className:`space-y-4`,children:[(0,H.jsx)(He,{children:`Tracked Events`}),(0,H.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Kanna sends these event names plus the limited property keys below, depending on the event type.`}),(0,H.jsxs)(`div`,{className:`max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted/40 p-3`,children:[(0,H.jsx)(`div`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,children:`Event Names`}),(0,H.jsx)(`ul`,{className:`mt-3 space-y-2 text-sm`,children:wa.map(e=>(0,H.jsx)(`li`,{className:`font-mono text-foreground`,children:e},e))}),(0,H.jsx)(`div`,{className:`mt-6 text-xs font-medium tracking-wide text-muted-foreground`,children:`Property Keys`}),(0,H.jsx)(`ul`,{className:`mt-3 space-y-2 text-sm`,children:Ta.map(e=>(0,H.jsx)(`li`,{className:`font-mono text-foreground`,children:e},e))})]})]}),(0,H.jsx)(ze,{children:(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>t(!1),children:`Close`})})]})})}function Xa({state:e,dom:t}){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(qa,{state:e,dom:t}),(0,H.jsx)(Ja,{state:e}),(0,H.jsx)(Ya,{})]})}var Za={path:`shareDefaultTtlHours`,min:1,max:1/0,integer:!0},Qa=6e5,$a={path:`subagentRuntime.runTimeoutMs`,min:3e4,max:864e5,integer:!0},eo={path:`claudeDriver.lifecycle.idleTimeoutMs`,min:ut,max:st,integer:!1},to={path:`claudeDriver.lifecycle.maxConcurrent`,min:1,max:16,integer:!1};function no(e,t,n){let r=Number(e);if(!qt(n,r))return{kind:`invalid`};let i=Math.round(r);return i===t?{kind:`unchanged`}:{kind:`write`,value:i}}function ro({title:e,description:t,min:n,max:r,step:i,value:a,onValueChange:o,onCommit:s,hint:c,unit:l,ariaLabel:u,bordered:d}){let f=(0,H.jsx)(R,{type:`number`,min:n,max:r,step:i,value:a,onChange:e=>o(e.target.value),onBlur:s,onKeyDown:e=>ca(e,s),className:E(`hide-number-steppers w-full text-left font-mono`,l?`tabular-nums md:w-24 md:text-right`:`md:w-28 md:text-right`),"aria-label":u});return(0,H.jsx)(U,{title:e,description:t,bordered:d,children:(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end`,children:[l?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 md:justify-end`,children:[f,(0,H.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:l})]}):f,(0,H.jsx)(`div`,{className:E(`text-left text-xs text-muted-foreground md:text-right`,l&&`tabular-nums`),children:c})]})})}function io({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.shareDefaultTtlHours??24),r=G(e=>e.drafts.shareDefaultTtl),i=G(e=>e.patchDrafts),a=G(e=>e.setAppSettingsError);(0,V.useEffect)(()=>{i({shareDefaultTtl:String(n)})},[n,i]);function o(){let e=no(r,n,Za);e.kind===`write`?t({shareDefaultTtlHours:e.value}):(i({shareDefaultTtl:String(n)}),e.kind===`invalid`&&a(`Default share link expiry must be a whole number of hours >= 1.`))}return(0,H.jsx)(`div`,{className:`border-b border-border`,children:(0,H.jsx)(ro,{title:`Public share links`,description:`Default expiry for read-only chat share links. Owners can revoke any link manually at any time.`,min:Za.min,step:1,value:r,onValueChange:e=>i({shareDefaultTtl:e}),onCommit:o,unit:`hours`,ariaLabel:`Default share link expiry in hours`,hint:`Minimum 1 hour · default 24`,bordered:!1})})}function ao({checked:e,onChange:t}){return(0,H.jsxs)(`label`,{className:`inline-flex items-center gap-2`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)}),`Enabled`]})}function oo(e,t){let n=G(t=>t.drafts[e]),r=G(e=>e.patchDrafts);return(0,V.useEffect)(()=>{r({[e]:String(t)})},[e,t,r]),{draft:n,setDraft:t=>r({[e]:t}),parsed:()=>{let e=Number(n);return Number.isFinite(e)?e:null},reset:()=>r({[e]:String(t)})}}function so({state:e}){let{write:t}=fa(e),n=z(jt),r=y(e=>e.setScrollbackLines),i=oo(`scrollback`,n);function a(){let e=i.parsed();e===null?i.reset():(r(e),t({terminal:{scrollbackLines:e}}))}return(0,H.jsx)(ro,{title:`Terminal Scrollback`,description:`Lines retained for embedded terminal history`,min:500,max:wt,step:100,value:i.draft,onValueChange:i.setDraft,onCommit:a,hint:(0,H.jsxs)(H.Fragment,{children:[500,`-`,wt,` lines`,n===1e3?` (default)`:``]})})}function co({state:e}){let{write:t}=fa(e),n=z(kt),r=y(e=>e.setMinColumnWidth),i=oo(`minColumnWidth`,n);function a(){let e=i.parsed();e===null?i.reset():(r(e),t({terminal:{minColumnWidth:e}}))}return(0,H.jsx)(ro,{title:`Terminal Min Column Width`,description:`Minimum width for each terminal pane`,min:250,max:900,step:10,value:i.draft,onValueChange:i.setDraft,onCommit:a,hint:(0,H.jsxs)(H.Fragment,{children:[250,`-`,900,` px`,n===450?` (default)`:``]})})}function lo({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.panes.tabMinWidth??60),r=oo(`tabMinWidth`,n);function i(){let e=r.parsed();e===null?r.reset():t({panes:{tabMinWidth:Gn(e)}})}return(0,H.jsx)(ro,{title:`Tab Minimum Width`,description:`How narrow a pane tab may get before the strip scrolls instead of shrinking`,min:60,max:200,step:10,value:r.draft,onValueChange:r.setDraft,onCommit:i,hint:(0,H.jsxs)(H.Fragment,{children:[60,`-`,200,` px`,n===60?` (default)`:``]})})}function uo({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.uploads.maxFileSizeMb??Qr.maxFileSizeMb),r=G(e=>e.drafts.uploadMaxFileSize),i=G(e=>e.patchDrafts),a=G(e=>e.setAppSettingsError);(0,V.useEffect)(()=>{i({uploadMaxFileSize:String(n)})},[n,i]);function o(){let e=no(r,n,$r);e.kind===`write`?t({uploads:{maxFileSizeMb:e.value}}):(i({uploadMaxFileSize:String(n)}),e.kind===`invalid`&&a(`Max file size must be between ${$r.min} and ${$r.max} MB.`))}return(0,H.jsx)(ro,{title:`Max upload file size`,description:`Largest single file the chat upload endpoint accepts.`,min:$r.min,max:$r.max,step:1,value:r,onValueChange:e=>i({uploadMaxFileSize:e}),onCommit:o,unit:`MB`,ariaLabel:`Max upload file size in megabytes`,hint:`${$r.min}–${$r.max} MB · default ${Qr.maxFileSizeMb}`})}function fo({state:e}){let t=o(e=>e.autoResumeOnRateLimit),n=o(e=>e.setAutoResumeOnRateLimit);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(so,{state:e}),(0,H.jsx)(co,{state:e}),(0,H.jsx)(lo,{state:e}),(0,H.jsx)(uo,{state:e}),(0,H.jsx)(U,{title:`Auto-resume on rate limit`,description:`When you hit a rate limit, automatically schedule "continue" at the reset time instead of asking. You can still cancel each one from the chat.`,children:(0,H.jsx)(ao,{checked:t,onChange:n})})]})}var po=[{value:`disabled`,label:`Off`},{value:`enabled`,label:`On`}],mo=[{value:`always-ask`,label:`Always ask`},{value:`auto-expose`,label:`Auto-expose`}],ho=`appSettings.setCloudflareTunnel`,go=M(ho,`cloudflaredPath`);function _o({state:e}){let t=z(e=>e.settings),n=G(e=>e.tunnelError),r=G(e=>e.setTunnelError),i=G(e=>e.drafts.cloudflaredPath),a=G(e=>e.patchDrafts),o=j(go),s=t?.cloudflareTunnel??Xr,c=s.enabled?`enabled`:`disabled`,l=t?.cloudflareTunnel.cloudflaredPath;(0,V.useEffect)(()=>{l!==void 0&&a({cloudflaredPath:l})},[l,a]);async function u(t){await B(r,()=>e.handleWriteCloudflareTunnel(t))}return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[n?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:n}):null,(0,H.jsx)(U,{title:`Cloudflare Tunnel`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[`When enabled, Claude can call the `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:`expose_port`}),` tool to expose a local port via Cloudflare Tunnel. The mode below controls whether each call requires your approval or is exposed automatically. Requires`,` `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:`cloudflared`}),` `,`to be installed.`]}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Stored in `,t?.filePathDisplay??`~/.kanna/data/settings.json`,`.`]})]}),bordered:!1,children:(0,H.jsx)(Ua,{pendingKey:M(ho,`enabled`),value:c,onValueChange:e=>u({enabled:e===`enabled`}),options:po,size:`sm`})}),s.enabled&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Tool mode`,description:`Always ask: each expose_port call shows an accept card. Auto-expose: expose_port calls spawn cloudflared immediately without prompting.`,children:(0,H.jsx)(Ua,{pendingKey:M(ho,`mode`),value:s.mode,onValueChange:e=>u({mode:e}),options:mo,size:`sm`})}),(0,H.jsx)(U,{title:`cloudflared path`,description:`Path to the cloudflared binary. Defaults to the one found on $PATH.`,children:(0,H.jsx)(R,{value:i,onChange:e=>a({cloudflaredPath:e.target.value}),onBlur:()=>A(go,()=>u({cloudflaredPath:i})),readOnly:o,"aria-busy":o||void 0,placeholder:`cloudflared`,className:`w-full font-mono md:w-64`})})]})]})}function vo({state:e,dom:t=nn}){let n=G(e=>e.appSettingsError);return(0,H.jsxs)(H.Fragment,{children:[n?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:n}):null,(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(Ca,{state:e}),(0,H.jsx)(fo,{state:e}),(0,H.jsx)(Xa,{state:e,dom:t})]}),(0,H.jsx)(_o,{state:e}),(0,H.jsx)(io,{state:e})]})}var yo=L()(e=>({draft:``,persistedAtMount:``,error:null,setDraft:t=>e({draft:t}),persistedChanged:t=>e({persistedAtMount:t,draft:t}),setError:t=>e({error:t})})),bo=`settings.globalInstructions`;function xo({state:e}){let t=z(e=>e.settings?.globalPromptAppend??``),n=yo(e=>e.draft),r=yo(e=>e.setDraft),i=yo(e=>e.persistedAtMount),a=yo(e=>e.persistedChanged),o=j(bo),s=yo(e=>e.error),c=yo(e=>e.setError);(0,V.useEffect)(()=>{t!==i&&a(t)},[t,i,a]);let l=n.replace(/\s+$/u,``),u=l.length>yt,d=l!==t,f=o||u||!d,p=(0,V.useCallback)(async()=>{f||await B(c,()=>e.handleWriteAppSettings({globalPromptAppend:l}))},[f,e,l,c]),m;return m=o?`Saving…`:d?`Save`:`Saved`,(0,H.jsx)(`div`,{className:`border-b border-border`,children:(0,H.jsx)(U,{title:`Global Instructions`,description:`Appended to every Claude and Codex turn — including subagent turns — as “Workspace instructions”. Kanna does not read CLAUDE.md or AGENTS.md from disk; paste your global instructions here. For rules that apply to one project only, use “Edit instructions” in that project's sidebar menu. Leave blank to disable.`,bordered:!1,alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex w-full flex-col gap-2 md:w-[420px]`,children:[(0,H.jsx)(`textarea`,{value:n,onChange:e=>r(e.target.value),placeholder:`e.g. Always write tests before implementation. Prefer Tailwind classes over inline styles.`,rows:8,"aria-label":`Global instructions`,className:E(`min-h-[160px] w-full resize-y rounded-md border bg-background px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,u?`border-destructive`:`border-input`),disabled:o}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,H.jsxs)(`span`,{className:u?`text-destructive`:`text-muted-foreground`,children:[l.length,` / `,yt,` characters`,u?` — over limit`:``]}),(0,H.jsx)(O,{type:`button`,size:`sm`,onClick:()=>A(bo,p),disabled:f,pending:o,children:m})]}),s?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:s}):null]})})})}function So(e){return{async onReload(t){await sn(e,{type:`plugins.reload`,pluginId:t})}}}function Co({plugins:e,handlers:t}){return e.length===0?(0,H.jsx)(ti,{icon:ne,message:`No plugins installed yet.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Plugins`}),(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(wo,{plugin:e,onReload:t.onReload},e.id))})]})}function wo({plugin:e,onReload:t}){let n=M(`plugins.reload`,e.id),r=j(n),i=(0,V.useCallback)(()=>{A(n,()=>t(e.id))},[t,e.id,n]);return(0,H.jsxs)(`li`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.id}),(0,H.jsx)(mn,{tone:e.enabled?`active`:`muted`,label:e.enabled?`Enabled`:`Disabled`})]}),(0,H.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.sourceDir})]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,"data-testid":`plugin-reload:${e.id}`,pending:r,onClick:i,children:`Reload`})]})}function To(){let e=z(Vt),t=z(Kt),n=an(),r=(0,V.useMemo)(()=>So(n),[n]);return e?(0,H.jsx)(Co,{plugins:t,handlers:r}):null}var Eo={},Do=L()(e=>({drafts:Eo,error:null,setDrafts:t=>e({drafts:t}),setDraft:(t,n)=>e(e=>e.drafts[t]===n?e:{drafts:{...e.drafts,[t]:n}}),setError:t=>e({error:t})}));function Oo(e){let t={};for(let n of vt)t[n]=un(e[n]??``);return{...lt,...t}}function ko(e){return M(`settings.writeKeybindings`,e)}function Ao({action:e,currentValue:t,bordered:n,onDraftChange:r,onCommit:i,onRestoreDefault:a}){let o=ko(e),s=j(o),c=dn(lt[e]),l=t!==c,u=()=>{A(o,i)};return(0,H.jsx)(U,{title:fn[e],description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Comma-separated shortcuts.`}),l?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:` `}),(0,H.jsxs)(`button`,{type:`button`,disabled:s,"aria-busy":s||void 0,onClick:()=>{A(o,()=>a(e))},className:`inline rounded text-foreground hover:text-foreground/80 disabled:opacity-60`,children:[`Restore: `,c]})]}):null]}),bordered:n,children:(0,H.jsxs)(`div`,{className:`flex min-w-0 max-w-[420px] flex-1 items-center gap-2`,children:[(0,H.jsx)(R,{type:`text`,value:t,"aria-busy":s||void 0,onChange:t=>r(e,t.target.value),onBlur:u,onKeyDown:e=>ca(e,u),className:`font-mono`}),s?(0,H.jsx)(T,{}):null]})})}function jo({state:e}){let t=Do(e=>e.drafts),n=Do(e=>e.setDrafts),r=Do(e=>e.setDraft),i=Do(e=>e.error),a=Do(e=>e.setError),o=(0,V.useMemo)(()=>ln(e.keybindings),[e.keybindings]);(0,V.useEffect)(()=>{n(Object.fromEntries(vt.map(e=>[e,dn(o.bindings[e])])))},[o,n]);async function s(t){await B(a,async()=>{await e.socket.command({type:`settings.writeKeybindings`,bindings:Oo(t)})})}async function c(){await s(t)}async function l(e){let r={...t,[e]:dn(lt[e])};n(r),await s(r)}return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[i?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:i}):null,o.warning?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground`,children:o.warning}):null,vt.map((e,n)=>(0,H.jsx)(Ao,{action:e,currentValue:t[e]??``,bordered:n!==0,onDraftChange:r,onCommit:c,onRestoreDefault:l},e))]})}function Mo(e){return e===null?{name:``,transport:`stdio`,command:``,argsText:``,envText:``,cwd:``,url:``,headersText:``}:e.transport===`stdio`?{name:e.name,transport:`stdio`,command:e.command,argsText:e.args.join(`
|
|
1
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./react-BWPDF9mI.js";import{l as n,u as r}from"./chunk-6KYCQHYJ-C0N1h4Su.js";import{t as i}from"./jsx-runtime-BB9-612F.js";import{A as a,E as o,N as s,P as c,St as l,T as u,U as d,_ as f,a as p,bt as m,c as h,d as g,g as _,h as v,j as y,l as b,m as x,n as S,o as ee,s as te,u as C,vt as w,xt as ne}from"./useAppGlobalState-BZY419Te.js";import{a as re,d as T,f as E,h as D,i as ie,l as O,m as k,n as A,o as ae,r as j,t as M,u as oe}from"./pendingActionsStore-tyIM7H15.js";import{a as se,l as ce,n as le,o as ue}from"./beacon-alias-Y46OkdpU.js";import{a as de,i as fe,n as pe,o as me,t as he}from"./copyFeedbackStore-DRdRTPSB.js";import{a as ge,i as N,n as P,o as _e,r as F,t as ve}from"./select-qh2tsZ5U.js";import{t as ye}from"./info-xjfw_aIo.js";import{c as be,r as xe,s as Se}from"./contextWindow-BqXKSvM3.js";import{t as Ce}from"./monitor-CJu2dBY2.js";import{t as we}from"./pencil-D74A5m1N.js";import{t as Te}from"./plus-1J-y2SUN.js";import{t as Ee}from"./refresh-cw-DQ0n_x3I.js";import{t as De}from"./search-WzAKqjaJ.js";import{T as Oe,a as ke,c as Ae,i as je,o as Me,r as Ne,s as Pe,t as Fe}from"./useProviderCatalog-CrJ_JTAN.js";import{g as Ie,i as Le,n as Re,o as ze,r as Be,t as Ve,u as He}from"./timer.adapter-CAyQ03SG.js";import{a as Ue,c as We,o as Ge,s as Ke,t as I}from"./segmented-control-DmiIJJuE.js";import{d as qe,f as L,i as Je,n as Ye,r as Xe,s as Ze}from"./log-BtILyPXN.js";import{t as R}from"./input-CzZyMS39.js";import{f as Qe,i as $e,o as et,u as tt}from"./core-types-Ds7PFmZN.js";import{$ as nt,A as rt,C as it,D as at,E as ot,G as st,H as ct,J as lt,K as ut,L as dt,M as ft,N as pt,O as mt,U as ht,V as gt,W as _t,X as vt,Y as yt,Z as bt,_ as xt,a as St,at as Ct,b as wt,c as Tt,ct as Et,d as Dt,et as Ot,f as kt,g as At,h as jt,i as Mt,it as Nt,j as Pt,k as Ft,l as It,m as Lt,n as Rt,nt as zt,o as Bt,p as Vt,q as Ht,r as Ut,rt as Wt,s as Gt,u as Kt,ut as qt,v as z,w as Jt}from"./tool-call-types-BPhjPQVt.js";import{M as Yt,N as Xt,iu as Zt,j as Qt,r as $t,ru as en}from"./useTheme-CoKiTydH.js";import{t as tn}from"./runDetached-C-tqrG01.js";import{t as nn}from"./dom.adapter-C26vNdMA.js";import{_ as rn,a as B,b as an,g as on,r as sn,v as cn}from"./commandFeedback-Lzlzc1iV.js";import{d as ln,f as un,l as dn,t as fn}from"./keybindings-D6ojTUcm.js";import{a as pn,n as mn}from"./state-mark-CZuog43J.js";import{_ as hn,a as gn,c as _n,d as vn,f as yn,g as bn,h as xn,i as Sn,n as Cn,o as wn,p as Tn,r as En,t as Dn,u as On,v as kn,x as An,y as jn}from"./types-Bzcas-On.js";import{n as Mn,t as Nn}from"./formatDuration-BbWTR_M_.js";import{St as Pn,_n as Fn,at as In,bt as Ln,nn as Rn,xn as zn,xt as Bn}from"./index-BlL72nKf.js";import{S as Vn,_ as Hn,b as Un,c as Wn,f as Gn,l as Kn,s as qn,u as Jn,v as Yn,y as Xn}from"./ChatPage-CYb-8oYP.js";import{a as Zn,c as Qn,d as $n,f as er,i as tr,l as nr,o as rr,p as ir,s as ar,t as or,u as sr}from"./searchable-select-Bs6L7YOH.js";import{f as cr,l as lr,t as ur,u as dr}from"./inboxAutonomy-CpkWYpCU.js";import{t as fr}from"./settings-header-button-BkWj0d5-.js";import{t as pr}from"./InboundHandlerFields-DLPkDYQo.js";var mr={name:`antenna`,size:24,node:[[`path`,{d:`M2 12 7 2`,key:`117k30`}],[`path`,{d:`m7 12 5-10`,key:`1tvx22`}],[`path`,{d:`m12 12 5-10`,key:`ev1o1a`}],[`path`,{d:`m17 12 5-10`,key:`1e4ti3`}],[`path`,{d:`M4.5 7h15`,key:`vlsxkz`}],[`path`,{d:`M12 16v6`,key:`c8a4gj`}]]};mr.node;var hr=D(mr),gr={name:`book-text`,size:24,node:[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]};gr.node;var _r=D(gr),vr={name:`circle-alert`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`]};vr.node;var yr=D(vr),br={name:`circle-arrow-up`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]],aliases:[`arrow-up-circle`]};br.node;var xr=D(br),Sr={name:`cloud-download`,size:24,node:[[`path`,{d:`M12 13v8l-4-4`,key:`1f5nwf`}],[`path`,{d:`m12 21 4-4`,key:`1lfcce`}],[`path`,{d:`M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284`,key:`ui1hmy`}]],aliases:[`download-cloud`]};Sr.node;var Cr=D(Sr),wr={name:`command`,size:24,node:[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]};wr.node;var Tr=D(wr),Er={name:`cpu`,size:24,node:[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]};Er.node;var Dr=D(Er),Or={name:`flask-conical`,size:24,node:[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]};Or.node;var kr=D(Or),Ar={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};Ar.node;var jr=D(Ar),Mr={name:`message-square-quote`,size:24,node:[[`path`,{d:`M14 14a2 2 0 0 0 2-2V8h-2`,key:`1r06pg`}],[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M8 14a2 2 0 0 0 2-2V8H8`,key:`1jzu5j`}]]};Mr.node;var Nr=D(Mr),Pr={name:`moon`,size:24,node:[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]};Pr.node;var Fr=D(Pr),Ir={name:`network`,size:24,node:[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]};Ir.node;var Lr=D(Ir),Rr={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};Rr.node;var zr=D(Rr),Br={name:`power-off`,size:24,node:[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};Br.node;var Vr=D(Br),Hr={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};Hr.node;var Ur=D(Hr),Wr={name:`sun`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]};Wr.node;var Gr=D(Wr),Kr={name:`type`,size:24,node:[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]};Kr.node;var qr=D(Kr),Jr={name:`waypoints`,size:24,node:[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]};Jr.node;var Yr=D(Jr),Xr={enabled:!1,cloudflaredPath:`cloudflared`,mode:`always-ask`},V=e(t(),1),H=e(i(),1);function Zr(e){let t=e.trim();if(t.startsWith(`https://`))try{let e=new URL(t);if(e.protocol!==`https:`)return!1;let n=e.hostname.toLowerCase();return!(n===`localhost`||!n.includes(`.`)||n.startsWith(`.`)||n.endsWith(`.`))}catch{return!1}if(t.startsWith(`mailto:`)){let e=t.slice(7),n=/^[^\s@]+@([^\s@]+)$/.exec(e);if(!n)return!1;let r=n[1].toLowerCase();return!(r===`localhost`||!r.includes(`.`)||r.startsWith(`.`)||r.endsWith(`.`))}return!1}var Qr={maxFileSizeMb:2048},$r={path:`uploads.maxFileSizeMb`,min:1,max:51200,integer:!1},ei=L()(e=>({authEnabled:!1,setAuthEnabled:t=>e({authEnabled:t})}));function U({title:e,description:t,children:n,bordered:r=!0,alignStart:i=!1}){return(0,H.jsx)(`div`,{className:r?`border-t border-border`:void 0,children:(0,H.jsxs)(`div`,{className:E(`flex flex-col gap-4 py-5 md:flex-row md:justify-between md:gap-8`,i?`md:items-start`:`md:items-center`),children:[(0,H.jsxs)(`div`,{className:`min-w-0 max-w-xl`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e}),(0,H.jsx)(`div`,{className:`mt-1 text-13 text-muted-foreground`,children:t})]}),(0,H.jsx)(`div`,{className:`flex items-center justify-start md:shrink-0 md:justify-end`,children:n})]})})}function ti({icon:e,message:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-md border border-dashed px-6 py-10 text-center`,children:[(0,H.jsx)(e,{className:`mb-3 h-8 w-8 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function ni({children:e}){return(0,H.jsx)(`ul`,{className:`flex flex-col divide-y rounded-md border`,children:e})}function ri({label:e,onEdit:t,onDelete:n,deletePending:r=!1}){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:t,"aria-label":`Edit ${e}`,children:(0,H.jsx)(we,{className:`h-4 w-4`})}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:n,pending:r,"aria-label":`Delete ${e}`,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})}var ii=new Set([`checking`,`downloading`,`installing`,`restarting`]);function ai(e){return e!==null&&ii.has(e.state)}function oi(e){switch(e.state){case`checking`:return`Checking ${e.version}…`;case`downloading`:return`Downloading ${e.version}…`;case`installing`:return`Installing ${e.version}…`;case`restarting`:return`Restarting…`;case`current`:return`Up to date`;case`failed`:return e.message===void 0?`Update failed`:`Update failed: ${e.message}`}}function si(e){switch(e.state){case`failed`:return`destructive`;case`current`:return`muted`;case`checking`:case`downloading`:case`installing`:case`restarting`:return`active`}}var ci={},li={},ui={},di={};function fi(e,t){return`${e}:${t}`}function pi(e,t,n){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e!==t));return Object.keys(r).length>0?r:n}var W=L()(e=>({pairing:null,expandedId:null,drafts:ci,updateErrors:li,aliasErrors:ui,openExplanations:di,setPairing:t=>e({pairing:t}),toggleExpanded:t=>e(e=>({expandedId:e.expandedId===t?null:t})),setDraft:(t,n)=>e(e=>({drafts:{...e.drafts,[t]:n}})),clearDraft:t=>e(e=>({drafts:pi(e.drafts,t,ci)})),setUpdateError:(t,n)=>e(e=>n===null?{updateErrors:pi(e.updateErrors,t,li)}:{updateErrors:{...e.updateErrors,[t]:n}}),beginAliasEdit:(t,n)=>e(e=>({drafts:{...e.drafts,[fi(t,`alias`)]:n}})),endAliasEdit:t=>e(e=>({drafts:pi(e.drafts,fi(t,`alias`),ci),aliasErrors:pi(e.aliasErrors,t,ui)})),setAliasError:(t,n)=>e(e=>n===null?{aliasErrors:pi(e.aliasErrors,t,ui)}:{aliasErrors:{...e.aliasErrors,[t]:n}}),toggleExplanation:t=>e(e=>({openExplanations:t in e.openExplanations?pi(e.openExplanations,t,di):{...e.openExplanations,[t]:!0}}))})),mi=`kanna-beacon`,hi=`ABCDEFGHJKLMNPQRSTUVWXYZ23456789`,gi=`https://github.com/cuongtranba/kanna/releases/latest`;RegExp(`^[${hi}]{8}$`);function _i(e){return`${mi}://pair?url=${encodeURIComponent(e.kannaUrl)}&code=${encodeURIComponent(e.code)}`}function vi(e){return`kanna-beacon pair ${e.kannaUrl} ${e.code}`}function yi(e){return e.replace(/^v/,``).split(`-`)[0].split(`.`).map(e=>Number.parseInt(e,10))}function bi(e,t){if(e===t)return!1;let n=yi(e),r=yi(t),i=Math.max(n.length,r.length);for(let a=0;a<i;a+=1){let i=n[a]??0,o=r[a]??0;if(Number.isNaN(i)||Number.isNaN(o))return e<t;if(i!==o)return i<o}return!1}var xi={outdated:`border-warning/40 text-warning-text bg-warning/10`,partial:`border-warning/40 text-warning-text bg-warning/10`,unknown:`border-border text-muted-foreground bg-muted/40`};function Si({beaconId:e,alias:t,displayName:n}){let r=W(e=>e.beginAliasEdit),i=(0,V.useCallback)(()=>{r(e,t??``)},[t,e,r]);return(0,H.jsx)(rn,{label:`Set a short name`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:i,"aria-label":`Set a short name for ${n}`,children:(0,H.jsx)(we,{className:`h-3.5 w-3.5`})})})}function Ci({beaconId:e,alias:t,displayName:n,onSetAlias:r}){let i=fi(e,`alias`),a=W(e=>e.drafts[i]),o=W(t=>t.aliasErrors[e]??null),s=W(e=>e.setDraft),c=W(e=>e.setAliasError),l=W(e=>e.endAliasEdit),u=M(`beacons.setAlias`,e),d=j(u),f=a??``,p=f.length===0?null:se(f),m=f.length>0&&p===null&&f!==t,h=p??o,g=(0,V.useCallback)(t=>{s(i,t.target.value.toLowerCase()),c(e,null)},[e,i,c,s]),_=(0,V.useCallback)(t=>{A(u,async()=>{try{await r(e,t),l(e)}catch(t){c(e,Ye(t))}})},[e,l,r,u,c]),v=(0,V.useCallback)(()=>{_(f)},[_,f]),y=(0,V.useCallback)(()=>{_(null)},[_]),b=(0,V.useCallback)(()=>{l(e)},[e,l]);return a===void 0?null:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(R,{value:f,onChange:g,placeholder:`office-mac`,disabled:d,"aria-label":`Short name for ${n}`,"aria-invalid":h!==null||void 0,className:`w-48`}),(0,H.jsx)(O,{size:`sm`,onClick:v,pending:d,disabled:!m,children:`Save`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:b,disabled:d,children:`Cancel`}),t!==null&&(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:y,disabled:d,children:`Clear alias`})]}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Type `,(0,H.jsxs)(`span`,{className:`font-mono`,children:[`@beacon/`,f.length>0?f:`name`]}),` in a message to refer to this machine.`]}),h!==null&&(0,H.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive-text`,children:h})]})}var wi=`Lets the agent run commands and scripts on this machine. Off means every command and script is refused, and the agent can only read and copy files inside the folders below. When on, each command still waits for your approval unless it is on the always-run list or you switch on running without asking.`,Ti=`Skips the approval prompt. Reads and writes inside the folders below, and every command and script, run immediately. Leave it off to review each action before it runs on this machine.`,Ei=`The agent can list, search, read and copy files off this machine only inside these folders and their subfolders. Anything outside is refused. With none listed it cannot read from this machine at all. Each read waits for your approval unless running without asking is on.`,Di=`The agent can copy files onto this machine only inside these folders and their subfolders. Leave empty and it cannot write to this machine at all. Each write waits for your approval unless running without asking is on.`,Oi=`Command names, such as git, that run immediately once running commands is allowed. Matching uses the command name only, so git covers every git subcommand. Anything not listed asks you first.`;function ki(e){return`beacon-explain-${e}`}function Ai({explanationKey:e,subject:t}){let n=W(t=>e in t.openExplanations),r=W(e=>e.toggleExplanation),i=(0,V.useCallback)(()=>{r(e)},[e,r]);return(0,H.jsx)(rn,{label:`What does this do?`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:i,"aria-expanded":n,"aria-controls":ki(e),"aria-label":`What does "${t}" do?`,children:(0,H.jsx)(ye,{className:`h-4 w-4`})})})}function ji({explanationKey:e,text:t}){let n=W(t=>e in t.openExplanations);return(0,H.jsx)(`p`,{id:ki(e),hidden:!n,className:`text-13 text-muted-foreground`,children:t})}function Mi({beaconId:e,scope:t,onSetScope:n}){let r=M(`beacons.setScope`,e),i=j(r),a=(0,V.useCallback)(t=>{A(r,()=>n(e,t))},[e,n,r]),o=(0,V.useCallback)(e=>{a({...t,exec:e.target.checked})},[a,t]),s=(0,V.useCallback)(e=>{a({...t,autoRunScripts:e.target.checked})},[a,t]),c=(0,V.useCallback)(e=>{a({...t,readRoots:e})},[a,t]),l=(0,V.useCallback)(e=>{a({...t,writeRoots:e})},[a,t]),u=(0,V.useCallback)(e=>{a({...t,execAllowlist:e})},[a,t]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border bg-muted/40 px-4 py-4`,"aria-busy":i||void 0,children:[(0,H.jsx)(Ni,{explanationKey:fi(e,`exec`),checked:t.exec,disabled:i,onChange:o,title:`Allow running commands`,explanation:wi}),(0,H.jsx)(Ni,{explanationKey:fi(e,`autoRunScripts`),checked:t.autoRunScripts,disabled:i,onChange:s,title:`Run commands and scripts from this chat without asking each time`,explanation:Ti}),(0,H.jsx)(Pi,{label:`Folders the agent may read`,explanation:Ei,placeholder:`/Users/me/projects`,draftKey:fi(e,`readRoots`),items:t.readRoots,disabled:i,onChange:c}),(0,H.jsx)(Pi,{label:`Folders the agent may write to`,explanation:Di,placeholder:`/Users/me/inbox`,draftKey:fi(e,`writeRoots`),items:t.writeRoots,disabled:i,onChange:l}),(0,H.jsx)(Pi,{label:`Commands that always run without asking`,explanation:Oi,placeholder:`git`,draftKey:fi(e,`execAllowlist`),items:t.execAllowlist,disabled:i,onChange:u})]})}function Ni({explanationKey:e,checked:t,disabled:n,onChange:r,title:i,explanation:a}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsxs)(`label`,{className:`flex min-w-0 cursor-pointer items-center gap-3`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:t,disabled:n,onChange:r}),(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i})]}),(0,H.jsx)(Ai,{explanationKey:e,subject:i})]}),(0,H.jsx)(`div`,{className:`pl-7`,children:(0,H.jsx)(ji,{explanationKey:e,text:a})})]})}function Pi({label:e,explanation:t,placeholder:n,draftKey:r,items:i,disabled:a,onChange:o}){let s=W(e=>e.drafts[r]??``),c=W(e=>e.setDraft),l=W(e=>e.clearDraft),u=s.trim(),d=u.length>0&&!i.includes(u),f=(0,V.useCallback)(e=>{c(r,e.target.value)},[r,c]),p=(0,V.useCallback)(()=>{o([...i,u]),l(r)},[l,r,i,o,u]),m=(0,V.useCallback)(e=>{o(i.filter(t=>t!==e))},[i,o]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e}),(0,H.jsx)(Ai,{explanationKey:r,subject:e})]}),(0,H.jsx)(ji,{explanationKey:r,text:t}),i.length===0?(0,H.jsx)(`span`,{className:`text-13 text-muted-foreground`,children:`None`}):(0,H.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.map(e=>(0,H.jsx)(Fi,{item:e,disabled:a,onRemove:m},e))}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{value:s,onChange:f,placeholder:n,disabled:a,"aria-label":e}),(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:p,disabled:a||!d,children:`Add`})]})]})}function Fi({item:e,disabled:t,onRemove:n}){let r=(0,V.useCallback)(()=>{n(e)},[e,n]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`code`,{className:`min-w-0 flex-1 break-all rounded-md border border-border bg-muted px-2 py-1 font-mono text-13`,children:e}),(0,H.jsx)(O,{variant:`ghost`,size:`icon-sm`,onClick:r,disabled:t,"aria-label":`Remove ${e}`,children:(0,H.jsx)(Ie,{className:`h-4 w-4`})})]})}var Ii=M(`beacons.mintPairingCode`);function Li(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return{id:e.id,label:e.label,alias:e.alias??null,os:e.os,enabled:e.enabled,online:t?.online??!1,lastSeenAt:t?.lastSeenAt??null,beaconVersion:t?.beaconVersion??null,canSelfUpdate:t?.canSelfUpdate??!1,update:t?.update??null}})}function Ri({rows:e,configs:t,handlers:n,serverVersion:r,dom:i=nn,clipboard:a=fe,timer:o=Ve}){let s=In(1e3),c=(0,V.useMemo)(()=>Li(e,t),[e,t]),l=(0,V.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(zi,{now:s,handlers:n,dom:i,clipboard:a,timer:o}),c.length===0?(0,H.jsx)(ti,{icon:Xn,message:`No machines paired yet. Pair a machine to let the agent read files and run approved commands there.`}):(0,H.jsx)(ni,{children:c.map(e=>(0,H.jsx)(Gi,{row:e,scope:l.get(e.id)?.scope??null,now:s,serverVersion:r,handlers:n,dom:i},e.id))})]})}function zi({now:e,handlers:t,dom:n,clipboard:r,timer:i}){let a=W(e=>e.pairing),o=W(e=>e.setPairing),s=j(Ii),c=(0,V.useCallback)(()=>{A(Ii,async()=>{o(await t.onMint())})},[t,o]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-border bg-card p-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Beacons`}),(0,H.jsx)(`p`,{className:`mt-1 text-13 text-muted-foreground`,children:`A beacon is a small program on your own machine. Once paired, the agent can read files and run commands there, only within the scope you grant below.`})]}),(0,H.jsxs)(O,{size:`sm`,variant:a?.ok===!0?`secondary`:`default`,onClick:c,pending:s,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Pair a machine`]})]}),a?.ok===!1&&(0,H.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive-text`,children:a.error}),a?.ok===!0&&(0,H.jsx)(Bi,{code:a.code,expiresAt:a.expiresAt,now:e,dom:n,clipboard:r,timer:i})]})}function Bi({code:e,expiresAt:t,now:n,dom:r,clipboard:i,timer:a}){let o=t-n,s=r.getOrigin(),c=vi({kannaUrl:s,code:e}),l=_i({kannaUrl:s,code:e}),u=M(`beacons.copyPairCommand`,e),d=j(u),f=pe(u),p=(0,V.useCallback)(()=>{A(u,()=>he(u,()=>i.writeText(c),a))},[i,c,u,a]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border pt-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,H.jsx)(`span`,{className:`font-mono text-2xl font-medium tabular-nums tracking-widest`,children:e}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:o>0?`Expires in ${Mn(o)}`:`Expired. Pair again for a new code.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,H.jsxs)(`a`,{href:l,className:oe({size:`sm`}),children:[(0,H.jsx)(Fn,{className:`mr-1 h-4 w-4`}),`Open in Kanna Beacon`]}),(0,H.jsx)(`a`,{href:gi,target:`_blank`,rel:`noreferrer`,className:`text-13 text-muted-foreground underline underline-offset-2 hover:text-foreground`,children:`Download Kanna Beacon`})]}),(0,H.jsx)(`p`,{className:`text-13 text-muted-foreground`,children:`Or run this on the machine you want to pair:`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`code`,{className:`min-w-0 flex-1 break-all rounded-md border border-border bg-muted px-3 py-2 font-mono text-13`,children:c}),(0,H.jsx)(rn,{label:f?`Copied`:`Copy command`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon`,onClick:p,pending:d,"aria-label":f?`Copied`:`Copy pairing command`,children:f?(0,H.jsx)(me,{className:`h-4 w-4 text-success-text`}):(0,H.jsx)(de,{className:`h-4 w-4`})})})]})]})}function Vi(e,t){return e.lastSeenAt===null?`Never connected`:`Last seen ${Nn(t-e.lastSeenAt)} ago`}var Hi=`This beacon is too old to update itself. Reinstall it once from the download page; after that, updates are one click.`;function Ui({canSelfUpdate:e}){let t=E(`rounded-full border px-2 py-0.5 text-xs`,xi.outdated);return e?(0,H.jsx)(`span`,{className:t,children:`Update available`}):(0,H.jsx)(rn,{label:Hi,children:(0,H.jsx)(`a`,{href:gi,target:`_blank`,rel:`noreferrer`,className:t,children:`Update available`})})}function Wi({row:e,updateAvailable:t,handlers:n}){let r=M(`beacons.update`,e.id),i=j(r),a=W(t=>t.updateErrors[e.id]??null),o=W(e=>e.setUpdateError),s=t&&e.online&&e.canSelfUpdate&&!ai(e.update),c=(0,V.useCallback)(()=>{A(r,async()=>{let t=await n.onUpdate(e.id);o(e.id,t.ok?null:t.error)})},[n,e.id,o,r]);return(0,H.jsxs)(H.Fragment,{children:[e.update!==null&&(0,H.jsx)(mn,{tone:si(e.update),label:oi(e.update)}),s&&(0,H.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:c,pending:i,"aria-label":`Update ${le(e)} now`,children:[(0,H.jsx)(xr,{className:`mr-1 h-4 w-4`}),`Update now`]}),a!==null&&(0,H.jsx)(`span`,{role:`alert`,className:`text-destructive-text`,children:a})]})}function Gi({row:e,scope:t,now:n,serverVersion:r,handlers:i,dom:a}){let o=W(t=>t.expandedId===e.id),s=W(e=>e.toggleExpanded),c=M(`beacons.setEnabled`,e.id),l=j(c),u=M(`beacons.delete`,e.id),d=j(u),f=le(e),p=e.beaconVersion!==null&&r!==void 0&&bi(e.beaconVersion,r),m=(0,V.useCallback)(t=>{let n=t.target.checked;A(c,()=>i.onSetEnabled(e.id,n))},[c,i,e.id]),h=(0,V.useCallback)(()=>{a.confirmDialog(`Revoke "${f}"? The agent will lose access to this machine until you pair it again.`)&&A(u,()=>i.onDelete(e.id))},[u,f,a,i,e.id]),g=(0,V.useCallback)(()=>{s(e.id)},[e.id,s]);return(0,H.jsxs)(`li`,{className:`flex flex-col`,"aria-busy":d||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,H.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`truncate font-medium`,children:f}),(0,H.jsx)(Si,{beaconId:e.id,alias:e.alias,displayName:f})]}),e.alias!==null&&(0,H.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`font-mono`,children:e.label}),(0,H.jsxs)(`span`,{className:`font-mono`,children:[`@beacon/`,e.alias]})]}),(0,H.jsx)(Ci,{beaconId:e.id,alias:e.alias,displayName:f,onSetAlias:i.onSetAlias}),(0,H.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,H.jsx)(mn,{tone:e.online?`active`:`muted`,label:e.online?`Online`:`Offline`}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:Vi(e,n)}),e.beaconVersion!==null&&(0,H.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[`v`,e.beaconVersion]}),p&&(0,H.jsx)(Ui,{canSelfUpdate:e.canSelfUpdate}),(0,H.jsx)(Wi,{row:e,updateAvailable:p,handlers:i}),(0,H.jsx)(`span`,{children:e.os})]})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[l?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:l,"aria-busy":l||void 0,onChange:m,"aria-label":`Enable ${f}`}),(0,H.jsx)(`span`,{children:e.enabled?`Enabled`:`Disabled`})]}),t!==null&&(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:g,"aria-expanded":o,children:[`Scope`,(0,H.jsx)(zn,{className:E(`ml-1 h-4 w-4 transition-transform`,o&&`rotate-180`)})]}),(0,H.jsx)(rn,{label:`Revoke this machine`,children:(0,H.jsx)(O,{variant:`ghost`,size:`icon`,onClick:h,pending:d,"aria-label":`Revoke ${f}`,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})})]})]}),o&&t!==null&&(0,H.jsx)(Mi,{beaconId:e.id,scope:t,onSetScope:i.onSetScope})]})}function Ki(e){let t=c(s),n=z(Mt),{handleWriteAppSettings:r,handleMintBeaconPairingCode:i,handleUpdateBeacon:a}=e.state,o=(0,V.useMemo)(()=>({onMint:i,onSetEnabled:async(e,t)=>{await r({customBeacons:{setEnabled:{id:e,enabled:t}}})},onSetScope:async(e,t)=>{await r({customBeacons:{setScope:{id:e,scope:t}}})},onSetAlias:async(e,t)=>{await r({customBeacons:{update:{id:e,patch:{alias:t}}}})},onDelete:async e=>{await r({customBeacons:{delete:{id:e}}})},onUpdate:a}),[r,i,a]);return(0,H.jsx)(Ri,{rows:t,configs:n,handlers:o,serverVersion:Ze})}var qi=3e5,Ji=null;function Yi(e=Date.now){return Ji?e()>=Ji.expiresAt?(Ji=null,null):Ji.releases:null}function Xi(e,t=Date.now){Ji={releases:e,expiresAt:t()+qi}}async function Zi(e,t){let n=t?.now??Date.now,r=t?.force?null:Yi(n);if(r)return r;let i=await e();return Xi(i,n),i}function Qi(e){return e.trim().replace(/^v/i,``)}function $i(e,t){let n=e=>Qi(e).split(`-`)[0].split(`.`).map(e=>Number.parseInt(e,10)).filter(e=>Number.isFinite(e)),r=n(e),i=n(t),a=Math.max(r.length,i.length);for(let e=0;e<a;e+=1){let t=r[e]??0,n=i[e]??0;if(t!==n)return t<n?-1:1}return 0}function ea(e,t,n){return Qi(e)===Qi(n)?{actionLabel:`Update`,pendingLabel:`Updating…`}:$i(e,t)<0?{actionLabel:`Rollback`,pendingLabel:`Rolling back…`}:{actionLabel:`Install`,pendingLabel:`Installing…`}}function ta(e){if(!e)return`Unpublished`;let t=new Date(e);return Number.isNaN(t.getTime())?`Unknown date`:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(t)}function na({status:e,releases:t,error:n,onRetry:r,updateSnapshot:i,currentVersion:a,onInstallUpdate:o,onCheckForUpdates:s,onForceReload:c}){let l=j(`update.check`),u=re(`update.install`),d=j(`update.redeploy`),f=ie(e=>e.inFlight),p=u||d,m=i?.latestVersion??t[0]?.tag_name??`Unknown`,h=i?.currentVersion??a,g=i?.status===`checking`||l,_=i?.status===`updating`||i?.status===`restart_pending`,v=_||p,y=i?.updateAvailable===!0,b=Qi(m),x=Qi(h),S=(0,V.useCallback)(async e=>{await o(e)},[o]),ee=(0,V.useCallback)(async()=>{await c()},[c]),te=d||_;return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[e===`loading`||e===`idle`?(0,H.jsx)(`div`,{className:`flex min-h-[180px] items-center justify-center rounded-2xl border border-border bg-card/40 px-6 py-8 text-sm text-muted-foreground`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(k,{className:`h-4 w-4 animate-spin`}),(0,H.jsx)(`span`,{children:`Loading release notes…`})]})}):null,e===`error`?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-6 py-5`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Could not load changelog`}),(0,H.jsx)(`div`,{className:`mt-1 text-sm text-muted-foreground`,children:n??`Unable to load changelog.`})]}),(0,H.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted`,children:`Retry`})]})}):null,e===`success`&&t.length===0?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 px-6 py-8`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No releases yet`}),(0,H.jsx)(`div`,{className:`mt-2 text-sm text-muted-foreground`,children:`GitHub did not return any published releases for this repository.`})]}):null,e===`success`?(0,H.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,H.jsx)(fr,{variant:`outline`,onClick:()=>A(`update.redeploy`,ee),disabled:v,children:te?(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Re-deploying…`]}):`Re-deploy`}),(0,H.jsx)(fr,{variant:`outline`,onClick:()=>A(`update.check`,s),disabled:g||v,children:g?(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Checking…`]}):`Check for updates`})]}):null,e===`success`&&t.length>0?t.map(e=>{let t=Qi(e.tag_name),n=t===b,r=t===x;return(0,H.jsxs)(`article`,{className:E(`rounded-xl border bg-card/30 pl-6 pr-4 py-4`,n?`border-border bg-muted`:`border-border`),children:[(0,H.jsxs)(`div`,{className:`flex flex-row items-center min-w-0 flex-1 gap-3 `,children:[(0,H.jsxs)(`div`,{className:`flex flex-row items-center min-w-0 flex-1 gap-2 `,children:[(0,H.jsx)(`div`,{className:`text-lg font-semibold tracking-[-0.2px] text-foreground`,children:e.name?.trim()||e.tag_name}),(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:ta(e.published_at)}),e.prerelease?(0,H.jsx)(`span`,{className:`rounded-full border border-border px-2.5 py-1 tracking-wide`,children:`Prerelease`}):null]})]}),(0,H.jsxs)(`div`,{className:`flex flex-row items-center justify-end min-w-0 flex-1 gap-2 `,children:[(0,H.jsx)(`a`,{href:e.html_url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`View release on GitHub`,className:E(oe({variant:`ghost`,size:`icon-sm`}),`h-11 w-11 md:h-8 md:w-8 shrink-0 rounded-md hover:!bg-transparent hover:border-border/0`),children:(0,H.jsx)(ra,{className:`h-4 w-4`})}),r?(0,H.jsx)(`span`,{className:E(`bg-transparent border border-border text-secondary-foreground`,`h-9 rounded-full px-3 text-sm`,`h-auto gap-1.5 px-3 py-1.5`),children:`Current`}):null,n&&y||!n&&!r?(()=>{let t=f[M(`update.install`,e.tag_name)]===!0||_&&!p,{actionLabel:n,pendingLabel:r}=ea(e.tag_name,h,m);return(0,H.jsx)(fr,{variant:`default`,className:``,onClick:()=>A(M(`update.install`,e.tag_name),()=>S(e.tag_name)),disabled:v,children:(0,H.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2`,children:[t?(0,H.jsx)(k,{className:`size-4 animate-spin`}):(0,H.jsx)(Cr,{className:`size-4`}),t?r:n]})})})():null]})]}),e.body?.trim()?(0,H.jsx)(`div`,{className:`prose prose-sm mt-5 max-w-none text-foreground dark:prose-invert`,children:ce(e.body)}):(0,H.jsx)(`div`,{className:`mt-5 text-sm text-muted-foreground`,children:`No release notes were provided.`})]},e.id)}):null]})}function ra({className:e}){return(0,H.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,className:e,children:(0,H.jsx)(`path`,{d:`M12 .5C5.649.5.5 5.649.5 12A11.5 11.5 0 0 0 8.36 22.04c.575.106.785-.25.785-.556 0-.274-.01-1-.015-1.962-3.181.691-3.853-1.532-3.853-1.532-.52-1.322-1.27-1.674-1.27-1.674-1.038-.71.08-.695.08-.695 1.148.08 1.752 1.178 1.752 1.178 1.02 1.748 2.676 1.243 3.328.95.103-.738.399-1.243.725-1.53-2.54-.289-5.211-1.27-5.211-5.65 0-1.248.446-2.27 1.177-3.07-.118-.288-.51-1.45.112-3.024 0 0 .96-.307 3.145 1.173A10.91 10.91 0 0 1 12 6.03c.973.004 1.954.132 2.87.387 2.182-1.48 3.14-1.173 3.14-1.173.625 1.573.233 2.736.115 3.024.734.8 1.175 1.822 1.175 3.07 0 4.39-2.676 5.358-5.224 5.642.41.353.776 1.05.776 2.117 0 1.528-.014 2.761-.014 3.136 0 .309.207.668.79.555A11.502 11.502 0 0 0 23.5 12C23.5 5.649 18.351.5 12 .5Z`})})}var ia=[],aa=L()(e=>({status:`idle`,releases:ia,error:null,loadStarted:()=>e({status:`loading`,error:null}),loaded:t=>e({releases:t,status:`success`}),loadFailed:t=>e({error:t,status:`error`})}));function oa(e){let t=aa(e=>e.status),n=aa(e=>e.releases),r=aa(e=>e.error),i=aa(e=>e.loadStarted),a=aa(e=>e.loaded),o=aa(e=>e.loadFailed),s=(0,V.useCallback)(async(t,n)=>{i();try{let r=await Zi(e,{force:t});n()||a(r)}catch(e){n()||o(Ye(e))}},[e,i,a,o]);return(0,V.useEffect)(()=>{let e=!1;return tn(`changelog.load`,s(!1,()=>e)),()=>{e=!0}},[s]),{status:t,releases:n,error:r,retry:(0,V.useCallback)(()=>{tn(`changelog.retry`,s(!0,()=>!1))},[s])}}function sa({state:e}){let{socket:t}=e,n=oa((0,V.useCallback)(()=>t.command({type:`settings.getChangelog`}),[t]));return(0,H.jsx)(na,{status:n.status,releases:n.releases,error:n.error,onRetry:n.retry,updateSnapshot:e.updateSnapshot,currentVersion:Ze,onInstallUpdate:t=>e.handleInstallUpdate(t),onCheckForUpdates:()=>e.handleCheckForUpdates({force:!0}),onForceReload:()=>e.handleForceReload()})}var G=L()(e=>({drafts:{scrollback:``,minColumnWidth:``,tabMinWidth:``,uploadMaxFileSize:``,editorCommand:``,cloudflaredPath:``,shareDefaultTtl:``},appSettingsError:null,tunnelError:null,analyticsDialogOpen:!1,patchDrafts:t=>e(e=>({drafts:{...e.drafts,...t}})),setAppSettingsError:t=>e({appSettingsError:t}),setTunnelError:t=>e({tunnelError:t}),setAnalyticsDialogOpen:t=>e({analyticsDialogOpen:t})}));function ca(e,t){e.key===`Enter`&&(t(),e.currentTarget.blur())}function la(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}var ua=$e.map(e=>({value:e,label:la(e)})),da=L()(e=>({chatSoundPreference:ct,chatSoundId:gt,setChatSoundPreference:t=>e({chatSoundPreference:_t(t)}),setChatSoundId:t=>e({chatSoundId:ht(t)})}));function fa(e){let t=G(e=>e.setAppSettingsError),{handleWriteAppSettings:n}=e,r=(0,V.useCallback)(e=>t(e.message),[t]);return{write:(0,V.useCallback)(e=>{n(e).catch(Je(r))},[n,r]),writeAsync:(0,V.useCallback)(e=>n(e).catch(Je(r)),[n,r])}}var pa=[{value:`light`,label:`Light`,icon:Gr},{value:`dark`,label:`Dark`,icon:Fr},{value:`system`,label:`System`,icon:Ce}],ma=[{value:`sm`,label:`Small`},{value:`md`,label:`Default`},{value:`lg`,label:`Large`},{value:`xl`,label:`Extra Large`},{value:`xxl`,label:`XX-Large`}],ha=[{value:`never`,label:`Never`},{value:`unfocused`,label:`When Unfocused`},{value:`always`,label:`Always`}],ga=`settings.chatSoundPreference`,_a=`settings.chatSoundId`;function va(e,t){return e!==t}function ya(e){return e?.status===`checking`?`Checking for updates…`:e?.status===`updating`?`Installing update…`:e?.status===`restart_pending`?`Restarting Kanna…`:e?.status===`available`?`Update available${e.latestVersion?`: ${e.latestVersion}`:``}`:e?.status===`up_to_date`?`Up to date`:e?.status===`error`?`Update check failed`:`Not checked yet`}function ba({updateSnapshot:e}){return(0,H.jsx)(U,{title:`Application Update`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[ya(e),`.`]}),e?.lastCheckedAt?(0,H.jsxs)(`span`,{children:[` Last checked `,new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(e.lastCheckedAt),`.`]}):null,e?.error?(0,H.jsxs)(`span`,{children:[` `,e.error]}):null]}),bordered:!1,children:(0,H.jsxs)(`div`,{className:`text-right text-sm text-foreground`,children:[(0,H.jsxs)(`div`,{children:[`Current: `,e?.currentVersion??Ze]}),(0,H.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Latest: `,e?.latestVersion??`Unknown`]})]})})}function xa({state:e}){let{writeAsync:t}=fa(e),n=z(Ut),r=z(Rt),i=da(e=>e.setChatSoundPreference),a=da(e=>e.setChatSoundId),o=j(ga),s=j(_a);function c(e){va(n,e)&&(i(e),A(ga,()=>t({chatSoundPreference:e})),tn(`chat sound preview`,Rn(r,1)))}function l(e){va(r,e)&&(a(e),A(_a,()=>t({chatSoundId:e})),tn(`chat sound preview`,Rn(e,1)))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Chat Sounds`,description:`Play a pop when a chat starts waiting on you or the unread chat count increases`,children:(0,H.jsxs)(ve,{disabled:o,value:n,onValueChange:e=>{Ot(e)&&c(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ha.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]})}),(0,H.jsx)(U,{title:`Chat Sound`,description:`The bundled sound used for chat notification playback and previews`,children:(0,H.jsxs)(ve,{disabled:s,value:r,onValueChange:e=>{nt(e)&&l(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ua.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]})})]})}function Sa({state:e}){let{write:t}=fa(e),n=z(It),r=z(Tt),i=y(e=>e.setEditorPreset),a=y(e=>e.setEditorCommandTemplate),o=G(e=>e.drafts.editorCommand),s=G(e=>e.patchDrafts);(0,V.useEffect)(()=>{s({editorCommand:r})},[r,s]);function c(){a(o),t({editor:{commandTemplate:o}})}function l(e){i(e);let n=e===`custom`?r:dt(e);t({editor:{preset:e,commandTemplate:n}})}let u=o.replaceAll(`{path}`,`/Users/jake/Projects/kanna/src/client/app/App.tsx`).replaceAll(`{line}`,`12`).replaceAll(`{column}`,`1`);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Default Editor`,description:`Used when opening transcript links or files from the git diff menu`,alignStart:!0,children:(0,H.jsxs)(ve,{value:n,onValueChange:e=>{zt(e)&&l(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:qn.map(e=>(0,H.jsx)(N,{value:e.value,children:(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Wn,{preset:e.value,className:`h-4 w-4 shrink-0`}),(0,H.jsx)(`span`,{children:e.label})]})},e.value))})})]})}),n===`custom`?(0,H.jsx)(`div`,{className:`border-t border-border`,children:(0,H.jsxs)(`div`,{className:`flex justify-between gap-8 py-5 pl-6`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 max-w-xl`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Command Template`}),(0,H.jsxs)(`div`,{className:`mt-1 text-13 text-muted-foreground`,children:[`Include `,`{path}`,` and optionally `,`{line}`,` and `,`{column}`,` in your command.`]})]}),(0,H.jsxs)(`div`,{className:`flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2`,children:[(0,H.jsx)(R,{type:`text`,value:o,onChange:e=>s({editorCommand:e.target.value}),onBlur:c,onKeyDown:e=>ca(e,c),className:`font-mono`}),(0,H.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Preview: `,(0,H.jsx)(`span`,{className:`font-mono`,children:u})]})]})]})}):null]})}function Ca({state:e}){let{write:t}=fa(e),{theme:n,setTheme:r}=$t(),i=o(e=>e.typographyOverride),a=o(e=>e.clearTypographyOverride),s=z(e=>e.settings?.typography.scale),c=Ct(i,s);function l(e){r(e),t({theme:e})}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(ba,{updateSnapshot:e.updateSnapshot}),(0,H.jsx)(U,{title:`Theme`,description:`Choose between light, dark, or system appearance`,children:(0,H.jsx)(I,{value:n,onValueChange:l,options:pa,size:`sm`})}),(0,H.jsx)(U,{title:`Typography Scale`,description:i?`This device uses its own text size instead of the account default.`:`Choose how large text and UI elements appear across the app.`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsxs)(ve,{value:c,onValueChange:e=>{Nt(e)&&t({typography:{scale:e}})},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:ma.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]}),i?(0,H.jsx)(O,{type:`button`,variant:`link`,size:`sm`,onClick:a,children:`Use account default`}):null]})}),(0,H.jsx)(xa,{state:e}),(0,H.jsx)(Sa,{state:e})]})}var wa=[`app_launch`,`project_opened`,`project_created`,`project_removed`,`project_deleted`,`chat_created`,`chat_deleted`,`message_sent`,`update_checked`,`update_installed`,`update_failed`,`analytics_enabled`,`analytics_disabled`],Ta=[`current_version`,`environment`,`latest_version`,`custom_port_enabled`,`no_open_enabled`,`password_enabled`,`strict_port_enabled`,`remote_enabled`,`host_enabled`,`share_quick_enabled`,`share_token_enabled`],Ea=L()(e=>({permissionState:`unsupported`,deviceId:null,error:null,contactSubjectDraft:``,detected:(t,n)=>e({permissionState:t,deviceId:n}),setPermissionState:t=>e({permissionState:t}),setDeviceId:t=>e({deviceId:t}),setError:t=>e({error:t}),setContactSubjectDraft:t=>e({contactSubjectDraft:t})})),Da=`inline-flex items-center justify-center rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium text-foreground transition-colors hover:bg-muted`,Oa=`inline-flex items-center justify-center rounded-lg bg-foreground px-3 py-1.5 text-sm font-medium text-background transition-colors hover:bg-foreground/90`,ka=`rounded bg-muted px-1 py-0.5 font-mono text-12 text-foreground`,Aa=`text-xs font-medium tracking-wide text-muted-foreground`,ja=`gap-1.5 disabled:cursor-default disabled:opacity-60`,Ma=`push.enable`,Na=`push.test`,Pa=`push.disable`,Fa=`push.contactSubject`;async function Ia(e){try{await e(),Ea.getState().setError(null)}catch(e){Ea.getState().setError(Ye(e))}}function La(e,t){A(e,()=>Ia(t))}function Ra(){let e=Ea(e=>e.error);return e?(0,H.jsx)(`p`,{role:`alert`,className:`rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive-text`,children:e}):null}function za({pendingKey:e,onRun:t,className:n,label:r,children:i}){let a=j(e);return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>La(e,t),disabled:a,"aria-busy":a||void 0,"aria-label":r,className:E(n,ja),children:[a?(0,H.jsx)(T,{}):null,i]})}function Ba({localPath:e,muted:t,onMuteToggle:n}){let r=M(`push.setProjectMute`,e),i=j(r);return(0,H.jsxs)(`label`,{"aria-busy":i||void 0,className:`flex cursor-pointer items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/50`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:!t,disabled:i,onChange:t=>La(r,()=>n(e,!t.target.checked)),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsx)(cn,{inline:!0,className:`min-w-0 flex-1 font-mono text-12 text-foreground`,tooltip:e,children:e}),i?(0,H.jsx)(T,{className:`text-muted-foreground`}):null]})}function Va(e){let{permissionState:t}=e,n=j(Fa);if(t===`unsupported`)return(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Push notifications are not supported in this browser.`});if(t===`insecure-context`)return(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Push requires HTTPS. Run `,(0,H.jsx)(`code`,{className:ka,children:`kanna --share`}),` or open Kanna over a tunnel, then enable on this device.`]});if(t===`denied`)return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You blocked notifications for this site. Re-enable them in your browser settings, then reload.`}),(0,H.jsx)(Ra,{})]});if(!(t===`granted`&&e.config.devices.some(t=>t.id===e.currentDeviceId)))return(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col items-start gap-2 md:w-[440px]`,children:[(0,H.jsx)(za,{pendingKey:Ma,onRun:e.onEnable,className:Oa,children:`Enable on this device`}),(0,H.jsx)(Ra,{})]});let r=new Set(e.config.preferences.mutedProjectPaths),i=e.contactSubjectDraft.trim(),a=Zr(i),o=i!==e.contactSubject,s=()=>{a&&o&&La(Fa,()=>e.onContactSubjectSave(i))};return(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-5 md:w-[440px]`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full border border-border bg-card/40 px-3 py-1 text-xs font-medium text-foreground`,children:[(0,H.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500`,"aria-hidden":!0}),`Enabled on this device`]}),(0,H.jsx)(za,{pendingKey:Na,onRun:e.onTest,className:Da,children:`Send test`}),(0,H.jsx)(za,{pendingKey:Pa,onRun:e.onDisable,className:Da,children:`Disable`})]}),(0,H.jsx)(Ra,{}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:E(Aa,`flex items-center gap-1.5`),children:[`Contact for delivery`,n?(0,H.jsx)(T,{}):null]}),(0,H.jsx)(R,{type:`text`,inputMode:`email`,spellCheck:!1,autoCapitalize:`none`,value:e.contactSubjectDraft,readOnly:n,"aria-busy":n||void 0,onChange:t=>e.onContactSubjectDraftChange(t.target.value),onBlur:s,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s())},placeholder:`mailto:you@example.com`,"aria-label":`Push contact subject`,"aria-invalid":i!==``&&!a,className:E(`font-mono`,i!==``&&!a&&`border-destructive`)}),i!==``&&!a?(0,H.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Must be a `,(0,H.jsx)(`code`,{className:ka,children:`mailto:`}),` address or`,` `,(0,H.jsx)(`code`,{className:ka,children:`https:`}),` URL with a routable domain (not localhost).`]}):(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Push services require a contact `,(0,H.jsx)(`code`,{className:ka,children:`mailto:`}),` or`,` `,(0,H.jsx)(`code`,{className:ka,children:`https:`}),` URL to sign notifications. Set your own so delivery isn’t rejected.`]})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:Aa,children:`Devices`}),(0,H.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.config.devices.map(t=>(0,H.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-border bg-card/40 px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.label}),(0,H.jsx)(`span`,{className:`line-clamp-2 break-all text-xs leading-snug text-muted-foreground`,children:t.userAgent})]}),!t.isCurrentDevice&&(0,H.jsx)(za,{pendingKey:M(`push.unsubscribe`,t.id),onRun:()=>e.onRemoveDevice(t.id),label:`Remove ${t.label}`,className:`inline-flex shrink-0 items-center rounded-md border border-border bg-background px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:`Remove`})]},t.id))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:Aa,children:`Per-project`}),(0,H.jsx)(`ul`,{className:`flex flex-col`,children:e.projects.map(t=>(0,H.jsx)(`li`,{children:(0,H.jsx)(Ba,{localPath:t.localPath,muted:r.has(t.localPath),onMuteToggle:e.onMuteToggle})},t.localPath))})]}),(0,H.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[`Phone setup: this page must be reachable over HTTPS. Run`,` `,(0,H.jsx)(`code`,{className:ka,children:`kanna --share`}),` or open Kanna over your tunnel on the phone, then enable on that device.`]})]})}function Ha(e){return e.map(e=>({...e,disabled:!0}))}function Ua({pendingKey:e,value:t,onValueChange:n,options:r,size:i}){let a=j(e);return(0,H.jsxs)(`div`,{className:`inline-flex items-center gap-2`,"aria-busy":a||void 0,children:[a?(0,H.jsx)(T,{className:`text-muted-foreground`}):null,(0,H.jsx)(I,{value:t,onValueChange:t=>A(e,()=>n(t)),options:a?Ha(r):r,size:i})]})}function Wa(e){let{pushConfig:t,socket:n}=e,r=Ea(e=>e.deviceId),i=Ea(e=>e.setDeviceId),a=Ea(e=>e.setPermissionState);return{handleEnablePush:(0,V.useCallback)(async()=>{if(t)try{let e=await b({vapidPublicKey:t.vapidPublicKey,sendToServer:async e=>{let t=await n.command({type:`push.subscribe`,subscription:e.subscription,label:e.label,userAgent:e.userAgent});return h(t.id),{id:t.id}}});i(e)}finally{a(ee().state)}},[t,n,i,a]),handleDisablePush:(0,V.useCallback)(async()=>{r&&(await C({pushDeviceId:r,sendToServer:async e=>{await n.command({type:`push.unsubscribe`,pushDeviceId:e})}}),p(),i(null))},[r,n,i])}}var Ga=[{value:`disabled`,label:`Off`},{value:`enabled`,label:`On`}],Ka=`~/.kanna/data/settings.json`;function qa({state:e,dom:t}){let n=z(e=>e.settings),r=Ea(e=>e.permissionState),i=Ea(e=>e.deviceId),a=Ea(e=>e.contactSubjectDraft),o=Ea(e=>e.setContactSubjectDraft),s=Ea(e=>e.detected),c=Ea(e=>e.setPermissionState),{handleEnablePush:l,handleDisablePush:u}=Wa(e),{pushConfig:d,socket:f}=e,p=n?.push.contactSubject;return(0,V.useLayoutEffect)(()=>{s(ee().state,te())},[s]),(0,V.useEffect)(()=>t.addWindowListener(`focus`,()=>c(ee().state)),[t,c]),(0,V.useEffect)(()=>{p!==void 0&&o(p)},[p,o]),d?(0,H.jsx)(U,{title:`Push notifications`,description:`Get notified when a chat is waiting for you, finishes, or fails. Works on iPhone (after Add to Home Screen), Android, and desktop browsers.`,bordered:!1,alignStart:!0,children:(0,H.jsx)(Va,{permissionState:r,config:d,projects:e.localProjects?.projects??[],currentDeviceId:i,contactSubject:p??``,contactSubjectDraft:a,onContactSubjectDraftChange:o,onContactSubjectSave:t=>e.handleWriteAppSettings({push:{contactSubject:t}}),onEnable:l,onDisable:u,onTest:async()=>{await f.command({type:`push.test`})},onMuteToggle:async(e,t)=>{await f.command({type:`push.setProjectMute`,localPath:e,muted:t})},onRemoveDevice:async e=>{await f.command({type:`push.unsubscribe`,pushDeviceId:e})}})}):null}function Ja({state:e}){let t=z(e=>e.settings),n=G(e=>e.setAppSettingsError),r=G(e=>e.setAnalyticsDialogOpen),i=t?.analyticsEnabled===!1?`disabled`:`enabled`,a=t?.telemetry?.enabled===!1?`disabled`:`enabled`;async function o(t){await B(n,()=>e.handleWriteAppSettings(t))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Anonymous Analytics`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Help improve Kanna with anonymous product analytics. Kanna sends tracked event names plus a small set of event properties like current version, environment, update version info, and launch flags. No message content, prompts, file paths, or provider credentials are sent.`}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Stored in `,t?.filePathDisplay??Ka,`.`,` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`underline underline-offset-2 text-foreground hover:text-foreground/80`,children:`View tracked events`})]}),t?.warning?(0,H.jsx)(`span`,{className:`mt-1 block`,children:t.warning}):null]}),children:(0,H.jsx)(Ua,{pendingKey:`settings.analytics`,value:i,onValueChange:e=>o({analyticsEnabled:e===`enabled`}),options:Ga,size:`sm`})}),(0,H.jsx)(U,{title:`Telemetry Tracing`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Export OpenTelemetry traces and metrics (turn timings, subagent runs, process memory) to Kanna's observability collector so each install can be monitored. This machine reports under its computer name. Turning it off stops the export immediately.`}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Collector: `,t?.telemetry?.endpoint??`not configured`,`. Stored in `,t?.filePathDisplay??Ka,`.`]})]}),children:(0,H.jsx)(Ua,{pendingKey:`settings.telemetry`,value:a,onValueChange:e=>o({telemetry:{enabled:e===`enabled`}}),options:Ga,size:`sm`})})]})}function Ya(){let e=G(e=>e.analyticsDialogOpen),t=G(e=>e.setAnalyticsDialogOpen);return(0,H.jsx)(Re,{open:e,onOpenChange:t,children:(0,H.jsxs)(Le,{size:`lg`,children:[(0,H.jsxs)(Be,{className:`space-y-4`,children:[(0,H.jsx)(He,{children:`Tracked Events`}),(0,H.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Kanna sends these event names plus the limited property keys below, depending on the event type.`}),(0,H.jsxs)(`div`,{className:`max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted/40 p-3`,children:[(0,H.jsx)(`div`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,children:`Event Names`}),(0,H.jsx)(`ul`,{className:`mt-3 space-y-2 text-sm`,children:wa.map(e=>(0,H.jsx)(`li`,{className:`font-mono text-foreground`,children:e},e))}),(0,H.jsx)(`div`,{className:`mt-6 text-xs font-medium tracking-wide text-muted-foreground`,children:`Property Keys`}),(0,H.jsx)(`ul`,{className:`mt-3 space-y-2 text-sm`,children:Ta.map(e=>(0,H.jsx)(`li`,{className:`font-mono text-foreground`,children:e},e))})]})]}),(0,H.jsx)(ze,{children:(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>t(!1),children:`Close`})})]})})}function Xa({state:e,dom:t}){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(qa,{state:e,dom:t}),(0,H.jsx)(Ja,{state:e}),(0,H.jsx)(Ya,{})]})}var Za={path:`shareDefaultTtlHours`,min:1,max:1/0,integer:!0},Qa=6e5,$a={path:`subagentRuntime.runTimeoutMs`,min:3e4,max:864e5,integer:!0},eo={path:`claudeDriver.lifecycle.idleTimeoutMs`,min:ut,max:st,integer:!1},to={path:`claudeDriver.lifecycle.maxConcurrent`,min:1,max:16,integer:!1};function no(e,t,n){let r=Number(e);if(!qt(n,r))return{kind:`invalid`};let i=Math.round(r);return i===t?{kind:`unchanged`}:{kind:`write`,value:i}}function ro({title:e,description:t,min:n,max:r,step:i,value:a,onValueChange:o,onCommit:s,hint:c,unit:l,ariaLabel:u,bordered:d}){let f=(0,H.jsx)(R,{type:`number`,min:n,max:r,step:i,value:a,onChange:e=>o(e.target.value),onBlur:s,onKeyDown:e=>ca(e,s),className:E(`hide-number-steppers w-full text-left font-mono`,l?`tabular-nums md:w-24 md:text-right`:`md:w-28 md:text-right`),"aria-label":u});return(0,H.jsx)(U,{title:e,description:t,bordered:d,children:(0,H.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end`,children:[l?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 md:justify-end`,children:[f,(0,H.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:l})]}):f,(0,H.jsx)(`div`,{className:E(`text-left text-xs text-muted-foreground md:text-right`,l&&`tabular-nums`),children:c})]})})}function io({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.shareDefaultTtlHours??24),r=G(e=>e.drafts.shareDefaultTtl),i=G(e=>e.patchDrafts),a=G(e=>e.setAppSettingsError);(0,V.useEffect)(()=>{i({shareDefaultTtl:String(n)})},[n,i]);function o(){let e=no(r,n,Za);e.kind===`write`?t({shareDefaultTtlHours:e.value}):(i({shareDefaultTtl:String(n)}),e.kind===`invalid`&&a(`Default share link expiry must be a whole number of hours >= 1.`))}return(0,H.jsx)(`div`,{className:`border-b border-border`,children:(0,H.jsx)(ro,{title:`Public share links`,description:`Default expiry for read-only chat share links. Owners can revoke any link manually at any time.`,min:Za.min,step:1,value:r,onValueChange:e=>i({shareDefaultTtl:e}),onCommit:o,unit:`hours`,ariaLabel:`Default share link expiry in hours`,hint:`Minimum 1 hour · default 24`,bordered:!1})})}function ao({checked:e,onChange:t}){return(0,H.jsxs)(`label`,{className:`inline-flex items-center gap-2`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)}),`Enabled`]})}function oo(e,t){let n=G(t=>t.drafts[e]),r=G(e=>e.patchDrafts);return(0,V.useEffect)(()=>{r({[e]:String(t)})},[e,t,r]),{draft:n,setDraft:t=>r({[e]:t}),parsed:()=>{let e=Number(n);return Number.isFinite(e)?e:null},reset:()=>r({[e]:String(t)})}}function so({state:e}){let{write:t}=fa(e),n=z(jt),r=y(e=>e.setScrollbackLines),i=oo(`scrollback`,n);function a(){let e=i.parsed();e===null?i.reset():(r(e),t({terminal:{scrollbackLines:e}}))}return(0,H.jsx)(ro,{title:`Terminal Scrollback`,description:`Lines retained for embedded terminal history`,min:500,max:wt,step:100,value:i.draft,onValueChange:i.setDraft,onCommit:a,hint:(0,H.jsxs)(H.Fragment,{children:[500,`-`,wt,` lines`,n===1e3?` (default)`:``]})})}function co({state:e}){let{write:t}=fa(e),n=z(kt),r=y(e=>e.setMinColumnWidth),i=oo(`minColumnWidth`,n);function a(){let e=i.parsed();e===null?i.reset():(r(e),t({terminal:{minColumnWidth:e}}))}return(0,H.jsx)(ro,{title:`Terminal Min Column Width`,description:`Minimum width for each terminal pane`,min:250,max:900,step:10,value:i.draft,onValueChange:i.setDraft,onCommit:a,hint:(0,H.jsxs)(H.Fragment,{children:[250,`-`,900,` px`,n===450?` (default)`:``]})})}function lo({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.panes.tabMinWidth??60),r=oo(`tabMinWidth`,n);function i(){let e=r.parsed();e===null?r.reset():t({panes:{tabMinWidth:Gn(e)}})}return(0,H.jsx)(ro,{title:`Tab Minimum Width`,description:`How narrow a pane tab may get before the strip scrolls instead of shrinking`,min:60,max:200,step:10,value:r.draft,onValueChange:r.setDraft,onCommit:i,hint:(0,H.jsxs)(H.Fragment,{children:[60,`-`,200,` px`,n===60?` (default)`:``]})})}function uo({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.uploads.maxFileSizeMb??Qr.maxFileSizeMb),r=G(e=>e.drafts.uploadMaxFileSize),i=G(e=>e.patchDrafts),a=G(e=>e.setAppSettingsError);(0,V.useEffect)(()=>{i({uploadMaxFileSize:String(n)})},[n,i]);function o(){let e=no(r,n,$r);e.kind===`write`?t({uploads:{maxFileSizeMb:e.value}}):(i({uploadMaxFileSize:String(n)}),e.kind===`invalid`&&a(`Max file size must be between ${$r.min} and ${$r.max} MB.`))}return(0,H.jsx)(ro,{title:`Max upload file size`,description:`Largest single file the chat upload endpoint accepts.`,min:$r.min,max:$r.max,step:1,value:r,onValueChange:e=>i({uploadMaxFileSize:e}),onCommit:o,unit:`MB`,ariaLabel:`Max upload file size in megabytes`,hint:`${$r.min}–${$r.max} MB · default ${Qr.maxFileSizeMb}`})}function fo({state:e}){let t=o(e=>e.autoResumeOnRateLimit),n=o(e=>e.setAutoResumeOnRateLimit);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(so,{state:e}),(0,H.jsx)(co,{state:e}),(0,H.jsx)(lo,{state:e}),(0,H.jsx)(uo,{state:e}),(0,H.jsx)(U,{title:`Auto-resume on rate limit`,description:`When you hit a rate limit, automatically schedule "continue" at the reset time instead of asking. You can still cancel each one from the chat.`,children:(0,H.jsx)(ao,{checked:t,onChange:n})})]})}var po=[{value:`disabled`,label:`Off`},{value:`enabled`,label:`On`}],mo=[{value:`always-ask`,label:`Always ask`},{value:`auto-expose`,label:`Auto-expose`}],ho=`appSettings.setCloudflareTunnel`,go=M(ho,`cloudflaredPath`);function _o({state:e}){let t=z(e=>e.settings),n=G(e=>e.tunnelError),r=G(e=>e.setTunnelError),i=G(e=>e.drafts.cloudflaredPath),a=G(e=>e.patchDrafts),o=j(go),s=t?.cloudflareTunnel??Xr,c=s.enabled?`enabled`:`disabled`,l=t?.cloudflareTunnel.cloudflaredPath;(0,V.useEffect)(()=>{l!==void 0&&a({cloudflaredPath:l})},[l,a]);async function u(t){await B(r,()=>e.handleWriteCloudflareTunnel(t))}return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[n?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:n}):null,(0,H.jsx)(U,{title:`Cloudflare Tunnel`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[`When enabled, Claude can call the `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:`expose_port`}),` tool to expose a local port via Cloudflare Tunnel. The mode below controls whether each call requires your approval or is exposed automatically. Requires`,` `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:`cloudflared`}),` `,`to be installed.`]}),(0,H.jsxs)(`span`,{className:`mt-1 block`,children:[`Stored in `,t?.filePathDisplay??`~/.kanna/data/settings.json`,`.`]})]}),bordered:!1,children:(0,H.jsx)(Ua,{pendingKey:M(ho,`enabled`),value:c,onValueChange:e=>u({enabled:e===`enabled`}),options:po,size:`sm`})}),s.enabled&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Tool mode`,description:`Always ask: each expose_port call shows an accept card. Auto-expose: expose_port calls spawn cloudflared immediately without prompting.`,children:(0,H.jsx)(Ua,{pendingKey:M(ho,`mode`),value:s.mode,onValueChange:e=>u({mode:e}),options:mo,size:`sm`})}),(0,H.jsx)(U,{title:`cloudflared path`,description:`Path to the cloudflared binary. Defaults to the one found on $PATH.`,children:(0,H.jsx)(R,{value:i,onChange:e=>a({cloudflaredPath:e.target.value}),onBlur:()=>A(go,()=>u({cloudflaredPath:i})),readOnly:o,"aria-busy":o||void 0,placeholder:`cloudflared`,className:`w-full font-mono md:w-64`})})]})]})}function vo({state:e,dom:t=nn}){let n=G(e=>e.appSettingsError);return(0,H.jsxs)(H.Fragment,{children:[n?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:n}):null,(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(Ca,{state:e}),(0,H.jsx)(fo,{state:e}),(0,H.jsx)(Xa,{state:e,dom:t})]}),(0,H.jsx)(_o,{state:e}),(0,H.jsx)(io,{state:e})]})}var yo=L()(e=>({draft:``,persistedAtMount:``,error:null,setDraft:t=>e({draft:t}),persistedChanged:t=>e({persistedAtMount:t,draft:t}),setError:t=>e({error:t})})),bo=`settings.globalInstructions`;function xo({state:e}){let t=z(e=>e.settings?.globalPromptAppend??``),n=yo(e=>e.draft),r=yo(e=>e.setDraft),i=yo(e=>e.persistedAtMount),a=yo(e=>e.persistedChanged),o=j(bo),s=yo(e=>e.error),c=yo(e=>e.setError);(0,V.useEffect)(()=>{t!==i&&a(t)},[t,i,a]);let l=n.replace(/\s+$/u,``),u=l.length>yt,d=l!==t,f=o||u||!d,p=(0,V.useCallback)(async()=>{f||await B(c,()=>e.handleWriteAppSettings({globalPromptAppend:l}))},[f,e,l,c]),m;return m=o?`Saving…`:d?`Save`:`Saved`,(0,H.jsx)(`div`,{className:`border-b border-border`,children:(0,H.jsx)(U,{title:`Global Instructions`,description:`Appended to every Claude and Codex turn — including subagent turns — as “Workspace instructions”. Kanna does not read CLAUDE.md or AGENTS.md from disk; paste your global instructions here. For rules that apply to one project only, use “Edit instructions” in that project's sidebar menu. Leave blank to disable.`,bordered:!1,alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex w-full flex-col gap-2 md:w-[420px]`,children:[(0,H.jsx)(`textarea`,{value:n,onChange:e=>r(e.target.value),placeholder:`e.g. Always write tests before implementation. Prefer Tailwind classes over inline styles.`,rows:8,"aria-label":`Global instructions`,className:E(`min-h-[160px] w-full resize-y rounded-md border bg-background px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,u?`border-destructive`:`border-input`),disabled:o}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,H.jsxs)(`span`,{className:u?`text-destructive`:`text-muted-foreground`,children:[l.length,` / `,yt,` characters`,u?` — over limit`:``]}),(0,H.jsx)(O,{type:`button`,size:`sm`,onClick:()=>A(bo,p),disabled:f,pending:o,children:m})]}),s?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:s}):null]})})})}function So(e){return{async onReload(t){await sn(e,{type:`plugins.reload`,pluginId:t})}}}function Co({plugins:e,handlers:t}){return e.length===0?(0,H.jsx)(ti,{icon:ne,message:`No plugins installed yet.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Plugins`}),(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(wo,{plugin:e,onReload:t.onReload},e.id))})]})}function wo({plugin:e,onReload:t}){let n=M(`plugins.reload`,e.id),r=j(n),i=(0,V.useCallback)(()=>{A(n,()=>t(e.id))},[t,e.id,n]);return(0,H.jsxs)(`li`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.id}),(0,H.jsx)(mn,{tone:e.enabled?`active`:`muted`,label:e.enabled?`Enabled`:`Disabled`})]}),(0,H.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.sourceDir})]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,"data-testid":`plugin-reload:${e.id}`,pending:r,onClick:i,children:`Reload`})]})}function To(){let e=z(Vt),t=z(Kt),n=an(),r=(0,V.useMemo)(()=>So(n),[n]);return e?(0,H.jsx)(Co,{plugins:t,handlers:r}):null}var Eo={},Do=L()(e=>({drafts:Eo,error:null,setDrafts:t=>e({drafts:t}),setDraft:(t,n)=>e(e=>e.drafts[t]===n?e:{drafts:{...e.drafts,[t]:n}}),setError:t=>e({error:t})}));function Oo(e){let t={};for(let n of vt)t[n]=un(e[n]??``);return{...lt,...t}}function ko(e){return M(`settings.writeKeybindings`,e)}function Ao({action:e,currentValue:t,bordered:n,onDraftChange:r,onCommit:i,onRestoreDefault:a}){let o=ko(e),s=j(o),c=dn(lt[e]),l=t!==c,u=()=>{A(o,i)};return(0,H.jsx)(U,{title:fn[e],description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Comma-separated shortcuts.`}),l?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:` `}),(0,H.jsxs)(`button`,{type:`button`,disabled:s,"aria-busy":s||void 0,onClick:()=>{A(o,()=>a(e))},className:`inline rounded text-foreground hover:text-foreground/80 disabled:opacity-60`,children:[`Restore: `,c]})]}):null]}),bordered:n,children:(0,H.jsxs)(`div`,{className:`flex min-w-0 max-w-[420px] flex-1 items-center gap-2`,children:[(0,H.jsx)(R,{type:`text`,value:t,"aria-busy":s||void 0,onChange:t=>r(e,t.target.value),onBlur:u,onKeyDown:e=>ca(e,u),className:`font-mono`}),s?(0,H.jsx)(T,{}):null]})})}function jo({state:e}){let t=Do(e=>e.drafts),n=Do(e=>e.setDrafts),r=Do(e=>e.setDraft),i=Do(e=>e.error),a=Do(e=>e.setError),o=(0,V.useMemo)(()=>ln(e.keybindings),[e.keybindings]);(0,V.useEffect)(()=>{n(Object.fromEntries(vt.map(e=>[e,dn(o.bindings[e])])))},[o,n]);async function s(t){await B(a,async()=>{await e.socket.command({type:`settings.writeKeybindings`,bindings:Oo(t)})})}async function c(){await s(t)}async function l(e){let r={...t,[e]:dn(lt[e])};n(r),await s(r)}return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[i?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:i}):null,o.warning?(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground`,children:o.warning}):null,vt.map((e,n)=>(0,H.jsx)(Ao,{action:e,currentValue:t[e]??``,bordered:n!==0,onDraftChange:r,onCommit:c,onRestoreDefault:l},e))]})}function Mo(e){return e===null?{name:``,transport:`stdio`,command:``,argsText:``,envText:``,cwd:``,url:``,headersText:``}:e.transport===`stdio`?{name:e.name,transport:`stdio`,command:e.command,argsText:e.args.join(`
|
|
2
2
|
`),envText:Object.entries(e.env).map(([e,t])=>`${e}=${t}`).join(`
|
|
3
3
|
`),cwd:e.cwd??``,url:``,headersText:``}:{name:e.name,transport:e.transport,command:``,argsText:``,envText:``,cwd:``,url:e.url,headersText:Object.entries(e.headers).map(([e,t])=>`${e}: ${t}`).join(`
|
|
4
4
|
`)}}function No(e,t,n){let r={};for(let i of e.split(`
|
|
5
5
|
`)){let e=i.indexOf(t);if(e<=0)continue;let a=i.slice(e+1);r[i.slice(0,e).trim()]=n?a.trim():a}return r}function Po(e){return e.transport===`stdio`?{name:e.name,transport:`stdio`,command:e.command,args:e.argsText.split(`
|
|
6
|
-
`).map(e=>e.trim()).filter(e=>e.length>0),env:No(e.envText,`=`,!1),cwd:e.cwd||void 0}:{name:e.name,transport:e.transport,url:e.url,headers:No(e.headersText,`:`,!0)}}var Fo={kind:`list`};function Io(e){return{...Mo(e),error:null,oauthEnabled:e!==null&&e.transport!==`stdio`?e.oauth?.enabled??!1:!1,authFlowUrl:null,callbackInput:``,oauthError:null,authenticating:!1,completing:!1}}var Lo=L()(e=>({editing:Fo,editorForm:Io(null),setEditing:t=>e({editing:t}),resetEditorForm:t=>e({editorForm:Io(t)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}}))})),Ro={customMcpServers:e=>({customMcpServers:e}),mcpSources:e=>({mcpSources:e}),customModels:e=>({customModels:e}),customProviders:e=>({customProviders:e}),textSnippets:e=>({textSnippets:e})},zo={customMcpServers:e=>({customMcpServers:{setEnabled:e}}),mcpSources:e=>({mcpSources:{setEnabled:e}})};function Bo(e,t){return(0,V.useMemo)(()=>{let n=Ro[e];return{onCreate:async e=>{await t.handleWriteAppSettings(n({create:e}))},onUpdate:async(e,r)=>{await t.handleWriteAppSettings(n({update:{id:e,patch:r}}))},onDelete:async e=>{await t.handleWriteAppSettings(n({delete:{id:e}}))}}},[e,t])}function Vo(e,t){return(0,V.useCallback)(async(n,r)=>{await t.handleWriteAppSettings(zo[e]({id:n,enabled:r}))},[e,t])}async function Ho(e){e.patch({error:null});try{await e.save(),e.onDone()}catch(t){e.patch({error:Ye(t)})}}function Uo(e){return e.submitting?`Saving…`:e.isEdit?`Save changes`:e.addLabel}function Wo({server:e,handlers:t,onEdit:n,dom:r=nn}){let i=M(`mcpServers.delete`,e.id),a=j(i),o=M(`mcpServers.setEnabled`,e.id),s=j(o),c=M(`settings.testMcpServer`,e.id),l=j(c),u=(0,V.useCallback)(()=>{r.confirmDialog(`Delete MCP server "${e.name}"?`)&&A(i,()=>t.onDelete(e.id))},[i,r,t,e.id,e.name]),d=(0,V.useCallback)(n=>{let r=n.target.checked;A(o,()=>t.onSetEnabled(e.id,r))},[t,e.id,o]),f=(0,V.useCallback)(()=>{A(c,()=>t.onTest(e.id))},[t,e.id,c]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsx)(Go,{transport:e.transport}),(0,H.jsx)(`span`,{className:`ml-2`,children:e.transport===`stdio`?e.command:e.url})]})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,H.jsx)(qo,{result:e.lastTest,pending:l}),e.transport!==`stdio`&&(0,H.jsx)(Jo,{oauth:e.oauth}),(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[s?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:s,"aria-busy":s||void 0,onChange:d,"aria-label":`Enabled`}),(0,H.jsx)(`span`,{children:`On`})]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:f,disabled:l,"aria-busy":l||void 0,title:`Test connection`,children:(0,H.jsx)(Ee,{className:E(`h-4 w-4`,l&&`animate-spin`)})}),(0,H.jsx)(ri,{label:e.name,onEdit:n,onDelete:u,deletePending:a})]})]})}function Go({transport:e}){return(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:e})}function Ko({label:e,detail:t}){return(0,H.jsx)(rn,{label:t||`No error details were recorded.`,contentClassName:`max-w-sm whitespace-pre-wrap break-words`,children:(0,H.jsxs)(`span`,{tabIndex:0,className:`inline-flex cursor-help items-center gap-1 text-xs text-destructive-text`,children:[(0,H.jsx)(yr,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e]})})}function qo({result:e,pending:t}){if(t||e.status===`pending`)return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Testing…`});switch(e.status){case`ok`:return(0,H.jsxs)(`span`,{className:`text-xs text-green-600`,children:[`OK · `,e.toolCount,` tools`]});case`error`:return(0,H.jsx)(Ko,{label:`Failed`,detail:e.message});default:return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Untested`})}}function Jo({oauth:e}){if(!e?.enabled)return null;switch(e.status){case`authenticated`:return(0,H.jsx)(`span`,{className:`text-xs text-green-600`,children:`OAuth ✓`});case`error`:return(0,H.jsx)(Ko,{label:`OAuth error`,detail:e.errorMessage});default:return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`OAuth: unauth`})}}var Yo=new Set([`stdio`,`http`,`sse`,`ws`]);function Xo(e){return Yo.has(e)}var Zo=`new`;function Qo({pending:e,copied:t}){return e?(0,H.jsx)(T,{className:`size-3`}):t?(0,H.jsx)(me,{className:`h-3 w-3 text-success-text`}):(0,H.jsx)(de,{className:`h-3 w-3`})}function $o(e){return e.editing.kind===`list`?e.servers.length===0?(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center px-6 py-16 text-center`,children:[(0,H.jsx)(zr,{className:`mb-4 h-10 w-10 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`h2`,{className:`text-lg font-medium`,children:`No custom MCP servers`}),(0,H.jsx)(`p`,{className:`mt-2 max-w-md text-sm text-muted-foreground`,children:`Install MCP servers to extend the model's tool surface. Supports stdio, http, sse, and ws transports.`}),(0,H.jsxs)(O,{className:`mt-6`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add server`]})]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Custom MCP servers`}),(0,H.jsxs)(O,{size:`sm`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add server`]})]}),(0,H.jsx)(ni,{children:e.servers.map(t=>(0,H.jsx)(Wo,{server:t,handlers:e.handlers,onEdit:()=>e.onSelect(t.id),dom:e.dom},t.id))})]}):(0,H.jsx)(es,{initial:e.editing.kind===`edit`?e.servers.find(t=>e.editing.kind===`edit`&&t.id===e.editing.id)??null:null,existingNames:e.servers.map(e=>({id:e.id,name:e.name})),onCancel:e.onCancelEditing,handlers:e.handlers})}function es({initial:e,existingNames:t,onCancel:n,handlers:r,clipboard:i=fe}){let a=Lo(e=>e.editorForm),o=Lo(e=>e.resetEditorForm),s=Lo(e=>e.patchEditorForm),c=(0,V.useCallback)(e=>{Xo(e)&&s({transport:e})},[s]),{name:l,transport:u,command:d,argsText:f,envText:p,cwd:m,url:h,headersText:g,error:_,oauthEnabled:v,authFlowUrl:y,callbackInput:b,oauthError:x,authenticating:S,completing:ee}=a,te=(0,V.useRef)(e);(0,V.useEffect)(()=>{o(te.current)},[o]);let C=e!==null&&e.transport!==`stdio`?e.oauth:void 0,w=e?.id??Zo,ne=M(`mcpServers.save`,w),re=j(ne),E=M(`mcpServers.toggleOAuth`,w),D=j(E),ie=M(`mcpServers.copyAuthUrl`,w),k=j(ie),ae=pe(ie),oe=(0,V.useCallback)(async t=>{s(t?{oauthEnabled:!0}:{oauthEnabled:!1,authFlowUrl:null,callbackInput:``,oauthError:null}),e&&await r.onUpdate(e.id,{oauth:{...C??{status:`unauthenticated`},enabled:t}})},[e,C,r,s]),se=(0,V.useCallback)(async()=>{if(e){s({authenticating:!0,oauthError:null});try{let t=await r.onStartMcpOAuth(e.id);t.ok?s({authFlowUrl:`authorizationUrl`in t?t.authorizationUrl:null}):s({oauthError:t.error})}finally{s({authenticating:!1})}}},[e,r,s]),ce=(0,V.useCallback)(async()=>{if(e){s({completing:!0,oauthError:null});try{let t=await r.onCompleteMcpOAuth(e.id,b);t.ok?s({authFlowUrl:null,callbackInput:``}):s({oauthError:t.error})}finally{s({completing:!1})}}},[e,b,r,s]),le=(0,V.useCallback)(e=>{let t=e.target.checked;A(E,()=>oe(t))},[oe,E]),ue=(0,V.useCallback)(()=>{A(M(`settings.startMcpOAuth`,w),se)},[w,se]),de=(0,V.useCallback)(()=>{A(M(`settings.completeMcpOAuth`,w),ce)},[ce,w]),me=(0,V.useCallback)(()=>{y&&A(ie,()=>he(ie,()=>i.writeText(y)))},[y,i,ie]),F=(0,V.useMemo)(()=>{if(l.length===0)return null;let n=Xt(l);return n===`INVALID_NAME`?`Name must start with a letter and contain only letters, digits, '_' or '-' (max 32 chars).`:n===`RESERVED_NAME`?`'${l}' is reserved.`:t.find(t=>t.name===l&&t.id!==e?.id)?`Name already taken.`:null},[l,t,e?.id]),ye=(0,V.useCallback)(async()=>{F||await Ho({patch:s,save:async()=>{let t=Po({name:l,transport:u,command:d,argsText:f,envText:p,cwd:m,url:h,headersText:g});e?await r.onUpdate(e.id,t):await r.onCreate(t)},onDone:n})},[f,d,m,p,r,g,e,l,F,n,u,h,s]),be=(0,V.useCallback)(()=>{A(ne,ye)},[ne,ye]),xe=Uo({submitting:re,isEdit:e!==null,addLabel:`Add server`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6 max-w-2xl`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:e?`Edit MCP server`:`Add MCP server`}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Name`}),(0,H.jsx)(R,{value:l,onChange:e=>s({name:e.target.value}),placeholder:`fs`}),F&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:F})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Transport`}),(0,H.jsxs)(ve,{value:u,onValueChange:c,children:[(0,H.jsx)(ge,{children:(0,H.jsx)(_e,{})}),(0,H.jsxs)(P,{children:[(0,H.jsx)(N,{value:`stdio`,children:`stdio (spawn local command)`}),(0,H.jsx)(N,{value:`http`,children:`http (Streamable HTTP)`}),(0,H.jsx)(N,{value:`sse`,children:`sse (Server-Sent Events)`}),(0,H.jsx)(N,{value:`ws`,children:`ws (WebSocket)`})]})]})]}),u===`stdio`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Command`}),(0,H.jsx)(R,{value:d,onChange:e=>s({command:e.target.value}),placeholder:`/usr/local/bin/mcp-filesystem`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Args (one per line)`}),(0,H.jsx)(on,{value:f,onChange:e=>s({argsText:e.target.value}),rows:3,className:`font-mono text-sm`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Env (KEY=value, one per line)`}),(0,H.jsx)(on,{value:p,onChange:e=>s({envText:e.target.value}),rows:3,className:`font-mono text-sm`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`cwd (optional)`}),(0,H.jsx)(R,{value:m,onChange:e=>s({cwd:e.target.value}),placeholder:`/optional/working/dir`})]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`URL`}),(0,H.jsx)(R,{value:h,onChange:e=>s({url:e.target.value}),placeholder:u===`ws`?`wss://example.com/mcp`:`https://example.com/mcp`})]}),u===`ws`?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Headers are not supported on the ws transport.`}):(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Headers (Key: value, one per line)`}),(0,H.jsx)(on,{value:g,onChange:e=>s({headersText:e.target.value}),rows:3,className:`font-mono text-sm`,disabled:v}),v&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Authorization header is managed by OAuth when enabled.`})]}),(u===`http`||u===`sse`)&&(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:`OAuth 2.1`}),(0,H.jsxs)(`label`,{className:`ml-auto flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[D?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:v,disabled:D,"aria-busy":D||void 0,onChange:le,"aria-label":`Enable OAuth`}),(0,H.jsx)(`span`,{children:`Enable`})]})]}),v&&!e&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save the server first, then authenticate.`}),v&&e&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Jo,{oauth:C}),C?.status===`authenticated`&&(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:ue,pending:S,children:`Re-authenticate`})]}),(C?.status!==`authenticated`||y)&&(y?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsxs)(`a`,{href:y,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-xs text-blue-600 underline`,children:[`Open authorization URL`,(0,H.jsx)(In,{className:`h-3 w-3`})]}),(0,H.jsx)(rn,{label:ae?`Copied`:`Copy URL`,children:(0,H.jsx)(`button`,{type:`button`,onClick:me,disabled:k,"aria-busy":k||void 0,className:`ml-1 text-muted-foreground hover:text-foreground`,"aria-label":ae?`Copied`:`Copy authorization URL`,children:(0,H.jsx)(Qo,{pending:k,copied:ae})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-1`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`After authorizing, paste the callback URL here:`}),(0,H.jsx)(R,{value:b,onChange:e=>s({callbackInput:e.target.value}),placeholder:`http://localhost:…/callback?code=…`,className:`font-mono text-xs`})]}),(0,H.jsx)(O,{variant:`outline`,size:`sm`,className:`w-fit`,onClick:de,pending:ee,disabled:b.length===0,children:ee?`Completing…`:`Complete`})]}):(0,H.jsx)(O,{variant:`outline`,size:`sm`,className:`w-fit`,onClick:ue,pending:S,children:S?`Starting…`:`Authenticate`})),x&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:x})]})]})]}),_&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:_}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,H.jsx)(O,{variant:`ghost`,onClick:n,disabled:re,children:`Cancel`}),(0,H.jsx)(O,{onClick:be,pending:re,disabled:!!F||l.length===0,children:xe})]})]})}function ts(e){let t=z(St),n=Lo(e=>e.editing),r=Lo(e=>e.setEditing),i=Bo(`customMcpServers`,e.state),a=Vo(`customMcpServers`,e.state),o=(0,V.useMemo)(()=>({...i,onDelete:async e=>{await i.onDelete(e),r({kind:`list`})},onSetEnabled:a,onTest:async t=>{await e.state.handleTestMcpServer(t)},onStartMcpOAuth:async t=>e.state.handleStartMcpOAuth(t),onCompleteMcpOAuth:async(t,n)=>e.state.handleCompleteMcpOAuth(t,n)}),[i,a,e.state,r]);return(0,H.jsx)($o,{servers:t,editing:n,onSelect:e=>r({kind:`edit`,id:e}),onStartCreate:()=>r({kind:`create`}),onCancelEditing:()=>r({kind:`list`}),handlers:o})}var ns=[`subscribe`,`poll`],rs=5e3,is=36e5,as=Qe(ns),os={disabled:`Disabled`,connecting:`Connecting`,listening:`Listening`,polling:`Polling`,backoff:`Retrying`,error:`Error`},ss={disabled:`muted`,connecting:`attention`,listening:`muted`,polling:`muted`,backoff:`attention`,error:`destructive`},cs={subscribe:`Subscribe`,poll:`Poll`},ls={subscribe:`Kanna listens for change notifications on the resources you name, reads each one that changes and catches up after a reconnect. A resync interval re-reads them on a timer. Needs a server that supports resource subscriptions.`,poll:`Kanna calls a tool on an interval and remembers a cursor, so each message is delivered once.`};function us(e){return os[e]}function ds(e){return ss[e]}function fs(e){return cs[e]}function ps(e){return ls[e]}function ms(){return`Between ${rs/1e3} and ${is/1e3}.`}var hs=[`zalo`],gs={zalo:{label:`Zalo`,mode:`subscribe`,resourceUris:[`zalo://inbox`],itemsPath:`messages`,itemKeyPath:`id`,resyncIntervalMs:3e5,threadKeyPath:`threadId`,senderPath:`senderName`,textPath:`text`,handler:{mode:`spawn`,template:`A new Zalo message arrived in a conversation. Read it, decide whether the user needs to act, and draft a reply in the same language the sender used.`,replyHint:`Send the reply with zalo_send_message to the conversation the message came from.`,pushEnabled:!0},reply:{tool:`zalo_send_message`,args:{threadId:`{{message.threadId}}`,threadType:{from:`message.threadType`,map:{dm:0,group:1}},text:`{{reply.text}}`},resultIdPath:`messageId`}}};function _s(e){return{autonomyLevel:e.level,autonomyThreshold:String(e.threshold),autonomyPerThreadPerHour:String(e.perThreadPerHour),autonomyPerSourcePerDay:String(e.perSourcePerDay),autonomyQuietStart:e.quietHours?.start??``,autonomyQuietEnd:e.quietHours?.end??``,autonomyAllowlist:e.allowlist.join(`
|
|
6
|
+
`).map(e=>e.trim()).filter(e=>e.length>0),env:No(e.envText,`=`,!1),cwd:e.cwd||void 0}:{name:e.name,transport:e.transport,url:e.url,headers:No(e.headersText,`:`,!0)}}var Fo={kind:`list`};function Io(e){return{...Mo(e),error:null,oauthEnabled:e!==null&&e.transport!==`stdio`?e.oauth?.enabled??!1:!1,authFlowUrl:null,callbackInput:``,oauthError:null,authenticating:!1,completing:!1}}var Lo=L()(e=>({editing:Fo,editorForm:Io(null),setEditing:t=>e({editing:t}),resetEditorForm:t=>e({editorForm:Io(t)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}}))})),Ro={customMcpServers:e=>({customMcpServers:e}),mcpSources:e=>({mcpSources:e}),customModels:e=>({customModels:e}),customProviders:e=>({customProviders:e}),textSnippets:e=>({textSnippets:e})},zo={customMcpServers:e=>({customMcpServers:{setEnabled:e}}),mcpSources:e=>({mcpSources:{setEnabled:e}})};function Bo(e,t){return(0,V.useMemo)(()=>{let n=Ro[e];return{onCreate:async e=>{await t.handleWriteAppSettings(n({create:e}))},onUpdate:async(e,r)=>{await t.handleWriteAppSettings(n({update:{id:e,patch:r}}))},onDelete:async e=>{await t.handleWriteAppSettings(n({delete:{id:e}}))}}},[e,t])}function Vo(e,t){return(0,V.useCallback)(async(n,r)=>{await t.handleWriteAppSettings(zo[e]({id:n,enabled:r}))},[e,t])}async function Ho(e){e.patch({error:null});try{await e.save(),e.onDone()}catch(t){e.patch({error:Ye(t)})}}function Uo(e){return e.submitting?`Saving…`:e.isEdit?`Save changes`:e.addLabel}function Wo({server:e,handlers:t,onEdit:n,dom:r=nn}){let i=M(`mcpServers.delete`,e.id),a=j(i),o=M(`mcpServers.setEnabled`,e.id),s=j(o),c=M(`settings.testMcpServer`,e.id),l=j(c),u=(0,V.useCallback)(()=>{r.confirmDialog(`Delete MCP server "${e.name}"?`)&&A(i,()=>t.onDelete(e.id))},[i,r,t,e.id,e.name]),d=(0,V.useCallback)(n=>{let r=n.target.checked;A(o,()=>t.onSetEnabled(e.id,r))},[t,e.id,o]),f=(0,V.useCallback)(()=>{A(c,()=>t.onTest(e.id))},[t,e.id,c]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsx)(Go,{transport:e.transport}),(0,H.jsx)(`span`,{className:`ml-2`,children:e.transport===`stdio`?e.command:e.url})]})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,H.jsx)(qo,{result:e.lastTest,pending:l}),e.transport!==`stdio`&&(0,H.jsx)(Jo,{oauth:e.oauth}),(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[s?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:s,"aria-busy":s||void 0,onChange:d,"aria-label":`Enabled`}),(0,H.jsx)(`span`,{children:`On`})]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:f,disabled:l,"aria-busy":l||void 0,title:`Test connection`,children:(0,H.jsx)(Ee,{className:E(`h-4 w-4`,l&&`animate-spin`)})}),(0,H.jsx)(ri,{label:e.name,onEdit:n,onDelete:u,deletePending:a})]})]})}function Go({transport:e}){return(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:e})}function Ko({label:e,detail:t}){return(0,H.jsx)(rn,{label:t||`No error details were recorded.`,contentClassName:`max-w-sm whitespace-pre-wrap break-words`,children:(0,H.jsxs)(`span`,{tabIndex:0,className:`inline-flex cursor-help items-center gap-1 text-xs text-destructive-text`,children:[(0,H.jsx)(yr,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e]})})}function qo({result:e,pending:t}){if(t||e.status===`pending`)return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Testing…`});switch(e.status){case`ok`:return(0,H.jsxs)(`span`,{className:`text-xs text-green-600`,children:[`OK · `,e.toolCount,` tools`]});case`error`:return(0,H.jsx)(Ko,{label:`Failed`,detail:e.message});default:return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Untested`})}}function Jo({oauth:e}){if(!e?.enabled)return null;switch(e.status){case`authenticated`:return(0,H.jsx)(`span`,{className:`text-xs text-green-600`,children:`OAuth ✓`});case`error`:return(0,H.jsx)(Ko,{label:`OAuth error`,detail:e.errorMessage});default:return(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`OAuth: unauth`})}}var Yo=new Set([`stdio`,`http`,`sse`,`ws`]);function Xo(e){return Yo.has(e)}var Zo=`new`;function Qo({pending:e,copied:t}){return e?(0,H.jsx)(T,{className:`size-3`}):t?(0,H.jsx)(me,{className:`h-3 w-3 text-success-text`}):(0,H.jsx)(de,{className:`h-3 w-3`})}function $o(e){return e.editing.kind===`list`?e.servers.length===0?(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center px-6 py-16 text-center`,children:[(0,H.jsx)(zr,{className:`mb-4 h-10 w-10 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`h2`,{className:`text-lg font-medium`,children:`No custom MCP servers`}),(0,H.jsx)(`p`,{className:`mt-2 max-w-md text-sm text-muted-foreground`,children:`Install MCP servers to extend the model's tool surface. Supports stdio, http, sse, and ws transports.`}),(0,H.jsxs)(O,{className:`mt-6`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add server`]})]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Custom MCP servers`}),(0,H.jsxs)(O,{size:`sm`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add server`]})]}),(0,H.jsx)(ni,{children:e.servers.map(t=>(0,H.jsx)(Wo,{server:t,handlers:e.handlers,onEdit:()=>e.onSelect(t.id),dom:e.dom},t.id))})]}):(0,H.jsx)(es,{initial:e.editing.kind===`edit`?e.servers.find(t=>e.editing.kind===`edit`&&t.id===e.editing.id)??null:null,existingNames:e.servers.map(e=>({id:e.id,name:e.name})),onCancel:e.onCancelEditing,handlers:e.handlers})}function es({initial:e,existingNames:t,onCancel:n,handlers:r,clipboard:i=fe}){let a=Lo(e=>e.editorForm),o=Lo(e=>e.resetEditorForm),s=Lo(e=>e.patchEditorForm),c=(0,V.useCallback)(e=>{Xo(e)&&s({transport:e})},[s]),{name:l,transport:u,command:d,argsText:f,envText:p,cwd:m,url:h,headersText:g,error:_,oauthEnabled:v,authFlowUrl:y,callbackInput:b,oauthError:x,authenticating:S,completing:ee}=a,te=(0,V.useRef)(e);(0,V.useEffect)(()=>{o(te.current)},[o]);let C=e!==null&&e.transport!==`stdio`?e.oauth:void 0,w=e?.id??Zo,ne=M(`mcpServers.save`,w),re=j(ne),E=M(`mcpServers.toggleOAuth`,w),D=j(E),ie=M(`mcpServers.copyAuthUrl`,w),k=j(ie),ae=pe(ie),oe=(0,V.useCallback)(async t=>{s(t?{oauthEnabled:!0}:{oauthEnabled:!1,authFlowUrl:null,callbackInput:``,oauthError:null}),e&&await r.onUpdate(e.id,{oauth:{...C??{status:`unauthenticated`},enabled:t}})},[e,C,r,s]),se=(0,V.useCallback)(async()=>{if(e){s({authenticating:!0,oauthError:null});try{let t=await r.onStartMcpOAuth(e.id);t.ok?s({authFlowUrl:`authorizationUrl`in t?t.authorizationUrl:null}):s({oauthError:t.error})}finally{s({authenticating:!1})}}},[e,r,s]),ce=(0,V.useCallback)(async()=>{if(e){s({completing:!0,oauthError:null});try{let t=await r.onCompleteMcpOAuth(e.id,b);t.ok?s({authFlowUrl:null,callbackInput:``}):s({oauthError:t.error})}finally{s({completing:!1})}}},[e,b,r,s]),le=(0,V.useCallback)(e=>{let t=e.target.checked;A(E,()=>oe(t))},[oe,E]),ue=(0,V.useCallback)(()=>{A(M(`settings.startMcpOAuth`,w),se)},[w,se]),de=(0,V.useCallback)(()=>{A(M(`settings.completeMcpOAuth`,w),ce)},[ce,w]),me=(0,V.useCallback)(()=>{y&&A(ie,()=>he(ie,()=>i.writeText(y)))},[y,i,ie]),F=(0,V.useMemo)(()=>{if(l.length===0)return null;let n=Xt(l);return n===`INVALID_NAME`?`Name must start with a letter and contain only letters, digits, '_' or '-' (max 32 chars).`:n===`RESERVED_NAME`?`'${l}' is reserved.`:t.find(t=>t.name===l&&t.id!==e?.id)?`Name already taken.`:null},[l,t,e?.id]),ye=(0,V.useCallback)(async()=>{F||await Ho({patch:s,save:async()=>{let t=Po({name:l,transport:u,command:d,argsText:f,envText:p,cwd:m,url:h,headersText:g});e?await r.onUpdate(e.id,t):await r.onCreate(t)},onDone:n})},[f,d,m,p,r,g,e,l,F,n,u,h,s]),be=(0,V.useCallback)(()=>{A(ne,ye)},[ne,ye]),xe=Uo({submitting:re,isEdit:e!==null,addLabel:`Add server`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6 max-w-2xl`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:e?`Edit MCP server`:`Add MCP server`}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Name`}),(0,H.jsx)(R,{value:l,onChange:e=>s({name:e.target.value}),placeholder:`fs`}),F&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:F})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Transport`}),(0,H.jsxs)(ve,{value:u,onValueChange:c,children:[(0,H.jsx)(ge,{children:(0,H.jsx)(_e,{})}),(0,H.jsxs)(P,{children:[(0,H.jsx)(N,{value:`stdio`,children:`stdio (spawn local command)`}),(0,H.jsx)(N,{value:`http`,children:`http (Streamable HTTP)`}),(0,H.jsx)(N,{value:`sse`,children:`sse (Server-Sent Events)`}),(0,H.jsx)(N,{value:`ws`,children:`ws (WebSocket)`})]})]})]}),u===`stdio`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Command`}),(0,H.jsx)(R,{value:d,onChange:e=>s({command:e.target.value}),placeholder:`/usr/local/bin/mcp-filesystem`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Args (one per line)`}),(0,H.jsx)(on,{value:f,onChange:e=>s({argsText:e.target.value}),rows:3,className:`font-mono text-sm`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Env (KEY=value, one per line)`}),(0,H.jsx)(on,{value:p,onChange:e=>s({envText:e.target.value}),rows:3,className:`font-mono text-sm`})]}),(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`cwd (optional)`}),(0,H.jsx)(R,{value:m,onChange:e=>s({cwd:e.target.value}),placeholder:`/optional/working/dir`})]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`URL`}),(0,H.jsx)(R,{value:h,onChange:e=>s({url:e.target.value}),placeholder:u===`ws`?`wss://example.com/mcp`:`https://example.com/mcp`})]}),u===`ws`?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Headers are not supported on the ws transport.`}):(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`Headers (Key: value, one per line)`}),(0,H.jsx)(on,{value:g,onChange:e=>s({headersText:e.target.value}),rows:3,className:`font-mono text-sm`,disabled:v}),v&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Authorization header is managed by OAuth when enabled.`})]}),(u===`http`||u===`sse`)&&(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:`OAuth 2.1`}),(0,H.jsxs)(`label`,{className:`ml-auto flex cursor-pointer items-center gap-1 text-xs text-muted-foreground`,children:[D?(0,H.jsx)(T,{}):null,(0,H.jsx)(`input`,{type:`checkbox`,checked:v,disabled:D,"aria-busy":D||void 0,onChange:le,"aria-label":`Enable OAuth`}),(0,H.jsx)(`span`,{children:`Enable`})]})]}),v&&!e&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save the server first, then authenticate.`}),v&&e&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Jo,{oauth:C}),C?.status===`authenticated`&&(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:ue,pending:S,children:`Re-authenticate`})]}),(C?.status!==`authenticated`||y)&&(y?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsxs)(`a`,{href:y,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-xs text-blue-600 underline`,children:[`Open authorization URL`,(0,H.jsx)(Fn,{className:`h-3 w-3`})]}),(0,H.jsx)(rn,{label:ae?`Copied`:`Copy URL`,children:(0,H.jsx)(`button`,{type:`button`,onClick:me,disabled:k,"aria-busy":k||void 0,className:`ml-1 text-muted-foreground hover:text-foreground`,"aria-label":ae?`Copied`:`Copy authorization URL`,children:(0,H.jsx)(Qo,{pending:k,copied:ae})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-1`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`After authorizing, paste the callback URL here:`}),(0,H.jsx)(R,{value:b,onChange:e=>s({callbackInput:e.target.value}),placeholder:`http://localhost:…/callback?code=…`,className:`font-mono text-xs`})]}),(0,H.jsx)(O,{variant:`outline`,size:`sm`,className:`w-fit`,onClick:de,pending:ee,disabled:b.length===0,children:ee?`Completing…`:`Complete`})]}):(0,H.jsx)(O,{variant:`outline`,size:`sm`,className:`w-fit`,onClick:ue,pending:S,children:S?`Starting…`:`Authenticate`})),x&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:x})]})]})]}),_&&(0,H.jsx)(`p`,{className:`text-xs text-red-600`,children:_}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,H.jsx)(O,{variant:`ghost`,onClick:n,disabled:re,children:`Cancel`}),(0,H.jsx)(O,{onClick:be,pending:re,disabled:!!F||l.length===0,children:xe})]})]})}function ts(e){let t=z(St),n=Lo(e=>e.editing),r=Lo(e=>e.setEditing),i=Bo(`customMcpServers`,e.state),a=Vo(`customMcpServers`,e.state),o=(0,V.useMemo)(()=>({...i,onDelete:async e=>{await i.onDelete(e),r({kind:`list`})},onSetEnabled:a,onTest:async t=>{await e.state.handleTestMcpServer(t)},onStartMcpOAuth:async t=>e.state.handleStartMcpOAuth(t),onCompleteMcpOAuth:async(t,n)=>e.state.handleCompleteMcpOAuth(t,n)}),[i,a,e.state,r]);return(0,H.jsx)($o,{servers:t,editing:n,onSelect:e=>r({kind:`edit`,id:e}),onStartCreate:()=>r({kind:`create`}),onCancelEditing:()=>r({kind:`list`}),handlers:o})}var ns=[`subscribe`,`poll`],rs=5e3,is=36e5,as=Qe(ns),os={disabled:`Disabled`,connecting:`Connecting`,listening:`Listening`,polling:`Polling`,backoff:`Retrying`,error:`Error`},ss={disabled:`muted`,connecting:`attention`,listening:`muted`,polling:`muted`,backoff:`attention`,error:`destructive`},cs={subscribe:`Subscribe`,poll:`Poll`},ls={subscribe:`Kanna listens for change notifications on the resources you name, reads each one that changes and catches up after a reconnect. A resync interval re-reads them on a timer. Needs a server that supports resource subscriptions.`,poll:`Kanna calls a tool on an interval and remembers a cursor, so each message is delivered once.`};function us(e){return os[e]}function ds(e){return ss[e]}function fs(e){return cs[e]}function ps(e){return ls[e]}function ms(){return`Between ${rs/1e3} and ${is/1e3}.`}var hs=[`zalo`],gs={zalo:{label:`Zalo`,mode:`subscribe`,resourceUris:[`zalo://inbox`],itemsPath:`messages`,itemKeyPath:`id`,resyncIntervalMs:3e5,threadKeyPath:`threadId`,senderPath:`senderName`,textPath:`text`,handler:{mode:`spawn`,template:`A new Zalo message arrived in a conversation. Read it, decide whether the user needs to act, and draft a reply in the same language the sender used.`,replyHint:`Send the reply with zalo_send_message to the conversation the message came from.`,pushEnabled:!0},reply:{tool:`zalo_send_message`,args:{threadId:`{{message.threadId}}`,threadType:{from:`message.threadType`,map:{dm:0,group:1}},text:`{{reply.text}}`},resultIdPath:`messageId`}}};function _s(e){return{autonomyLevel:e.level,autonomyThreshold:String(e.threshold),autonomyPerThreadPerHour:String(e.perThreadPerHour),autonomyPerSourcePerDay:String(e.perSourcePerDay),autonomyQuietStart:e.quietHours?.start??``,autonomyQuietEnd:e.quietHours?.end??``,autonomyAllowlist:e.allowlist.join(`
|
|
7
7
|
`),autonomyAllowUrls:e.allowUrls,autonomyMaxChars:String(e.maxChars),autonomySendDelaySeconds:String(e.sendDelaySeconds),autonomySendFromNotification:e.sendFromNotification}}function vs(){return _s(dr)}function ys(e,t){let n=e.text.trim(),r=Number(n);return n.length>0&&Number.isFinite(r)?r:(t.push(`${e.label} must be a number`),e.fallback)}function bs(e,t){let n=e.autonomyQuietStart.trim(),r=e.autonomyQuietEnd.trim();return n.length===0&&r.length===0?null:n.length===0||r.length===0?(t.push(`Quiet hours need both a start and an end, or leave both empty`),null):{start:n,end:r}}function xs(e){let t=dr,n=[];return{autonomy:{level:e.autonomyLevel,threshold:ys({text:e.autonomyThreshold,label:`Confidence threshold`,fallback:t.threshold},n),perThreadPerHour:ys({text:e.autonomyPerThreadPerHour,label:`Per-thread hourly limit`,fallback:t.perThreadPerHour},n),perSourcePerDay:ys({text:e.autonomyPerSourcePerDay,label:`Per-source daily limit`,fallback:t.perSourcePerDay},n),quietHours:bs(e,n),allowlist:e.autonomyAllowlist.split(`
|
|
8
8
|
`).map(e=>e.trim()).filter(e=>e.length>0),allowUrls:e.autonomyAllowUrls,maxChars:ys({text:e.autonomyMaxChars,label:`Max characters`,fallback:t.maxChars},n),sendDelaySeconds:ys({text:e.autonomySendDelaySeconds,label:`Send delay`,fallback:t.sendDelaySeconds},n),sendFromNotification:e.autonomySendFromNotification},errors:n}}function Ss(e){return e.trim().length>0}function Cs(e){return[...ir(e.handler),...er(e.handler.template,{required:!0}),...$n(e.handler.replyHint)]}function ws(e){if(e.mode===`subscribe`)return e.resourceUris.some(Ss)?[]:[`At least one resource URI is required`];let t=[],n=[[`Tool`,e.tool],[`Cursor argument`,e.cursorArg],[`Cursor path`,e.cursorPath],[`Items path`,e.itemsPath]];for(let[e,r]of n)Ss(r)||t.push(`${e} is required`);return en(e.args)||t.push(`Arguments must be a JSON object`),t}function Ts(e){if(e==null)return[];let t=[];Ss(e.tool)||t.push(`Reply tool is required`);for(let[n,r]of Object.entries(e.args))Ss(n)||t.push(`Reply argument names must not be empty`),typeof r!=`string`&&Object.keys(r.map).length===0&&t.push(`Reply argument "${n}" needs at least one mapping`);return t.push(...sr([e.resultIdPath])),t}function Es(e){let t=[];return t.push(...nr(e.name)),Ss(e.serverId)||t.push(`An MCP server is required`),as(e.mode)?t.push(...ws(e)):t.push(`Mode must be subscribe or poll`),t.push(...sr([e.threadKeyPath,e.senderPath,e.textPath,e.itemsPath,e.itemKeyPath])),t.push(...Cs(e)),t.push(...Ts(e.reply)),t.push(...cr(e.autonomy,e.reply!==null&&e.reply!==void 0)),t}function Ds(e){let t=e.trim();if(t.length===0)return{args:{}};let n=Zt(t);return n!==null&&en(n)?{args:n}:{error:`Arguments must be a JSON object`}}function Os(e){if(typeof e==`string`)return e;if(!en(e))return null;let{from:t,map:n}=e;return typeof t!=`string`||n===void 0||!en(n)?null:e.default===void 0?{from:t,map:n}:{from:t,map:n,default:e.default}}function ks(e){let t=e.trim();if(t.length===0)return{args:{}};let n=Zt(t);if(n===null||!en(n))return{error:`Reply arguments must be a JSON object`};let r={};for(let[e,t]of Object.entries(n)){let n=Os(t);if(n===null)return{error:`Reply argument "${e}" must be a string or an object with "from" and "map"`};r[e]=n}return{args:r}}var As=`A new message arrived. Read it, decide whether the user needs to act, and draft a reply if one is appropriate.`,js=`30`;function Ms(){return{name:``,serverId:``,mode:`subscribe`,resourceUris:``,subscribeItemsPath:``,subscribeItemKeyPath:``,resyncSeconds:``,tool:``,argsText:`{}`,cursorArg:``,cursorPath:``,itemsPath:``,itemKeyPath:``,intervalSeconds:js,threadKeyPath:``,senderPath:``,textPath:``,handlerMode:`spawn`,chatId:``,projectId:``,modelValue:``,template:As,replyHint:``,pushEnabled:!0,pushPreview:!1,...Ns(null),...vs()}}function Ns(e){return{replyTool:e?.tool??``,replyArgsText:JSON.stringify(e?.args??{},null,2),replyResultIdPath:e?.resultIdPath??``}}function Ps(e){return{handlerMode:e.mode,chatId:e.chatId??``,projectId:e.projectId??``,modelValue:e.provider&&e.model?ar(e.provider,e.model):``,template:e.template,replyHint:e.replyHint,pushEnabled:e.pushEnabled,pushPreview:e.pushPreview===!0}}function Fs(e){let t={...Ms(),name:e.name,serverId:e.serverId,mode:e.mode,threadKeyPath:e.threadKeyPath,senderPath:e.senderPath,textPath:e.textPath,...Ps(e.handler),...Ns(e.reply),..._s(e.autonomy)};return e.mode===`subscribe`?{...t,resourceUris:e.resourceUris.join(`
|
|
9
9
|
`),subscribeItemsPath:e.itemsPath,subscribeItemKeyPath:e.itemKeyPath??``,resyncSeconds:Is(e.resyncIntervalMs)}:{...t,tool:e.tool,argsText:JSON.stringify(e.args,null,2),cursorArg:e.cursorArg,cursorPath:e.cursorPath,itemsPath:e.itemsPath,itemKeyPath:e.itemKeyPath??``,intervalSeconds:String(Math.round(e.intervalMs/1e3))}}function Is(e){return e===null?``:String(Math.round(e/1e3))}function Ls(e,t){let n=gs[t],r={...e,name:e.name.trim().length>0?e.name:n.label,mode:n.mode,threadKeyPath:n.threadKeyPath,senderPath:n.senderPath,textPath:n.textPath??``,...Ps({...n.handler,projectId:e.projectId||void 0}),...Ns(n.reply??null)};return n.mode===`subscribe`?{...r,resourceUris:n.resourceUris.join(`
|
|
10
10
|
`),subscribeItemsPath:n.itemsPath??``,subscribeItemKeyPath:n.itemKeyPath??``,resyncSeconds:Is(n.resyncIntervalMs??null)}:{...r,tool:n.tool,argsText:JSON.stringify(n.args,null,2),cursorArg:n.cursorArg,cursorPath:n.cursorPath,itemsPath:n.itemsPath,itemKeyPath:n.itemKeyPath??``,intervalSeconds:String(Math.round(n.intervalMs/1e3))}}function Rs(e){let t=e.handlerMode===`notify`?null:rr(e.modelValue);return{mode:e.handlerMode,template:e.template,replyHint:e.replyHint,pushEnabled:e.pushEnabled,...e.pushPreview?{pushPreview:!0}:{},...Qn(e.handlerMode,e.chatId,e.projectId),...t?{provider:t.provider,model:t.model}:{}}}function zs(e){let t=e.replyTool.trim();if(t.length===0)return{reply:null,errors:[]};let n=ks(e.replyArgsText);return`error`in n?{reply:null,errors:[n.error]}:{reply:{tool:t,args:n.args,resultIdPath:e.replyResultIdPath.trim()},errors:[]}}function Bs(e){let{reply:t,errors:n}=zs(e),{autonomy:r,errors:i}=xs(e),a={name:e.name.trim(),serverId:e.serverId,threadKeyPath:e.threadKeyPath.trim(),senderPath:e.senderPath.trim(),textPath:e.textPath.trim(),handler:Rs(e),reply:t,autonomy:r};if(e.mode===`subscribe`){let t=e.resyncSeconds.trim(),r=Number(t),o=t.length===0||Number.isFinite(r)&&r>0,s={...a,mode:`subscribe`,resourceUris:e.resourceUris.split(`
|
|
11
|
-
`).map(e=>e.trim()).filter(e=>e.length>0),itemsPath:e.subscribeItemsPath.trim(),itemKeyPath:e.subscribeItemKeyPath.trim()||null,resyncIntervalMs:t.length>0&&o?Math.round(r*1e3):null},c=[...o?[]:[`Resync interval must be a number of seconds`],...n,...i,...Es(s)];return c.length>0?{ok:!1,errors:c}:{ok:!0,input:s}}let o=Ds(e.argsText),s=Number(e.intervalSeconds),c={...a,mode:`poll`,tool:e.tool.trim(),args:`args`in o?o.args:{},cursorArg:e.cursorArg.trim(),cursorPath:e.cursorPath.trim(),itemsPath:e.itemsPath.trim(),itemKeyPath:e.itemKeyPath.trim()||null,intervalMs:Number.isFinite(s)?Math.round(s*1e3):rs},l=[...`error`in o?[o.error]:[],...Number.isFinite(s)&&s>0?[]:[`Interval must be a number of seconds`],...n,...i,...Es(c)];return l.length>0?{ok:!1,errors:l}:{ok:!0,input:c}}function Vs(e){let{enabled:t,...n}=e;return n}var Hs=L()(e=>({editing:Fo,draft:Ms(),error:null,confirmingDeleteId:null,startCreate:()=>e({editing:{kind:`create`},draft:Ms(),error:null}),startEdit:t=>e({editing:{kind:`edit`,id:t.id},draft:Fs(t),error:null}),closeEditor:()=>e({editing:Fo,error:null}),patchDraft:t=>e(e=>({draft:{...e.draft,...t}})),applyPreset:t=>e(e=>({draft:Ls(e.draft,t)})),setError:t=>e({error:t}),askDelete:t=>e({confirmingDeleteId:t}),cancelDelete:()=>e({confirmingDeleteId:null})}));function K({id:e,label:t,hint:n,children:r}){return(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`label`,{htmlFor:e,className:`block text-sm font-medium text-foreground`,children:t}),r,n?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}):null]})}var Us=lr.map(e=>({value:e,label:ur[e]})),Ws={off:`The agent only reads and reports. It cannot propose a reply.`,suggest:`The agent proposes a reply and Kanna saves it as a draft you can edit and send.`,approve:`The agent proposes a reply and Kanna shows an approval card. Nothing is sent until you press Send.`,auto:`Kanna sends the reply after the delay unless a guardrail blocks it, and you can Undo until then. Guardrails that fail turn it into an approval card.`};function Gs({draft:e,onChange:t}){return(0,H.jsxs)(`section`,{"aria-label":`Autonomy`,className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Autonomy`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`How far the agent may go when it wants to reply. Approve and Auto need a reply tool above, and Auto also needs a Claude handler model, because only Claude turns can be stopped from sending on their own. Each thread can override this level in the Inbox.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`Level`}),(0,H.jsx)(I,{value:e.autonomyLevel,onValueChange:e=>t({autonomyLevel:e}),options:Us,size:`sm`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Ws[e.autonomyLevel]})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-autonomy-threshold`,label:`Confidence threshold`,hint:`Auto only when the agent's confidence, from 0 to 1, is at least this.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-threshold`,inputMode:`decimal`,className:`tabular-nums`,value:e.autonomyThreshold,onChange:e=>t({autonomyThreshold:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-delay`,label:`Send delay (seconds)`,hint:`How long an auto-send waits so you can Undo it. 10 to 300.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-delay`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomySendDelaySeconds,onChange:e=>t({autonomySendDelaySeconds:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-thread-cap`,label:`Auto-sends per thread per hour`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-thread-cap`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyPerThreadPerHour,onChange:e=>t({autonomyPerThreadPerHour:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-source-cap`,label:`Auto-sends per source per day`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-source-cap`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyPerSourcePerDay,onChange:e=>t({autonomyPerSourcePerDay:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-quiet-start`,label:`Quiet hours start`,hint:`Server local time. Leave both empty for none; Auto becomes an approval card inside quiet hours.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-quiet-start`,type:`time`,className:`tabular-nums`,value:e.autonomyQuietStart,onChange:e=>t({autonomyQuietStart:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-quiet-end`,label:`Quiet hours end`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-quiet-end`,type:`time`,className:`tabular-nums`,value:e.autonomyQuietEnd,onChange:e=>t({autonomyQuietEnd:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-max-chars`,label:`Max characters`,hint:`Longer replies need your approval.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-max-chars`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyMaxChars,onChange:e=>t({autonomyMaxChars:e.target.value})})})]}),(0,H.jsx)(K,{id:`mcp-source-autonomy-allowlist`,label:`Auto allowlist`,hint:`One thread key per line. Auto only sends to these contacts; you can also add one from a thread in the Inbox.`,children:(0,H.jsx)(on,{id:`mcp-source-autonomy-allowlist`,rows:3,className:`font-mono`,value:e.autonomyAllowlist,onChange:e=>t({autonomyAllowlist:e.target.value})})}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e.autonomyAllowUrls,onChange:e=>t({autonomyAllowUrls:e.target.checked}),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),`Allow links in auto-sent replies`]}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e.autonomySendFromNotification,onChange:e=>t({autonomySendFromNotification:e.target.checked}),className:`mt-0.5 h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsxs)(`span`,{children:[`Add a Send button to the notification of an approval card`,(0,H.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Off by default. Pressing it sends the proposed text without opening Kanna, using your signed-in browser session. It needs push notifications for this source.`})]})]})]})}var Ks=[`subscribe`,`poll`].map(e=>({value:e,label:fs(e)}));function qs(e,t){let n=e.filter(e=>e.transport!==`ws`&&(e.enabled||e.id===t)),r=n.filter(e=>e.transport!==`stdio`),i=n.filter(e=>e.transport===`stdio`);return[...r,...i].map(e=>({value:e.id,label:e.name,hint:e.transport}))}function Js({draft:e,onChange:t}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(K,{id:`mcp-source-uris`,label:`Resource URIs`,hint:`One URI per line. Kanna subscribes to each and reads it whenever the server says it changed.`,children:(0,H.jsx)(on,{id:`mcp-source-uris`,rows:3,className:`font-mono`,value:e.resourceUris,onChange:e=>t({resourceUris:e.target.value})})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-sub-items-path`,label:`Items path`,hint:`Optional. Where the array of messages sits in the resource. Leave empty to deliver the whole resource as one message.`,children:(0,H.jsx)(R,{id:`mcp-source-sub-items-path`,className:`font-mono`,value:e.subscribeItemsPath,onChange:e=>t({subscribeItemsPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-sub-item-key`,label:`Item key path`,hint:`Optional. A field that is unique per message. Leave empty to hash the whole item.`,children:(0,H.jsx)(R,{id:`mcp-source-sub-item-key`,className:`font-mono`,value:e.subscribeItemKeyPath,onChange:e=>t({subscribeItemKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-resync`,label:`Resync every (seconds)`,hint:`Optional. Re-reads the resources on a timer to catch missed notifications. ${ms()}`,children:(0,H.jsx)(R,{id:`mcp-source-resync`,inputMode:`numeric`,className:`tabular-nums`,value:e.resyncSeconds,onChange:e=>t({resyncSeconds:e.target.value})})})]})]})}function Ys({draft:e,onChange:t}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(K,{id:`mcp-source-tool`,label:`List tool`,hint:`The tool Kanna calls on every poll.`,children:(0,H.jsx)(R,{id:`mcp-source-tool`,className:`font-mono`,value:e.tool,onChange:e=>t({tool:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-args`,label:`Arguments`,hint:`A JSON object sent with every call. The cursor is added under the cursor argument.`,children:(0,H.jsx)(on,{id:`mcp-source-args`,rows:3,className:`font-mono`,value:e.argsText,onChange:e=>t({argsText:e.target.value})})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-cursor-arg`,label:`Cursor argument`,children:(0,H.jsx)(R,{id:`mcp-source-cursor-arg`,className:`font-mono`,value:e.cursorArg,onChange:e=>t({cursorArg:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-cursor-path`,label:`Cursor path`,hint:`Where the next cursor sits in the result.`,children:(0,H.jsx)(R,{id:`mcp-source-cursor-path`,className:`font-mono`,value:e.cursorPath,onChange:e=>t({cursorPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-items-path`,label:`Items path`,hint:`Where the array of messages sits in the result.`,children:(0,H.jsx)(R,{id:`mcp-source-items-path`,className:`font-mono`,value:e.itemsPath,onChange:e=>t({itemsPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-item-key`,label:`Item key path`,hint:`A field that is unique per message. Leave empty to hash the whole item.`,children:(0,H.jsx)(R,{id:`mcp-source-item-key`,className:`font-mono`,value:e.itemKeyPath,onChange:e=>t({itemKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-interval`,label:`Interval (seconds)`,hint:ms(),children:(0,H.jsx)(R,{id:`mcp-source-interval`,inputMode:`numeric`,className:`tabular-nums`,value:e.intervalSeconds,onChange:e=>t({intervalSeconds:e.target.value})})})]})]})}function Xs({draft:e,onChange:t}){let n=(0,V.useMemo)(()=>{if(e.replyTool.trim().length===0)return null;let t=ks(e.replyArgsText);return`error`in t?t.error:null},[e.replyArgsText,e.replyTool]);return(0,H.jsxs)(`section`,{"aria-label":`Reply tool`,className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Reply tool`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. When set, Send in the Inbox calls this tool on the server itself, with no agent, in every handler mode. Leave the tool name empty to reply through the handler chat instead.`})]}),(0,H.jsx)(K,{id:`mcp-source-reply-tool`,label:`Tool name`,children:(0,H.jsx)(R,{id:`mcp-source-reply-tool`,className:`font-mono`,value:e.replyTool,onChange:e=>t({replyTool:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-reply-args`,label:`Arguments`,hint:(0,H.jsxs)(H.Fragment,{children:[`A JSON object. Use `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{message.<field>}}`}),` for a field of the latest message and `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{reply.text}}`}),` for your reply. A value that is exactly one placeholder keeps its type. Turn a value into another with `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{"from": "message.threadType", "map": {"dm": 0, "group": 1}}`}),`; add `,(0,H.jsx)(`code`,{className:`font-mono`,children:`default`}),` for unmatched values.`]}),children:(0,H.jsx)(on,{id:`mcp-source-reply-args`,rows:6,className:`font-mono`,value:e.replyArgsText,onChange:e=>t({replyArgsText:e.target.value})})}),n?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:n}):null,(0,H.jsx)(K,{id:`mcp-source-reply-result-id`,label:`Result id path`,hint:`Optional. Where the sent message's id sits in the tool result, so Kanna does not ingest its own message when it comes back.`,children:(0,H.jsx)(R,{id:`mcp-source-reply-result-id`,className:`font-mono`,value:e.replyResultIdPath,onChange:e=>t({replyResultIdPath:e.target.value})})})]})}function Zs({presetId:e,onApply:t}){let n=(0,V.useCallback)(()=>t(e),[t,e]);return(0,H.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:n,children:[gs[e].label,` preset`]})}function Qs({editing:e,servers:t,sidebarData:n,handlers:r}){let i=Fe(),a=Hs(e=>e.draft),o=Hs(e=>e.error),s=Hs(e=>e.patchDraft),c=Hs(e=>e.applyPreset),l=Hs(e=>e.closeEditor),u=Hs(e=>e.setError),d=M(`mcpSources.save`,e?.id??`new`),f=j(d),p=(0,V.useMemo)(()=>Zn(n),[n]),m=(0,V.useMemo)(()=>tr(i),[i]),h=(0,V.useMemo)(()=>qs(t,a.serverId),[t,a.serverId]),g=(0,V.useMemo)(()=>Bs(a),[a]),_=a.handlerMode!==`notify`,v=(0,V.useCallback)(e=>s({name:e.target.value}),[s]),y=(0,V.useCallback)(()=>{g.ok&&A(d,()=>B(u,async()=>{e?await r.onUpdate(e.id,Vs(g.input)):await r.onCreate(g.input),l()}))},[l,e,r,g,d,u]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-5 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:e?`Edit MCP source`:`Add MCP source`}),(0,H.jsx)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:hs.map(e=>(0,H.jsx)(Zs,{presetId:e,onApply:c},e))})]}),(0,H.jsx)(K,{id:`mcp-source-name`,label:`Name`,children:(0,H.jsx)(R,{id:`mcp-source-name`,value:a.name,onChange:v,placeholder:`Zalo`,autoFocus:!0})}),(0,H.jsx)(K,{id:`mcp-source-server`,label:`MCP server`,hint:`A stdio server started here is a separate process from the one your chats use — prefer http or sse.`,children:(0,H.jsx)(or,{id:`mcp-source-server`,value:a.serverId,options:h,placeholder:`Choose an MCP server`,searchPlaceholder:`Search servers...`,emptyMessage:`Add an MCP server first`,onValueChange:e=>s({serverId:e})})}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`How messages arrive`}),(0,H.jsx)(I,{value:a.mode,onValueChange:e=>s({mode:e}),options:Ks,size:`sm`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:ps(a.mode)})]}),a.mode===`subscribe`?(0,H.jsx)(Js,{draft:a,onChange:s}):(0,H.jsx)(Ys,{draft:a,onChange:s}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-thread-key`,label:`Thread key path`,hint:`Messages with the same value share one Inbox thread.`,children:(0,H.jsx)(R,{id:`mcp-source-thread-key`,className:`font-mono`,value:a.threadKeyPath,onChange:e=>s({threadKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-sender`,label:`Sender path`,hint:`Shown as the sender of the thread.`,children:(0,H.jsx)(R,{id:`mcp-source-sender`,className:`font-mono`,value:a.senderPath,onChange:e=>s({senderPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-text`,label:`Text path`,hint:`Optional. The field holding the message text, shown as the Inbox preview. Leave empty to show the raw item.`,children:(0,H.jsx)(R,{id:`mcp-source-text`,className:`font-mono`,value:a.textPath,onChange:e=>s({textPath:e.target.value})})})]}),(0,H.jsx)(pr,{idPrefix:`mcp-source`,mode:a.handlerMode,chatId:a.chatId,projectId:a.projectId,modelValue:a.modelValue,targets:p,modelOptions:m,modelHint:`The model the turn started by each message runs with.`,showModeControl:!0,startsTurn:_,onModeChange:e=>s({handlerMode:e}),onChatChange:e=>s({chatId:e}),onProjectChange:e=>s({projectId:e}),onModelChange:e=>s({modelValue:e})}),(0,H.jsx)(K,{id:`mcp-source-template`,label:`Instruction template`,hint:(0,H.jsxs)(H.Fragment,{children:[`Insert fields from the message with `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{senderName}}`}),`. The message is appended as untrusted data.`]}),children:(0,H.jsx)(on,{id:`mcp-source-template`,rows:4,value:a.template,onChange:e=>s({template:e.target.value})})}),(0,H.jsx)(Xs,{draft:a,onChange:s}),(0,H.jsx)(Gs,{draft:a,onChange:s}),(0,H.jsx)(K,{id:`mcp-source-reply-hint`,label:`Reply hint`,hint:`Used only when there is no reply tool: tells the agent how to send a reply through the server's tools when you answer from the Inbox.`,children:(0,H.jsx)(on,{id:`mcp-source-reply-hint`,rows:3,value:a.replyHint,onChange:e=>s({replyHint:e.target.value})})}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:a.pushEnabled,onChange:e=>s({pushEnabled:e.target.checked}),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),`Send a push notification for new messages`]}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:a.pushPreview,disabled:!a.pushEnabled,onChange:e=>s({pushPreview:e.target.checked}),className:`mt-0.5 h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsxs)(`span`,{children:[`Show a preview of the message in the notification`,(0,H.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Off by default. The preview passes through your push service and appears on your lock screen.`})]})]}),!g.ok&&a.name.length>0?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:g.errors[0]}):null,o?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:o}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:y,pending:f,disabled:!g.ok,children:e?`Save changes`:`Add source`}),(0,H.jsx)(O,{variant:`ghost`,onClick:l,disabled:f,children:`Cancel`})]})]})}function $s({source:e,serverName:t,status:n,now:r,confirmingDelete:i,handlers:a}){let o=Hs(e=>e.startEdit),s=Hs(e=>e.askDelete),c=Hs(e=>e.cancelDelete),l=M(`mcpSources.setEnabled`,e.id),u=M(`mcpSources.delete`,e.id),d=j(l),f=j(u),p=n?.state??(e.enabled?`connecting`:`disabled`),m=pn(n?.lastItemAt??void 0,r),h=(0,V.useCallback)(()=>{A(l,()=>a.onSetEnabled(e.id,!e.enabled))},[l,a,e.enabled,e.id]),g=(0,V.useCallback)(()=>o(e),[e,o]),_=(0,V.useCallback)(()=>s(e.id),[s,e.id]),v=(0,V.useCallback)(()=>{A(u,async()=>{await a.onDelete(e.id),c()})},[c,u,a,e.id]);return(0,H.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,"aria-busy":d||f||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),(0,H.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[t,` · `,fs(e.mode)]}),n?.lastError?(0,H.jsx)(`span`,{className:`text-xs text-destructive-text`,children:n.lastError}):null]}),(0,H.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(mn,{tone:ds(p),label:us(p)}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:m?`last ${m}`:`no items yet`}),(0,H.jsxs)(`span`,{className:`tabular-nums`,children:[n?.itemCount??0,` items`]}),(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:h,pending:d,children:e.enabled?`Disable`:`Enable`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:g,"aria-label":`Edit ${e.name}`,children:`Edit`}),i?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(O,{variant:`destructive`,size:`sm`,onClick:v,pending:f,children:[`Delete `,e.name,`?`]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:c,disabled:f,children:`Keep`})]}):(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:_,"aria-label":`Delete ${e.name}`,children:`Delete`})]})]})}function ec({sources:e,statuses:t,servers:n,sidebarData:r,handlers:i}){let a=Hs(e=>e.editing),o=Hs(e=>e.confirmingDeleteId),s=Hs(e=>e.startCreate),c=Ln(3e4);if(a.kind!==`list`){let t=a.kind===`edit`?e.find(e=>e.id===a.id)??null:null;return(0,H.jsx)(Qs,{editing:t,servers:n,sidebarData:r,handlers:i})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`MCP sources`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Let Kanna listen to an MCP server you already added, such as a Zalo or mail server, and put what arrives into the Inbox. Replies go back out through the same server.`})]}),(0,H.jsxs)(O,{size:`sm`,onClick:s,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add source`]})]}),e.length===0?(0,H.jsx)(ti,{icon:hr,message:`No MCP sources yet. Add one to bring a server's messages into the Inbox.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)($s,{source:e,serverName:n.find(t=>t.id===e.serverId)?.name??`Missing server`,status:t.find(t=>t.id===e.id),now:c,confirmingDelete:o===e.id,handlers:i},e.id))})]})}function tc({state:e}){let t=z(Dt),n=z(St),r=f(e=>e.statuses),i=Bo(`mcpSources`,e),a=Vo(`mcpSources`,e),o=(0,V.useMemo)(()=>({...i,onSetEnabled:a}),[i,a]);return(0,H.jsx)(ec,{sources:t,statuses:r,servers:n,sidebarData:e.sidebarData,handlers:o})}var nc={id:``,label:``,modelProvider:`claude`,supportedEfforts:[],offersOneMillionContext:!1};function rc(e){return{...e,error:null}}var ic=L()(e=>({editing:Fo,editorForm:rc(nc),setEditing:t=>e({editing:t}),resetEditorForm:t=>e({editorForm:rc(t)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}})),toggleSupportedEffort:t=>e(e=>{let n=e.editorForm.supportedEfforts,r=n.includes(t)?n.filter(e=>e!==t):[...n,t];return{editorForm:{...e.editorForm,supportedEfforts:r}}}),toggleOneMillionContext:()=>e(e=>({editorForm:{...e.editorForm,offersOneMillionContext:!e.editorForm.offersOneMillionContext}}))}));function ac({models:e,handlers:t,dom:n=nn}){let r=ic(e=>e.editing),i=ic(e=>e.setEditing),a=ic(e=>e.resetEditorForm);function o(t){if(t.kind===`create`)a({id:``,label:``,modelProvider:t.provider,supportedEfforts:[],offersOneMillionContext:!1});else if(t.kind===`edit`){let n=e.find(e=>e.id===t.id)??null;n&&a({id:n.id,label:n.label,modelProvider:n.provider,supportedEfforts:n.supportedEfforts??[],offersOneMillionContext:Tn(n.provider,n.id,n.contextWindowOptions).some(e=>e.id===`1m`)})}i(t)}if(r.kind!==`list`){let n=r.kind===`edit`?e.find(e=>e.id===r.id)??null:null;return(0,H.jsx)(sc,{initial:n,existing:e.map(e=>({id:e.id,provider:e.provider})),handlers:t,onDone:()=>i({kind:`list`})})}return(0,H.jsx)(`div`,{className:`flex flex-col gap-6 px-6 py-6`,children:wn.map(r=>{let i=e.filter(e=>e.provider===r);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`h2`,{className:`text-base font-medium`,children:[xn(r).label,` models`]}),(0,H.jsxs)(O,{size:`sm`,onClick:()=>o({kind:`create`,provider:r}),children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add model`]})]}),i.length===0?(0,H.jsx)(ti,{icon:Dr,message:`No ${xn(r).label} models configured.`}):(0,H.jsx)(ni,{children:i.map(e=>(0,H.jsx)(oc,{model:e,onEdit:()=>o({kind:`edit`,id:e.id}),onDelete:t.onDelete,dom:n},e.id))})]},r)})})}function oc({model:e,onEdit:t,onDelete:n,dom:r}){let i=M(`models.delete`,e.provider,e.id),a=j(i),o=(0,V.useCallback)(()=>{r.confirmDialog(`Delete model "${e.label}"?`)&&A(i,()=>n(e.id))},[i,r,e.id,e.label,n]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,H.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.id})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(e.supportedEfforts?.length??0)>0&&(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:`effort`}),e.supportedEfforts?.includes(`max`)&&(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:`max`}),(0,H.jsx)(ri,{label:e.label,onEdit:t,onDelete:o,deletePending:a})]})]})}function sc({initial:e,existing:t,handlers:n,onDone:r}){let i=ic(e=>e.editorForm),a=ic(e=>e.patchEditorForm),o=ic(e=>e.toggleSupportedEffort),s=ic(e=>e.toggleOneMillionContext),c=(0,V.useCallback)(e=>{jn(e)&&a({modelProvider:e})},[a]),{id:l,label:u,modelProvider:d,supportedEfforts:f,offersOneMillionContext:p,error:m}=i,h=M(`models.save`,e?.id??`new`),g=j(h),_=p?En:En.filter(e=>e.id===`200k`),v=e!==null,y=(0,V.useMemo)(()=>!v&&t.some(e=>e.id===l.trim()&&e.provider===d),[t,l,v,d]),b=l.trim().length>0&&u.trim().length>0&&!y&&!g,x=()=>Ho({patch:a,save:async()=>{v&&e?await n.onUpdate(e.id,{label:u.trim(),supportedEfforts:f.length>0?f:null,...d===`claude`?{contextWindowOptions:_}:{}}):await n.onCreate({id:l.trim(),label:u.trim(),provider:d,...f.length>0?{supportedEfforts:f}:{},...d===`claude`?{contextWindowOptions:_}:{}})},onDone:r}),S=Uo({submitting:g,isEdit:v,addLabel:`Add model`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:v?`Edit model`:`Add model`}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Provider`}),(0,H.jsxs)(ve,{value:d,onValueChange:c,disabled:v,children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:wn.map(e=>(0,H.jsx)(N,{value:e,children:xn(e).label},e))})]})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Model ID`}),(0,H.jsx)(R,{value:l,onChange:e=>a({id:e.target.value}),placeholder:`claude-opus-4-9`,disabled:v,className:`font-mono`}),y&&(0,H.jsx)(`span`,{className:`text-xs text-red-600`,children:`A model with this id already exists.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Label`}),(0,H.jsx)(R,{value:u,onChange:e=>a({label:e.target.value}),placeholder:`Opus 4.9`})]}),d===`claude`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Supported effort levels`}),Sn.map(e=>(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-2 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:f.includes(e.id),onChange:()=>o(e.id)}),(0,H.jsx)(`span`,{children:e.label})]},e.id))]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Context window`}),(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-2 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:p,onChange:s}),(0,H.jsx)(`span`,{children:`Offer the 1M context window`})]}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Off means every turn on this model runs on the 200k window.`})]})]}),m&&(0,H.jsx)(`span`,{className:`text-xs text-red-600`,children:m}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:()=>{A(h,x)},pending:g,disabled:!b,children:S}),(0,H.jsx)(O,{variant:`ghost`,onClick:r,disabled:g,children:`Cancel`})]})]})}function cc(e){let t=z(Bt),n=Bo(`customModels`,e.state);return(0,H.jsx)(ac,{models:t,handlers:n})}function lc(e){if(!e)return`—`;let t=e.trim();if(!t)return`—`;let n=t.slice(-4);return`${t.startsWith(`sk-ant-`)?`sk-ant-`:``}…${n}`}var q=L()(e=>({addLabel:``,addToken:``,addBaseUrl:``,addSubmitting:!1,tokenRowStates:{},baseUrlDrafts:{},setAddLabel:t=>e({addLabel:t}),setAddToken:t=>e({addToken:t}),setAddBaseUrl:t=>e({addBaseUrl:t}),setAddSubmitting:t=>e({addSubmitting:t}),resetAddForm:()=>e({addLabel:``,addToken:``,addBaseUrl:``}),setTokenRowTesting:(t,n)=>e(e=>({tokenRowStates:{...e.tokenRowStates,[t]:{...e.tokenRowStates[t]??{testResult:null,testing:!1},testing:n}}})),setTokenRowTestResult:(t,n)=>e(e=>({tokenRowStates:{...e.tokenRowStates,[t]:{...e.tokenRowStates[t]??{testResult:null,testing:!1},testResult:n}}})),clearTokenRowState:t=>e(e=>({tokenRowStates:ae(e.tokenRowStates,t)})),setBaseUrlDraft:(t,n)=>e(e=>({baseUrlDrafts:{...e.baseUrlDrafts,[t]:n}})),clearBaseUrlDraft:t=>e(e=>({baseUrlDrafts:ae(e.baseUrlDrafts,t)}))}));function uc(e){if(e<=0)return`reset now`;let t=Math.ceil(e/1e3),n=Math.floor(t/60),r=t%60;return n<60?`reset in ${n}m ${r.toString().padStart(2,`0`)}s`:`reset in ${Math.floor(n/60)}h ${(n%60).toString().padStart(2,`00`)}m`}function dc({entry:e,now:t}){if(e.status===`active`)return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground/50`,"aria-hidden":`true`}),`Active`]});if(e.status===`limited`){let n=e.limitedUntil===null?null:uc(e.limitedUntil-t);return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-amber-500`,"aria-hidden":`true`}),`Limited`,n!==null&&(0,H.jsxs)(H.Fragment,{children:[` `,`(`,(0,H.jsx)(`span`,{className:`tabular-nums`,children:n}),`)`]})]})}if(e.status===`disabled`)return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground/60`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground/30`,"aria-hidden":`true`}),`Disabled`]});let n=e.lastErrorMessage??`Unknown error`;return(0,H.jsx)(Ke,{children:(0,H.jsxs)(Ue,{children:[(0,H.jsx)(We,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex cursor-default items-center gap-1.5 text-xs text-destructive`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-destructive`,"aria-hidden":`true`}),`Error`,(0,H.jsx)(`span`,{className:`sr-only`,children:n})]})}),(0,H.jsx)(Ge,{"aria-hidden":`true`,children:n})]})})}var fc=3e3;function pc(){return(0,H.jsx)(`div`,{className:`mt-1 text-xs text-destructive`,children:Pe})}function mc({entry:e,now:t,isCurrent:n,concurrencyDefault:r,onRemove:i,onToggleDisabled:a,onTest:o,onChangeMaxConcurrent:s,onChangeBaseUrl:c,ports:l}){let u=l?.timer??Ve,d=q(e=>e.tokenRowStates),f=q(e=>e.setTokenRowTesting),p=q(e=>e.setTokenRowTestResult),m=q(e=>e.baseUrlDrafts),h=q(e=>e.setBaseUrlDraft),g=d[e.id],_=g?.testResult??null,v=g?.testing??!1,y=m[e.id]??e.baseUrl??``,b=Ae(y,512).kind===`invalid`,x=M(`oauthPool.remove`,e.id),S=M(`oauthPool.toggle`,e.id),ee=M(`oauthPool.concurrency`,e.id),te=M(`oauthPool.baseUrl`,e.id),C=M(`oauthPool.test`,e.id),w=j(x),ne=j(S),re=j(ee),E=j(te),D=()=>A(te,()=>c(e.id,y)),ie=e=>{e.key===`Enter`&&e.currentTarget.blur()},O=async()=>{f(e.id,!0),p(e.id,null);try{let t=await o(e.token,e.baseUrl),n=t.ok?`OK`:t.error??`Error`;p(e.id,n)}catch{p(e.id,`Error`)}finally{f(e.id,!1),u.setTimeout(()=>p(e.id,null),fc)}},k=e.status===`disabled`,ae=k?Ur:Vr,oe=e.maxConcurrent??r;return(0,H.jsxs)(`div`,{className:`border-t border-border py-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium ${k?`text-muted-foreground/60`:`text-foreground`}`,children:e.label}),(0,H.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:lc(e.token)}),n&&(0,H.jsx)(`span`,{className:`inline-flex shrink-0 items-center whitespace-nowrap rounded-full border border-primary/40 bg-primary/10 px-1.5 py-0.5 text-xs font-medium tracking-wide text-primary`,children:`In use`})]}),(0,H.jsx)(`div`,{className:`mt-0.5`,children:(0,H.jsx)(dc,{entry:e,now:t})})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,H.jsx)(rn,{label:`Maximum concurrent chats sharing this OAuth token. Higher = risks Anthropic rate limits.`,children:(0,H.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:`Concurrent`}),re?(0,H.jsx)(T,{className:`size-3`}):null,(0,H.jsx)(R,{type:`number`,value:oe,readOnly:re,"aria-busy":re||void 0,onChange:t=>A(ee,()=>s(e.id,bt(Number(t.target.value)))),min:1,"aria-label":`Max concurrent chats`,className:`h-7 w-14 text-xs`,disabled:k})]})}),_!==null&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_}),(0,H.jsxs)(`button`,{type:`button`,"aria-label":`Test`,onClick:()=>A(C,O),disabled:v||k,"aria-busy":v||void 0,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,children:[v?(0,H.jsx)(T,{className:`size-3`}):(0,H.jsx)(kr,{className:`size-3`,"aria-hidden":`true`}),`Test`]}),(0,H.jsx)(Ke,{children:(0,H.jsxs)(Ue,{children:[(0,H.jsx)(We,{asChild:!0,children:(0,H.jsxs)(`button`,{type:`button`,"aria-label":k?`Enable`:`Disable`,onClick:()=>A(S,a),disabled:ne,"aria-busy":ne||void 0,className:`rounded p-1 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,children:[ne?(0,H.jsx)(T,{}):(0,H.jsx)(ae,{"aria-hidden":`true`,className:`size-3.5`}),(0,H.jsx)(`span`,{className:`sr-only`,children:k?`Enable`:`Disable`})]})}),(0,H.jsx)(Ge,{children:k?`Enable`:`Disable`})]})}),(0,H.jsxs)(`button`,{type:`button`,"aria-label":`Remove`,onClick:()=>A(x,i),disabled:w,"aria-busy":w||void 0,className:`rounded p-1 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,children:[w?(0,H.jsx)(T,{}):(0,H.jsx)(Oe,{className:`size-3.5`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`sr-only`,children:`Remove`})]})]})]}),(0,H.jsx)(rn,{label:`Anthropic API endpoint this token authenticates against. Leave empty for the default api.anthropic.com; set it to route this credential through a proxy.`,children:(0,H.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`shrink-0`,children:`Base URL`}),E?(0,H.jsx)(T,{className:`size-3`}):null,(0,H.jsx)(R,{value:y,readOnly:E,"aria-busy":E||void 0,onChange:t=>h(e.id,t.target.value),onBlur:D,onKeyDown:ie,placeholder:`(default)`,maxLength:512,"aria-label":`Anthropic base URL for ${e.label}`,className:`h-7 flex-1 text-xs font-mono`,disabled:k})]})}),b&&(0,H.jsx)(pc,{})]})}function hc({tokens:e,onWrite:t}){let n=q(e=>e.addLabel),r=q(e=>e.addToken),i=q(e=>e.addBaseUrl),a=q(e=>e.addSubmitting),o=q(e=>e.setAddLabel),s=q(e=>e.setAddToken),c=q(e=>e.setAddBaseUrl),l=q(e=>e.setAddSubmitting),u=q(e=>e.resetAddForm),d=Ae(i,512),f=d.kind===`invalid`,p=n.trim().length>0&&r.trim().length>0&&!f&&!a,m=async()=>{if(p){l(!0);try{let i={id:crypto.randomUUID(),label:n.trim(),token:r.trim(),status:`active`,limitedUntil:null,lastUsedAt:null,lastErrorAt:null,lastErrorMessage:null,addedAt:Date.now(),...d.kind===`url`?{baseUrl:d.url}:{}};await t({tokens:[...e,i]}),u()}finally{l(!1)}}};return(0,H.jsxs)(`div`,{className:`border-t border-border pt-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-end sm:gap-3`,children:[(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(R,{value:n,onChange:e=>o(e.target.value),placeholder:`e.g. personal`,maxLength:64,className:`text-sm`,"aria-label":`Token label`})}),(0,H.jsx)(`div`,{className:`flex-[2]`,children:(0,H.jsx)(R,{value:r,onChange:e=>s(e.target.value),type:`password`,placeholder:`sk-ant-...`,maxLength:1024,className:`text-sm font-mono`,"aria-label":`OAuth token`})}),(0,H.jsxs)(`button`,{type:`button`,onClick:()=>A(`oauthPool.add`,m),disabled:!p,"aria-busy":a||void 0,className:`inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,children:[a?(0,H.jsx)(T,{}):null,`Add token`]})]}),(0,H.jsxs)(`div`,{className:`mt-2`,children:[(0,H.jsx)(R,{value:i,onChange:e=>c(e.target.value),placeholder:`Base URL — leave empty for api.anthropic.com`,maxLength:512,className:`text-sm font-mono`,"aria-label":`Anthropic base URL`}),f&&(0,H.jsx)(pc,{})]})]})}function gc({tokens:e,concurrencyDefault:t,onWrite:n,onTest:r,now:i,ports:a}){let o=i??Date.now(),s=q(e=>e.clearBaseUrlDraft),c=e.reduce((e,t)=>t.lastUsedAt!==null&&(e===null||t.lastUsedAt>(e.lastUsedAt??0))?t:e,null)?.id??null,l=t=>n({tokens:e.filter(e=>e.id!==t)}),u=t=>n({tokens:e.map(e=>e.id===t?{...e,status:e.status===`disabled`?`active`:`disabled`}:e)}),d=(t,r)=>n({tokens:e.map(e=>e.id===t?{...e,maxConcurrent:r}:e)}),f=async(t,r)=>{let i=e.find(e=>e.id===t);if(!i)return;let a=Ae(r,512);if(a.kind===`invalid`)return;let o=a.kind===`url`?a.url:null;s(t),o!==(i.baseUrl??null)&&await n({tokens:e.map(e=>{if(e.id!==t)return e;let{baseUrl:n,...r}=e;return o===null?r:{...e,baseUrl:o}})})},p=j(`oauthPool.concurrencyDefault`),m=e=>{A(`oauthPool.concurrencyDefault`,()=>n({concurrencyDefault:bt(e)}))};return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-3`,children:[(0,H.jsx)(rn,{label:`Default concurrent-chat cap applied to any OAuth token whose row does not override it. Sharing across N chats burns Anthropic quota and risks 429s.`,children:(0,H.jsxs)(`label`,{className:`flex flex-col gap-0.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:`Default concurrency per token`}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Cap for tokens without an explicit per-row override. Minimum `,1,`, no upper limit.`]})]})}),p?(0,H.jsx)(T,{className:`ml-auto text-muted-foreground`}):null,(0,H.jsx)(R,{type:`number`,value:t,readOnly:p,"aria-busy":p||void 0,onChange:e=>m(Number(e.target.value)),min:1,"aria-label":`Default concurrency per token`,className:`h-8 w-16 text-sm`})]}),e.map(e=>(0,H.jsx)(mc,{entry:e,now:o,isCurrent:e.id===c,concurrencyDefault:t,onRemove:()=>l(e.id),onToggleDisabled:()=>u(e.id),onTest:r,onChangeMaxConcurrent:d,onChangeBaseUrl:f,ports:a},e.id)),(0,H.jsx)(hc,{tokens:e,onWrite:n})]})}var J=L()(e=>({claudeIdleMinutesDraft:``,claudeMaxConcurrentDraft:``,llmProviderDraft:{provider:`openai`,apiKey:``,model:``,baseUrl:``},llmProviderError:null,llmValidationStatus:`idle`,llmValidationError:null,llmValidationDialogOpen:!1,setClaudeIdleMinutesDraft:t=>e({claudeIdleMinutesDraft:t}),setClaudeMaxConcurrentDraft:t=>e({claudeMaxConcurrentDraft:t}),setLlmProviderDraft:t=>e({llmProviderDraft:t}),setLlmProviderError:t=>e({llmProviderError:t}),llmDraftChanged:()=>e({llmValidationStatus:`idle`,llmValidationError:null}),llmValidated:(t,n)=>e({llmValidationStatus:t,llmValidationError:n}),setLlmValidationDialogOpen:t=>e({llmValidationDialogOpen:t})})),_c=32,vc=`-`;function yc(){return{id:``,idTouched:!1,label:``,baseUrl:``,apiKey:``,models:[bc()],contextWindow:``,hint:null}}function bc(){return{id:``,label:``}}function xc(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^[^a-z]+/,``).replace(/-+$/,``).slice(0,_c).replace(/-+$/,``)}function Sc(e,t){if(e.length===0||!t.includes(e))return e;for(let n=2;;n+=1){let r=`-${n}`,i=`${e.slice(0,_c-r.length)}${r}`;if(!t.includes(i))return i}}function Cc(e,t){return{id:Sc(e.id,t),idTouched:!0,label:e.label,baseUrl:e.baseUrl,apiKey:e.defaultApiKey??``,models:e.models.length>0?e.models.map(e=>({...e})):[bc()],contextWindow:e.contextWindow===void 0?``:String(e.contextWindow),hint:e.hint??null}}function wc(e){return{id:e.id,idTouched:!0,label:e.label,baseUrl:e.baseUrl,apiKey:``,models:e.models.map(e=>({...e})),contextWindow:e.contextWindow===void 0?``:String(e.contextWindow),hint:null}}function Tc(e,t){return Sc(xc(e),t)}function Ec(e){return e.map(e=>({id:e.id.trim(),label:e.label.trim()})).filter(e=>e.id.length>0||e.label.length>0)}function Dc(e){let t=e.replace(/[\s,_]/g,``);return t.length===0?void 0:Number(t)}function Oc(e){let t=Dc(e.contextWindow);return{id:e.id.trim(),label:e.label.trim(),baseUrl:e.baseUrl.trim(),apiKey:e.apiKey.trim(),models:Ec(e.models),...t===void 0?{}:{contextWindow:t}}}function kc(e){let t=e.apiKey.trim();return{label:e.label.trim(),baseUrl:e.baseUrl.trim(),models:Ec(e.models),contextWindow:Dc(e.contextWindow)??null,...t.length>0?{apiKey:t}:{}}}function Ac(e,t,n){let r=Oc(e),i=ke({...r,apiKey:t===`edit`&&r.apiKey.length===0?vc:r.apiKey},n);return i===null?null:i.code===`INVALID_ID`?`Id must be lowercase letters, digits or dashes, start with a letter, and be at most ${_c} characters (${je}).`:i.message}function jc(e){return`${e<1e6&&e%1024==0?`${e/1024}k`:xe(e)} context`}function Mc(e){return e===null?`Key set`:`Key ••••${e}`}function Nc(e,t){return e===`create`?`API key`:t===null?`Leave blank to keep the saved key`:`Leave blank to keep ••••${t}`}function Pc(e){return{...e,error:null}}var Y=L()(e=>({editing:Fo,menuOpen:!1,listError:null,editorForm:Pc(yc()),setMenuOpen:t=>e({menuOpen:t}),setListError:t=>e({listError:t}),startEditing:(t,n)=>e({editing:t,menuOpen:!1,listError:null,editorForm:Pc(n)}),discardEditor:()=>e({editing:Fo,menuOpen:!1,editorForm:Pc(yc())}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}})),setLabel:(t,n)=>e(e=>({editorForm:{...e.editorForm,label:t,id:e.editorForm.idTouched?e.editorForm.id:Tc(t,n)}})),setId:t=>e(e=>({editorForm:{...e.editorForm,id:t.toLowerCase(),idTouched:!0}})),setModelField:(t,n,r)=>e(e=>({editorForm:{...e.editorForm,models:e.editorForm.models.map((e,i)=>i===t?{...e,[n]:r}:e)}})),addModelRow:()=>e(e=>({editorForm:{...e.editorForm,models:[...e.editorForm.models,{id:``,label:``}]}})),removeModelRow:t=>e(e=>({editorForm:{...e.editorForm,models:e.editorForm.models.filter((e,n)=>n!==t)}}))})),Fc=[{id:`glm`,label:`GLM (Z.AI)`,baseUrl:`https://api.z.ai/api/anthropic`,models:[{id:`glm-5.3`,label:`GLM-5.3`},{id:`glm-5.3-flash`,label:`GLM-5.3 Flash`}]},{id:`qwen`,label:`Qwen (Alibaba Model Studio)`,baseUrl:`https://coding-intl.dashscope.aliyuncs.com/apps/anthropic`,models:[{id:`qwen3.7-plus`,label:`Qwen3.7 Plus`},{id:`qwen3.7-max`,label:`Qwen3.7 Max`}],hint:`Coding Plan endpoint. Pay-as-you-go uses https://{WorkspaceId}.<region>.maas.aliyuncs.com/apps/anthropic.`},{id:`kimi`,label:`Kimi (Moonshot)`,baseUrl:`https://api.moonshot.ai/anthropic`,models:[{id:`kimi-k3`,label:`Kimi K3`},{id:`kimi-k2.7-code`,label:`Kimi K2.7 Code`}]},{id:`deepseek`,label:`DeepSeek`,baseUrl:`https://api.deepseek.com/anthropic`,models:[{id:`deepseek-v4-pro`,label:`DeepSeek V4 Pro`},{id:`deepseek-flash`,label:`DeepSeek Flash`}]},{id:`minimax`,label:`MiniMax`,baseUrl:`https://api.minimax.io/anthropic`,models:[{id:`MiniMax-M3.1`,label:`MiniMax M3.1`}],hint:`Mainland China: https://api.minimaxi.com/anthropic`},{id:`ollama`,label:`Ollama (local)`,baseUrl:`http://localhost:11434`,models:[],contextWindow:65536,defaultApiKey:`ollama`,hint:"Runs on this machine. Ollama ignores the API key, so any value works. Add the exact model names from `ollama list`, and set Context window to your OLLAMA_CONTEXT_LENGTH."}],Ic=`Anthropic-compatible endpoints such as GLM, Qwen, Kimi, DeepSeek or MiniMax. They run through the Claude agent, so tools, skills and MCP work as usual. Pick them in the chat composer under Custom endpoints.`;function Lc(e){return`${e} ${e===1?`model`:`models`}`}function Rc({providers:e,handlers:t,dom:n=nn}){let r=Y(e=>e.editing),i=Y(e=>e.discardEditor);return(0,V.useEffect)(()=>{i()},[i]),(0,H.jsxs)(`div`,{className:`border-t border-border pb-5`,children:[(0,H.jsx)(U,{title:`Custom endpoints`,description:Ic,bordered:!1,alignStart:!0,children:r.kind===`list`?(0,H.jsx)(zc,{providers:e}):null}),r.kind===`list`?(0,H.jsx)(Bc,{providers:e,onDelete:t.onDelete,dom:n}):(0,H.jsx)(Hc,{providers:e,editingId:r.kind===`edit`?r.id:null,handlers:t})]})}function zc({providers:e}){let t=Y(e=>e.menuOpen),n=Y(e=>e.setMenuOpen),r=Y(e=>e.startEditing),i=(0,V.useMemo)(()=>e.map(e=>e.id),[e]),a=(0,V.useCallback)(e=>{r({kind:`create`},Cc(e,i))},[r,i]),o=(0,V.useCallback)(()=>{r({kind:`create`},yc())},[r]);return(0,H.jsxs)(Bn,{open:t,onOpenChange:n,children:[(0,H.jsx)(zn,{asChild:!0,children:(0,H.jsxs)(O,{size:`sm`,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add endpoint`]})}),(0,H.jsx)(Fn,{align:`end`,className:`w-64 p-1`,children:(0,H.jsxs)(`div`,{className:`space-y-1`,children:[Fc.map(e=>(0,H.jsx)(Jn,{onClick:()=>a(e),selected:!1,icon:(0,H.jsx)(Yn,{className:`h-4 w-4 text-muted-foreground`}),label:e.label},e.id)),(0,H.jsx)(Jn,{onClick:o,selected:!1,icon:(0,H.jsx)(Te,{className:`h-4 w-4 text-muted-foreground`}),label:`Custom…`,description:`Any Anthropic-compatible URL`})]})})]})}function Bc({providers:e,onDelete:t,dom:n}){let r=Y(e=>e.listError);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[r?(0,H.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:r}):null,e.length===0?(0,H.jsx)(ti,{icon:Yn,message:`No custom endpoints yet.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(Vc,{provider:e,onDelete:t,dom:n},e.id))})]})}function Vc({provider:e,onDelete:t,dom:n}){let r=Y(e=>e.startEditing),i=Y(e=>e.setListError),a=M(`settings.customProviders.delete`,e.id),o=j(a),s=(0,V.useCallback)(()=>{r({kind:`edit`,id:e.id},wc(e))},[e,r]),c=(0,V.useCallback)(()=>{n.confirmDialog(`Delete endpoint "${e.label}"?`)&&A(a,async()=>{i(null);try{await t(e.id)}catch(e){i(Ye(e))}})},[a,n,t,e.id,e.label,i]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":o||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,H.jsx)(cn,{tooltip:e.baseUrl,className:`font-mono text-xs text-muted-foreground`,children:e.baseUrl})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-0.5 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`tabular-nums`,children:Lc(e.models.length)}),e.contextWindow===void 0?null:(0,H.jsx)(`span`,{className:`tabular-nums`,children:jc(e.contextWindow)}),(0,H.jsx)(`span`,{children:Mc(e.apiKeyHint)})]}),(0,H.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:(0,H.jsx)(ri,{label:e.label,onEdit:s,onDelete:c,deletePending:o})})]})}function Hc({providers:e,editingId:t,handlers:n}){let r=Y(e=>e.editorForm),i=Y(e=>e.patchEditorForm),a=Y(e=>e.setLabel),o=Y(e=>e.setId),s=Y(e=>e.setModelField),c=Y(e=>e.addModelRow),l=Y(e=>e.removeModelRow),u=Y(e=>e.discardEditor),d=t!==null,f=d?`edit`:`create`,p=(0,V.useMemo)(()=>e.find(e=>e.id===t)??null,[e,t]),m=(0,V.useMemo)(()=>e.filter(e=>e.id!==t).map(e=>e.id),[e,t]),h=M(`settings.customProviders`,t??`new`),g=j(h),_=(0,V.useCallback)(e=>{a(e,m)},[m,a]),v=(0,V.useCallback)(()=>{let e=Ac(r,f,m);e===null?A(h,()=>Ho({patch:i,save:async()=>{t===null?await n.onCreate(Oc(r)):await n.onUpdate(t,kc(r))},onDone:u})):i({error:e})},[u,t,r,n,f,m,i,h]),y=g;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-md border border-border px-4 py-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium`,children:d?`Edit ${p?.label??t}`:`Add endpoint`}),r.hint?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.hint}):null,(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Label`}),(0,H.jsx)(R,{value:r.label,onChange:e=>_(e.target.value),maxLength:64,placeholder:`GLM (Z.AI)`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Id`}),(0,H.jsx)(R,{value:r.id,onChange:e=>o(e.target.value),disabled:d,placeholder:`glm`,className:`font-mono`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Part of every model id, so it cannot change after the endpoint is created.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Base URL`}),(0,H.jsx)(R,{value:r.baseUrl,onChange:e=>i({baseUrl:e.target.value}),placeholder:`https://api.example.com/anthropic`,className:`font-mono`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`API key`}),(0,H.jsx)(R,{type:`password`,autoComplete:`off`,value:r.apiKey,onChange:e=>i({apiKey:e.target.value}),maxLength:Ne,placeholder:Nc(f,p?.apiKeyHint??null),className:`font-mono`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Context window (tokens)`}),(0,H.jsx)(R,{inputMode:`numeric`,value:r.contextWindow,onChange:e=>i({contextWindow:e.target.value}),placeholder:`200000`,className:`font-mono tabular-nums`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`The model's real context window. The agent compacts the conversation before reaching it. Leave empty to assume 200,000. For Ollama use your OLLAMA_CONTEXT_LENGTH.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Models`}),r.models.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{value:e.id,onChange:e=>s(t,`id`,e.target.value),maxLength:128,placeholder:`Model id`,"aria-label":`Model ${t+1} id`,className:`font-mono`}),(0,H.jsx)(R,{value:e.label,onChange:e=>s(t,`label`,e.target.value),maxLength:64,placeholder:`Label (optional)`,"aria-label":`Model ${t+1} label`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:()=>l(t),"aria-label":`Remove model ${t+1}`,children:(0,H.jsx)(Ie,{className:`h-4 w-4`})})]},t)),(0,H.jsx)(`div`,{children:(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add model`]})})]}),r.error?(0,H.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:r.error}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:v,pending:y,children:Uo({submitting:y,isEdit:d,addLabel:`Add endpoint`})}),(0,H.jsx)(O,{variant:`ghost`,onClick:u,disabled:y,children:`Cancel`})]})]})}function Uc(e){let t=z(Gt),n=Bo(`customProviders`,e.state);return(0,H.jsx)(Rc,{providers:t,handlers:n})}function Wc(e){return e===`openai`?et:e===`openrouter`?vn:``}function Gc(e,t){return{...e,provider:t,model:Wc(t),baseUrl:t===`custom`?e.baseUrl:``}}var Kc=`settings.writeLlmProvider`,qc=[{value:`openai`,label:`OpenAI`},{value:`openrouter`,label:`OpenRouter`},{value:`custom`,label:`Custom`}];function Jc({saving:e,busy:t}){let n=J(e=>e.llmValidationStatus),r=J(e=>e.llmValidationError),i=J(e=>e.setLlmValidationDialogOpen),a,o;return t?(a=`inline-flex items-center gap-1.5 text-muted-foreground`,o=(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(T,{}),e?`Saving…`:`Loading…`]})):n===`valid`?(a=`text-success-text`,o=`Credentials valid & saved`):n===`invalid`?(a=`text-destructive`,o=(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Credentials invalid.`}),r?(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>i(!0),className:`underline underline-offset-2`,children:`See error`})]}):null]})):(a=`hidden`,o=null),(0,H.jsx)(`span`,{className:E(`mt-2 block text-sm font-medium`,a),children:o})}function Yc(){let e=J(e=>e.llmValidationDialogOpen),t=J(e=>e.setLlmValidationDialogOpen),n=J(e=>e.llmValidationError),r=n?JSON.stringify(n,null,2):``;return(0,H.jsx)(Re,{open:e,onOpenChange:t,children:(0,H.jsxs)(Le,{size:`lg`,children:[(0,H.jsxs)(Be,{className:`space-y-4`,children:[(0,H.jsx)(He,{children:`Validation Error`}),(0,H.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted p-3 text-xs font-mono whitespace-pre-wrap break-words`,children:r})]}),(0,H.jsx)(ze,{children:(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>t(!1),children:`Close`})})]})})}function Xc({state:e}){let{llmProvider:t,handleReadLlmProvider:n,handleWriteLlmProvider:r,handleValidateLlmProvider:i}=e,a=J(e=>e.llmProviderDraft),o=J(e=>e.setLlmProviderDraft),s=J(e=>e.llmProviderError),c=J(e=>e.setLlmProviderError),l=J(e=>e.llmDraftChanged),u=J(e=>e.llmValidated),d=j(Kc),f=j(S),p=d||f;(0,V.useEffect)(()=>{A(S,n)},[n]),(0,V.useEffect)(()=>{t&&o({provider:t.provider,apiKey:t.apiKey,model:t.model,baseUrl:t.baseUrl})},[t,o]),(0,V.useEffect)(()=>{l()},[a.provider,a.apiKey,a.model,a.baseUrl,l]);let m=(0,V.useCallback)(async e=>{try{c(null),await r(e);let t=await i(e);u(t.ok?`valid`:`invalid`,t.error)}catch(e){let t=e instanceof Error?{name:e.name,message:e.message}:be(e);u(`invalid`,t),c(Ye(e))}},[r,i,c,u]);function h(e=a){A(Kc,()=>m(e))}function g(e){let t=Gc(a,e);o(t),h(t)}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Quick Response SDK`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[`Use an OpenAI-compatible API for title and commit message generation before Claude and Codex. Stored in `,t?.filePathDisplay??`the active llm-provider.json file`,`.`]}),(0,H.jsx)(Jc,{saving:d,busy:p})]}),alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex w-full max-w-[420px] flex-col gap-3`,children:[s?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:s}):null,t?.warning?(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground`,children:t.warning}):null,(0,H.jsxs)(ve,{value:a.provider,disabled:p,onValueChange:e=>{Wt(e)&&g(e)},children:[(0,H.jsx)(ge,{className:`w-full`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:qc.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]}),a.provider===`custom`?(0,H.jsx)(R,{value:a.baseUrl,onChange:e=>o({...a,baseUrl:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`https://your-provider.example/v1`}):null,(0,H.jsx)(R,{type:`password`,value:a.apiKey,onChange:e=>o({...a,apiKey:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`API key`}),(0,H.jsx)(R,{value:a.model,onChange:e=>o({...a,model:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`Model id`})]})}),(0,H.jsx)(Yc,{})]})}var Zc=Math.round(eo.min/6e4),Qc=Math.round(eo.max/6e4),$c={min:Zc,max:Qc},el=Math.round(Ht.idleTimeoutMs/6e4);function tl({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.claudeDriver.lifecycle),r=G(e=>e.setAppSettingsError),i=Math.round((n?.idleTimeoutMs??Ht.idleTimeoutMs)/6e4),a=n?.maxConcurrent??Ht.maxConcurrent,o=J(e=>e.claudeIdleMinutesDraft),s=J(e=>e.setClaudeIdleMinutesDraft),c=J(e=>e.claudeMaxConcurrentDraft),l=J(e=>e.setClaudeMaxConcurrentDraft);(0,V.useEffect)(()=>{s(String(i))},[i,s]),(0,V.useEffect)(()=>{l(String(a))},[a,l]);function u(){let e=no(o,i,$c);e.kind===`write`?t({claudeDriver:{lifecycle:{idleTimeoutMs:e.value*6e4}}}):(s(String(i)),e.kind===`invalid`&&r(`Idle timeout must be between ${Zc} and ${Qc} minutes.`))}function d(){let e=no(c,a,to);e.kind===`write`?t({claudeDriver:{lifecycle:{maxConcurrent:e.value}}}):(l(String(a)),e.kind===`invalid`&&r(`Max concurrent sessions must be between ${to.min} and ${to.max}.`))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(ro,{title:`Claude session idle timeout`,description:`Stop a Claude session after this many minutes without user activity. Lower values free memory sooner; higher values keep cold-start latency low.`,min:Zc,max:Qc,step:1,value:o,onValueChange:s,onCommit:u,hint:`${Zc}–${Qc} min · default ${el}`}),(0,H.jsx)(ro,{title:`Max concurrent Claude sessions`,description:`Hard cap on resident Claude processes. Excess sessions are evicted LRU; their next activation cold-starts.`,min:to.min,max:to.max,step:1,value:c,onValueChange:l,onCommit:d,hint:`${to.min}–${to.max} · default ${Ht.maxConcurrent}`})]})}function nl({state:e}){let{write:t}=fa(e),n=Fe(),r=a(e=>e.defaultProvider),i=a(e=>e.providerDefaults),o=a(e=>e.setDefaultProvider),s=a(e=>e.setProviderDefaultModel),c=a(e=>e.setProviderDefaultModelOptions),l=a(e=>e.setProviderDefaultPlanMode);function u(e){o(e),t({defaultProvider:e})}function d(e,n){s(e,n),t({providerDefaults:{[e]:{model:n}}})}function f(e,n){c(e,n),t({providerDefaults:{[e]:{modelOptions:n}}})}function p(e,n){l(e,n),t({providerDefaults:{[e]:{planMode:n}}})}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Default Provider`,description:`The default harness used for new chats before a provider is locked by an existing session.`,children:(0,H.jsxs)(ve,{value:r,onValueChange:e=>{(e===`last_used`||tt(e))&&u(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsxs)(F,{children:[(0,H.jsx)(N,{value:`last_used`,children:`Last Used`}),n.map(e=>(0,H.jsx)(N,{value:e.id,children:e.label},e.id))]})})]})}),(0,H.jsx)(Uc,{state:e}),(0,H.jsx)(U,{title:`Claude Code Defaults`,description:`Saved defaults when using Claude Code.`,alignStart:!0,children:(0,H.jsx)(`div`,{className:`max-w-[420px]`,children:(0,H.jsx)(Kn,{availableProviders:n,selectedProvider:`claude`,showProviderPicker:!1,model:i.claude.model,modelOptions:i.claude.modelOptions,onModelChange:(e,t)=>{d(`claude`,t)},onModelOptionChange:e=>{e.type===`claudeReasoningEffort`?f(`claude`,{reasoningEffort:e.effort}):e.type===`contextWindow`&&f(`claude`,{contextWindow:e.contextWindow})},planMode:i.claude.planMode,onPlanModeChange:e=>p(`claude`,e),includePlanMode:!0,className:`justify-start flex-wrap`})})}),(0,H.jsx)(U,{title:`Codex Defaults`,description:`Saved defaults when using Codex.`,alignStart:!0,children:(0,H.jsx)(`div`,{className:`max-w-[420px]`,children:(0,H.jsx)(Kn,{availableProviders:n,selectedProvider:`codex`,showProviderPicker:!1,model:i.codex.model,modelOptions:i.codex.modelOptions,onModelChange:(e,t)=>{d(`codex`,t)},onModelOptionChange:e=>{e.type===`codexReasoningEffort`?f(`codex`,{reasoningEffort:e.effort}):e.type===`fastMode`&&f(`codex`,{fastMode:e.fastMode})},planMode:i.codex.planMode,onPlanModeChange:e=>p(`codex`,e),includePlanMode:!0,className:`justify-start flex-wrap`})})})]})}function rl({state:e}){let t=z(e=>e.settings?.claudeAuth);return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(U,{title:`Claude OAuth tokens`,description:`Manage multiple Claude OAuth tokens. Kanna switches automatically when one hits its rate limit.`,bordered:!1,alignStart:!0,children:(0,H.jsx)(`div`,{className:`w-full md:w-[420px]`,children:(0,H.jsx)(gc,{tokens:t?.tokens??[],concurrencyDefault:t?.concurrencyDefault??1,onWrite:e.handleWriteClaudeAuth,onTest:e.handleTestOAuthToken})})}),(0,H.jsx)(tl,{state:e}),(0,H.jsx)(nl,{state:e}),(0,H.jsx)(Xc,{state:e})]})}var il={disabled:`Disabled`,installing:`Installing`,starting:`Starting`,connecting:`Connecting`,connected:`Connected`,reconnecting:`Reconnecting`,restarting:`Restarting`,error:`Error`},al={disabled:`muted`,installing:`attention`,starting:`attention`,connecting:`attention`,connected:`muted`,reconnecting:`attention`,restarting:`attention`,error:`destructive`};function ol(e){return il[e]}function sl(e){return al[e]}var X=L()(e=>({connection:null,stream:null,embedded:null,consumerEditor:null,resetConfirm:!1,error:null,editConnection:(t,n)=>e(e=>({connection:{...e.connection??t,...n}})),discardConnection:()=>e({connection:null}),editStream:(t,n)=>e(e=>({stream:{...e.stream??t,...n}})),discardStream:()=>e({stream:null}),editEmbedded:(t,n)=>e(e=>({embedded:{...e.embedded??t,...n}})),discardEmbedded:()=>e({embedded:null}),openConsumerEditor:(t,n)=>e({consumerEditor:{target:t,draft:n}}),editConsumer:t=>e(e=>e.consumerEditor===null?e:{consumerEditor:{...e.consumerEditor,draft:{...e.consumerEditor.draft,...t}}}),closeConsumerEditor:()=>e({consumerEditor:null}),askResetConfirm:()=>e({resetConfirm:!0}),cancelResetConfirm:()=>e({resetConfirm:!1}),setError:t=>e({error:t})})),cl=`auto`;function ll(e){return{name:e.name,subjectPrefix:e.subjectPrefix,extraSubjects:e.extraSubjects.join(`
|
|
11
|
+
`).map(e=>e.trim()).filter(e=>e.length>0),itemsPath:e.subscribeItemsPath.trim(),itemKeyPath:e.subscribeItemKeyPath.trim()||null,resyncIntervalMs:t.length>0&&o?Math.round(r*1e3):null},c=[...o?[]:[`Resync interval must be a number of seconds`],...n,...i,...Es(s)];return c.length>0?{ok:!1,errors:c}:{ok:!0,input:s}}let o=Ds(e.argsText),s=Number(e.intervalSeconds),c={...a,mode:`poll`,tool:e.tool.trim(),args:`args`in o?o.args:{},cursorArg:e.cursorArg.trim(),cursorPath:e.cursorPath.trim(),itemsPath:e.itemsPath.trim(),itemKeyPath:e.itemKeyPath.trim()||null,intervalMs:Number.isFinite(s)?Math.round(s*1e3):rs},l=[...`error`in o?[o.error]:[],...Number.isFinite(s)&&s>0?[]:[`Interval must be a number of seconds`],...n,...i,...Es(c)];return l.length>0?{ok:!1,errors:l}:{ok:!0,input:c}}function Vs(e){let{enabled:t,...n}=e;return n}var Hs=L()(e=>({editing:Fo,draft:Ms(),error:null,confirmingDeleteId:null,startCreate:()=>e({editing:{kind:`create`},draft:Ms(),error:null}),startEdit:t=>e({editing:{kind:`edit`,id:t.id},draft:Fs(t),error:null}),closeEditor:()=>e({editing:Fo,error:null}),patchDraft:t=>e(e=>({draft:{...e.draft,...t}})),applyPreset:t=>e(e=>({draft:Ls(e.draft,t)})),setError:t=>e({error:t}),askDelete:t=>e({confirmingDeleteId:t}),cancelDelete:()=>e({confirmingDeleteId:null})}));function K({id:e,label:t,hint:n,children:r}){return(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`label`,{htmlFor:e,className:`block text-sm font-medium text-foreground`,children:t}),r,n?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}):null]})}var Us=lr.map(e=>({value:e,label:ur[e]})),Ws={off:`The agent only reads and reports. It cannot propose a reply.`,suggest:`The agent proposes a reply and Kanna saves it as a draft you can edit and send.`,approve:`The agent proposes a reply and Kanna shows an approval card. Nothing is sent until you press Send.`,auto:`Kanna sends the reply after the delay unless a guardrail blocks it, and you can Undo until then. Guardrails that fail turn it into an approval card.`};function Gs({draft:e,onChange:t}){return(0,H.jsxs)(`section`,{"aria-label":`Autonomy`,className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Autonomy`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`How far the agent may go when it wants to reply. Approve and Auto need a reply tool above, and Auto also needs a Claude handler model, because only Claude turns can be stopped from sending on their own. Each thread can override this level in the Inbox.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`Level`}),(0,H.jsx)(I,{value:e.autonomyLevel,onValueChange:e=>t({autonomyLevel:e}),options:Us,size:`sm`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Ws[e.autonomyLevel]})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-autonomy-threshold`,label:`Confidence threshold`,hint:`Auto only when the agent's confidence, from 0 to 1, is at least this.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-threshold`,inputMode:`decimal`,className:`tabular-nums`,value:e.autonomyThreshold,onChange:e=>t({autonomyThreshold:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-delay`,label:`Send delay (seconds)`,hint:`How long an auto-send waits so you can Undo it. 10 to 300.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-delay`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomySendDelaySeconds,onChange:e=>t({autonomySendDelaySeconds:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-thread-cap`,label:`Auto-sends per thread per hour`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-thread-cap`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyPerThreadPerHour,onChange:e=>t({autonomyPerThreadPerHour:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-source-cap`,label:`Auto-sends per source per day`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-source-cap`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyPerSourcePerDay,onChange:e=>t({autonomyPerSourcePerDay:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-quiet-start`,label:`Quiet hours start`,hint:`Server local time. Leave both empty for none; Auto becomes an approval card inside quiet hours.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-quiet-start`,type:`time`,className:`tabular-nums`,value:e.autonomyQuietStart,onChange:e=>t({autonomyQuietStart:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-quiet-end`,label:`Quiet hours end`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-quiet-end`,type:`time`,className:`tabular-nums`,value:e.autonomyQuietEnd,onChange:e=>t({autonomyQuietEnd:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-autonomy-max-chars`,label:`Max characters`,hint:`Longer replies need your approval.`,children:(0,H.jsx)(R,{id:`mcp-source-autonomy-max-chars`,inputMode:`numeric`,className:`tabular-nums`,value:e.autonomyMaxChars,onChange:e=>t({autonomyMaxChars:e.target.value})})})]}),(0,H.jsx)(K,{id:`mcp-source-autonomy-allowlist`,label:`Auto allowlist`,hint:`One thread key per line. Auto only sends to these contacts; you can also add one from a thread in the Inbox.`,children:(0,H.jsx)(on,{id:`mcp-source-autonomy-allowlist`,rows:3,className:`font-mono`,value:e.autonomyAllowlist,onChange:e=>t({autonomyAllowlist:e.target.value})})}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e.autonomyAllowUrls,onChange:e=>t({autonomyAllowUrls:e.target.checked}),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),`Allow links in auto-sent replies`]}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e.autonomySendFromNotification,onChange:e=>t({autonomySendFromNotification:e.target.checked}),className:`mt-0.5 h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsxs)(`span`,{children:[`Add a Send button to the notification of an approval card`,(0,H.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Off by default. Pressing it sends the proposed text without opening Kanna, using your signed-in browser session. It needs push notifications for this source.`})]})]})]})}var Ks=[`subscribe`,`poll`].map(e=>({value:e,label:fs(e)}));function qs(e,t){let n=e.filter(e=>e.transport!==`ws`&&(e.enabled||e.id===t)),r=n.filter(e=>e.transport!==`stdio`),i=n.filter(e=>e.transport===`stdio`);return[...r,...i].map(e=>({value:e.id,label:e.name,hint:e.transport}))}function Js({draft:e,onChange:t}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(K,{id:`mcp-source-uris`,label:`Resource URIs`,hint:`One URI per line. Kanna subscribes to each and reads it whenever the server says it changed.`,children:(0,H.jsx)(on,{id:`mcp-source-uris`,rows:3,className:`font-mono`,value:e.resourceUris,onChange:e=>t({resourceUris:e.target.value})})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-sub-items-path`,label:`Items path`,hint:`Optional. Where the array of messages sits in the resource. Leave empty to deliver the whole resource as one message.`,children:(0,H.jsx)(R,{id:`mcp-source-sub-items-path`,className:`font-mono`,value:e.subscribeItemsPath,onChange:e=>t({subscribeItemsPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-sub-item-key`,label:`Item key path`,hint:`Optional. A field that is unique per message. Leave empty to hash the whole item.`,children:(0,H.jsx)(R,{id:`mcp-source-sub-item-key`,className:`font-mono`,value:e.subscribeItemKeyPath,onChange:e=>t({subscribeItemKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-resync`,label:`Resync every (seconds)`,hint:`Optional. Re-reads the resources on a timer to catch missed notifications. ${ms()}`,children:(0,H.jsx)(R,{id:`mcp-source-resync`,inputMode:`numeric`,className:`tabular-nums`,value:e.resyncSeconds,onChange:e=>t({resyncSeconds:e.target.value})})})]})]})}function Ys({draft:e,onChange:t}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(K,{id:`mcp-source-tool`,label:`List tool`,hint:`The tool Kanna calls on every poll.`,children:(0,H.jsx)(R,{id:`mcp-source-tool`,className:`font-mono`,value:e.tool,onChange:e=>t({tool:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-args`,label:`Arguments`,hint:`A JSON object sent with every call. The cursor is added under the cursor argument.`,children:(0,H.jsx)(on,{id:`mcp-source-args`,rows:3,className:`font-mono`,value:e.argsText,onChange:e=>t({argsText:e.target.value})})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-cursor-arg`,label:`Cursor argument`,children:(0,H.jsx)(R,{id:`mcp-source-cursor-arg`,className:`font-mono`,value:e.cursorArg,onChange:e=>t({cursorArg:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-cursor-path`,label:`Cursor path`,hint:`Where the next cursor sits in the result.`,children:(0,H.jsx)(R,{id:`mcp-source-cursor-path`,className:`font-mono`,value:e.cursorPath,onChange:e=>t({cursorPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-items-path`,label:`Items path`,hint:`Where the array of messages sits in the result.`,children:(0,H.jsx)(R,{id:`mcp-source-items-path`,className:`font-mono`,value:e.itemsPath,onChange:e=>t({itemsPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-item-key`,label:`Item key path`,hint:`A field that is unique per message. Leave empty to hash the whole item.`,children:(0,H.jsx)(R,{id:`mcp-source-item-key`,className:`font-mono`,value:e.itemKeyPath,onChange:e=>t({itemKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-interval`,label:`Interval (seconds)`,hint:ms(),children:(0,H.jsx)(R,{id:`mcp-source-interval`,inputMode:`numeric`,className:`tabular-nums`,value:e.intervalSeconds,onChange:e=>t({intervalSeconds:e.target.value})})})]})]})}function Xs({draft:e,onChange:t}){let n=(0,V.useMemo)(()=>{if(e.replyTool.trim().length===0)return null;let t=ks(e.replyArgsText);return`error`in t?t.error:null},[e.replyArgsText,e.replyTool]);return(0,H.jsxs)(`section`,{"aria-label":`Reply tool`,className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Reply tool`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. When set, Send in the Inbox calls this tool on the server itself, with no agent, in every handler mode. Leave the tool name empty to reply through the handler chat instead.`})]}),(0,H.jsx)(K,{id:`mcp-source-reply-tool`,label:`Tool name`,children:(0,H.jsx)(R,{id:`mcp-source-reply-tool`,className:`font-mono`,value:e.replyTool,onChange:e=>t({replyTool:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-reply-args`,label:`Arguments`,hint:(0,H.jsxs)(H.Fragment,{children:[`A JSON object. Use `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{message.<field>}}`}),` for a field of the latest message and `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{reply.text}}`}),` for your reply. A value that is exactly one placeholder keeps its type. Turn a value into another with `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{"from": "message.threadType", "map": {"dm": 0, "group": 1}}`}),`; add `,(0,H.jsx)(`code`,{className:`font-mono`,children:`default`}),` for unmatched values.`]}),children:(0,H.jsx)(on,{id:`mcp-source-reply-args`,rows:6,className:`font-mono`,value:e.replyArgsText,onChange:e=>t({replyArgsText:e.target.value})})}),n?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:n}):null,(0,H.jsx)(K,{id:`mcp-source-reply-result-id`,label:`Result id path`,hint:`Optional. Where the sent message's id sits in the tool result, so Kanna does not ingest its own message when it comes back.`,children:(0,H.jsx)(R,{id:`mcp-source-reply-result-id`,className:`font-mono`,value:e.replyResultIdPath,onChange:e=>t({replyResultIdPath:e.target.value})})})]})}function Zs({presetId:e,onApply:t}){let n=(0,V.useCallback)(()=>t(e),[t,e]);return(0,H.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:n,children:[gs[e].label,` preset`]})}function Qs({editing:e,servers:t,sidebarData:n,handlers:r}){let i=Fe(),a=Hs(e=>e.draft),o=Hs(e=>e.error),s=Hs(e=>e.patchDraft),c=Hs(e=>e.applyPreset),l=Hs(e=>e.closeEditor),u=Hs(e=>e.setError),d=M(`mcpSources.save`,e?.id??`new`),f=j(d),p=(0,V.useMemo)(()=>Zn(n),[n]),m=(0,V.useMemo)(()=>tr(i),[i]),h=(0,V.useMemo)(()=>qs(t,a.serverId),[t,a.serverId]),g=(0,V.useMemo)(()=>Bs(a),[a]),_=a.handlerMode!==`notify`,v=(0,V.useCallback)(e=>s({name:e.target.value}),[s]),y=(0,V.useCallback)(()=>{g.ok&&A(d,()=>B(u,async()=>{e?await r.onUpdate(e.id,Vs(g.input)):await r.onCreate(g.input),l()}))},[l,e,r,g,d,u]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-5 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:e?`Edit MCP source`:`Add MCP source`}),(0,H.jsx)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:hs.map(e=>(0,H.jsx)(Zs,{presetId:e,onApply:c},e))})]}),(0,H.jsx)(K,{id:`mcp-source-name`,label:`Name`,children:(0,H.jsx)(R,{id:`mcp-source-name`,value:a.name,onChange:v,placeholder:`Zalo`,autoFocus:!0})}),(0,H.jsx)(K,{id:`mcp-source-server`,label:`MCP server`,hint:`A stdio server started here is a separate process from the one your chats use — prefer http or sse.`,children:(0,H.jsx)(or,{id:`mcp-source-server`,value:a.serverId,options:h,placeholder:`Choose an MCP server`,searchPlaceholder:`Search servers...`,emptyMessage:`Add an MCP server first`,onValueChange:e=>s({serverId:e})})}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`How messages arrive`}),(0,H.jsx)(I,{value:a.mode,onValueChange:e=>s({mode:e}),options:Ks,size:`sm`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:ps(a.mode)})]}),a.mode===`subscribe`?(0,H.jsx)(Js,{draft:a,onChange:s}):(0,H.jsx)(Ys,{draft:a,onChange:s}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,H.jsx)(K,{id:`mcp-source-thread-key`,label:`Thread key path`,hint:`Messages with the same value share one Inbox thread.`,children:(0,H.jsx)(R,{id:`mcp-source-thread-key`,className:`font-mono`,value:a.threadKeyPath,onChange:e=>s({threadKeyPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-sender`,label:`Sender path`,hint:`Shown as the sender of the thread.`,children:(0,H.jsx)(R,{id:`mcp-source-sender`,className:`font-mono`,value:a.senderPath,onChange:e=>s({senderPath:e.target.value})})}),(0,H.jsx)(K,{id:`mcp-source-text`,label:`Text path`,hint:`Optional. The field holding the message text, shown as the Inbox preview. Leave empty to show the raw item.`,children:(0,H.jsx)(R,{id:`mcp-source-text`,className:`font-mono`,value:a.textPath,onChange:e=>s({textPath:e.target.value})})})]}),(0,H.jsx)(pr,{idPrefix:`mcp-source`,mode:a.handlerMode,chatId:a.chatId,projectId:a.projectId,modelValue:a.modelValue,targets:p,modelOptions:m,modelHint:`The model the turn started by each message runs with.`,showModeControl:!0,startsTurn:_,onModeChange:e=>s({handlerMode:e}),onChatChange:e=>s({chatId:e}),onProjectChange:e=>s({projectId:e}),onModelChange:e=>s({modelValue:e})}),(0,H.jsx)(K,{id:`mcp-source-template`,label:`Instruction template`,hint:(0,H.jsxs)(H.Fragment,{children:[`Insert fields from the message with `,(0,H.jsx)(`code`,{className:`font-mono`,children:`{{senderName}}`}),`. The message is appended as untrusted data.`]}),children:(0,H.jsx)(on,{id:`mcp-source-template`,rows:4,value:a.template,onChange:e=>s({template:e.target.value})})}),(0,H.jsx)(Xs,{draft:a,onChange:s}),(0,H.jsx)(Gs,{draft:a,onChange:s}),(0,H.jsx)(K,{id:`mcp-source-reply-hint`,label:`Reply hint`,hint:`Used only when there is no reply tool: tells the agent how to send a reply through the server's tools when you answer from the Inbox.`,children:(0,H.jsx)(on,{id:`mcp-source-reply-hint`,rows:3,value:a.replyHint,onChange:e=>s({replyHint:e.target.value})})}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:a.pushEnabled,onChange:e=>s({pushEnabled:e.target.checked}),className:`h-4 w-4 shrink-0 rounded border-border accent-foreground`}),`Send a push notification for new messages`]}),(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:a.pushPreview,disabled:!a.pushEnabled,onChange:e=>s({pushPreview:e.target.checked}),className:`mt-0.5 h-4 w-4 shrink-0 rounded border-border accent-foreground`}),(0,H.jsxs)(`span`,{children:[`Show a preview of the message in the notification`,(0,H.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Off by default. The preview passes through your push service and appears on your lock screen.`})]})]}),!g.ok&&a.name.length>0?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:g.errors[0]}):null,o?(0,H.jsx)(`p`,{className:`text-xs text-destructive-text`,children:o}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:y,pending:f,disabled:!g.ok,children:e?`Save changes`:`Add source`}),(0,H.jsx)(O,{variant:`ghost`,onClick:l,disabled:f,children:`Cancel`})]})]})}function $s({source:e,serverName:t,status:n,now:r,confirmingDelete:i,handlers:a}){let o=Hs(e=>e.startEdit),s=Hs(e=>e.askDelete),c=Hs(e=>e.cancelDelete),l=M(`mcpSources.setEnabled`,e.id),u=M(`mcpSources.delete`,e.id),d=j(l),f=j(u),p=n?.state??(e.enabled?`connecting`:`disabled`),m=pn(n?.lastItemAt??void 0,r),h=(0,V.useCallback)(()=>{A(l,()=>a.onSetEnabled(e.id,!e.enabled))},[l,a,e.enabled,e.id]),g=(0,V.useCallback)(()=>o(e),[e,o]),_=(0,V.useCallback)(()=>s(e.id),[s,e.id]),v=(0,V.useCallback)(()=>{A(u,async()=>{await a.onDelete(e.id),c()})},[c,u,a,e.id]);return(0,H.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3`,"aria-busy":d||f||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),(0,H.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[t,` · `,fs(e.mode)]}),n?.lastError?(0,H.jsx)(`span`,{className:`text-xs text-destructive-text`,children:n.lastError}):null]}),(0,H.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(mn,{tone:ds(p),label:us(p)}),(0,H.jsx)(`span`,{className:`tabular-nums`,children:m?`last ${m}`:`no items yet`}),(0,H.jsxs)(`span`,{className:`tabular-nums`,children:[n?.itemCount??0,` items`]}),(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:h,pending:d,children:e.enabled?`Disable`:`Enable`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:g,"aria-label":`Edit ${e.name}`,children:`Edit`}),i?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(O,{variant:`destructive`,size:`sm`,onClick:v,pending:f,children:[`Delete `,e.name,`?`]}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:c,disabled:f,children:`Keep`})]}):(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:_,"aria-label":`Delete ${e.name}`,children:`Delete`})]})]})}function ec({sources:e,statuses:t,servers:n,sidebarData:r,handlers:i}){let a=Hs(e=>e.editing),o=Hs(e=>e.confirmingDeleteId),s=Hs(e=>e.startCreate),c=In(3e4);if(a.kind!==`list`){let t=a.kind===`edit`?e.find(e=>e.id===a.id)??null:null;return(0,H.jsx)(Qs,{editing:t,servers:n,sidebarData:r,handlers:i})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`MCP sources`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Let Kanna listen to an MCP server you already added, such as a Zalo or mail server, and put what arrives into the Inbox. Replies go back out through the same server.`})]}),(0,H.jsxs)(O,{size:`sm`,onClick:s,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add source`]})]}),e.length===0?(0,H.jsx)(ti,{icon:hr,message:`No MCP sources yet. Add one to bring a server's messages into the Inbox.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)($s,{source:e,serverName:n.find(t=>t.id===e.serverId)?.name??`Missing server`,status:t.find(t=>t.id===e.id),now:c,confirmingDelete:o===e.id,handlers:i},e.id))})]})}function tc({state:e}){let t=z(Dt),n=z(St),r=f(e=>e.statuses),i=Bo(`mcpSources`,e),a=Vo(`mcpSources`,e),o=(0,V.useMemo)(()=>({...i,onSetEnabled:a}),[i,a]);return(0,H.jsx)(ec,{sources:t,statuses:r,servers:n,sidebarData:e.sidebarData,handlers:o})}var nc={id:``,label:``,modelProvider:`claude`,supportedEfforts:[],offersOneMillionContext:!1};function rc(e){return{...e,error:null}}var ic=L()(e=>({editing:Fo,editorForm:rc(nc),setEditing:t=>e({editing:t}),resetEditorForm:t=>e({editorForm:rc(t)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}})),toggleSupportedEffort:t=>e(e=>{let n=e.editorForm.supportedEfforts,r=n.includes(t)?n.filter(e=>e!==t):[...n,t];return{editorForm:{...e.editorForm,supportedEfforts:r}}}),toggleOneMillionContext:()=>e(e=>({editorForm:{...e.editorForm,offersOneMillionContext:!e.editorForm.offersOneMillionContext}}))}));function ac({models:e,handlers:t,dom:n=nn}){let r=ic(e=>e.editing),i=ic(e=>e.setEditing),a=ic(e=>e.resetEditorForm);function o(t){if(t.kind===`create`)a({id:``,label:``,modelProvider:t.provider,supportedEfforts:[],offersOneMillionContext:!1});else if(t.kind===`edit`){let n=e.find(e=>e.id===t.id)??null;n&&a({id:n.id,label:n.label,modelProvider:n.provider,supportedEfforts:n.supportedEfforts??[],offersOneMillionContext:Tn(n.provider,n.id,n.contextWindowOptions).some(e=>e.id===`1m`)})}i(t)}if(r.kind!==`list`){let n=r.kind===`edit`?e.find(e=>e.id===r.id)??null:null;return(0,H.jsx)(sc,{initial:n,existing:e.map(e=>({id:e.id,provider:e.provider})),handlers:t,onDone:()=>i({kind:`list`})})}return(0,H.jsx)(`div`,{className:`flex flex-col gap-6 px-6 py-6`,children:wn.map(r=>{let i=e.filter(e=>e.provider===r);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`h2`,{className:`text-base font-medium`,children:[xn(r).label,` models`]}),(0,H.jsxs)(O,{size:`sm`,onClick:()=>o({kind:`create`,provider:r}),children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add model`]})]}),i.length===0?(0,H.jsx)(ti,{icon:Dr,message:`No ${xn(r).label} models configured.`}):(0,H.jsx)(ni,{children:i.map(e=>(0,H.jsx)(oc,{model:e,onEdit:()=>o({kind:`edit`,id:e.id}),onDelete:t.onDelete,dom:n},e.id))})]},r)})})}function oc({model:e,onEdit:t,onDelete:n,dom:r}){let i=M(`models.delete`,e.provider,e.id),a=j(i),o=(0,V.useCallback)(()=>{r.confirmDialog(`Delete model "${e.label}"?`)&&A(i,()=>n(e.id))},[i,r,e.id,e.label,n]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,H.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.id})]}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(e.supportedEfforts?.length??0)>0&&(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:`effort`}),e.supportedEfforts?.includes(`max`)&&(0,H.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs`,children:`max`}),(0,H.jsx)(ri,{label:e.label,onEdit:t,onDelete:o,deletePending:a})]})]})}function sc({initial:e,existing:t,handlers:n,onDone:r}){let i=ic(e=>e.editorForm),a=ic(e=>e.patchEditorForm),o=ic(e=>e.toggleSupportedEffort),s=ic(e=>e.toggleOneMillionContext),c=(0,V.useCallback)(e=>{jn(e)&&a({modelProvider:e})},[a]),{id:l,label:u,modelProvider:d,supportedEfforts:f,offersOneMillionContext:p,error:m}=i,h=M(`models.save`,e?.id??`new`),g=j(h),_=p?En:En.filter(e=>e.id===`200k`),v=e!==null,y=(0,V.useMemo)(()=>!v&&t.some(e=>e.id===l.trim()&&e.provider===d),[t,l,v,d]),b=l.trim().length>0&&u.trim().length>0&&!y&&!g,x=()=>Ho({patch:a,save:async()=>{v&&e?await n.onUpdate(e.id,{label:u.trim(),supportedEfforts:f.length>0?f:null,...d===`claude`?{contextWindowOptions:_}:{}}):await n.onCreate({id:l.trim(),label:u.trim(),provider:d,...f.length>0?{supportedEfforts:f}:{},...d===`claude`?{contextWindowOptions:_}:{}})},onDone:r}),S=Uo({submitting:g,isEdit:v,addLabel:`Add model`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:v?`Edit model`:`Add model`}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Provider`}),(0,H.jsxs)(ve,{value:d,onValueChange:c,disabled:v,children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:wn.map(e=>(0,H.jsx)(N,{value:e,children:xn(e).label},e))})]})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Model ID`}),(0,H.jsx)(R,{value:l,onChange:e=>a({id:e.target.value}),placeholder:`claude-opus-4-9`,disabled:v,className:`font-mono`}),y&&(0,H.jsx)(`span`,{className:`text-xs text-red-600`,children:`A model with this id already exists.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Label`}),(0,H.jsx)(R,{value:u,onChange:e=>a({label:e.target.value}),placeholder:`Opus 4.9`})]}),d===`claude`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Supported effort levels`}),Sn.map(e=>(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-2 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:f.includes(e.id),onChange:()=>o(e.id)}),(0,H.jsx)(`span`,{children:e.label})]},e.id))]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Context window`}),(0,H.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-2 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:p,onChange:s}),(0,H.jsx)(`span`,{children:`Offer the 1M context window`})]}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Off means every turn on this model runs on the 200k window.`})]})]}),m&&(0,H.jsx)(`span`,{className:`text-xs text-red-600`,children:m}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:()=>{A(h,x)},pending:g,disabled:!b,children:S}),(0,H.jsx)(O,{variant:`ghost`,onClick:r,disabled:g,children:`Cancel`})]})]})}function cc(e){let t=z(Bt),n=Bo(`customModels`,e.state);return(0,H.jsx)(ac,{models:t,handlers:n})}function lc(e){if(!e)return`—`;let t=e.trim();if(!t)return`—`;let n=t.slice(-4);return`${t.startsWith(`sk-ant-`)?`sk-ant-`:``}…${n}`}var q=L()(e=>({addLabel:``,addToken:``,addBaseUrl:``,addSubmitting:!1,tokenRowStates:{},baseUrlDrafts:{},setAddLabel:t=>e({addLabel:t}),setAddToken:t=>e({addToken:t}),setAddBaseUrl:t=>e({addBaseUrl:t}),setAddSubmitting:t=>e({addSubmitting:t}),resetAddForm:()=>e({addLabel:``,addToken:``,addBaseUrl:``}),setTokenRowTesting:(t,n)=>e(e=>({tokenRowStates:{...e.tokenRowStates,[t]:{...e.tokenRowStates[t]??{testResult:null,testing:!1},testing:n}}})),setTokenRowTestResult:(t,n)=>e(e=>({tokenRowStates:{...e.tokenRowStates,[t]:{...e.tokenRowStates[t]??{testResult:null,testing:!1},testResult:n}}})),clearTokenRowState:t=>e(e=>({tokenRowStates:ae(e.tokenRowStates,t)})),setBaseUrlDraft:(t,n)=>e(e=>({baseUrlDrafts:{...e.baseUrlDrafts,[t]:n}})),clearBaseUrlDraft:t=>e(e=>({baseUrlDrafts:ae(e.baseUrlDrafts,t)}))}));function uc(e){if(e<=0)return`reset now`;let t=Math.ceil(e/1e3),n=Math.floor(t/60),r=t%60;return n<60?`reset in ${n}m ${r.toString().padStart(2,`0`)}s`:`reset in ${Math.floor(n/60)}h ${(n%60).toString().padStart(2,`00`)}m`}function dc({entry:e,now:t}){if(e.status===`active`)return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground/50`,"aria-hidden":`true`}),`Active`]});if(e.status===`limited`){let n=e.limitedUntil===null?null:uc(e.limitedUntil-t);return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-amber-500`,"aria-hidden":`true`}),`Limited`,n!==null&&(0,H.jsxs)(H.Fragment,{children:[` `,`(`,(0,H.jsx)(`span`,{className:`tabular-nums`,children:n}),`)`]})]})}if(e.status===`disabled`)return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground/60`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground/30`,"aria-hidden":`true`}),`Disabled`]});let n=e.lastErrorMessage??`Unknown error`;return(0,H.jsx)(Ke,{children:(0,H.jsxs)(Ue,{children:[(0,H.jsx)(We,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex cursor-default items-center gap-1.5 text-xs text-destructive`,children:[(0,H.jsx)(`span`,{className:`size-1.5 rounded-full bg-destructive`,"aria-hidden":`true`}),`Error`,(0,H.jsx)(`span`,{className:`sr-only`,children:n})]})}),(0,H.jsx)(Ge,{"aria-hidden":`true`,children:n})]})})}var fc=3e3;function pc(){return(0,H.jsx)(`div`,{className:`mt-1 text-xs text-destructive`,children:Pe})}function mc({entry:e,now:t,isCurrent:n,concurrencyDefault:r,onRemove:i,onToggleDisabled:a,onTest:o,onChangeMaxConcurrent:s,onChangeBaseUrl:c,ports:l}){let u=l?.timer??Ve,d=q(e=>e.tokenRowStates),f=q(e=>e.setTokenRowTesting),p=q(e=>e.setTokenRowTestResult),m=q(e=>e.baseUrlDrafts),h=q(e=>e.setBaseUrlDraft),g=d[e.id],_=g?.testResult??null,v=g?.testing??!1,y=m[e.id]??e.baseUrl??``,b=Ae(y,512).kind===`invalid`,x=M(`oauthPool.remove`,e.id),S=M(`oauthPool.toggle`,e.id),ee=M(`oauthPool.concurrency`,e.id),te=M(`oauthPool.baseUrl`,e.id),C=M(`oauthPool.test`,e.id),w=j(x),ne=j(S),re=j(ee),E=j(te),D=()=>A(te,()=>c(e.id,y)),ie=e=>{e.key===`Enter`&&e.currentTarget.blur()},O=async()=>{f(e.id,!0),p(e.id,null);try{let t=await o(e.token,e.baseUrl),n=t.ok?`OK`:t.error??`Error`;p(e.id,n)}catch{p(e.id,`Error`)}finally{f(e.id,!1),u.setTimeout(()=>p(e.id,null),fc)}},k=e.status===`disabled`,ae=k?Ur:Vr,oe=e.maxConcurrent??r;return(0,H.jsxs)(`div`,{className:`border-t border-border py-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium ${k?`text-muted-foreground/60`:`text-foreground`}`,children:e.label}),(0,H.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:lc(e.token)}),n&&(0,H.jsx)(`span`,{className:`inline-flex shrink-0 items-center whitespace-nowrap rounded-full border border-primary/40 bg-primary/10 px-1.5 py-0.5 text-xs font-medium tracking-wide text-primary`,children:`In use`})]}),(0,H.jsx)(`div`,{className:`mt-0.5`,children:(0,H.jsx)(dc,{entry:e,now:t})})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,H.jsx)(rn,{label:`Maximum concurrent chats sharing this OAuth token. Higher = risks Anthropic rate limits.`,children:(0,H.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:`Concurrent`}),re?(0,H.jsx)(T,{className:`size-3`}):null,(0,H.jsx)(R,{type:`number`,value:oe,readOnly:re,"aria-busy":re||void 0,onChange:t=>A(ee,()=>s(e.id,bt(Number(t.target.value)))),min:1,"aria-label":`Max concurrent chats`,className:`h-7 w-14 text-xs`,disabled:k})]})}),_!==null&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_}),(0,H.jsxs)(`button`,{type:`button`,"aria-label":`Test`,onClick:()=>A(C,O),disabled:v||k,"aria-busy":v||void 0,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,children:[v?(0,H.jsx)(T,{className:`size-3`}):(0,H.jsx)(kr,{className:`size-3`,"aria-hidden":`true`}),`Test`]}),(0,H.jsx)(Ke,{children:(0,H.jsxs)(Ue,{children:[(0,H.jsx)(We,{asChild:!0,children:(0,H.jsxs)(`button`,{type:`button`,"aria-label":k?`Enable`:`Disable`,onClick:()=>A(S,a),disabled:ne,"aria-busy":ne||void 0,className:`rounded p-1 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,children:[ne?(0,H.jsx)(T,{}):(0,H.jsx)(ae,{"aria-hidden":`true`,className:`size-3.5`}),(0,H.jsx)(`span`,{className:`sr-only`,children:k?`Enable`:`Disable`})]})}),(0,H.jsx)(Ge,{children:k?`Enable`:`Disable`})]})}),(0,H.jsxs)(`button`,{type:`button`,"aria-label":`Remove`,onClick:()=>A(x,i),disabled:w,"aria-busy":w||void 0,className:`rounded p-1 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,children:[w?(0,H.jsx)(T,{}):(0,H.jsx)(Oe,{className:`size-3.5`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`sr-only`,children:`Remove`})]})]})]}),(0,H.jsx)(rn,{label:`Anthropic API endpoint this token authenticates against. Leave empty for the default api.anthropic.com; set it to route this credential through a proxy.`,children:(0,H.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`shrink-0`,children:`Base URL`}),E?(0,H.jsx)(T,{className:`size-3`}):null,(0,H.jsx)(R,{value:y,readOnly:E,"aria-busy":E||void 0,onChange:t=>h(e.id,t.target.value),onBlur:D,onKeyDown:ie,placeholder:`(default)`,maxLength:512,"aria-label":`Anthropic base URL for ${e.label}`,className:`h-7 flex-1 text-xs font-mono`,disabled:k})]})}),b&&(0,H.jsx)(pc,{})]})}function hc({tokens:e,onWrite:t}){let n=q(e=>e.addLabel),r=q(e=>e.addToken),i=q(e=>e.addBaseUrl),a=q(e=>e.addSubmitting),o=q(e=>e.setAddLabel),s=q(e=>e.setAddToken),c=q(e=>e.setAddBaseUrl),l=q(e=>e.setAddSubmitting),u=q(e=>e.resetAddForm),d=Ae(i,512),f=d.kind===`invalid`,p=n.trim().length>0&&r.trim().length>0&&!f&&!a,m=async()=>{if(p){l(!0);try{let i={id:crypto.randomUUID(),label:n.trim(),token:r.trim(),status:`active`,limitedUntil:null,lastUsedAt:null,lastErrorAt:null,lastErrorMessage:null,addedAt:Date.now(),...d.kind===`url`?{baseUrl:d.url}:{}};await t({tokens:[...e,i]}),u()}finally{l(!1)}}};return(0,H.jsxs)(`div`,{className:`border-t border-border pt-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-end sm:gap-3`,children:[(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(R,{value:n,onChange:e=>o(e.target.value),placeholder:`e.g. personal`,maxLength:64,className:`text-sm`,"aria-label":`Token label`})}),(0,H.jsx)(`div`,{className:`flex-[2]`,children:(0,H.jsx)(R,{value:r,onChange:e=>s(e.target.value),type:`password`,placeholder:`sk-ant-...`,maxLength:1024,className:`text-sm font-mono`,"aria-label":`OAuth token`})}),(0,H.jsxs)(`button`,{type:`button`,onClick:()=>A(`oauthPool.add`,m),disabled:!p,"aria-busy":a||void 0,className:`inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,children:[a?(0,H.jsx)(T,{}):null,`Add token`]})]}),(0,H.jsxs)(`div`,{className:`mt-2`,children:[(0,H.jsx)(R,{value:i,onChange:e=>c(e.target.value),placeholder:`Base URL — leave empty for api.anthropic.com`,maxLength:512,className:`text-sm font-mono`,"aria-label":`Anthropic base URL`}),f&&(0,H.jsx)(pc,{})]})]})}function gc({tokens:e,concurrencyDefault:t,onWrite:n,onTest:r,now:i,ports:a}){let o=i??Date.now(),s=q(e=>e.clearBaseUrlDraft),c=e.reduce((e,t)=>t.lastUsedAt!==null&&(e===null||t.lastUsedAt>(e.lastUsedAt??0))?t:e,null)?.id??null,l=t=>n({tokens:e.filter(e=>e.id!==t)}),u=t=>n({tokens:e.map(e=>e.id===t?{...e,status:e.status===`disabled`?`active`:`disabled`}:e)}),d=(t,r)=>n({tokens:e.map(e=>e.id===t?{...e,maxConcurrent:r}:e)}),f=async(t,r)=>{let i=e.find(e=>e.id===t);if(!i)return;let a=Ae(r,512);if(a.kind===`invalid`)return;let o=a.kind===`url`?a.url:null;s(t),o!==(i.baseUrl??null)&&await n({tokens:e.map(e=>{if(e.id!==t)return e;let{baseUrl:n,...r}=e;return o===null?r:{...e,baseUrl:o}})})},p=j(`oauthPool.concurrencyDefault`),m=e=>{A(`oauthPool.concurrencyDefault`,()=>n({concurrencyDefault:bt(e)}))};return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pb-3`,children:[(0,H.jsx)(rn,{label:`Default concurrent-chat cap applied to any OAuth token whose row does not override it. Sharing across N chats burns Anthropic quota and risks 429s.`,children:(0,H.jsxs)(`label`,{className:`flex flex-col gap-0.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:`Default concurrency per token`}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Cap for tokens without an explicit per-row override. Minimum `,1,`, no upper limit.`]})]})}),p?(0,H.jsx)(T,{className:`ml-auto text-muted-foreground`}):null,(0,H.jsx)(R,{type:`number`,value:t,readOnly:p,"aria-busy":p||void 0,onChange:e=>m(Number(e.target.value)),min:1,"aria-label":`Default concurrency per token`,className:`h-8 w-16 text-sm`})]}),e.map(e=>(0,H.jsx)(mc,{entry:e,now:o,isCurrent:e.id===c,concurrencyDefault:t,onRemove:()=>l(e.id),onToggleDisabled:()=>u(e.id),onTest:r,onChangeMaxConcurrent:d,onChangeBaseUrl:f,ports:a},e.id)),(0,H.jsx)(hc,{tokens:e,onWrite:n})]})}var J=L()(e=>({claudeIdleMinutesDraft:``,claudeMaxConcurrentDraft:``,llmProviderDraft:{provider:`openai`,apiKey:``,model:``,baseUrl:``},llmProviderError:null,llmValidationStatus:`idle`,llmValidationError:null,llmValidationDialogOpen:!1,setClaudeIdleMinutesDraft:t=>e({claudeIdleMinutesDraft:t}),setClaudeMaxConcurrentDraft:t=>e({claudeMaxConcurrentDraft:t}),setLlmProviderDraft:t=>e({llmProviderDraft:t}),setLlmProviderError:t=>e({llmProviderError:t}),llmDraftChanged:()=>e({llmValidationStatus:`idle`,llmValidationError:null}),llmValidated:(t,n)=>e({llmValidationStatus:t,llmValidationError:n}),setLlmValidationDialogOpen:t=>e({llmValidationDialogOpen:t})})),_c=32,vc=`-`;function yc(){return{id:``,idTouched:!1,label:``,baseUrl:``,apiKey:``,models:[bc()],contextWindow:``,hint:null}}function bc(){return{id:``,label:``}}function xc(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^[^a-z]+/,``).replace(/-+$/,``).slice(0,_c).replace(/-+$/,``)}function Sc(e,t){if(e.length===0||!t.includes(e))return e;for(let n=2;;n+=1){let r=`-${n}`,i=`${e.slice(0,_c-r.length)}${r}`;if(!t.includes(i))return i}}function Cc(e,t){return{id:Sc(e.id,t),idTouched:!0,label:e.label,baseUrl:e.baseUrl,apiKey:e.defaultApiKey??``,models:e.models.length>0?e.models.map(e=>({...e})):[bc()],contextWindow:e.contextWindow===void 0?``:String(e.contextWindow),hint:e.hint??null}}function wc(e){return{id:e.id,idTouched:!0,label:e.label,baseUrl:e.baseUrl,apiKey:``,models:e.models.map(e=>({...e})),contextWindow:e.contextWindow===void 0?``:String(e.contextWindow),hint:null}}function Tc(e,t){return Sc(xc(e),t)}function Ec(e){return e.map(e=>({id:e.id.trim(),label:e.label.trim()})).filter(e=>e.id.length>0||e.label.length>0)}function Dc(e){let t=e.replace(/[\s,_]/g,``);return t.length===0?void 0:Number(t)}function Oc(e){let t=Dc(e.contextWindow);return{id:e.id.trim(),label:e.label.trim(),baseUrl:e.baseUrl.trim(),apiKey:e.apiKey.trim(),models:Ec(e.models),...t===void 0?{}:{contextWindow:t}}}function kc(e){let t=e.apiKey.trim();return{label:e.label.trim(),baseUrl:e.baseUrl.trim(),models:Ec(e.models),contextWindow:Dc(e.contextWindow)??null,...t.length>0?{apiKey:t}:{}}}function Ac(e,t,n){let r=Oc(e),i=ke({...r,apiKey:t===`edit`&&r.apiKey.length===0?vc:r.apiKey},n);return i===null?null:i.code===`INVALID_ID`?`Id must be lowercase letters, digits or dashes, start with a letter, and be at most ${_c} characters (${je}).`:i.message}function jc(e){return`${e<1e6&&e%1024==0?`${e/1024}k`:xe(e)} context`}function Mc(e){return e===null?`Key set`:`Key ••••${e}`}function Nc(e,t){return e===`create`?`API key`:t===null?`Leave blank to keep the saved key`:`Leave blank to keep ••••${t}`}function Pc(e){return{...e,error:null}}var Y=L()(e=>({editing:Fo,menuOpen:!1,listError:null,editorForm:Pc(yc()),setMenuOpen:t=>e({menuOpen:t}),setListError:t=>e({listError:t}),startEditing:(t,n)=>e({editing:t,menuOpen:!1,listError:null,editorForm:Pc(n)}),discardEditor:()=>e({editing:Fo,menuOpen:!1,editorForm:Pc(yc())}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}})),setLabel:(t,n)=>e(e=>({editorForm:{...e.editorForm,label:t,id:e.editorForm.idTouched?e.editorForm.id:Tc(t,n)}})),setId:t=>e(e=>({editorForm:{...e.editorForm,id:t.toLowerCase(),idTouched:!0}})),setModelField:(t,n,r)=>e(e=>({editorForm:{...e.editorForm,models:e.editorForm.models.map((e,i)=>i===t?{...e,[n]:r}:e)}})),addModelRow:()=>e(e=>({editorForm:{...e.editorForm,models:[...e.editorForm.models,{id:``,label:``}]}})),removeModelRow:t=>e(e=>({editorForm:{...e.editorForm,models:e.editorForm.models.filter((e,n)=>n!==t)}}))})),Fc=[{id:`glm`,label:`GLM (Z.AI)`,baseUrl:`https://api.z.ai/api/anthropic`,models:[{id:`glm-5.3`,label:`GLM-5.3`},{id:`glm-5.3-flash`,label:`GLM-5.3 Flash`}]},{id:`qwen`,label:`Qwen (Alibaba Model Studio)`,baseUrl:`https://coding-intl.dashscope.aliyuncs.com/apps/anthropic`,models:[{id:`qwen3.7-plus`,label:`Qwen3.7 Plus`},{id:`qwen3.7-max`,label:`Qwen3.7 Max`}],hint:`Coding Plan endpoint. Pay-as-you-go uses https://{WorkspaceId}.<region>.maas.aliyuncs.com/apps/anthropic.`},{id:`kimi`,label:`Kimi (Moonshot)`,baseUrl:`https://api.moonshot.ai/anthropic`,models:[{id:`kimi-k3`,label:`Kimi K3`},{id:`kimi-k2.7-code`,label:`Kimi K2.7 Code`}]},{id:`deepseek`,label:`DeepSeek`,baseUrl:`https://api.deepseek.com/anthropic`,models:[{id:`deepseek-v4-pro`,label:`DeepSeek V4 Pro`},{id:`deepseek-flash`,label:`DeepSeek Flash`}]},{id:`minimax`,label:`MiniMax`,baseUrl:`https://api.minimax.io/anthropic`,models:[{id:`MiniMax-M3.1`,label:`MiniMax M3.1`}],hint:`Mainland China: https://api.minimaxi.com/anthropic`},{id:`ollama`,label:`Ollama (local)`,baseUrl:`http://localhost:11434`,models:[],contextWindow:65536,defaultApiKey:`ollama`,hint:"Runs on this machine. Ollama ignores the API key, so any value works. Add the exact model names from `ollama list`, and set Context window to your OLLAMA_CONTEXT_LENGTH."}],Ic=`Anthropic-compatible endpoints such as GLM, Qwen, Kimi, DeepSeek or MiniMax. They run through the Claude agent, so tools, skills and MCP work as usual. Pick them in the chat composer under Custom endpoints.`;function Lc(e){return`${e} ${e===1?`model`:`models`}`}function Rc({providers:e,handlers:t,dom:n=nn}){let r=Y(e=>e.editing),i=Y(e=>e.discardEditor);return(0,V.useEffect)(()=>{i()},[i]),(0,H.jsxs)(`div`,{className:`border-t border-border pb-5`,children:[(0,H.jsx)(U,{title:`Custom endpoints`,description:Ic,bordered:!1,alignStart:!0,children:r.kind===`list`?(0,H.jsx)(zc,{providers:e}):null}),r.kind===`list`?(0,H.jsx)(Bc,{providers:e,onDelete:t.onDelete,dom:n}):(0,H.jsx)(Hc,{providers:e,editingId:r.kind===`edit`?r.id:null,handlers:t})]})}function zc({providers:e}){let t=Y(e=>e.menuOpen),n=Y(e=>e.setMenuOpen),r=Y(e=>e.startEditing),i=(0,V.useMemo)(()=>e.map(e=>e.id),[e]),a=(0,V.useCallback)(e=>{r({kind:`create`},Cc(e,i))},[r,i]),o=(0,V.useCallback)(()=>{r({kind:`create`},yc())},[r]);return(0,H.jsxs)(Ln,{open:t,onOpenChange:n,children:[(0,H.jsx)(Pn,{asChild:!0,children:(0,H.jsxs)(O,{size:`sm`,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add endpoint`]})}),(0,H.jsx)(Bn,{align:`end`,className:`w-64 p-1`,children:(0,H.jsxs)(`div`,{className:`space-y-1`,children:[Fc.map(e=>(0,H.jsx)(Jn,{onClick:()=>a(e),selected:!1,icon:(0,H.jsx)(Yn,{className:`h-4 w-4 text-muted-foreground`}),label:e.label},e.id)),(0,H.jsx)(Jn,{onClick:o,selected:!1,icon:(0,H.jsx)(Te,{className:`h-4 w-4 text-muted-foreground`}),label:`Custom…`,description:`Any Anthropic-compatible URL`})]})})]})}function Bc({providers:e,onDelete:t,dom:n}){let r=Y(e=>e.listError);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[r?(0,H.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:r}):null,e.length===0?(0,H.jsx)(ti,{icon:Yn,message:`No custom endpoints yet.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(Vc,{provider:e,onDelete:t,dom:n},e.id))})]})}function Vc({provider:e,onDelete:t,dom:n}){let r=Y(e=>e.startEditing),i=Y(e=>e.setListError),a=M(`settings.customProviders.delete`,e.id),o=j(a),s=(0,V.useCallback)(()=>{r({kind:`edit`,id:e.id},wc(e))},[e,r]),c=(0,V.useCallback)(()=>{n.confirmDialog(`Delete endpoint "${e.label}"?`)&&A(a,async()=>{i(null);try{await t(e.id)}catch(e){i(Ye(e))}})},[a,n,t,e.id,e.label,i]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":o||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,H.jsx)(cn,{tooltip:e.baseUrl,className:`font-mono text-xs text-muted-foreground`,children:e.baseUrl})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-0.5 text-xs text-muted-foreground`,children:[(0,H.jsx)(`span`,{className:`tabular-nums`,children:Lc(e.models.length)}),e.contextWindow===void 0?null:(0,H.jsx)(`span`,{className:`tabular-nums`,children:jc(e.contextWindow)}),(0,H.jsx)(`span`,{children:Mc(e.apiKeyHint)})]}),(0,H.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:(0,H.jsx)(ri,{label:e.label,onEdit:s,onDelete:c,deletePending:o})})]})}function Hc({providers:e,editingId:t,handlers:n}){let r=Y(e=>e.editorForm),i=Y(e=>e.patchEditorForm),a=Y(e=>e.setLabel),o=Y(e=>e.setId),s=Y(e=>e.setModelField),c=Y(e=>e.addModelRow),l=Y(e=>e.removeModelRow),u=Y(e=>e.discardEditor),d=t!==null,f=d?`edit`:`create`,p=(0,V.useMemo)(()=>e.find(e=>e.id===t)??null,[e,t]),m=(0,V.useMemo)(()=>e.filter(e=>e.id!==t).map(e=>e.id),[e,t]),h=M(`settings.customProviders`,t??`new`),g=j(h),_=(0,V.useCallback)(e=>{a(e,m)},[m,a]),v=(0,V.useCallback)(()=>{let e=Ac(r,f,m);e===null?A(h,()=>Ho({patch:i,save:async()=>{t===null?await n.onCreate(Oc(r)):await n.onUpdate(t,kc(r))},onDone:u})):i({error:e})},[u,t,r,n,f,m,i,h]),y=g;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-md border border-border px-4 py-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium`,children:d?`Edit ${p?.label??t}`:`Add endpoint`}),r.hint?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.hint}):null,(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Label`}),(0,H.jsx)(R,{value:r.label,onChange:e=>_(e.target.value),maxLength:64,placeholder:`GLM (Z.AI)`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Id`}),(0,H.jsx)(R,{value:r.id,onChange:e=>o(e.target.value),disabled:d,placeholder:`glm`,className:`font-mono`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Part of every model id, so it cannot change after the endpoint is created.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Base URL`}),(0,H.jsx)(R,{value:r.baseUrl,onChange:e=>i({baseUrl:e.target.value}),placeholder:`https://api.example.com/anthropic`,className:`font-mono`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`API key`}),(0,H.jsx)(R,{type:`password`,autoComplete:`off`,value:r.apiKey,onChange:e=>i({apiKey:e.target.value}),maxLength:Ne,placeholder:Nc(f,p?.apiKeyHint??null),className:`font-mono`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Context window (tokens)`}),(0,H.jsx)(R,{inputMode:`numeric`,value:r.contextWindow,onChange:e=>i({contextWindow:e.target.value}),placeholder:`200000`,className:`font-mono tabular-nums`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`The model's real context window. The agent compacts the conversation before reaching it. Leave empty to assume 200,000. For Ollama use your OLLAMA_CONTEXT_LENGTH.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Models`}),r.models.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{value:e.id,onChange:e=>s(t,`id`,e.target.value),maxLength:128,placeholder:`Model id`,"aria-label":`Model ${t+1} id`,className:`font-mono`}),(0,H.jsx)(R,{value:e.label,onChange:e=>s(t,`label`,e.target.value),maxLength:64,placeholder:`Label (optional)`,"aria-label":`Model ${t+1} label`}),(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:()=>l(t),"aria-label":`Remove model ${t+1}`,children:(0,H.jsx)(Ie,{className:`h-4 w-4`})})]},t)),(0,H.jsx)(`div`,{children:(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add model`]})})]}),r.error?(0,H.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:r.error}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:v,pending:y,children:Uo({submitting:y,isEdit:d,addLabel:`Add endpoint`})}),(0,H.jsx)(O,{variant:`ghost`,onClick:u,disabled:y,children:`Cancel`})]})]})}function Uc(e){let t=z(Gt),n=Bo(`customProviders`,e.state);return(0,H.jsx)(Rc,{providers:t,handlers:n})}function Wc(e){return e===`openai`?et:e===`openrouter`?vn:``}function Gc(e,t){return{...e,provider:t,model:Wc(t),baseUrl:t===`custom`?e.baseUrl:``}}var Kc=`settings.writeLlmProvider`,qc=[{value:`openai`,label:`OpenAI`},{value:`openrouter`,label:`OpenRouter`},{value:`custom`,label:`Custom`}];function Jc({saving:e,busy:t}){let n=J(e=>e.llmValidationStatus),r=J(e=>e.llmValidationError),i=J(e=>e.setLlmValidationDialogOpen),a,o;return t?(a=`inline-flex items-center gap-1.5 text-muted-foreground`,o=(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(T,{}),e?`Saving…`:`Loading…`]})):n===`valid`?(a=`text-success-text`,o=`Credentials valid & saved`):n===`invalid`?(a=`text-destructive`,o=(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{children:`Credentials invalid.`}),r?(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`button`,{type:`button`,onClick:()=>i(!0),className:`underline underline-offset-2`,children:`See error`})]}):null]})):(a=`hidden`,o=null),(0,H.jsx)(`span`,{className:E(`mt-2 block text-sm font-medium`,a),children:o})}function Yc(){let e=J(e=>e.llmValidationDialogOpen),t=J(e=>e.setLlmValidationDialogOpen),n=J(e=>e.llmValidationError),r=n?JSON.stringify(n,null,2):``;return(0,H.jsx)(Re,{open:e,onOpenChange:t,children:(0,H.jsxs)(Le,{size:`lg`,children:[(0,H.jsxs)(Be,{className:`space-y-4`,children:[(0,H.jsx)(He,{children:`Validation Error`}),(0,H.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted p-3 text-xs font-mono whitespace-pre-wrap break-words`,children:r})]}),(0,H.jsx)(ze,{children:(0,H.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>t(!1),children:`Close`})})]})})}function Xc({state:e}){let{llmProvider:t,handleReadLlmProvider:n,handleWriteLlmProvider:r,handleValidateLlmProvider:i}=e,a=J(e=>e.llmProviderDraft),o=J(e=>e.setLlmProviderDraft),s=J(e=>e.llmProviderError),c=J(e=>e.setLlmProviderError),l=J(e=>e.llmDraftChanged),u=J(e=>e.llmValidated),d=j(Kc),f=j(S),p=d||f;(0,V.useEffect)(()=>{A(S,n)},[n]),(0,V.useEffect)(()=>{t&&o({provider:t.provider,apiKey:t.apiKey,model:t.model,baseUrl:t.baseUrl})},[t,o]),(0,V.useEffect)(()=>{l()},[a.provider,a.apiKey,a.model,a.baseUrl,l]);let m=(0,V.useCallback)(async e=>{try{c(null),await r(e);let t=await i(e);u(t.ok?`valid`:`invalid`,t.error)}catch(e){let t=e instanceof Error?{name:e.name,message:e.message}:be(e);u(`invalid`,t),c(Ye(e))}},[r,i,c,u]);function h(e=a){A(Kc,()=>m(e))}function g(e){let t=Gc(a,e);o(t),h(t)}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Quick Response SDK`,description:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{children:[`Use an OpenAI-compatible API for title and commit message generation before Claude and Codex. Stored in `,t?.filePathDisplay??`the active llm-provider.json file`,`.`]}),(0,H.jsx)(Jc,{saving:d,busy:p})]}),alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex w-full max-w-[420px] flex-col gap-3`,children:[s?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:s}):null,t?.warning?(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground`,children:t.warning}):null,(0,H.jsxs)(ve,{value:a.provider,disabled:p,onValueChange:e=>{Wt(e)&&g(e)},children:[(0,H.jsx)(ge,{className:`w-full`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsx)(F,{children:qc.map(e=>(0,H.jsx)(N,{value:e.value,children:e.label},e.value))})})]}),a.provider===`custom`?(0,H.jsx)(R,{value:a.baseUrl,onChange:e=>o({...a,baseUrl:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`https://your-provider.example/v1`}):null,(0,H.jsx)(R,{type:`password`,value:a.apiKey,onChange:e=>o({...a,apiKey:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`API key`}),(0,H.jsx)(R,{value:a.model,onChange:e=>o({...a,model:e.target.value}),onBlur:()=>h(),onKeyDown:e=>ca(e,h),readOnly:p,placeholder:`Model id`})]})}),(0,H.jsx)(Yc,{})]})}var Zc=Math.round(eo.min/6e4),Qc=Math.round(eo.max/6e4),$c={min:Zc,max:Qc},el=Math.round(Ht.idleTimeoutMs/6e4);function tl({state:e}){let{write:t}=fa(e),n=z(e=>e.settings?.claudeDriver.lifecycle),r=G(e=>e.setAppSettingsError),i=Math.round((n?.idleTimeoutMs??Ht.idleTimeoutMs)/6e4),a=n?.maxConcurrent??Ht.maxConcurrent,o=J(e=>e.claudeIdleMinutesDraft),s=J(e=>e.setClaudeIdleMinutesDraft),c=J(e=>e.claudeMaxConcurrentDraft),l=J(e=>e.setClaudeMaxConcurrentDraft);(0,V.useEffect)(()=>{s(String(i))},[i,s]),(0,V.useEffect)(()=>{l(String(a))},[a,l]);function u(){let e=no(o,i,$c);e.kind===`write`?t({claudeDriver:{lifecycle:{idleTimeoutMs:e.value*6e4}}}):(s(String(i)),e.kind===`invalid`&&r(`Idle timeout must be between ${Zc} and ${Qc} minutes.`))}function d(){let e=no(c,a,to);e.kind===`write`?t({claudeDriver:{lifecycle:{maxConcurrent:e.value}}}):(l(String(a)),e.kind===`invalid`&&r(`Max concurrent sessions must be between ${to.min} and ${to.max}.`))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(ro,{title:`Claude session idle timeout`,description:`Stop a Claude session after this many minutes without user activity. Lower values free memory sooner; higher values keep cold-start latency low.`,min:Zc,max:Qc,step:1,value:o,onValueChange:s,onCommit:u,hint:`${Zc}–${Qc} min · default ${el}`}),(0,H.jsx)(ro,{title:`Max concurrent Claude sessions`,description:`Hard cap on resident Claude processes. Excess sessions are evicted LRU; their next activation cold-starts.`,min:to.min,max:to.max,step:1,value:c,onValueChange:l,onCommit:d,hint:`${to.min}–${to.max} · default ${Ht.maxConcurrent}`})]})}function nl({state:e}){let{write:t}=fa(e),n=Fe(),r=a(e=>e.defaultProvider),i=a(e=>e.providerDefaults),o=a(e=>e.setDefaultProvider),s=a(e=>e.setProviderDefaultModel),c=a(e=>e.setProviderDefaultModelOptions),l=a(e=>e.setProviderDefaultPlanMode);function u(e){o(e),t({defaultProvider:e})}function d(e,n){s(e,n),t({providerDefaults:{[e]:{model:n}}})}function f(e,n){c(e,n),t({providerDefaults:{[e]:{modelOptions:n}}})}function p(e,n){l(e,n),t({providerDefaults:{[e]:{planMode:n}}})}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{title:`Default Provider`,description:`The default harness used for new chats before a provider is locked by an existing session.`,children:(0,H.jsxs)(ve,{value:r,onValueChange:e=>{(e===`last_used`||tt(e))&&u(e)},children:[(0,H.jsx)(ge,{className:`min-w-[180px]`,children:(0,H.jsx)(_e,{})}),(0,H.jsx)(P,{children:(0,H.jsxs)(F,{children:[(0,H.jsx)(N,{value:`last_used`,children:`Last Used`}),n.map(e=>(0,H.jsx)(N,{value:e.id,children:e.label},e.id))]})})]})}),(0,H.jsx)(Uc,{state:e}),(0,H.jsx)(U,{title:`Claude Code Defaults`,description:`Saved defaults when using Claude Code.`,alignStart:!0,children:(0,H.jsx)(`div`,{className:`max-w-[420px]`,children:(0,H.jsx)(Kn,{availableProviders:n,selectedProvider:`claude`,showProviderPicker:!1,model:i.claude.model,modelOptions:i.claude.modelOptions,onModelChange:(e,t)=>{d(`claude`,t)},onModelOptionChange:e=>{e.type===`claudeReasoningEffort`?f(`claude`,{reasoningEffort:e.effort}):e.type===`contextWindow`&&f(`claude`,{contextWindow:e.contextWindow})},planMode:i.claude.planMode,onPlanModeChange:e=>p(`claude`,e),includePlanMode:!0,className:`justify-start flex-wrap`})})}),(0,H.jsx)(U,{title:`Codex Defaults`,description:`Saved defaults when using Codex.`,alignStart:!0,children:(0,H.jsx)(`div`,{className:`max-w-[420px]`,children:(0,H.jsx)(Kn,{availableProviders:n,selectedProvider:`codex`,showProviderPicker:!1,model:i.codex.model,modelOptions:i.codex.modelOptions,onModelChange:(e,t)=>{d(`codex`,t)},onModelOptionChange:e=>{e.type===`codexReasoningEffort`?f(`codex`,{reasoningEffort:e.effort}):e.type===`fastMode`&&f(`codex`,{fastMode:e.fastMode})},planMode:i.codex.planMode,onPlanModeChange:e=>p(`codex`,e),includePlanMode:!0,className:`justify-start flex-wrap`})})})]})}function rl({state:e}){let t=z(e=>e.settings?.claudeAuth);return(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(U,{title:`Claude OAuth tokens`,description:`Manage multiple Claude OAuth tokens. Kanna switches automatically when one hits its rate limit.`,bordered:!1,alignStart:!0,children:(0,H.jsx)(`div`,{className:`w-full md:w-[420px]`,children:(0,H.jsx)(gc,{tokens:t?.tokens??[],concurrencyDefault:t?.concurrencyDefault??1,onWrite:e.handleWriteClaudeAuth,onTest:e.handleTestOAuthToken})})}),(0,H.jsx)(tl,{state:e}),(0,H.jsx)(nl,{state:e}),(0,H.jsx)(Xc,{state:e})]})}var il={disabled:`Disabled`,installing:`Installing`,starting:`Starting`,connecting:`Connecting`,connected:`Connected`,reconnecting:`Reconnecting`,restarting:`Restarting`,error:`Error`},al={disabled:`muted`,installing:`attention`,starting:`attention`,connecting:`attention`,connected:`muted`,reconnecting:`attention`,restarting:`attention`,error:`destructive`};function ol(e){return il[e]}function sl(e){return al[e]}var X=L()(e=>({connection:null,stream:null,embedded:null,consumerEditor:null,resetConfirm:!1,error:null,editConnection:(t,n)=>e(e=>({connection:{...e.connection??t,...n}})),discardConnection:()=>e({connection:null}),editStream:(t,n)=>e(e=>({stream:{...e.stream??t,...n}})),discardStream:()=>e({stream:null}),editEmbedded:(t,n)=>e(e=>({embedded:{...e.embedded??t,...n}})),discardEmbedded:()=>e({embedded:null}),openConsumerEditor:(t,n)=>e({consumerEditor:{target:t,draft:n}}),editConsumer:t=>e(e=>e.consumerEditor===null?e:{consumerEditor:{...e.consumerEditor,draft:{...e.consumerEditor.draft,...t}}}),closeConsumerEditor:()=>e({consumerEditor:null}),askResetConfirm:()=>e({resetConfirm:!0}),cancelResetConfirm:()=>e({resetConfirm:!1}),setError:t=>e({error:t})})),cl=`auto`;function ll(e){return{name:e.name,subjectPrefix:e.subjectPrefix,extraSubjects:e.extraSubjects.join(`
|
|
12
12
|
`),retention:e.retention,storage:e.storage,maxAgeDays:String(e.maxAgeDays),maxBytesMb:String(e.maxBytesMb),maxMsgs:String(e.maxMsgs),discard:e.discard,duplicateWindowSec:String(e.duplicateWindowSec),replicas:String(e.replicas)}}function ul(e){return e.trim()===``?NaN:Number(e)}function dl(e){return{name:e.name.trim(),subjectPrefix:e.subjectPrefix.trim(),extraSubjects:e.extraSubjects.split(`
|
|
13
|
-
`).map(e=>e.trim()).filter(e=>e.length>0),retention:e.retention,storage:e.storage,maxAgeDays:ul(e.maxAgeDays),maxBytesMb:ul(e.maxBytesMb),maxMsgs:ul(e.maxMsgs),discard:e.discard,duplicateWindowSec:ul(e.duplicateWindowSec),replicas:ul(e.replicas)}}function fl(e){return{durableName:e.durableName,filterSubject:e.filterSubject,ackPolicy:e.ackPolicy,deliverPolicy:e.deliverPolicy,maxAckPending:String(e.maxAckPending),ackWaitSec:String(e.ackWaitSec)}}function pl(e){return{durableName:``,filterSubject:`${e}.>`,ackPolicy:mt.ackPolicy,deliverPolicy:mt.deliverPolicy,maxAckPending:String(mt.maxAckPending),ackWaitSec:String(mt.ackWaitSec)}}function ml(e){return{durableName:e.durableName.trim(),filterSubject:e.filterSubject.trim(),ackPolicy:e.ackPolicy,deliverPolicy:e.deliverPolicy,maxAckPending:ul(e.maxAckPending),ackWaitSec:ul(e.ackWaitSec)}}function hl(e){return{maxMemoryStoreMb:String(e.maxMemoryStoreMb),maxFileStoreMb:String(e.maxFileStoreMb),port:String(e.port),logLevel:e.logLevel}}function gl(e){let t=e.port.trim().toLowerCase()===`auto`?cl:ul(e.port);return{maxMemoryStoreMb:ul(e.maxMemoryStoreMb),maxFileStoreMb:ul(e.maxFileStoreMb),port:t,logLevel:e.logLevel}}function _l(e,t){return pt({...e,...t})}function vl(e,t){let n=[];return e.retention!==t.retention&&n.push(`retention`),e.storage!==t.storage&&n.push(`storage`),e.replicas!==t.replicas&&n.push(`replicas`),n}function yl(e,t){return t.maxAgeDays<e.maxAgeDays||t.maxBytesMb<e.maxBytesMb}function bl(e,t){return JSON.stringify(ll(e))===JSON.stringify(t)}function Z({label:e,note:t,warn:n=!1,children:r}){return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,H.jsx)(`div`,{className:`text-13 font-medium text-foreground`,children:e}),r,t?(0,H.jsx)(`div`,{className:E(`text-xs`,n?`text-warning-text`:`text-muted-foreground`),children:t}):null]})}function xl({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,H.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,H.jsx)(`dd`,{className:`font-mono text-13 tabular-nums text-foreground`,children:t})]})}function Sl({problems:e}){return e.length===0?null:(0,H.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-xs text-destructive-text`,role:`alert`,children:e.map(e=>(0,H.jsx)(`li`,{children:e},e))})}var Cl=M(`settings.serviceBus`,`consumers`),wl={explicit:`Explicit`,all:`All`,none:`None`},Tl=it.map(e=>({value:e,label:wl[e]})),El={all:`All`,new:`New`,last:`Last`},Dl=Jt.map(e=>({value:e,label:El[e]}));function Ol({consumer:e,onEdit:t,onRemove:n}){let r=_(t=>t.status.consumers.find(t=>t.name===e.durableName)),i=j(M(`settings.serviceBus`,`consumer`,e.durableName));return(0,H.jsxs)(`li`,{className:`flex flex-col gap-1 px-4 py-3 md:flex-row md:items-center md:justify-between`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.durableName}),(0,H.jsxs)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,children:[e.filterSubject||`all subjects`,` · ack `,e.ackPolicy,` · deliver `,e.deliverPolicy]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:r?`${String(r.pending)} pending · ${String(r.ackPending)} ack pending`:`not reported yet`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Edit ${e.durableName}`,onClick:t,children:(0,H.jsx)(we,{className:`h-4 w-4`})}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Remove ${e.durableName}`,pending:i,onClick:n,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})]})}function kl({state:e}){let t=z(At),n=X(e=>e.consumerEditor),r=X(e=>e.openConsumerEditor),i=X(e=>e.editConsumer),a=X(e=>e.closeConsumerEditor),o=X(e=>e.setError),s=j(Cl),c=(0,V.useCallback)(t=>B(o,async()=>{await e.handleWriteAppSettings({serviceBus:{consumers:t}}),a()}),[e,a,o]),l=n?ml(n.draft):null,u=n?.target.kind===`edit`?n.target.durableName:null,d=t.consumers.filter(e=>e.durableName!==u),f=l?_l(t,{consumers:[...d,l]}):[],p=(0,V.useCallback)(async()=>{if(l===null)return;let e=t.consumers.map(e=>e.durableName===u?l:e);await c(u===null?[...t.consumers,l]:e)},[l,u,t.consumers,c]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsxs)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:[`Consumers `,(0,H.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:t.consumers.length})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 border-t border-border py-3`,children:[(0,H.jsx)(`p`,{className:`px-4 text-13 text-muted-foreground`,children:`Durable pull consumers Kanna creates on the stream. Kanna removes only the ones it created, and never touches consumers you add elsewhere.`}),t.consumers.length===0?(0,H.jsx)(`div`,{className:`px-4 text-13 text-muted-foreground`,children:`No consumers configured`}):(0,H.jsx)(`ul`,{className:`flex flex-col divide-y divide-border border-y border-border`,children:t.consumers.map(e=>(0,H.jsx)(Ol,{consumer:e,onEdit:()=>r({kind:`edit`,durableName:e.durableName},fl(e)),onRemove:()=>A(M(`settings.serviceBus`,`consumer`,e.durableName),()=>c(t.consumers.filter(t=>t.durableName!==e.durableName)))},e.durableName))}),n?(0,H.jsxs)(`div`,{className:`mx-4 flex flex-col gap-4 rounded-lg border border-border p-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Durable name`,children:(0,H.jsx)(R,{"aria-label":`Durable name`,value:n.draft.durableName,disabled:u!==null,onChange:e=>i({durableName:e.target.value}),spellCheck:!1})}),(0,H.jsx)(Z,{label:`Filter subject`,note:`Leave empty for every subject in the stream`,children:(0,H.jsx)(R,{"aria-label":`Filter subject`,value:n.draft.filterSubject,onChange:e=>i({filterSubject:e.target.value}),spellCheck:!1})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Acknowledgement`,note:u===null?void 0:`Cannot change on an existing consumer; remove and add it again`,children:(0,H.jsx)(I,{size:`sm`,value:n.draft.ackPolicy,onValueChange:e=>i({ackPolicy:e}),options:Tl})}),(0,H.jsx)(Z,{label:`Deliver`,children:(0,H.jsx)(I,{size:`sm`,value:n.draft.deliverPolicy,onValueChange:e=>i({deliverPolicy:e}),options:Dl})}),(0,H.jsx)(Z,{label:`Max ack pending`,children:(0,H.jsx)(R,{"aria-label":`Max ack pending`,inputMode:`numeric`,className:`tabular-nums`,value:n.draft.maxAckPending,onChange:e=>i({maxAckPending:e.target.value})})}),(0,H.jsx)(Z,{label:`Ack wait (s)`,children:(0,H.jsx)(R,{"aria-label":`Ack wait in seconds`,inputMode:`numeric`,className:`tabular-nums`,value:n.draft.ackWaitSec,onChange:e=>i({ackWaitSec:e.target.value})})})]}),(0,H.jsx)(Sl,{problems:f}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:s,onClick:a,children:`Cancel`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:f.length>0,pending:s,onClick:()=>A(Cl,p),children:`Save consumer`})]})]}):(0,H.jsx)(`div`,{className:`px-4`,children:(0,H.jsxs)(O,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r({kind:`new`},pl(t.stream.subjectPrefix)),children:[(0,H.jsx)(Te,{className:`mr-1.5 h-4 w-4`}),`Add consumer`]})})]})]})}var Al=M(`settings.serviceBus`,`embedded`),jl=M(`serviceBus.resetStore`),Ml={info:`Info`,debug:`Debug`},Nl=ot.map(e=>({value:e,label:Ml[e]}));function Pl({state:e}){let t=an(),n=z(At),r=hl(n.embedded),i=X(e=>e.embedded)??r,a=X(e=>e.editEmbedded),o=X(e=>e.discardEmbedded),s=X(e=>e.resetConfirm),c=X(e=>e.askResetConfirm),l=X(e=>e.cancelResetConfirm),u=X(e=>e.setError),d=j(Al),f=j(jl),p=_l(n,{embedded:gl(i)}),m=JSON.stringify(r)!==JSON.stringify(i),h=e=>a(r,e),g=(0,V.useCallback)(()=>B(u,async()=>{await e.handleWriteAppSettings({serviceBus:{embedded:gl(i)}}),o()}),[e,i,o,u]),_=(0,V.useCallback)(async()=>{await B(u,async()=>{await sn(t,{type:`serviceBus.resetStore`})}),l()},[t,l,u]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:`Embedded server`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border px-4 py-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Memory store (MB)`,children:(0,H.jsx)(R,{"aria-label":`Memory store in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:i.maxMemoryStoreMb,onChange:e=>h({maxMemoryStoreMb:e.target.value})})}),(0,H.jsx)(Z,{label:`File store (MB)`,children:(0,H.jsx)(R,{"aria-label":`File store in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:i.maxFileStoreMb,onChange:e=>h({maxFileStoreMb:e.target.value})})}),(0,H.jsx)(Z,{label:`Port`,note:`auto picks a free loopback port`,children:(0,H.jsx)(R,{"aria-label":`Port`,inputMode:`numeric`,className:`tabular-nums`,value:i.port,onChange:e=>h({port:e.target.value})})})]}),(0,H.jsx)(Z,{label:`Server log level`,children:(0,H.jsx)(I,{size:`sm`,value:i.logLevel,onValueChange:e=>h({logLevel:e}),options:Nl})}),(0,H.jsx)(Sl,{problems:p}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:!m||d,onClick:o,children:`Revert`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!m||p.length>0,pending:d,onClick:()=>A(Al,g),children:`Save server`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border pt-4`,children:[(0,H.jsx)(`div`,{className:`text-13 font-medium text-foreground`,children:`Reset store`}),(0,H.jsx)(`p`,{className:`text-13 text-muted-foreground`,children:`Stops the embedded server, deletes every message it holds and starts it again. Kanna's own history is not touched.`}),s?(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`destructive`,size:`sm`,pending:f,onClick:()=>A(jl,_),children:`Delete the store`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:f,onClick:l,children:`Cancel`})]}):(0,H.jsx)(`div`,{children:(0,H.jsx)(O,{type:`button`,variant:`outline`,size:`sm`,onClick:c,children:`Reset store`})})]})]})]})}var Fl=M(`settings.serviceBus`,`stream`),Il=`Changing this requires recreating the stream`,Ll=`Lowering this drops older messages`,Rl={limits:`Limits`,interest:`Interest`,workqueue:`Work queue`},zl=Pt.map(e=>({value:e,label:Rl[e]})),Bl={file:`File`,memory:`Memory`},Vl=ft.map(e=>({value:e,label:Bl[e]})),Hl={old:`Oldest`,new:`Newest`},Ul=rt.map(e=>({value:e,label:Hl[e]}));function Wl({state:e}){let t=z(At),n=ll(t.stream),r=X(e=>e.stream)??n,i=X(e=>e.editStream),a=X(e=>e.discardStream),o=X(e=>e.setError),s=j(Fl),c=dl(r),l=_l(t,{stream:c}),u=!bl(t.stream,r),d=vl(t.stream,c),f=yl(t.stream,c),p=e=>i(n,e),m=(0,V.useCallback)(()=>B(o,async()=>{await e.handleWriteAppSettings({serviceBus:{stream:dl(r)}}),a()}),[e,r,a,o]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:`Stream`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border px-4 py-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Stream name`,children:(0,H.jsx)(R,{"aria-label":`Stream name`,value:r.name,onChange:e=>p({name:e.target.value}),spellCheck:!1})}),(0,H.jsx)(Z,{label:`Subject prefix`,note:`Kanna publishes under ${r.subjectPrefix||`…`}.>`,children:(0,H.jsx)(R,{"aria-label":`Subject prefix`,value:r.subjectPrefix,onChange:e=>p({subjectPrefix:e.target.value}),spellCheck:!1})})]}),(0,H.jsx)(Z,{label:`Extra subjects`,note:`One per line; the stream also captures these`,children:(0,H.jsx)(on,{"aria-label":`Extra subjects`,rows:2,value:r.extraSubjects,onChange:e=>p({extraSubjects:e.target.value}),spellCheck:!1})}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Retention`,note:Il,warn:d.includes(`retention`),children:(0,H.jsx)(I,{size:`sm`,value:r.retention,onValueChange:e=>p({retention:e}),options:zl})}),(0,H.jsx)(Z,{label:`Storage`,note:Il,warn:d.includes(`storage`),children:(0,H.jsx)(I,{size:`sm`,value:r.storage,onValueChange:e=>p({storage:e}),options:Vl})}),(0,H.jsx)(Z,{label:`Replicas`,note:Il,warn:d.includes(`replicas`),children:(0,H.jsx)(R,{"aria-label":`Replicas`,inputMode:`numeric`,className:`tabular-nums`,value:r.replicas,onChange:e=>p({replicas:e.target.value})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Max age (days)`,note:Ll,warn:f,children:(0,H.jsx)(R,{"aria-label":`Max age in days`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxAgeDays,onChange:e=>p({maxAgeDays:e.target.value})})}),(0,H.jsx)(Z,{label:`Max bytes (MB)`,note:Ll,warn:f,children:(0,H.jsx)(R,{"aria-label":`Max bytes in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxBytesMb,onChange:e=>p({maxBytesMb:e.target.value})})}),(0,H.jsx)(Z,{label:`Max messages`,note:`-1 means unlimited`,children:(0,H.jsx)(R,{"aria-label":`Max messages`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxMsgs,onChange:e=>p({maxMsgs:e.target.value})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`When full, discard`,children:(0,H.jsx)(I,{size:`sm`,value:r.discard,onValueChange:e=>p({discard:e}),options:Ul})}),(0,H.jsx)(Z,{label:`Duplicate window (s)`,note:`Messages with the same id inside this window are stored once`,children:(0,H.jsx)(R,{"aria-label":`Duplicate window in seconds`,inputMode:`numeric`,className:`tabular-nums`,value:r.duplicateWindowSec,onChange:e=>p({duplicateWindowSec:e.target.value})})})]}),(0,H.jsx)(Sl,{problems:l}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:!u||s,onClick:a,children:`Revert`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!u||l.length>0,pending:s,onClick:()=>A(Fl,m),children:`Save stream`})]})]})]})}var Gl=M(`settings.serviceBus`,`enabled`),Kl=M(`settings.serviceBus`,`mode`),ql=M(`settings.serviceBus`,`start`),Jl=M(`settings.serviceBus`,`connection`),Yl=M(`settings.serviceBus`,`token`),Xl=[{value:`enabled`,label:`Enabled`},{value:`disabled`,label:`Disabled`}],Zl={embedded:`Embedded`,external:`External`},Ql=Ft.map(e=>({value:e,label:Zl[e]}));function $l(){let e=_(v),t=e=>e.toLocaleString(`en-US`);return(0,H.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-3 md:grid-cols-4`,children:[e.stream?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(xl,{label:`Messages`,value:t(e.stream.messages)}),(0,H.jsx)(xl,{label:`Size`,value:ue(e.stream.bytes)}),(0,H.jsx)(xl,{label:`First seq`,value:t(e.stream.firstSeq)}),(0,H.jsx)(xl,{label:`Last seq`,value:t(e.stream.lastSeq)})]}):null,(0,H.jsx)(xl,{label:`Published`,value:t(e.published)}),(0,H.jsx)(xl,{label:`Dropped`,value:t(e.dropped)}),(0,H.jsx)(xl,{label:`Queued`,value:t(e.queued)}),e.serverVersion?(0,H.jsx)(xl,{label:`Server`,value:`v${e.serverVersion}${e.port?` · :${String(e.port)}`:``}`}):null]})}function eu({state:e}){let t=z(At),n=X(e=>e.connection)??{url:t.url,token:``},r=X(e=>e.editConnection),i=X(e=>e.discardConnection),a=X(e=>e.setError),o=j(Jl),s=j(Yl),c=n.url.trim(),l=_l({...t,mode:`external`},{url:c}),u=c!==t.url,d=(0,V.useCallback)(()=>B(a,async()=>{await e.handleWriteAppSettings({serviceBus:{url:c}}),i()}),[e,c,i,a]),f=(0,V.useCallback)(t=>B(a,async()=>{await e.handleWriteAppSettings({serviceBus:{token:t}}),i()}),[e,i,a]),p={url:t.url,token:``};return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border py-5`,children:[(0,H.jsx)(Z,{label:`Server URL`,note:`Where your own nats-server listens, for example nats://nats.internal:4222`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{"aria-label":`Server URL`,value:n.url,onChange:e=>r(p,{url:e.target.value}),spellCheck:!1}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!u||l.length>0,pending:o,onClick:()=>A(Jl,d),children:`Save`})]})}),(0,H.jsx)(Z,{label:`Token`,note:t.tokenHint?`A token ending in ${t.tokenHint} is stored. Kanna never shows it again.`:`No token stored`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{"aria-label":`Token`,type:`password`,autoComplete:`off`,value:n.token,placeholder:t.tokenHint?`Enter a new token to replace it`:`Token`,onChange:e=>r(p,{token:e.target.value})}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:n.token.trim()===``,pending:s,onClick:()=>A(Yl,()=>f(n.token.trim())),children:`Replace token`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:t.tokenHint===null,onClick:()=>A(Yl,()=>f(null)),children:`Clear`})]})}),(0,H.jsx)(Sl,{problems:l})]})}function tu({state:e}){let t=z(At),n=_(v),r=X(e=>e.error),i=X(e=>e.setError),a=j(ql),o=(0,V.useCallback)(t=>B(i,()=>e.handleWriteAppSettings({serviceBus:t})),[e,i]),s=(0,V.useCallback)(e=>o({enabled:e===`enabled`}),[o]),c=(0,V.useCallback)(e=>o({mode:e}),[o]),l=(0,V.useCallback)(async()=>{t.enabled&&await o({enabled:!1}),await o({enabled:!0})},[t.enabled,o]),u=t.mode===`embedded`,d=u&&(!t.enabled||n.state===`error`);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1 pb-2`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Service bus`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Mirror every durable event Kanna records into a NATS JetStream stream, so other programs can read them with the nats CLI or any NATS client. Kanna's own history is not affected, and a bus outage never blocks a chat.`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-13 text-muted-foreground`,children:`Embedded mode downloads nats-server v${at} from GitHub on first start and runs it on loopback with a private token.`})]}),(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(U,{title:`Mirror to NATS`,description:`When off, nothing is downloaded, started or published.`,children:(0,H.jsx)(Ua,{pendingKey:Gl,value:t.enabled?`enabled`:`disabled`,onValueChange:s,options:Xl,size:`sm`})}),(0,H.jsx)(U,{title:`Server`,description:`Embedded runs a nats-server that Kanna manages. External connects to one you run.`,children:(0,H.jsx)(Ua,{pendingKey:Kl,value:t.mode,onValueChange:c,options:Ql,size:`sm`})}),(0,H.jsx)(U,{title:`Status`,description:n.lastError?(0,H.jsx)(`span`,{className:`text-destructive-text`,children:n.lastError}):`Live state of the mirror.`,alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(mn,{tone:sl(n.state),label:ol(n.state)}),d?(0,H.jsx)(O,{type:`button`,size:`sm`,pending:a,onClick:()=>A(ql,l),children:t.enabled?`Retry`:`Install & start`}):null]})})]}),r?(0,H.jsx)(`div`,{className:`text-xs text-destructive-text`,role:`alert`,children:r}):null,t.enabled||n.state!==`disabled`?(0,H.jsx)(`div`,{className:`py-3`,children:(0,H.jsx)($l,{})}):null,u?null:(0,H.jsx)(eu,{state:e}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 pt-2`,children:[(0,H.jsx)(Wl,{state:e}),(0,H.jsx)(kl,{state:e}),u?(0,H.jsx)(Pl,{state:e}):null]})]})}function nu(e,t){if(!e.pinnedRef)return null;let n=t.latestVersion;return!n||n===e.pinnedRef?null:n}var ru={outdated:`Outdated`,partial:`Partial`,unknown:`Unknown`};function iu(e){if(!e)return null;let t=nu(e,e.update);if(t)return`Re-pin to ${t}`;if(e.pinnedRef)return null;let n=e.update.availability;return n===`outdated`||n===`partial`?`Update`:null}function au({availability:e}){return e===void 0||e===`up_to_date`?null:(0,H.jsx)(`span`,{className:E(`rounded-full border px-2 py-0.5 text-xs font-medium`,xi[e]),children:ru[e]})}function ou({label:e,updating:t,onClick:n}){return(0,H.jsxs)(O,{type:`button`,size:`sm`,variant:`secondary`,disabled:t,"aria-busy":t||void 0,onClick:n,className:`h-6 rounded-full px-2 text-xs`,children:[t?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):null,e]})}function su({skill:e,packageEntry:t,uninstalling:n,applying:r,onUninstall:i,onUpdate:a}){let o=e.source?`https://skills.sh/${e.source}/${e.name}`:null,s=t?.versionLabel??t?.revision?.slice(0,7)??t?.updatedAt??null,c=t?.pinnedRef??null,l=iu(t);return(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,H.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.source||`Unknown source`}),s?(0,H.jsx)(`div`,{className:`font-mono tabular-nums text-xs text-muted-foreground/70`,children:s}):null,c?(0,H.jsxs)(`div`,{className:`truncate font-mono tabular-nums text-xs text-muted-foreground/70`,children:[`Pinned `,c]}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,H.jsx)(au,{availability:t?.update.availability}),l?(0,H.jsx)(ou,{label:l,updating:r,onClick:a}):null,o?(0,H.jsx)(`a`,{href:o,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} on skills.sh`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(In,{className:`h-4 w-4`})}):null,(0,H.jsx)(`button`,{type:`button`,"aria-label":`Uninstall ${e.name}`,disabled:n,onClick:i,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:pointer-events-none disabled:opacity-50`,children:n?(0,H.jsx)(k,{className:`h-4 w-4 animate-spin`}):(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})]})}var cu=[],lu=[],uu={},du=`Installed globally`;function fu(e){return new Set(e.map(e=>e.name))}function pu(e,t){let{[t]:n,...r}=e;return r}var Q=L()(e=>({query:``,results:cu,searchLoading:!1,searchError:null,installedSkills:lu,installedSkillIds:new Set,installedLoading:!1,installedError:null,operationError:null,installMessages:uu,setQuery:t=>e({query:t}),searchCleared:t=>e({results:cu,searchError:t,searchLoading:!1}),searchStarted:()=>e({searchLoading:!0,searchError:null}),searchSucceeded:t=>e({results:t,searchLoading:!1}),searchFailed:t=>e({results:cu,searchError:t,searchLoading:!1}),installedCleared:()=>e({installedSkills:lu,installedSkillIds:new Set,installedError:null,installedLoading:!1}),installedLoadStarted:()=>e({installedLoading:!0,installedError:null}),installedLoaded:t=>e({installedSkills:t,installedSkillIds:fu(t)}),installedLoadFailed:t=>e({installedSkills:lu,installedSkillIds:new Set,installedError:t}),installedLoadFinished:()=>e({installedLoading:!1}),setOperationError:t=>e({operationError:t}),installStarted:t=>e(e=>({operationError:null,installMessages:pu(e.installMessages,t)})),installSucceeded:t=>e(e=>({installedSkillIds:new Set([...e.installedSkillIds,t]),installMessages:{...e.installMessages,[t]:du}})),uninstallSucceeded:t=>e(e=>({installedSkills:e.installedSkills.filter(e=>e.name!==t),installedSkillIds:new Set([...e.installedSkillIds].filter(e=>e!==t)),installMessages:pu(e.installMessages,t)}))}));function mu(e){return M(`skills.install`,e)}function hu(e){return!e||e<=0?`0 installs`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M installs`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K installs`:`${e} install${e===1?``:`s`}`}var gu=M(`packages.checkUpdates`),_u=M(`packages.updateAll`,`skill`);function vu(e){return`skill:${e}`}function yu({skill:e,packageEntry:t,applying:n,onUninstall:r,onUpdate:i}){let a=vu(e.name),o=j(M(`packages.update`,a)),s=j(M(`skills.uninstall`,e.name));return(0,H.jsx)(su,{skill:e,packageEntry:t,uninstalling:s,applying:n||o,onUninstall:()=>r(e),onUpdate:()=>i(a)})}function bu({message:e}){return(0,H.jsx)(`pre`,{className:`max-w-full overflow-x-auto whitespace-pre-wrap rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive`,children:e})}function xu({skill:e,installing:t,installed:n,message:r,onInstall:i}){let a;return a=n?`Installed`:t?`Installing`:`Get`,(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,H.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[e.source,` · `,hu(e.installs)]}),n&&r?(0,H.jsx)(`div`,{className:`mt-1 truncate text-xs text-emerald-500`,children:r}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,H.jsx)(`a`,{href:`https://skills.sh/${e.id}`,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} on skills.sh`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(In,{className:`h-4 w-4`})}),(0,H.jsxs)(O,{type:`button`,size:`sm`,variant:n?`secondary`:`default`,disabled:t||n,onClick:i,className:`h-6 rounded-full px-2 text-xs`,children:[t?(0,H.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):null,a]})]})]})}function Su({state:e,ports:t}){let n=t?.timer??Ve,r=e.socket,i=e.connectionStatus,a=Q(e=>e.query),o=Q(e=>e.setQuery),s=Q(e=>e.results),c=Q(e=>e.searchLoading),l=Q(e=>e.searchError),u=Q(e=>e.searchCleared),d=Q(e=>e.searchStarted),f=Q(e=>e.searchSucceeded),p=Q(e=>e.searchFailed),m=Q(e=>e.installedSkills),h=Q(e=>e.installedSkillIds),g=Q(e=>e.installedLoading),_=Q(e=>e.installedError),v=Q(e=>e.installedCleared),y=Q(e=>e.installedLoadStarted),b=Q(e=>e.installedLoaded),S=Q(e=>e.installedLoadFailed),ee=Q(e=>e.installedLoadFinished),te=Q(e=>e.operationError),C=Q(e=>e.setOperationError),w=ie(e=>e.inFlight),ne=Q(e=>e.installMessages),re=Q(e=>e.installStarted),T=Q(e=>e.installSucceeded),E=Q(e=>e.uninstallSucceeded),D=x(e=>e.updateSnapshot),ae=D?.status===`checking`,oe=D?.packages.filter(e=>e.kind===`skill`&&!e.pinnedRef).filter(e=>e.update.availability===`outdated`||e.update.availability===`partial`).map(e=>e.id)??[],se=oe.length,ce=D?.lastCheckedAt?new Date(D.lastCheckedAt).toLocaleTimeString():null,le=j(gu),ue=j(_u),de=ae||le;async function fe(e){await B(C,()=>r.command(e))}function pe(){A(gu,()=>fe({type:`packages.checkUpdates`}))}function me(e){A(M(`packages.update`,e),()=>fe({type:`packages.update`,id:e}))}function he(){oe.length!==0&&A(_u,()=>fe({type:`packages.updateAll`,ids:oe}))}function ge(e){A(mu(e.id),()=>_e(e))}function N(e){A(M(`skills.uninstall`,e.name),()=>F(e))}let P=(0,V.useCallback)(async()=>{if(i!==`connected`)v();else try{y();let e=await r.command({type:`skills.listInstalled`});b(e.skills)}catch(e){S(Ye(e))}finally{ee()}},[i,r,v,y,b,S,ee]);(0,V.useEffect)(()=>{tn(`skills.listInstalled`,P())},[i,P,r]),(0,V.useEffect)(()=>{let e=a.trim();if(e.length<2){u(null);return}if(i!==`connected`){u(`Backend connection required.`);return}let t=!1;d();let o=n.setTimeout(()=>{r.command({type:`skills.search`,query:e,limit:100}).then(e=>{t||f(e.skills)}).catch(e=>{t||p(Ye(e))})},250);return()=>{t=!0,n.clearTimeout(o)}},[i,a,r,u,d,f,p,n]);async function _e(e){if(i!==`connected`)C(`Backend connection required.`);else try{re(e.skillId),await r.command({type:`skills.install`,source:e.source,skillId:e.skillId}),T(e.skillId),tn(`skills.listInstalled`,P())}catch(e){C(Ye(e))}}async function F(e){i===`connected`?await B(C,async()=>{await r.command({type:`skills.uninstall`,skillId:e.name}),E(e.name),tn(`skills.listInstalled`,P())}):C(`Backend connection required.`)}let ve;return ve=m.length>0?(0,H.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:m.map(e=>(0,H.jsx)(yu,{skill:e,packageEntry:D?.packages.find(t=>t.kind===`skill`&&t.name===e.name)??null,applying:D?.applying.includes(vu(e.name))??!1,onUninstall:N,onUpdate:me},`${e.source}/${e.name}`))}):g?null:(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:`No global skills installed.`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[te?(0,H.jsx)(bu,{message:te}):null,(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Installed`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ce?(0,H.jsxs)(`span`,{className:`tabular-nums text-xs text-muted-foreground`,children:[`Checked `,ce]}):null,se>0?(0,H.jsxs)(O,{size:`sm`,variant:`secondary`,className:`h-6 rounded-full px-2 text-xs`,pending:ue,onClick:he,children:[`Update all (`,se,`)`]}):null,(0,H.jsxs)(O,{size:`sm`,variant:`ghost`,className:`h-6 rounded-full px-2 text-xs`,disabled:de,"aria-busy":de||void 0,onClick:pe,children:[de?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):null,`Check`]}),g?(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}):null]})]}),_?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:_}):null,ve]}),(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Discover`}),(0,H.jsxs)(`div`,{className:`flex h-10 items-center gap-2 rounded-lg border border-border bg-card/30 px-3`,children:[(0,H.jsx)(De,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,H.jsx)(`input`,{type:`text`,role:`searchbox`,value:a,onChange:e=>o(e.target.value),placeholder:`Search skills`,className:`min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground`}),a?(0,H.jsx)(`button`,{type:`button`,"aria-label":`Clear skills search`,onClick:()=>o(``),className:`touch-manipulation inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(Ie,{className:`h-3.5 w-3.5`})}):null,c?(0,H.jsx)(k,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):null]}),l?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:l}):null,(0,H.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:s.map(e=>(0,H.jsx)(xu,{skill:e,installing:w[mu(e.id)]===!0,installed:h.has(e.skillId),message:ne[e.skillId],onInstall:()=>{ge(e)}},e.id))}),!c&&!l&&a.trim().length>=2&&s.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:`No skills found.`}):null]})]})}var Cu=`auto`;function wu(e){return e.triggerMode??`auto`}function Tu(e,t,n){return t?.[e].model||n?.find(t=>t.id===e)?.defaultModel||xn(e).defaultModel}function Eu(e,t){return e===`claude`?{...t?.claude.modelOptions??_n}:e===`codex`?{...t?.codex.modelOptions??On}:{}}function Du(e,t,n){return{name:``,provider:e,model:Tu(e,t,n),modelOptions:Eu(e,t),systemPrompt:``,contextScope:`previous-assistant-reply`,triggerMode:Cu}}function Ou(e){return{name:e.name,description:e.description,provider:e.provider,model:e.model,modelOptions:e.modelOptions,systemPrompt:e.systemPrompt,contextScope:e.contextScope,triggerMode:e.triggerMode,workingDir:e.workingDir,allowedPaths:e.allowedPaths,maxTurns:e.maxTurns,allowBeaconTools:e.allowBeaconTools}}function ku(e){return{...e,maxTurns:e.maxTurns??null}}function Au(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function ju(e,t){if(!Xe(e)||!Xe(t))return!1;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n)if(e[r]!==t[r])return!1;return!0}var Mu={name:(e,t)=>e.name===t.name,description:(e,t)=>(e.description??``)===(t.description??``),provider:(e,t)=>e.provider===t.provider,model:(e,t)=>e.model===t.model,modelOptions:(e,t)=>ju(e.modelOptions,t.modelOptions),systemPrompt:(e,t)=>e.systemPrompt===t.systemPrompt,contextScope:(e,t)=>e.contextScope===t.contextScope,triggerMode:(e,t)=>wu(e)===wu(t),workingDir:(e,t)=>(e.workingDir??``)===(t.workingDir??``),allowedPaths:(e,t)=>Au(e.allowedPaths,t.allowedPaths),maxTurns:(e,t)=>(e.maxTurns??null)===(t.maxTurns??null),allowBeaconTools:(e,t)=>(e.allowBeaconTools??!1)===(t.allowBeaconTools??!1)};function Nu(e,t){return Object.values(Mu).some(n=>!n(e,t))}var Pu=new Set([`EMPTY_NAME`,`INVALID_CHAR`,`RESERVED_NAME`,`DUPLICATE_NAME`,`TOO_LONG`]);function Fu(e){return Pu.has(e.code)?{field:`name`,message:e.message}:{field:`general`,message:e.message}}function Iu(e){return e.toLowerCase().replace(Yt,`-`).slice(0,64)}function Lu(){return{draft:Du(`claude`,void 0),error:null,confirmDelete:!1}}var Ru=L()(e=>({editing:Fo,form:Lu(),timeoutDraft:``,loopError:null,setEditing:t=>e({editing:t}),resetForm:t=>e({form:{draft:t,error:null,confirmDelete:!1}}),patchForm:t=>e(e=>({form:{...e.form,...t}})),patchFormDraft:t=>e(e=>({form:{...e.form,draft:{...e.form.draft,...t}}})),setTimeoutDraft:t=>e({timeoutDraft:t}),setLoopError:t=>e({loopError:t})}));function $(e){return(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e.label}),e.children,e.hint?(0,H.jsx)(`span`,{className:E(`text-xs`,e.hintTone===`destructive`?`text-destructive`:`text-muted-foreground`),children:e.hint}):null]})}function zu(e){let{draft:t,patchDraft:n}=e;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($,{label:`Working directory`,hint:`Optional. Relative to the parent chat cwd. Restricts the subagent's filesystem access to this subtree.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-working-dir`,value:t.workingDir??``,onChange:e=>{let t=e.target.value;n({workingDir:t.length>0?t:void 0})},placeholder:`docs`})}),(0,H.jsx)($,{label:`Allowed paths`,hint:`Optional. Newline-separated, relative to the parent chat cwd. When set, file tools can only read/write inside these roots.`,children:(0,H.jsx)(on,{"data-testid":`subagent-form-allowed-paths`,value:(t.allowedPaths??[]).join(`
|
|
13
|
+
`).map(e=>e.trim()).filter(e=>e.length>0),retention:e.retention,storage:e.storage,maxAgeDays:ul(e.maxAgeDays),maxBytesMb:ul(e.maxBytesMb),maxMsgs:ul(e.maxMsgs),discard:e.discard,duplicateWindowSec:ul(e.duplicateWindowSec),replicas:ul(e.replicas)}}function fl(e){return{durableName:e.durableName,filterSubject:e.filterSubject,ackPolicy:e.ackPolicy,deliverPolicy:e.deliverPolicy,maxAckPending:String(e.maxAckPending),ackWaitSec:String(e.ackWaitSec)}}function pl(e){return{durableName:``,filterSubject:`${e}.>`,ackPolicy:mt.ackPolicy,deliverPolicy:mt.deliverPolicy,maxAckPending:String(mt.maxAckPending),ackWaitSec:String(mt.ackWaitSec)}}function ml(e){return{durableName:e.durableName.trim(),filterSubject:e.filterSubject.trim(),ackPolicy:e.ackPolicy,deliverPolicy:e.deliverPolicy,maxAckPending:ul(e.maxAckPending),ackWaitSec:ul(e.ackWaitSec)}}function hl(e){return{maxMemoryStoreMb:String(e.maxMemoryStoreMb),maxFileStoreMb:String(e.maxFileStoreMb),port:String(e.port),logLevel:e.logLevel}}function gl(e){let t=e.port.trim().toLowerCase()===`auto`?cl:ul(e.port);return{maxMemoryStoreMb:ul(e.maxMemoryStoreMb),maxFileStoreMb:ul(e.maxFileStoreMb),port:t,logLevel:e.logLevel}}function _l(e,t){return pt({...e,...t})}function vl(e,t){let n=[];return e.retention!==t.retention&&n.push(`retention`),e.storage!==t.storage&&n.push(`storage`),e.replicas!==t.replicas&&n.push(`replicas`),n}function yl(e,t){return t.maxAgeDays<e.maxAgeDays||t.maxBytesMb<e.maxBytesMb}function bl(e,t){return JSON.stringify(ll(e))===JSON.stringify(t)}function Z({label:e,note:t,warn:n=!1,children:r}){return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,H.jsx)(`div`,{className:`text-13 font-medium text-foreground`,children:e}),r,t?(0,H.jsx)(`div`,{className:E(`text-xs`,n?`text-warning-text`:`text-muted-foreground`),children:t}):null]})}function xl({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,H.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,H.jsx)(`dd`,{className:`font-mono text-13 tabular-nums text-foreground`,children:t})]})}function Sl({problems:e}){return e.length===0?null:(0,H.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-xs text-destructive-text`,role:`alert`,children:e.map(e=>(0,H.jsx)(`li`,{children:e},e))})}var Cl=M(`settings.serviceBus`,`consumers`),wl={explicit:`Explicit`,all:`All`,none:`None`},Tl=it.map(e=>({value:e,label:wl[e]})),El={all:`All`,new:`New`,last:`Last`},Dl=Jt.map(e=>({value:e,label:El[e]}));function Ol({consumer:e,onEdit:t,onRemove:n}){let r=_(t=>t.status.consumers.find(t=>t.name===e.durableName)),i=j(M(`settings.serviceBus`,`consumer`,e.durableName));return(0,H.jsxs)(`li`,{className:`flex flex-col gap-1 px-4 py-3 md:flex-row md:items-center md:justify-between`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.durableName}),(0,H.jsxs)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,children:[e.filterSubject||`all subjects`,` · ack `,e.ackPolicy,` · deliver `,e.deliverPolicy]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:r?`${String(r.pending)} pending · ${String(r.ackPending)} ack pending`:`not reported yet`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Edit ${e.durableName}`,onClick:t,children:(0,H.jsx)(we,{className:`h-4 w-4`})}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Remove ${e.durableName}`,pending:i,onClick:n,children:(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})]})}function kl({state:e}){let t=z(At),n=X(e=>e.consumerEditor),r=X(e=>e.openConsumerEditor),i=X(e=>e.editConsumer),a=X(e=>e.closeConsumerEditor),o=X(e=>e.setError),s=j(Cl),c=(0,V.useCallback)(t=>B(o,async()=>{await e.handleWriteAppSettings({serviceBus:{consumers:t}}),a()}),[e,a,o]),l=n?ml(n.draft):null,u=n?.target.kind===`edit`?n.target.durableName:null,d=t.consumers.filter(e=>e.durableName!==u),f=l?_l(t,{consumers:[...d,l]}):[],p=(0,V.useCallback)(async()=>{if(l===null)return;let e=t.consumers.map(e=>e.durableName===u?l:e);await c(u===null?[...t.consumers,l]:e)},[l,u,t.consumers,c]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsxs)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:[`Consumers `,(0,H.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:t.consumers.length})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 border-t border-border py-3`,children:[(0,H.jsx)(`p`,{className:`px-4 text-13 text-muted-foreground`,children:`Durable pull consumers Kanna creates on the stream. Kanna removes only the ones it created, and never touches consumers you add elsewhere.`}),t.consumers.length===0?(0,H.jsx)(`div`,{className:`px-4 text-13 text-muted-foreground`,children:`No consumers configured`}):(0,H.jsx)(`ul`,{className:`flex flex-col divide-y divide-border border-y border-border`,children:t.consumers.map(e=>(0,H.jsx)(Ol,{consumer:e,onEdit:()=>r({kind:`edit`,durableName:e.durableName},fl(e)),onRemove:()=>A(M(`settings.serviceBus`,`consumer`,e.durableName),()=>c(t.consumers.filter(t=>t.durableName!==e.durableName)))},e.durableName))}),n?(0,H.jsxs)(`div`,{className:`mx-4 flex flex-col gap-4 rounded-lg border border-border p-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Durable name`,children:(0,H.jsx)(R,{"aria-label":`Durable name`,value:n.draft.durableName,disabled:u!==null,onChange:e=>i({durableName:e.target.value}),spellCheck:!1})}),(0,H.jsx)(Z,{label:`Filter subject`,note:`Leave empty for every subject in the stream`,children:(0,H.jsx)(R,{"aria-label":`Filter subject`,value:n.draft.filterSubject,onChange:e=>i({filterSubject:e.target.value}),spellCheck:!1})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Acknowledgement`,note:u===null?void 0:`Cannot change on an existing consumer; remove and add it again`,children:(0,H.jsx)(I,{size:`sm`,value:n.draft.ackPolicy,onValueChange:e=>i({ackPolicy:e}),options:Tl})}),(0,H.jsx)(Z,{label:`Deliver`,children:(0,H.jsx)(I,{size:`sm`,value:n.draft.deliverPolicy,onValueChange:e=>i({deliverPolicy:e}),options:Dl})}),(0,H.jsx)(Z,{label:`Max ack pending`,children:(0,H.jsx)(R,{"aria-label":`Max ack pending`,inputMode:`numeric`,className:`tabular-nums`,value:n.draft.maxAckPending,onChange:e=>i({maxAckPending:e.target.value})})}),(0,H.jsx)(Z,{label:`Ack wait (s)`,children:(0,H.jsx)(R,{"aria-label":`Ack wait in seconds`,inputMode:`numeric`,className:`tabular-nums`,value:n.draft.ackWaitSec,onChange:e=>i({ackWaitSec:e.target.value})})})]}),(0,H.jsx)(Sl,{problems:f}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:s,onClick:a,children:`Cancel`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:f.length>0,pending:s,onClick:()=>A(Cl,p),children:`Save consumer`})]})]}):(0,H.jsx)(`div`,{className:`px-4`,children:(0,H.jsxs)(O,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r({kind:`new`},pl(t.stream.subjectPrefix)),children:[(0,H.jsx)(Te,{className:`mr-1.5 h-4 w-4`}),`Add consumer`]})})]})]})}var Al=M(`settings.serviceBus`,`embedded`),jl=M(`serviceBus.resetStore`),Ml={info:`Info`,debug:`Debug`},Nl=ot.map(e=>({value:e,label:Ml[e]}));function Pl({state:e}){let t=an(),n=z(At),r=hl(n.embedded),i=X(e=>e.embedded)??r,a=X(e=>e.editEmbedded),o=X(e=>e.discardEmbedded),s=X(e=>e.resetConfirm),c=X(e=>e.askResetConfirm),l=X(e=>e.cancelResetConfirm),u=X(e=>e.setError),d=j(Al),f=j(jl),p=_l(n,{embedded:gl(i)}),m=JSON.stringify(r)!==JSON.stringify(i),h=e=>a(r,e),g=(0,V.useCallback)(()=>B(u,async()=>{await e.handleWriteAppSettings({serviceBus:{embedded:gl(i)}}),o()}),[e,i,o,u]),_=(0,V.useCallback)(async()=>{await B(u,async()=>{await sn(t,{type:`serviceBus.resetStore`})}),l()},[t,l,u]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:`Embedded server`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border px-4 py-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Memory store (MB)`,children:(0,H.jsx)(R,{"aria-label":`Memory store in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:i.maxMemoryStoreMb,onChange:e=>h({maxMemoryStoreMb:e.target.value})})}),(0,H.jsx)(Z,{label:`File store (MB)`,children:(0,H.jsx)(R,{"aria-label":`File store in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:i.maxFileStoreMb,onChange:e=>h({maxFileStoreMb:e.target.value})})}),(0,H.jsx)(Z,{label:`Port`,note:`auto picks a free loopback port`,children:(0,H.jsx)(R,{"aria-label":`Port`,inputMode:`numeric`,className:`tabular-nums`,value:i.port,onChange:e=>h({port:e.target.value})})})]}),(0,H.jsx)(Z,{label:`Server log level`,children:(0,H.jsx)(I,{size:`sm`,value:i.logLevel,onValueChange:e=>h({logLevel:e}),options:Nl})}),(0,H.jsx)(Sl,{problems:p}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:!m||d,onClick:o,children:`Revert`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!m||p.length>0,pending:d,onClick:()=>A(Al,g),children:`Save server`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-border pt-4`,children:[(0,H.jsx)(`div`,{className:`text-13 font-medium text-foreground`,children:`Reset store`}),(0,H.jsx)(`p`,{className:`text-13 text-muted-foreground`,children:`Stops the embedded server, deletes every message it holds and starts it again. Kanna's own history is not touched.`}),s?(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`destructive`,size:`sm`,pending:f,onClick:()=>A(jl,_),children:`Delete the store`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:f,onClick:l,children:`Cancel`})]}):(0,H.jsx)(`div`,{children:(0,H.jsx)(O,{type:`button`,variant:`outline`,size:`sm`,onClick:c,children:`Reset store`})})]})]})]})}var Fl=M(`settings.serviceBus`,`stream`),Il=`Changing this requires recreating the stream`,Ll=`Lowering this drops older messages`,Rl={limits:`Limits`,interest:`Interest`,workqueue:`Work queue`},zl=Pt.map(e=>({value:e,label:Rl[e]})),Bl={file:`File`,memory:`Memory`},Vl=ft.map(e=>({value:e,label:Bl[e]})),Hl={old:`Oldest`,new:`Newest`},Ul=rt.map(e=>({value:e,label:Hl[e]}));function Wl({state:e}){let t=z(At),n=ll(t.stream),r=X(e=>e.stream)??n,i=X(e=>e.editStream),a=X(e=>e.discardStream),o=X(e=>e.setError),s=j(Fl),c=dl(r),l=_l(t,{stream:c}),u=!bl(t.stream,r),d=vl(t.stream,c),f=yl(t.stream,c),p=e=>i(n,e),m=(0,V.useCallback)(()=>B(o,async()=>{await e.handleWriteAppSettings({serviceBus:{stream:dl(r)}}),a()}),[e,r,a,o]);return(0,H.jsxs)(`details`,{className:`rounded-lg border border-border`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-foreground`,children:`Stream`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border px-4 py-4`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,H.jsx)(Z,{label:`Stream name`,children:(0,H.jsx)(R,{"aria-label":`Stream name`,value:r.name,onChange:e=>p({name:e.target.value}),spellCheck:!1})}),(0,H.jsx)(Z,{label:`Subject prefix`,note:`Kanna publishes under ${r.subjectPrefix||`…`}.>`,children:(0,H.jsx)(R,{"aria-label":`Subject prefix`,value:r.subjectPrefix,onChange:e=>p({subjectPrefix:e.target.value}),spellCheck:!1})})]}),(0,H.jsx)(Z,{label:`Extra subjects`,note:`One per line; the stream also captures these`,children:(0,H.jsx)(on,{"aria-label":`Extra subjects`,rows:2,value:r.extraSubjects,onChange:e=>p({extraSubjects:e.target.value}),spellCheck:!1})}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Retention`,note:Il,warn:d.includes(`retention`),children:(0,H.jsx)(I,{size:`sm`,value:r.retention,onValueChange:e=>p({retention:e}),options:zl})}),(0,H.jsx)(Z,{label:`Storage`,note:Il,warn:d.includes(`storage`),children:(0,H.jsx)(I,{size:`sm`,value:r.storage,onValueChange:e=>p({storage:e}),options:Vl})}),(0,H.jsx)(Z,{label:`Replicas`,note:Il,warn:d.includes(`replicas`),children:(0,H.jsx)(R,{"aria-label":`Replicas`,inputMode:`numeric`,className:`tabular-nums`,value:r.replicas,onChange:e=>p({replicas:e.target.value})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`Max age (days)`,note:Ll,warn:f,children:(0,H.jsx)(R,{"aria-label":`Max age in days`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxAgeDays,onChange:e=>p({maxAgeDays:e.target.value})})}),(0,H.jsx)(Z,{label:`Max bytes (MB)`,note:Ll,warn:f,children:(0,H.jsx)(R,{"aria-label":`Max bytes in megabytes`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxBytesMb,onChange:e=>p({maxBytesMb:e.target.value})})}),(0,H.jsx)(Z,{label:`Max messages`,note:`-1 means unlimited`,children:(0,H.jsx)(R,{"aria-label":`Max messages`,inputMode:`numeric`,className:`tabular-nums`,value:r.maxMsgs,onChange:e=>p({maxMsgs:e.target.value})})})]}),(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,H.jsx)(Z,{label:`When full, discard`,children:(0,H.jsx)(I,{size:`sm`,value:r.discard,onValueChange:e=>p({discard:e}),options:Ul})}),(0,H.jsx)(Z,{label:`Duplicate window (s)`,note:`Messages with the same id inside this window are stored once`,children:(0,H.jsx)(R,{"aria-label":`Duplicate window in seconds`,inputMode:`numeric`,className:`tabular-nums`,value:r.duplicateWindowSec,onChange:e=>p({duplicateWindowSec:e.target.value})})})]}),(0,H.jsx)(Sl,{problems:l}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:!u||s,onClick:a,children:`Revert`}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!u||l.length>0,pending:s,onClick:()=>A(Fl,m),children:`Save stream`})]})]})]})}var Gl=M(`settings.serviceBus`,`enabled`),Kl=M(`settings.serviceBus`,`mode`),ql=M(`settings.serviceBus`,`start`),Jl=M(`settings.serviceBus`,`connection`),Yl=M(`settings.serviceBus`,`token`),Xl=[{value:`enabled`,label:`Enabled`},{value:`disabled`,label:`Disabled`}],Zl={embedded:`Embedded`,external:`External`},Ql=Ft.map(e=>({value:e,label:Zl[e]}));function $l(){let e=_(v),t=e=>e.toLocaleString(`en-US`);return(0,H.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-3 md:grid-cols-4`,children:[e.stream?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(xl,{label:`Messages`,value:t(e.stream.messages)}),(0,H.jsx)(xl,{label:`Size`,value:ue(e.stream.bytes)}),(0,H.jsx)(xl,{label:`First seq`,value:t(e.stream.firstSeq)}),(0,H.jsx)(xl,{label:`Last seq`,value:t(e.stream.lastSeq)})]}):null,(0,H.jsx)(xl,{label:`Published`,value:t(e.published)}),(0,H.jsx)(xl,{label:`Dropped`,value:t(e.dropped)}),(0,H.jsx)(xl,{label:`Queued`,value:t(e.queued)}),e.serverVersion?(0,H.jsx)(xl,{label:`Server`,value:`v${e.serverVersion}${e.port?` · :${String(e.port)}`:``}`}):null]})}function eu({state:e}){let t=z(At),n=X(e=>e.connection)??{url:t.url,token:``},r=X(e=>e.editConnection),i=X(e=>e.discardConnection),a=X(e=>e.setError),o=j(Jl),s=j(Yl),c=n.url.trim(),l=_l({...t,mode:`external`},{url:c}),u=c!==t.url,d=(0,V.useCallback)(()=>B(a,async()=>{await e.handleWriteAppSettings({serviceBus:{url:c}}),i()}),[e,c,i,a]),f=(0,V.useCallback)(t=>B(a,async()=>{await e.handleWriteAppSettings({serviceBus:{token:t}}),i()}),[e,i,a]),p={url:t.url,token:``};return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-border py-5`,children:[(0,H.jsx)(Z,{label:`Server URL`,note:`Where your own nats-server listens, for example nats://nats.internal:4222`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{"aria-label":`Server URL`,value:n.url,onChange:e=>r(p,{url:e.target.value}),spellCheck:!1}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:!u||l.length>0,pending:o,onClick:()=>A(Jl,d),children:`Save`})]})}),(0,H.jsx)(Z,{label:`Token`,note:t.tokenHint?`A token ending in ${t.tokenHint} is stored. Kanna never shows it again.`:`No token stored`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(R,{"aria-label":`Token`,type:`password`,autoComplete:`off`,value:n.token,placeholder:t.tokenHint?`Enter a new token to replace it`:`Token`,onChange:e=>r(p,{token:e.target.value})}),(0,H.jsx)(O,{type:`button`,size:`sm`,disabled:n.token.trim()===``,pending:s,onClick:()=>A(Yl,()=>f(n.token.trim())),children:`Replace token`}),(0,H.jsx)(O,{type:`button`,variant:`ghost`,size:`sm`,disabled:t.tokenHint===null,onClick:()=>A(Yl,()=>f(null)),children:`Clear`})]})}),(0,H.jsx)(Sl,{problems:l})]})}function tu({state:e}){let t=z(At),n=_(v),r=X(e=>e.error),i=X(e=>e.setError),a=j(ql),o=(0,V.useCallback)(t=>B(i,()=>e.handleWriteAppSettings({serviceBus:t})),[e,i]),s=(0,V.useCallback)(e=>o({enabled:e===`enabled`}),[o]),c=(0,V.useCallback)(e=>o({mode:e}),[o]),l=(0,V.useCallback)(async()=>{t.enabled&&await o({enabled:!1}),await o({enabled:!0})},[t.enabled,o]),u=t.mode===`embedded`,d=u&&(!t.enabled||n.state===`error`);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1 pb-2`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Service bus`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Mirror every durable event Kanna records into a NATS JetStream stream, so other programs can read them with the nats CLI or any NATS client. Kanna's own history is not affected, and a bus outage never blocks a chat.`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-13 text-muted-foreground`,children:`Embedded mode downloads nats-server v${at} from GitHub on first start and runs it on loopback with a private token.`})]}),(0,H.jsxs)(`div`,{className:`border-b border-border`,children:[(0,H.jsx)(U,{title:`Mirror to NATS`,description:`When off, nothing is downloaded, started or published.`,children:(0,H.jsx)(Ua,{pendingKey:Gl,value:t.enabled?`enabled`:`disabled`,onValueChange:s,options:Xl,size:`sm`})}),(0,H.jsx)(U,{title:`Server`,description:`Embedded runs a nats-server that Kanna manages. External connects to one you run.`,children:(0,H.jsx)(Ua,{pendingKey:Kl,value:t.mode,onValueChange:c,options:Ql,size:`sm`})}),(0,H.jsx)(U,{title:`Status`,description:n.lastError?(0,H.jsx)(`span`,{className:`text-destructive-text`,children:n.lastError}):`Live state of the mirror.`,alignStart:!0,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(mn,{tone:sl(n.state),label:ol(n.state)}),d?(0,H.jsx)(O,{type:`button`,size:`sm`,pending:a,onClick:()=>A(ql,l),children:t.enabled?`Retry`:`Install & start`}):null]})})]}),r?(0,H.jsx)(`div`,{className:`text-xs text-destructive-text`,role:`alert`,children:r}):null,t.enabled||n.state!==`disabled`?(0,H.jsx)(`div`,{className:`py-3`,children:(0,H.jsx)($l,{})}):null,u?null:(0,H.jsx)(eu,{state:e}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 pt-2`,children:[(0,H.jsx)(Wl,{state:e}),(0,H.jsx)(kl,{state:e}),u?(0,H.jsx)(Pl,{state:e}):null]})]})}function nu(e,t){if(!e.pinnedRef)return null;let n=t.latestVersion;return!n||n===e.pinnedRef?null:n}var ru={outdated:`Outdated`,partial:`Partial`,unknown:`Unknown`};function iu(e){if(!e)return null;let t=nu(e,e.update);if(t)return`Re-pin to ${t}`;if(e.pinnedRef)return null;let n=e.update.availability;return n===`outdated`||n===`partial`?`Update`:null}function au({availability:e}){return e===void 0||e===`up_to_date`?null:(0,H.jsx)(`span`,{className:E(`rounded-full border px-2 py-0.5 text-xs font-medium`,xi[e]),children:ru[e]})}function ou({label:e,updating:t,onClick:n}){return(0,H.jsxs)(O,{type:`button`,size:`sm`,variant:`secondary`,disabled:t,"aria-busy":t||void 0,onClick:n,className:`h-6 rounded-full px-2 text-xs`,children:[t?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):null,e]})}function su({skill:e,packageEntry:t,uninstalling:n,applying:r,onUninstall:i,onUpdate:a}){let o=e.source?`https://skills.sh/${e.source}/${e.name}`:null,s=t?.versionLabel??t?.revision?.slice(0,7)??t?.updatedAt??null,c=t?.pinnedRef??null,l=iu(t);return(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,H.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.source||`Unknown source`}),s?(0,H.jsx)(`div`,{className:`font-mono tabular-nums text-xs text-muted-foreground/70`,children:s}):null,c?(0,H.jsxs)(`div`,{className:`truncate font-mono tabular-nums text-xs text-muted-foreground/70`,children:[`Pinned `,c]}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,H.jsx)(au,{availability:t?.update.availability}),l?(0,H.jsx)(ou,{label:l,updating:r,onClick:a}):null,o?(0,H.jsx)(`a`,{href:o,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} on skills.sh`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(Fn,{className:`h-4 w-4`})}):null,(0,H.jsx)(`button`,{type:`button`,"aria-label":`Uninstall ${e.name}`,disabled:n,onClick:i,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:pointer-events-none disabled:opacity-50`,children:n?(0,H.jsx)(k,{className:`h-4 w-4 animate-spin`}):(0,H.jsx)(Oe,{className:`h-4 w-4`})})]})]})}var cu=[],lu=[],uu={},du=`Installed globally`;function fu(e){return new Set(e.map(e=>e.name))}function pu(e,t){let{[t]:n,...r}=e;return r}var Q=L()(e=>({query:``,results:cu,searchLoading:!1,searchError:null,installedSkills:lu,installedSkillIds:new Set,installedLoading:!1,installedError:null,operationError:null,installMessages:uu,setQuery:t=>e({query:t}),searchCleared:t=>e({results:cu,searchError:t,searchLoading:!1}),searchStarted:()=>e({searchLoading:!0,searchError:null}),searchSucceeded:t=>e({results:t,searchLoading:!1}),searchFailed:t=>e({results:cu,searchError:t,searchLoading:!1}),installedCleared:()=>e({installedSkills:lu,installedSkillIds:new Set,installedError:null,installedLoading:!1}),installedLoadStarted:()=>e({installedLoading:!0,installedError:null}),installedLoaded:t=>e({installedSkills:t,installedSkillIds:fu(t)}),installedLoadFailed:t=>e({installedSkills:lu,installedSkillIds:new Set,installedError:t}),installedLoadFinished:()=>e({installedLoading:!1}),setOperationError:t=>e({operationError:t}),installStarted:t=>e(e=>({operationError:null,installMessages:pu(e.installMessages,t)})),installSucceeded:t=>e(e=>({installedSkillIds:new Set([...e.installedSkillIds,t]),installMessages:{...e.installMessages,[t]:du}})),uninstallSucceeded:t=>e(e=>({installedSkills:e.installedSkills.filter(e=>e.name!==t),installedSkillIds:new Set([...e.installedSkillIds].filter(e=>e!==t)),installMessages:pu(e.installMessages,t)}))}));function mu(e){return M(`skills.install`,e)}function hu(e){return!e||e<=0?`0 installs`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M installs`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K installs`:`${e} install${e===1?``:`s`}`}var gu=M(`packages.checkUpdates`),_u=M(`packages.updateAll`,`skill`);function vu(e){return`skill:${e}`}function yu({skill:e,packageEntry:t,applying:n,onUninstall:r,onUpdate:i}){let a=vu(e.name),o=j(M(`packages.update`,a)),s=j(M(`skills.uninstall`,e.name));return(0,H.jsx)(su,{skill:e,packageEntry:t,uninstalling:s,applying:n||o,onUninstall:()=>r(e),onUpdate:()=>i(a)})}function bu({message:e}){return(0,H.jsx)(`pre`,{className:`max-w-full overflow-x-auto whitespace-pre-wrap rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive`,children:e})}function xu({skill:e,installing:t,installed:n,message:r,onInstall:i}){let a;return a=n?`Installed`:t?`Installing`:`Get`,(0,H.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,H.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[e.source,` · `,hu(e.installs)]}),n&&r?(0,H.jsx)(`div`,{className:`mt-1 truncate text-xs text-emerald-500`,children:r}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,H.jsx)(`a`,{href:`https://skills.sh/${e.id}`,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} on skills.sh`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(Fn,{className:`h-4 w-4`})}),(0,H.jsxs)(O,{type:`button`,size:`sm`,variant:n?`secondary`:`default`,disabled:t||n,onClick:i,className:`h-6 rounded-full px-2 text-xs`,children:[t?(0,H.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):null,a]})]})]})}function Su({state:e,ports:t}){let n=t?.timer??Ve,r=e.socket,i=e.connectionStatus,a=Q(e=>e.query),o=Q(e=>e.setQuery),s=Q(e=>e.results),c=Q(e=>e.searchLoading),l=Q(e=>e.searchError),u=Q(e=>e.searchCleared),d=Q(e=>e.searchStarted),f=Q(e=>e.searchSucceeded),p=Q(e=>e.searchFailed),m=Q(e=>e.installedSkills),h=Q(e=>e.installedSkillIds),g=Q(e=>e.installedLoading),_=Q(e=>e.installedError),v=Q(e=>e.installedCleared),y=Q(e=>e.installedLoadStarted),b=Q(e=>e.installedLoaded),S=Q(e=>e.installedLoadFailed),ee=Q(e=>e.installedLoadFinished),te=Q(e=>e.operationError),C=Q(e=>e.setOperationError),w=ie(e=>e.inFlight),ne=Q(e=>e.installMessages),re=Q(e=>e.installStarted),T=Q(e=>e.installSucceeded),E=Q(e=>e.uninstallSucceeded),D=x(e=>e.updateSnapshot),ae=D?.status===`checking`,oe=D?.packages.filter(e=>e.kind===`skill`&&!e.pinnedRef).filter(e=>e.update.availability===`outdated`||e.update.availability===`partial`).map(e=>e.id)??[],se=oe.length,ce=D?.lastCheckedAt?new Date(D.lastCheckedAt).toLocaleTimeString():null,le=j(gu),ue=j(_u),de=ae||le;async function fe(e){await B(C,()=>r.command(e))}function pe(){A(gu,()=>fe({type:`packages.checkUpdates`}))}function me(e){A(M(`packages.update`,e),()=>fe({type:`packages.update`,id:e}))}function he(){oe.length!==0&&A(_u,()=>fe({type:`packages.updateAll`,ids:oe}))}function ge(e){A(mu(e.id),()=>_e(e))}function N(e){A(M(`skills.uninstall`,e.name),()=>F(e))}let P=(0,V.useCallback)(async()=>{if(i!==`connected`)v();else try{y();let e=await r.command({type:`skills.listInstalled`});b(e.skills)}catch(e){S(Ye(e))}finally{ee()}},[i,r,v,y,b,S,ee]);(0,V.useEffect)(()=>{tn(`skills.listInstalled`,P())},[i,P,r]),(0,V.useEffect)(()=>{let e=a.trim();if(e.length<2){u(null);return}if(i!==`connected`){u(`Backend connection required.`);return}let t=!1;d();let o=n.setTimeout(()=>{r.command({type:`skills.search`,query:e,limit:100}).then(e=>{t||f(e.skills)}).catch(e=>{t||p(Ye(e))})},250);return()=>{t=!0,n.clearTimeout(o)}},[i,a,r,u,d,f,p,n]);async function _e(e){if(i!==`connected`)C(`Backend connection required.`);else try{re(e.skillId),await r.command({type:`skills.install`,source:e.source,skillId:e.skillId}),T(e.skillId),tn(`skills.listInstalled`,P())}catch(e){C(Ye(e))}}async function F(e){i===`connected`?await B(C,async()=>{await r.command({type:`skills.uninstall`,skillId:e.name}),E(e.name),tn(`skills.listInstalled`,P())}):C(`Backend connection required.`)}let ve;return ve=m.length>0?(0,H.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:m.map(e=>(0,H.jsx)(yu,{skill:e,packageEntry:D?.packages.find(t=>t.kind===`skill`&&t.name===e.name)??null,applying:D?.applying.includes(vu(e.name))??!1,onUninstall:N,onUpdate:me},`${e.source}/${e.name}`))}):g?null:(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:`No global skills installed.`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[te?(0,H.jsx)(bu,{message:te}):null,(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Installed`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ce?(0,H.jsxs)(`span`,{className:`tabular-nums text-xs text-muted-foreground`,children:[`Checked `,ce]}):null,se>0?(0,H.jsxs)(O,{size:`sm`,variant:`secondary`,className:`h-6 rounded-full px-2 text-xs`,pending:ue,onClick:he,children:[`Update all (`,se,`)`]}):null,(0,H.jsxs)(O,{size:`sm`,variant:`ghost`,className:`h-6 rounded-full px-2 text-xs`,disabled:de,"aria-busy":de||void 0,onClick:pe,children:[de?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):null,`Check`]}),g?(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}):null]})]}),_?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:_}):null,ve]}),(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`Discover`}),(0,H.jsxs)(`div`,{className:`flex h-10 items-center gap-2 rounded-lg border border-border bg-card/30 px-3`,children:[(0,H.jsx)(De,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,H.jsx)(`input`,{type:`text`,role:`searchbox`,value:a,onChange:e=>o(e.target.value),placeholder:`Search skills`,className:`min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground`}),a?(0,H.jsx)(`button`,{type:`button`,"aria-label":`Clear skills search`,onClick:()=>o(``),className:`touch-manipulation inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(Ie,{className:`h-3.5 w-3.5`})}):null,c?(0,H.jsx)(k,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):null]}),l?(0,H.jsx)(`div`,{className:`text-xs text-destructive`,children:l}):null,(0,H.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:s.map(e=>(0,H.jsx)(xu,{skill:e,installing:w[mu(e.id)]===!0,installed:h.has(e.skillId),message:ne[e.skillId],onInstall:()=>{ge(e)}},e.id))}),!c&&!l&&a.trim().length>=2&&s.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:`No skills found.`}):null]})]})}var Cu=`auto`;function wu(e){return e.triggerMode??`auto`}function Tu(e,t,n){return t?.[e].model||n?.find(t=>t.id===e)?.defaultModel||xn(e).defaultModel}function Eu(e,t){return e===`claude`?{...t?.claude.modelOptions??_n}:e===`codex`?{...t?.codex.modelOptions??On}:{}}function Du(e,t,n){return{name:``,provider:e,model:Tu(e,t,n),modelOptions:Eu(e,t),systemPrompt:``,contextScope:`previous-assistant-reply`,triggerMode:Cu}}function Ou(e){return{name:e.name,description:e.description,provider:e.provider,model:e.model,modelOptions:e.modelOptions,systemPrompt:e.systemPrompt,contextScope:e.contextScope,triggerMode:e.triggerMode,workingDir:e.workingDir,allowedPaths:e.allowedPaths,maxTurns:e.maxTurns,allowBeaconTools:e.allowBeaconTools}}function ku(e){return{...e,maxTurns:e.maxTurns??null}}function Au(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function ju(e,t){if(!Xe(e)||!Xe(t))return!1;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n)if(e[r]!==t[r])return!1;return!0}var Mu={name:(e,t)=>e.name===t.name,description:(e,t)=>(e.description??``)===(t.description??``),provider:(e,t)=>e.provider===t.provider,model:(e,t)=>e.model===t.model,modelOptions:(e,t)=>ju(e.modelOptions,t.modelOptions),systemPrompt:(e,t)=>e.systemPrompt===t.systemPrompt,contextScope:(e,t)=>e.contextScope===t.contextScope,triggerMode:(e,t)=>wu(e)===wu(t),workingDir:(e,t)=>(e.workingDir??``)===(t.workingDir??``),allowedPaths:(e,t)=>Au(e.allowedPaths,t.allowedPaths),maxTurns:(e,t)=>(e.maxTurns??null)===(t.maxTurns??null),allowBeaconTools:(e,t)=>(e.allowBeaconTools??!1)===(t.allowBeaconTools??!1)};function Nu(e,t){return Object.values(Mu).some(n=>!n(e,t))}var Pu=new Set([`EMPTY_NAME`,`INVALID_CHAR`,`RESERVED_NAME`,`DUPLICATE_NAME`,`TOO_LONG`]);function Fu(e){return Pu.has(e.code)?{field:`name`,message:e.message}:{field:`general`,message:e.message}}function Iu(e){return e.toLowerCase().replace(Yt,`-`).slice(0,64)}function Lu(){return{draft:Du(`claude`,void 0),error:null,confirmDelete:!1}}var Ru=L()(e=>({editing:Fo,form:Lu(),timeoutDraft:``,loopError:null,setEditing:t=>e({editing:t}),resetForm:t=>e({form:{draft:t,error:null,confirmDelete:!1}}),patchForm:t=>e(e=>({form:{...e.form,...t}})),patchFormDraft:t=>e(e=>({form:{...e.form,draft:{...e.form.draft,...t}}})),setTimeoutDraft:t=>e({timeoutDraft:t}),setLoopError:t=>e({loopError:t})}));function $(e){return(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e.label}),e.children,e.hint?(0,H.jsx)(`span`,{className:E(`text-xs`,e.hintTone===`destructive`?`text-destructive`:`text-muted-foreground`),children:e.hint}):null]})}function zu(e){let{draft:t,patchDraft:n}=e;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($,{label:`Working directory`,hint:`Optional. Relative to the parent chat cwd. Restricts the subagent's filesystem access to this subtree.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-working-dir`,value:t.workingDir??``,onChange:e=>{let t=e.target.value;n({workingDir:t.length>0?t:void 0})},placeholder:`docs`})}),(0,H.jsx)($,{label:`Allowed paths`,hint:`Optional. Newline-separated, relative to the parent chat cwd. When set, file tools can only read/write inside these roots.`,children:(0,H.jsx)(on,{"data-testid":`subagent-form-allowed-paths`,value:(t.allowedPaths??[]).join(`
|
|
14
14
|
`),onChange:e=>{let t=e.target.value.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);n({allowedPaths:t.length>0?t:void 0})},placeholder:`docs
|
|
15
|
-
wiki`,rows:3})}),(0,H.jsx)($,{label:`Beacon tools`,hint:`Off by default. When on, this subagent can run commands and read files on your paired machines. Each call still asks for your approval.`,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-foreground`,children:[(0,H.jsx)(`input`,{type:`checkbox`,"data-testid":`subagent-form-allow-beacon-tools`,checked:t.allowBeaconTools===!0,onChange:e=>{n({allowBeaconTools:e.target.checked})}}),(0,H.jsx)(`span`,{children:`Allow this subagent to use beacon tools (run on your paired machines)`})]})})]})}function Bu(e){return`contextWindow`in e}function Vu(e){return`fastMode`in e}function Hu(e){let t=e.editing,n=(0,V.useMemo)(()=>t.kind===`edit`?e.subagents.find(e=>e.id===t.id)??null:null,[t,e.subagents]),r=t.kind,i=r!==`list`,a=e.subagents.length===0;return a&&!i?(0,H.jsx)(Uu,{onStartCreate:e.onStartCreate}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6 md:flex-row md:items-start md:gap-8`,children:[a?null:(0,H.jsx)(Gu,{subagents:e.subagents,editing:e.editing,onSelect:e.onSelect,onStartCreate:e.onStartCreate}),i?(0,H.jsx)(Zu,{mode:r,subject:r===`edit`?n:null,providerDefaults:e.providerDefaults,availableProviders:e.availableProviders,handlers:e.handlers,onCancelEditing:e.onCancelEditing},r===`edit`?n?.id??`edit`:`create`):(0,H.jsx)(Wu,{})]})}function Uu(e){return(0,H.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 rounded-lg border border-dashed border-border px-6 py-14 text-center`,"data-testid":`subagent-empty`,children:[(0,H.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground`,children:(0,H.jsx)(Vn,{className:`size-5`,"aria-hidden":!0})}),(0,H.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`No subagents yet`}),(0,H.jsxs)(O,{variant:`default`,size:`sm`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1.5 size-4`}),` Create subagent`]})]})}function Wu(){return(0,H.jsx)(`div`,{className:`hidden flex-1 items-center justify-center rounded-lg border border-dashed border-border px-6 py-12 text-center text-sm text-muted-foreground md:flex`,children:`Select a subagent to edit, or create a new one.`})}function Gu(e){let t=e.editing.kind===`edit`?e.editing.id:null;return(0,H.jsxs)(`aside`,{className:`flex w-full flex-col gap-2 md:w-64 md:flex-shrink-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsxs)(`span`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,style:{fontVariantNumeric:`tabular-nums`},children:[e.subagents.length,` `,e.subagents.length===1?`agent`:`agents`]}),(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:e.onStartCreate,"data-testid":`subagent-create`,children:[(0,H.jsx)(Te,{className:`size-4`}),(0,H.jsx)(`span`,{className:`sr-only`,children:`Create subagent`})]})]}),(0,H.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.subagents.map(n=>{let r=n.description?.trim()||(n.contextScope===`previous-assistant-reply`?`Last reply`:`Full transcript`);return(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,"data-testid":`subagent-row:${n.id}`,onClick:()=>e.onSelect(n.id),className:E(`flex w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted`,t===n.id&&`bg-muted`),children:[(0,H.jsxs)(`span`,{className:`flex w-full items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:n.name}),(0,H.jsx)(Ku,{provider:n.provider})]}),(0,H.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:r})]})},n.id)})})]})}function Ku({provider:e}){let t=xn(e).label;return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-border bg-card px-1.5 py-0.5 text-xs font-medium tracking-wide text-muted-foreground`,children:[(0,H.jsx)(Vn,{className:`size-3`}),` `,t]})}function qu(e,t){return(e.some(e=>e.id===t)?e:[...e,xn(t)]).map(e=>({value:e.id,label:e.label}))}function Ju(e,t){return t.length===0?e:e.map(e=>e.id===`openrouter`?{...e,models:t.map(e=>({id:e.id,label:e.label}))}:e)}var Yu=[{value:`previous-assistant-reply`,label:`Last reply`},{value:`full-transcript`,label:`Full transcript`}],Xu=[{value:`auto`,label:`Auto`},{value:`manual`,label:`Manual`}];function Zu(e){let t=(0,V.useMemo)(()=>e.mode===`edit`&&e.subject?Ou(e.subject):Du(`claude`,e.providerDefaults,e.availableProviders),[e.mode,e.subject,e.providerDefaults,e.availableProviders]),n=Ru(e=>e.resetForm),r=Ru(e=>e.form),i=Ru(e=>e.patchFormDraft),a=Ru(e=>e.patchForm);(0,V.useEffect)(()=>{n(t)},[]);let{draft:o,error:s,confirmDelete:c}=r,l=M(`subagent.save`,e.subject?.id??`new`),u=M(`subagent.delete`,e.subject?.id??``),d=j(l),f=j(u),p=d||f,m=qu(e.availableProviders,o.provider),h=s?.field===`name`?s.message:null,g=s?.field===`general`?s.message:null,_=Nu(o,t),v=o.name.trim().length>0&&(e.mode===`create`||_);function y(e){i(e),s?.field===`name`&&`name`in e&&a({error:null})}function b(t){if(t===o.provider)return;let n=Du(t,e.providerDefaults,e.availableProviders);i({provider:t,model:n.model,modelOptions:n.modelOptions})}function x(e){if(o.provider!==`claude`)return;let t=Bu(o.modelOptions)?o.modelOptions:_n;i({modelOptions:{..._n,...t,reasoningEffort:e}})}function S(e){if(o.provider!==`claude`)return;let t=Bu(o.modelOptions)?o.modelOptions:_n;i({modelOptions:{..._n,...t,contextWindow:e}})}function ee(e){if(o.provider!==`codex`)return;let t=Vu(o.modelOptions)?o.modelOptions:On;i({modelOptions:{...On,...t,reasoningEffort:e}})}async function te(){if(v&&!f){a({error:null,confirmDelete:!1});try{let t=e.mode===`create`?await e.handlers.onCreate(o):await e.handlers.onUpdate(e.subject.id,o);t.ok||a({error:Fu(t.error)})}catch(e){a({error:{field:`general`,message:Ye(e)}})}}}async function C(){if(e.mode===`edit`&&e.subject){if(!c)a({confirmDelete:!0});else{a({error:null});try{await e.handlers.onDelete(e.subject.id)}catch(e){a({error:{field:`general`,message:Ye(e)}})}finally{a({confirmDelete:!1})}}}}let w=o.provider===`claude`?{..._n,...Bu(o.modelOptions)?o.modelOptions:{}}:null,ne=o.provider===`codex`?{...On,...Vu(o.modelOptions)?o.modelOptions:{}}:null,re=e.availableProviders.find(e=>e.id===o.provider)??xn(o.provider);return(0,H.jsxs)(`section`,{className:`flex w-full flex-1 flex-col gap-4`,children:[(0,H.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.mode===`create`?`New subagent`:o.name||`Subagent`}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Mention with `,(0,H.jsxs)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:[`@agent/`,o.name||`<name>`]}),` in chat.`]})]}),g?(0,H.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:g}):null,(0,H.jsx)($,{label:`Name`,hint:h,hintTone:h?`destructive`:`muted`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-name`,value:o.name,onChange:e=>y({name:Iu(e.target.value)}),maxLength:64,placeholder:`reviewer`,className:`font-mono`})}),(0,H.jsx)($,{label:`Description`,hint:`Optional. Shown next to the name.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-description`,value:o.description??``,onChange:e=>y({description:e.target.value}),placeholder:`Reviews diffs against the repo style`})}),(0,H.jsx)($,{label:`Provider`,children:(0,H.jsx)(I,{value:o.provider,onValueChange:e=>{tt(e)&&b(e)},options:m,size:`sm`})}),(0,H.jsx)($,{label:`Model`,children:(0,H.jsxs)(ve,{value:o.model,onValueChange:e=>y({model:e}),children:[(0,H.jsx)(ge,{"data-testid":`subagent-form-model`,className:`w-full md:w-72`,children:(0,H.jsx)(_e,{placeholder:`Select a model`})}),(0,H.jsx)(P,{children:re.models.map(e=>(0,H.jsx)(N,{value:e.id,children:e.label},e.id))})]})}),w?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($,{label:`Reasoning effort`,children:(0,H.jsx)(I,{value:w.reasoningEffort,onValueChange:e=>{hn(e)&&x(e)},options:Sn.map(e=>({value:e.id,label:e.label})),size:`sm`})}),(0,H.jsx)($,{label:`Context window`,children:(0,H.jsx)(I,{value:w.contextWindow,onValueChange:e=>{bn(e)&&S(e)},options:En.map(e=>({value:e.id,label:e.label})),size:`sm`})})]}):null,ne?(0,H.jsx)($,{label:`Reasoning effort`,children:(0,H.jsx)(I,{value:ne.reasoningEffort,onValueChange:e=>{kn(e)&&ee(e)},options:gn.map(e=>({value:e.id,label:e.label})),size:`sm`})}):null,(0,H.jsx)($,{label:`Context scope`,children:(0,H.jsx)(I,{value:o.contextScope,onValueChange:e=>{Dn(e)&&y({contextScope:e})},options:Yu,size:`sm`})}),(0,H.jsx)($,{label:`Trigger`,hint:`Auto: the main agent may delegate on its own. Manual: only runs when you @-mention it.`,children:(0,H.jsx)(I,{value:wu(o),onValueChange:e=>{Cn(e)&&y({triggerMode:e})},options:Xu,size:`sm`})}),(0,H.jsx)($,{label:`System prompt`,hint:`What this persona should focus on. Plain text.`,children:(0,H.jsx)(on,{"data-testid":`subagent-form-system-prompt`,value:o.systemPrompt,onChange:e=>y({systemPrompt:e.target.value}),placeholder:`You are a careful code reviewer...`,rows:6,className:`min-h-32`})}),(0,H.jsx)($,{label:`Max turns`,hint:`Optional. Caps the agentic turns per run (like Claude Code's per-agent maxTurns). Empty = unbounded. Claude SDK runs stop gracefully at the limit; Codex runs are aborted.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-max-turns`,type:`number`,min:1,step:1,value:o.maxTurns?.toString()??``,onChange:e=>{let t=Number.parseInt(e.target.value,10);y({maxTurns:Number.isInteger(t)&&t>0?t:void 0})},placeholder:`unbounded`,className:`w-36`})}),o.provider===`claude`?(0,H.jsx)(zu,{draft:o,patchDraft:y}):null,(0,H.jsxs)(`footer`,{className:`flex flex-wrap items-center justify-end gap-2 pt-2`,children:[(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:e.onCancelEditing,children:`Cancel`}),e.mode===`edit`?(0,H.jsx)(O,{variant:`destructive`,size:`sm`,"data-testid":`subagent-form-delete`,disabled:p,pending:f,onClick:()=>{A(u,C)},children:c?`Confirm delete`:`Delete`}):null,(0,H.jsx)(O,{variant:`default`,size:`sm`,"data-testid":`subagent-form-save`,disabled:!v||p,pending:d,onClick:()=>{A(l,te)},children:p?`Saving…`:`Save`})]})]})}var Qu=[];function $u(e){let t=z(e=>e.settings?.subagents??Qu),n=z(e=>e.settings?.providerDefaults),r=z(Bt),i=z(Gt),a=u(Se(e=>e.models)),o=(0,V.useMemo)(()=>Ju(Me(An([...yn],r),i),a),[r,i,a]),s=Ru(e=>e.editing),c=Ru(e=>e.setEditing),l=(0,V.useMemo)(()=>({onCreate:async t=>{let n=await e.state.socket.command({type:`subagent.create`,input:t});return n.ok&&c({kind:`edit`,id:n.subagent.id}),n},onUpdate:async(t,n)=>await e.state.socket.command({type:`subagent.update`,id:t,patch:ku(n)}),onDelete:async t=>{await e.state.socket.command({type:`subagent.delete`,id:t}),c({kind:`list`})}}),[e.state.socket,c]),d=(0,V.useCallback)(e=>{c({kind:`edit`,id:e})},[c]),f=(0,V.useCallback)(()=>{c({kind:`create`})},[c]),p=(0,V.useCallback)(()=>{c({kind:`list`})},[c]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-6 px-6 py-6`,children:[(0,H.jsx)(ad,{subagents:t,handleWriteAppSettings:e.state.handleWriteAppSettings}),(0,H.jsx)(Hu,{subagents:t,providerDefaults:n,availableProviders:o,editing:s,onSelect:d,onStartCreate:f,onCancelEditing:p,handlers:l})]})}var ed=`__none__`,td=$a.min/1e3,nd=$a.max/1e3,rd={min:td,max:nd,integer:!0},id=Qa/1e3;function ad(e){let t=z(e=>e.settings?.subagentRuntime),n=t?Math.round(t.runTimeoutMs/1e3):id,r=t?.defaultLoopSubagentId??null,i=Ru(e=>e.timeoutDraft),a=Ru(e=>e.setTimeoutDraft),o=Ru(e=>e.loopError),s=Ru(e=>e.setLoopError);(0,V.useEffect)(()=>{a(String(n))},[n]);function c(){let t=Number(i);qt(rd,t)?(s(null),t!==n&&e.handleWriteAppSettings({subagentRuntime:{runTimeoutMs:t*1e3}}).catch(Je(e=>s(e.message)))):(a(String(n)),s(`Timeout must be a whole number of seconds between ${td} and ${nd}.`))}function l(t){s(null);let n=t===ed?null:t;e.handleWriteAppSettings({subagentRuntime:{defaultLoopSubagentId:n}}).catch(Je(e=>s(e.message)))}return(0,H.jsxs)(`section`,{className:`flex flex-col gap-4 rounded-lg border border-border/60 bg-card/40 p-4`,children:[(0,H.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Loop & runtime`}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applies to background subagent runs and the autonomous `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono`,children:`/loop`}),`.`]})]}),o?(0,H.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:o}):null,(0,H.jsx)($,{label:`Stall timeout (seconds)`,hint:`A subagent run is aborted only after this long with no streamed activity — not a total wall-clock cap. A steadily-working run is never killed.`,children:(0,H.jsx)(R,{type:`number`,inputMode:`numeric`,min:td,max:nd,value:i,onChange:e=>a(e.target.value),onBlur:c,onKeyDown:e=>{e.key===`Enter`&&(c(),e.currentTarget.blur())},className:`w-full md:w-48 tabular-nums`})}),(0,H.jsx)($,{label:`Default loop subagent`,hint:`The subagent setup_loop delegates each chunk to when no explicit id is given.`,children:(0,H.jsxs)(ve,{value:r??ed,onValueChange:l,children:[(0,H.jsx)(ge,{className:`w-full md:w-72`,children:(0,H.jsx)(_e,{placeholder:`None`})}),(0,H.jsxs)(P,{children:[(0,H.jsx)(N,{value:ed,children:`None (require explicit id)`}),e.subagents.map(e=>(0,H.jsx)(N,{value:e.id,children:e.name},e.id))]})]})})]})}function od(e,t){return{shortcut:e,expansion:t,error:null}}var sd=L()(e=>({editing:Fo,editorForm:od(``,``),setEditing:t=>e({editing:t}),resetEditorForm:(t,n)=>e({editorForm:od(t,n)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}}))}));function cd({snippets:e,handlers:t,dom:n=nn}){let r=sd(e=>e.editing),i=sd(e=>e.setEditing),a=sd(e=>e.resetEditorForm);function o(t){if(t.kind===`create`)a(``,``);else if(t.kind===`edit`){let n=e.find(e=>e.id===t.id)??null;n&&a(n.shortcut,n.expansion)}i(t)}if(r.kind!==`list`){let n=r.kind===`edit`?e.find(e=>e.id===r.id)??null:null;return(0,H.jsx)(ud,{initial:n,existing:e.map(e=>({id:e.id,shortcut:e.shortcut})),handlers:t,onDone:()=>i({kind:`list`})})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Text snippets`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Type a shortcut in the chat composer and press Tab to expand it into the full text. Handy for prompts you send often.`})]}),(0,H.jsxs)(O,{size:`sm`,onClick:()=>o({kind:`create`}),children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add snippet`]})]}),e.length===0?(0,H.jsx)(ti,{icon:qr,message:`No snippets yet. Add one to expand a shortcut with Tab.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(ld,{snippet:e,onEdit:()=>o({kind:`edit`,id:e.id}),onDelete:t.onDelete,dom:n},e.id))})]})}function ld({snippet:e,onEdit:t,onDelete:n,dom:r}){let i=M(`textSnippets.delete`,e.id),a=j(i),o=(0,V.useCallback)(()=>{r.confirmDialog(`Delete snippet "${e.shortcut}"?`)&&A(i,()=>n(e.id))},[i,r,n,e.id,e.shortcut]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-sm`,children:e.shortcut}),(0,H.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.expansion})]}),(0,H.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,H.jsx)(ri,{label:e.shortcut,onEdit:t,onDelete:o,deletePending:a})})]})}function ud({initial:e,existing:t,handlers:n,onDone:r}){let i=sd(e=>e.editorForm),a=sd(e=>e.patchEditorForm),{shortcut:o,expansion:s,error:c}=i,l=M(`textSnippets.save`,e?.id??`new`),u=j(l),d=e!==null,f=o.trim(),p=Qt.test(f),m=(0,V.useMemo)(()=>t.some(t=>t.shortcut===f&&t.id!==e?.id),[t,f,e?.id]),h=p&&!m&&s.length>0&&!u,g=()=>Ho({patch:a,save:async()=>{d&&e?await n.onUpdate(e.id,{shortcut:f,expansion:s}):await n.onCreate({shortcut:f,expansion:s})},onDone:r}),_=Uo({submitting:u,isEdit:d,addLabel:`Add snippet`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:d?`Edit snippet`:`Add snippet`}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Shortcut`}),(0,H.jsx)(R,{value:o,onChange:e=>a({shortcut:e.target.value}),placeholder:`pgm`,className:`font-mono`,autoFocus:!0}),o.length>0&&!p&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:`Shortcut must be 1-32 characters with no spaces.`}),m&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:`A snippet with this shortcut already exists.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Expands to`}),(0,H.jsx)(on,{value:s,onChange:e=>a({expansion:e.target.value}),placeholder:`pull request green then merge`,rows:4})]}),c&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:c}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:()=>{A(l,g)},pending:u,disabled:!h,children:_}),(0,H.jsx)(O,{variant:`ghost`,onClick:r,disabled:u,children:`Cancel`})]})]})}function dd(e){let t=z(xt),n=Bo(`textSnippets`,e.state);return(0,H.jsx)(cd,{snippets:t,handlers:n})}var fd=M(`packages.checkUpdates`);function pd(e){return M(`packages.update`,e)}var md=[],hd=[],gd=[],_d=[];function vd({pkg:e,packageEntry:t,applying:n,onUpdate:r}){let i=j(pd(e.id)),a=n||i,o=e.versionLabel??e.version??e.revision?.slice(0,7)??null,s=iu(t);return(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),o?(0,H.jsx)(`div`,{className:`font-mono tabular-nums text-xs text-muted-foreground/70`,children:o}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,H.jsx)(au,{availability:t?.update.availability}),s?(0,H.jsx)(ou,{label:s,updating:a,onClick:r}):null,e.sourceUrl?(0,H.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} source`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(In,{className:`h-4 w-4`})}):null]})]})}function yd({source:e,packages:t,updateEntries:n,applying:r,isChecking:i,onCheckUpdates:a,onUpdate:o}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`div`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,children:e}),(0,H.jsxs)(O,{size:`sm`,variant:`ghost`,className:`h-6 rounded-full px-2 text-xs`,disabled:i,"aria-busy":i||void 0,onClick:a,children:[i?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):(0,H.jsx)(Ee,{className:`mr-1 h-3 w-3`}),`Refresh`]})]}),(0,H.jsx)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:t.map(e=>{let t=n.find(t=>t.id===e.id)??null;return(0,H.jsx)(vd,{pkg:e,packageEntry:t,applying:r.includes(e.id),onUpdate:()=>o(e.id)},e.id)})})]})}function bd({label:e,kind:t,packages:n,errors:r,updateEntries:i,applying:a,isChecking:o,onCheckUpdates:s,onUpdate:c}){let l=r.find(e=>e.kind===t),u=n.filter(e=>e.kind===t),d=new Map;for(let e of u){let t=e.source||`Unknown`,n=d.get(t);n?n.push(e):d.set(t,[e])}let f=t===`claude-plugin`?`Claude Code CLI`:`Codex CLI`,p;return p=l?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:[f,` not found — install it to manage `,e,` plugins.`]}):u.length===0?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:[`No `,e,` plugins installed.`]}):(0,H.jsx)(`div`,{className:`flex flex-col gap-4`,children:[...d.entries()].map(([e,t])=>(0,H.jsx)(yd,{source:e,packages:t,updateEntries:i,applying:a,isChecking:o,onCheckUpdates:s,onUpdate:c},e))}),(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e}),p]})}function xd({state:e}){let{socket:t,connectionStatus:n}=e,r=x(e=>e.inventory),i=x(e=>e.loading),a=x(e=>e.error),o=x(e=>e.inventoryCleared),s=x(e=>e.inventoryLoadStarted),c=x(e=>e.inventoryLoaded),l=x(e=>e.inventoryLoadFailed),u=x(e=>e.inventoryLoadFinished),d=x(e=>e.updateSnapshot),f=(0,V.useCallback)(async()=>{if(n!==`connected`)o();else try{s(),c(await t.command({type:`packages.listInstalled`}))}catch(e){l(Ye(e))}finally{u()}},[n,t,o,s,c,l,u]);(0,V.useEffect)(()=>{tn(`packages.listInstalled`,f())},[f]);let p=(0,V.useCallback)(()=>{A(fd,()=>sn(t,{type:`packages.checkUpdates`}))},[t]),m=(0,V.useCallback)(e=>{A(pd(e),()=>sn(t,{type:`packages.update`,id:e}))},[t]),h=j(fd),g=d?.status===`checking`||h,_=d?.applying??_d,v=d?.packages.filter(e=>e.kind===`claude-plugin`||e.kind===`codex-plugin`)??gd,y=r?.packages??md,b=r?.errors??hd;return a?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:a}):i&&!r?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,H.jsx)(bd,{label:`Claude Code`,kind:`claude-plugin`,packages:y,errors:b,updateEntries:v,applying:_,isChecking:g,onCheckUpdates:p,onUpdate:m}),(0,H.jsx)(bd,{label:`Codex`,kind:`codex-plugin`,packages:y,errors:b,updateEntries:v,applying:_,isChecking:g,onCheckUpdates:p,onUpdate:m})]})}var Sd=L()(e=>({publicUrlDraft:null,error:null,setPublicUrlDraft:t=>e({publicUrlDraft:t}),setError:t=>e({error:t})})),Cd=`<your Kanna password>`,wd=`Start Kanna with --password first; the remote MCP server is off without it. `,Td=`The URL must be https and reachable from the internet (a Cloudflare tunnel or --share).`;function Ed(e){return`${e}/mcp`}function Dd({publicOrigin:e,passwordConfigured:t}){let n=Ed(e??`https://<your-public-kanna-url>`),r=t?``:wd;return[{id:`claude-code`,client:`claude-code`,title:`Claude Code`,instructions:`${r}Add the server with your Kanna password as a bearer header, or add it without one and sign in through OAuth.`,snippet:[`claude mcp add --transport http kanna ${n} --header "Authorization: Bearer ${Cd}"`,``,`claude mcp add --transport http kanna ${n}`,`# then run /mcp inside Claude Code and choose Authenticate to sign in with OAuth`].join(`
|
|
15
|
+
wiki`,rows:3})}),(0,H.jsx)($,{label:`Beacon tools`,hint:`Off by default. When on, this subagent can run commands and read files on your paired machines. Each call still asks for your approval.`,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-foreground`,children:[(0,H.jsx)(`input`,{type:`checkbox`,"data-testid":`subagent-form-allow-beacon-tools`,checked:t.allowBeaconTools===!0,onChange:e=>{n({allowBeaconTools:e.target.checked})}}),(0,H.jsx)(`span`,{children:`Allow this subagent to use beacon tools (run on your paired machines)`})]})})]})}function Bu(e){return`contextWindow`in e}function Vu(e){return`fastMode`in e}function Hu(e){let t=e.editing,n=(0,V.useMemo)(()=>t.kind===`edit`?e.subagents.find(e=>e.id===t.id)??null:null,[t,e.subagents]),r=t.kind,i=r!==`list`,a=e.subagents.length===0;return a&&!i?(0,H.jsx)(Uu,{onStartCreate:e.onStartCreate}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6 md:flex-row md:items-start md:gap-8`,children:[a?null:(0,H.jsx)(Gu,{subagents:e.subagents,editing:e.editing,onSelect:e.onSelect,onStartCreate:e.onStartCreate}),i?(0,H.jsx)(Zu,{mode:r,subject:r===`edit`?n:null,providerDefaults:e.providerDefaults,availableProviders:e.availableProviders,handlers:e.handlers,onCancelEditing:e.onCancelEditing},r===`edit`?n?.id??`edit`:`create`):(0,H.jsx)(Wu,{})]})}function Uu(e){return(0,H.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 rounded-lg border border-dashed border-border px-6 py-14 text-center`,"data-testid":`subagent-empty`,children:[(0,H.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground`,children:(0,H.jsx)(Vn,{className:`size-5`,"aria-hidden":!0})}),(0,H.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`No subagents yet`}),(0,H.jsxs)(O,{variant:`default`,size:`sm`,onClick:e.onStartCreate,children:[(0,H.jsx)(Te,{className:`mr-1.5 size-4`}),` Create subagent`]})]})}function Wu(){return(0,H.jsx)(`div`,{className:`hidden flex-1 items-center justify-center rounded-lg border border-dashed border-border px-6 py-12 text-center text-sm text-muted-foreground md:flex`,children:`Select a subagent to edit, or create a new one.`})}function Gu(e){let t=e.editing.kind===`edit`?e.editing.id:null;return(0,H.jsxs)(`aside`,{className:`flex w-full flex-col gap-2 md:w-64 md:flex-shrink-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsxs)(`span`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,style:{fontVariantNumeric:`tabular-nums`},children:[e.subagents.length,` `,e.subagents.length===1?`agent`:`agents`]}),(0,H.jsxs)(O,{variant:`ghost`,size:`sm`,onClick:e.onStartCreate,"data-testid":`subagent-create`,children:[(0,H.jsx)(Te,{className:`size-4`}),(0,H.jsx)(`span`,{className:`sr-only`,children:`Create subagent`})]})]}),(0,H.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.subagents.map(n=>{let r=n.description?.trim()||(n.contextScope===`previous-assistant-reply`?`Last reply`:`Full transcript`);return(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,"data-testid":`subagent-row:${n.id}`,onClick:()=>e.onSelect(n.id),className:E(`flex w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted`,t===n.id&&`bg-muted`),children:[(0,H.jsxs)(`span`,{className:`flex w-full items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:n.name}),(0,H.jsx)(Ku,{provider:n.provider})]}),(0,H.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:r})]})},n.id)})})]})}function Ku({provider:e}){let t=xn(e).label;return(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-border bg-card px-1.5 py-0.5 text-xs font-medium tracking-wide text-muted-foreground`,children:[(0,H.jsx)(Vn,{className:`size-3`}),` `,t]})}function qu(e,t){return(e.some(e=>e.id===t)?e:[...e,xn(t)]).map(e=>({value:e.id,label:e.label}))}function Ju(e,t){return t.length===0?e:e.map(e=>e.id===`openrouter`?{...e,models:t.map(e=>({id:e.id,label:e.label}))}:e)}var Yu=[{value:`previous-assistant-reply`,label:`Last reply`},{value:`full-transcript`,label:`Full transcript`}],Xu=[{value:`auto`,label:`Auto`},{value:`manual`,label:`Manual`}];function Zu(e){let t=(0,V.useMemo)(()=>e.mode===`edit`&&e.subject?Ou(e.subject):Du(`claude`,e.providerDefaults,e.availableProviders),[e.mode,e.subject,e.providerDefaults,e.availableProviders]),n=Ru(e=>e.resetForm),r=Ru(e=>e.form),i=Ru(e=>e.patchFormDraft),a=Ru(e=>e.patchForm);(0,V.useEffect)(()=>{n(t)},[]);let{draft:o,error:s,confirmDelete:c}=r,l=M(`subagent.save`,e.subject?.id??`new`),u=M(`subagent.delete`,e.subject?.id??``),d=j(l),f=j(u),p=d||f,m=qu(e.availableProviders,o.provider),h=s?.field===`name`?s.message:null,g=s?.field===`general`?s.message:null,_=Nu(o,t),v=o.name.trim().length>0&&(e.mode===`create`||_);function y(e){i(e),s?.field===`name`&&`name`in e&&a({error:null})}function b(t){if(t===o.provider)return;let n=Du(t,e.providerDefaults,e.availableProviders);i({provider:t,model:n.model,modelOptions:n.modelOptions})}function x(e){if(o.provider!==`claude`)return;let t=Bu(o.modelOptions)?o.modelOptions:_n;i({modelOptions:{..._n,...t,reasoningEffort:e}})}function S(e){if(o.provider!==`claude`)return;let t=Bu(o.modelOptions)?o.modelOptions:_n;i({modelOptions:{..._n,...t,contextWindow:e}})}function ee(e){if(o.provider!==`codex`)return;let t=Vu(o.modelOptions)?o.modelOptions:On;i({modelOptions:{...On,...t,reasoningEffort:e}})}async function te(){if(v&&!f){a({error:null,confirmDelete:!1});try{let t=e.mode===`create`?await e.handlers.onCreate(o):await e.handlers.onUpdate(e.subject.id,o);t.ok||a({error:Fu(t.error)})}catch(e){a({error:{field:`general`,message:Ye(e)}})}}}async function C(){if(e.mode===`edit`&&e.subject){if(!c)a({confirmDelete:!0});else{a({error:null});try{await e.handlers.onDelete(e.subject.id)}catch(e){a({error:{field:`general`,message:Ye(e)}})}finally{a({confirmDelete:!1})}}}}let w=o.provider===`claude`?{..._n,...Bu(o.modelOptions)?o.modelOptions:{}}:null,ne=o.provider===`codex`?{...On,...Vu(o.modelOptions)?o.modelOptions:{}}:null,re=e.availableProviders.find(e=>e.id===o.provider)??xn(o.provider);return(0,H.jsxs)(`section`,{className:`flex w-full flex-1 flex-col gap-4`,children:[(0,H.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.mode===`create`?`New subagent`:o.name||`Subagent`}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Mention with `,(0,H.jsxs)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:[`@agent/`,o.name||`<name>`]}),` in chat.`]})]}),g?(0,H.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive`,children:g}):null,(0,H.jsx)($,{label:`Name`,hint:h,hintTone:h?`destructive`:`muted`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-name`,value:o.name,onChange:e=>y({name:Iu(e.target.value)}),maxLength:64,placeholder:`reviewer`,className:`font-mono`})}),(0,H.jsx)($,{label:`Description`,hint:`Optional. Shown next to the name.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-description`,value:o.description??``,onChange:e=>y({description:e.target.value}),placeholder:`Reviews diffs against the repo style`})}),(0,H.jsx)($,{label:`Provider`,children:(0,H.jsx)(I,{value:o.provider,onValueChange:e=>{tt(e)&&b(e)},options:m,size:`sm`})}),(0,H.jsx)($,{label:`Model`,children:(0,H.jsxs)(ve,{value:o.model,onValueChange:e=>y({model:e}),children:[(0,H.jsx)(ge,{"data-testid":`subagent-form-model`,className:`w-full md:w-72`,children:(0,H.jsx)(_e,{placeholder:`Select a model`})}),(0,H.jsx)(P,{children:re.models.map(e=>(0,H.jsx)(N,{value:e.id,children:e.label},e.id))})]})}),w?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($,{label:`Reasoning effort`,children:(0,H.jsx)(I,{value:w.reasoningEffort,onValueChange:e=>{hn(e)&&x(e)},options:Sn.map(e=>({value:e.id,label:e.label})),size:`sm`})}),(0,H.jsx)($,{label:`Context window`,children:(0,H.jsx)(I,{value:w.contextWindow,onValueChange:e=>{bn(e)&&S(e)},options:En.map(e=>({value:e.id,label:e.label})),size:`sm`})})]}):null,ne?(0,H.jsx)($,{label:`Reasoning effort`,children:(0,H.jsx)(I,{value:ne.reasoningEffort,onValueChange:e=>{kn(e)&&ee(e)},options:gn.map(e=>({value:e.id,label:e.label})),size:`sm`})}):null,(0,H.jsx)($,{label:`Context scope`,children:(0,H.jsx)(I,{value:o.contextScope,onValueChange:e=>{Dn(e)&&y({contextScope:e})},options:Yu,size:`sm`})}),(0,H.jsx)($,{label:`Trigger`,hint:`Auto: the main agent may delegate on its own. Manual: only runs when you @-mention it.`,children:(0,H.jsx)(I,{value:wu(o),onValueChange:e=>{Cn(e)&&y({triggerMode:e})},options:Xu,size:`sm`})}),(0,H.jsx)($,{label:`System prompt`,hint:`What this persona should focus on. Plain text.`,children:(0,H.jsx)(on,{"data-testid":`subagent-form-system-prompt`,value:o.systemPrompt,onChange:e=>y({systemPrompt:e.target.value}),placeholder:`You are a careful code reviewer...`,rows:6,className:`min-h-32`})}),(0,H.jsx)($,{label:`Max turns`,hint:`Optional. Caps the agentic turns per run (like Claude Code's per-agent maxTurns). Empty = unbounded. Claude SDK runs stop gracefully at the limit; Codex runs are aborted.`,children:(0,H.jsx)(R,{"data-testid":`subagent-form-max-turns`,type:`number`,min:1,step:1,value:o.maxTurns?.toString()??``,onChange:e=>{let t=Number.parseInt(e.target.value,10);y({maxTurns:Number.isInteger(t)&&t>0?t:void 0})},placeholder:`unbounded`,className:`w-36`})}),o.provider===`claude`?(0,H.jsx)(zu,{draft:o,patchDraft:y}):null,(0,H.jsxs)(`footer`,{className:`flex flex-wrap items-center justify-end gap-2 pt-2`,children:[(0,H.jsx)(O,{variant:`ghost`,size:`sm`,onClick:e.onCancelEditing,children:`Cancel`}),e.mode===`edit`?(0,H.jsx)(O,{variant:`destructive`,size:`sm`,"data-testid":`subagent-form-delete`,disabled:p,pending:f,onClick:()=>{A(u,C)},children:c?`Confirm delete`:`Delete`}):null,(0,H.jsx)(O,{variant:`default`,size:`sm`,"data-testid":`subagent-form-save`,disabled:!v||p,pending:d,onClick:()=>{A(l,te)},children:p?`Saving…`:`Save`})]})]})}var Qu=[];function $u(e){let t=z(e=>e.settings?.subagents??Qu),n=z(e=>e.settings?.providerDefaults),r=z(Bt),i=z(Gt),a=u(Se(e=>e.models)),o=(0,V.useMemo)(()=>Ju(Me(An([...yn],r),i),a),[r,i,a]),s=Ru(e=>e.editing),c=Ru(e=>e.setEditing),l=(0,V.useMemo)(()=>({onCreate:async t=>{let n=await e.state.socket.command({type:`subagent.create`,input:t});return n.ok&&c({kind:`edit`,id:n.subagent.id}),n},onUpdate:async(t,n)=>await e.state.socket.command({type:`subagent.update`,id:t,patch:ku(n)}),onDelete:async t=>{await e.state.socket.command({type:`subagent.delete`,id:t}),c({kind:`list`})}}),[e.state.socket,c]),d=(0,V.useCallback)(e=>{c({kind:`edit`,id:e})},[c]),f=(0,V.useCallback)(()=>{c({kind:`create`})},[c]),p=(0,V.useCallback)(()=>{c({kind:`list`})},[c]);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-6 px-6 py-6`,children:[(0,H.jsx)(ad,{subagents:t,handleWriteAppSettings:e.state.handleWriteAppSettings}),(0,H.jsx)(Hu,{subagents:t,providerDefaults:n,availableProviders:o,editing:s,onSelect:d,onStartCreate:f,onCancelEditing:p,handlers:l})]})}var ed=`__none__`,td=$a.min/1e3,nd=$a.max/1e3,rd={min:td,max:nd,integer:!0},id=Qa/1e3;function ad(e){let t=z(e=>e.settings?.subagentRuntime),n=t?Math.round(t.runTimeoutMs/1e3):id,r=t?.defaultLoopSubagentId??null,i=Ru(e=>e.timeoutDraft),a=Ru(e=>e.setTimeoutDraft),o=Ru(e=>e.loopError),s=Ru(e=>e.setLoopError);(0,V.useEffect)(()=>{a(String(n))},[n]);function c(){let t=Number(i);qt(rd,t)?(s(null),t!==n&&e.handleWriteAppSettings({subagentRuntime:{runTimeoutMs:t*1e3}}).catch(Je(e=>s(e.message)))):(a(String(n)),s(`Timeout must be a whole number of seconds between ${td} and ${nd}.`))}function l(t){s(null);let n=t===ed?null:t;e.handleWriteAppSettings({subagentRuntime:{defaultLoopSubagentId:n}}).catch(Je(e=>s(e.message)))}return(0,H.jsxs)(`section`,{className:`flex flex-col gap-4 rounded-lg border border-border/60 bg-card/40 p-4`,children:[(0,H.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Loop & runtime`}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applies to background subagent runs and the autonomous `,(0,H.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono`,children:`/loop`}),`.`]})]}),o?(0,H.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:o}):null,(0,H.jsx)($,{label:`Stall timeout (seconds)`,hint:`A subagent run is aborted only after this long with no streamed activity — not a total wall-clock cap. A steadily-working run is never killed.`,children:(0,H.jsx)(R,{type:`number`,inputMode:`numeric`,min:td,max:nd,value:i,onChange:e=>a(e.target.value),onBlur:c,onKeyDown:e=>{e.key===`Enter`&&(c(),e.currentTarget.blur())},className:`w-full md:w-48 tabular-nums`})}),(0,H.jsx)($,{label:`Default loop subagent`,hint:`The subagent setup_loop delegates each chunk to when no explicit id is given.`,children:(0,H.jsxs)(ve,{value:r??ed,onValueChange:l,children:[(0,H.jsx)(ge,{className:`w-full md:w-72`,children:(0,H.jsx)(_e,{placeholder:`None`})}),(0,H.jsxs)(P,{children:[(0,H.jsx)(N,{value:ed,children:`None (require explicit id)`}),e.subagents.map(e=>(0,H.jsx)(N,{value:e.id,children:e.name},e.id))]})]})})]})}function od(e,t){return{shortcut:e,expansion:t,error:null}}var sd=L()(e=>({editing:Fo,editorForm:od(``,``),setEditing:t=>e({editing:t}),resetEditorForm:(t,n)=>e({editorForm:od(t,n)}),patchEditorForm:t=>e(e=>({editorForm:{...e.editorForm,...t}}))}));function cd({snippets:e,handlers:t,dom:n=nn}){let r=sd(e=>e.editing),i=sd(e=>e.setEditing),a=sd(e=>e.resetEditorForm);function o(t){if(t.kind===`create`)a(``,``);else if(t.kind===`edit`){let n=e.find(e=>e.id===t.id)??null;n&&a(n.shortcut,n.expansion)}i(t)}if(r.kind!==`list`){let n=r.kind===`edit`?e.find(e=>e.id===r.id)??null:null;return(0,H.jsx)(ud,{initial:n,existing:e.map(e=>({id:e.id,shortcut:e.shortcut})),handlers:t,onDone:()=>i({kind:`list`})})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:`Text snippets`}),(0,H.jsx)(`p`,{className:`max-w-[65ch] text-sm text-muted-foreground`,children:`Type a shortcut in the chat composer and press Tab to expand it into the full text. Handy for prompts you send often.`})]}),(0,H.jsxs)(O,{size:`sm`,onClick:()=>o({kind:`create`}),children:[(0,H.jsx)(Te,{className:`mr-1 h-4 w-4`}),`Add snippet`]})]}),e.length===0?(0,H.jsx)(ti,{icon:qr,message:`No snippets yet. Add one to expand a shortcut with Tab.`}):(0,H.jsx)(ni,{children:e.map(e=>(0,H.jsx)(ld,{snippet:e,onEdit:()=>o({kind:`edit`,id:e.id}),onDelete:t.onDelete,dom:n},e.id))})]})}function ld({snippet:e,onEdit:t,onDelete:n,dom:r}){let i=M(`textSnippets.delete`,e.id),a=j(i),o=(0,V.useCallback)(()=>{r.confirmDialog(`Delete snippet "${e.shortcut}"?`)&&A(i,()=>n(e.id))},[i,r,n,e.id,e.shortcut]);return(0,H.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,"aria-busy":a||void 0,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-sm`,children:e.shortcut}),(0,H.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.expansion})]}),(0,H.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,H.jsx)(ri,{label:e.shortcut,onEdit:t,onDelete:o,deletePending:a})})]})}function ud({initial:e,existing:t,handlers:n,onDone:r}){let i=sd(e=>e.editorForm),a=sd(e=>e.patchEditorForm),{shortcut:o,expansion:s,error:c}=i,l=M(`textSnippets.save`,e?.id??`new`),u=j(l),d=e!==null,f=o.trim(),p=Qt.test(f),m=(0,V.useMemo)(()=>t.some(t=>t.shortcut===f&&t.id!==e?.id),[t,f,e?.id]),h=p&&!m&&s.length>0&&!u,g=()=>Ho({patch:a,save:async()=>{d&&e?await n.onUpdate(e.id,{shortcut:f,expansion:s}):await n.onCreate({shortcut:f,expansion:s})},onDone:r}),_=Uo({submitting:u,isEdit:d,addLabel:`Add snippet`});return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 px-6 py-6`,children:[(0,H.jsx)(`h2`,{className:`text-base font-medium`,children:d?`Edit snippet`:`Add snippet`}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Shortcut`}),(0,H.jsx)(R,{value:o,onChange:e=>a({shortcut:e.target.value}),placeholder:`pgm`,className:`font-mono`,autoFocus:!0}),o.length>0&&!p&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:`Shortcut must be 1-32 characters with no spaces.`}),m&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:`A snippet with this shortcut already exists.`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:`Expands to`}),(0,H.jsx)(on,{value:s,onChange:e=>a({expansion:e.target.value}),placeholder:`pull request green then merge`,rows:4})]}),c&&(0,H.jsx)(`span`,{className:`text-xs text-destructive`,children:c}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{onClick:()=>{A(l,g)},pending:u,disabled:!h,children:_}),(0,H.jsx)(O,{variant:`ghost`,onClick:r,disabled:u,children:`Cancel`})]})]})}function dd(e){let t=z(xt),n=Bo(`textSnippets`,e.state);return(0,H.jsx)(cd,{snippets:t,handlers:n})}var fd=M(`packages.checkUpdates`);function pd(e){return M(`packages.update`,e)}var md=[],hd=[],gd=[],_d=[];function vd({pkg:e,packageEntry:t,applying:n,onUpdate:r}){let i=j(pd(e.id)),a=n||i,o=e.versionLabel??e.version??e.revision?.slice(0,7)??null,s=iu(t);return(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3 rounded-lg border border-border bg-card/30 p-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),o?(0,H.jsx)(`div`,{className:`font-mono tabular-nums text-xs text-muted-foreground/70`,children:o}):null]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,H.jsx)(au,{availability:t?.update.availability}),s?(0,H.jsx)(ou,{label:s,updating:a,onClick:r}):null,e.sourceUrl?(0,H.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,"aria-label":`View ${e.name} source`,className:`touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,H.jsx)(Fn,{className:`h-4 w-4`})}):null]})]})}function yd({source:e,packages:t,updateEntries:n,applying:r,isChecking:i,onCheckUpdates:a,onUpdate:o}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`div`,{className:`text-xs font-medium tracking-wide text-muted-foreground`,children:e}),(0,H.jsxs)(O,{size:`sm`,variant:`ghost`,className:`h-6 rounded-full px-2 text-xs`,disabled:i,"aria-busy":i||void 0,onClick:a,children:[i?(0,H.jsx)(k,{className:`mr-1 h-3 w-3 animate-spin`}):(0,H.jsx)(Ee,{className:`mr-1 h-3 w-3`}),`Refresh`]})]}),(0,H.jsx)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:t.map(e=>{let t=n.find(t=>t.id===e.id)??null;return(0,H.jsx)(vd,{pkg:e,packageEntry:t,applying:r.includes(e.id),onUpdate:()=>o(e.id)},e.id)})})]})}function bd({label:e,kind:t,packages:n,errors:r,updateEntries:i,applying:a,isChecking:o,onCheckUpdates:s,onUpdate:c}){let l=r.find(e=>e.kind===t),u=n.filter(e=>e.kind===t),d=new Map;for(let e of u){let t=e.source||`Unknown`,n=d.get(t);n?n.push(e):d.set(t,[e])}let f=t===`claude-plugin`?`Claude Code CLI`:`Codex CLI`,p;return p=l?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:[f,` not found — install it to manage `,e,` plugins.`]}):u.length===0?(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground`,children:[`No `,e,` plugins installed.`]}):(0,H.jsx)(`div`,{className:`flex flex-col gap-4`,children:[...d.entries()].map(([e,t])=>(0,H.jsx)(yd,{source:e,packages:t,updateEntries:i,applying:a,isChecking:o,onCheckUpdates:s,onUpdate:c},e))}),(0,H.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e}),p]})}function xd({state:e}){let{socket:t,connectionStatus:n}=e,r=x(e=>e.inventory),i=x(e=>e.loading),a=x(e=>e.error),o=x(e=>e.inventoryCleared),s=x(e=>e.inventoryLoadStarted),c=x(e=>e.inventoryLoaded),l=x(e=>e.inventoryLoadFailed),u=x(e=>e.inventoryLoadFinished),d=x(e=>e.updateSnapshot),f=(0,V.useCallback)(async()=>{if(n!==`connected`)o();else try{s(),c(await t.command({type:`packages.listInstalled`}))}catch(e){l(Ye(e))}finally{u()}},[n,t,o,s,c,l,u]);(0,V.useEffect)(()=>{tn(`packages.listInstalled`,f())},[f]);let p=(0,V.useCallback)(()=>{A(fd,()=>sn(t,{type:`packages.checkUpdates`}))},[t]),m=(0,V.useCallback)(e=>{A(pd(e),()=>sn(t,{type:`packages.update`,id:e}))},[t]),h=j(fd),g=d?.status===`checking`||h,_=d?.applying??_d,v=d?.packages.filter(e=>e.kind===`claude-plugin`||e.kind===`codex-plugin`)??gd,y=r?.packages??md,b=r?.errors??hd;return a?(0,H.jsx)(`div`,{className:`rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive`,children:a}):i&&!r?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,H.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,H.jsx)(bd,{label:`Claude Code`,kind:`claude-plugin`,packages:y,errors:b,updateEntries:v,applying:_,isChecking:g,onCheckUpdates:p,onUpdate:m}),(0,H.jsx)(bd,{label:`Codex`,kind:`codex-plugin`,packages:y,errors:b,updateEntries:v,applying:_,isChecking:g,onCheckUpdates:p,onUpdate:m})]})}var Sd=L()(e=>({publicUrlDraft:null,error:null,setPublicUrlDraft:t=>e({publicUrlDraft:t}),setError:t=>e({error:t})})),Cd=`<your Kanna password>`,wd=`Start Kanna with --password first; the remote MCP server is off without it. `,Td=`The URL must be https and reachable from the internet (a Cloudflare tunnel or --share).`;function Ed(e){return`${e}/mcp`}function Dd({publicOrigin:e,passwordConfigured:t}){let n=Ed(e??`https://<your-public-kanna-url>`),r=t?``:wd;return[{id:`claude-code`,client:`claude-code`,title:`Claude Code`,instructions:`${r}Add the server with your Kanna password as a bearer header, or add it without one and sign in through OAuth.`,snippet:[`claude mcp add --transport http kanna ${n} --header "Authorization: Bearer ${Cd}"`,``,`claude mcp add --transport http kanna ${n}`,`# then run /mcp inside Claude Code and choose Authenticate to sign in with OAuth`].join(`
|
|
16
16
|
`)},{id:`codex`,client:`codex`,title:`Codex`,instructions:`${r}Put the block in ~/.codex/config.toml and export your Kanna password as KANNA_PASSWORD, or sign in through OAuth instead.`,snippet:[`[mcp_servers.kanna]`,`url = "${n}"`,`bearer_token_env_var = "KANNA_PASSWORD"`,``,`# OAuth alternative: drop bearer_token_env_var and run`,`codex mcp login kanna`].join(`
|
|
17
17
|
`)},{id:`claude-desktop`,client:`claude-desktop`,title:`Claude Desktop and claude.ai`,instructions:`${r}Open Settings, Connectors, Add custom connector and enter the URL. Add the request header below, or leave it empty to sign in through OAuth. ${Td}`,snippet:[`URL: ${n}`,`Header: Authorization: Bearer ${Cd}`].join(`
|
|
18
18
|
`)},{id:`chatgpt`,client:`chatgpt`,title:`ChatGPT`,instructions:`${r}Open chatgpt.com/plugins, select the plus button, then Add custom MCP server; enter the URL and choose OAuth as the authentication. ${Td}`,snippet:[`URL: ${n}`,`Authentication: OAuth`].join(`
|