hmcp-web 0.2.4 → 0.2.5
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-ui/assets/{Activity-CQw7bFh4.js → Activity-CJfJp0fB.js} +1 -1
- package/dist-ui/assets/{Approvals-_rFRWRyy.js → Approvals-BhFnOJyz.js} +1 -1
- package/dist-ui/assets/{AttachApp-eNBD48eb.js → AttachApp-CuSl69fx.js} +1 -1
- package/dist-ui/assets/{Connections-_AV8r8_W.js → Connections-Cp8DIzBt.js} +1 -1
- package/dist-ui/assets/{PreApprovals-Bwrhm8hr.js → PreApprovals-DBqqV2f7.js} +1 -1
- package/dist-ui/assets/{Protection-CM1fEDmQ.js → Protection-DypDlImQ.js} +1 -1
- package/dist-ui/assets/{Safety-BbtS6-Sw.js → Safety-DIYb13J7.js} +1 -1
- package/dist-ui/assets/{Settings-BjarVZaa.js → Settings-DAI3wzcR.js} +1 -1
- package/dist-ui/assets/{StartPage-CUFNfiyY.js → StartPage-D3Q3ZPQL.js} +1 -1
- package/dist-ui/assets/{Suggestions-CfqM3_Ik.js → Suggestions-M3t7IPCO.js} +1 -1
- package/dist-ui/assets/{Tools-jM5XlNbn.js → Tools-B-M1k2c3.js} +1 -1
- package/dist-ui/assets/{connect-app-words-Dy16Vpfd.js → connect-app-words-B_5RQcK_.js} +1 -1
- package/dist-ui/assets/{index-DywhXnhV.js → index-2otwle61.js} +3 -3
- package/dist-ui/index.html +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$ as e,A as t,At as n,B as r,Ct as i,D as a,E as o,Et as s,G as c,H as l,It as u,J as d,M as f,N as p,Nt as m,O as h,Ot as g,Pt as _,S as v,St as y,U as b,V as x,Y as S,Z as C,_ as w,_t as T,at as E,b as D,bt as O,c as k,et as A,f as j,ft as M,gt as N,ht as P,it as F,k as I,kt as L,l as R,lt as z,m as ee,mt as te,p as ne,pt as re,q as ie,s as B,st as V,u as ae,vt as oe,w as se,wt as ce,x as le,xt as ue,y as H,yt as U,z as de}from"./kit-BHB_ha4i.js";import{r as fe,t as pe}from"./server-name-D9u6r07i.js";import{$ as me,$t as he,An as ge,Cn as _e,Dn as ve,En as ye,Ft as be,Gt as xe,Ht as Se,It as Ce,Kt as W,Mn as we,On as Te,Q as Ee,Qt as De,Rt as G,Tn as Oe,Ut as ke,Vt as Ae,Wt as je,X as Me,Xt as Ne,Z as Pe,Zt as Fe,_ as Ie,an as Le,bn as Re,cn as K,d as ze,en as Be,et as q,f as Ve,g as He,h as Ue,hn as We,in as Ge,kn as Ke,m as qe,mn as J,p as Je,qt as Ye,rn as Y,s as Xe,tn as Ze,tt as X,v as Qe,wn as $e,xn as et,y as tt,yn as nt}from"./index-DywhXnhV.js";import{a as rt,c as it,d as at,f as ot,i as st,l as ct,n as lt,o as ut,r as dt,s as ft,t as pt,u as mt}from"./AttachApp-eNBD48eb.js";import{m as ht,p as gt}from"./connect-app-words-Dy16Vpfd.js";var Z=u(),Q=L(),_t=[`Choose an app`,`Choose how it starts`,`Check what will happen`,`Connect`],vt={mode:`observe`,posture:`approve-writes`,onUnclassified:`approve`,packs:!0,clientAllow:!1,gatewayName:``,entryName:``,rename:[],copyEnv:!1,allowLocalHttp:!1,strictEgress:!1,relativeConfig:!1,outDir:``,id:``};function yt(e,t,n,r){let i=Object.fromEntries(r.rename.filter(([e,t])=>e.trim()&&t.trim()).map(([e,t])=>[e.trim(),t.trim()]));return{scope:e,...n&&t?{projectDir:t}:{},mode:r.mode,posture:r.posture,onUnclassified:r.onUnclassified,packs:r.packs,...Ne(e)&&r.mode===`enforce`?{clientAllow:r.clientAllow}:{},...r.gatewayName.trim()?{gatewayName:r.gatewayName.trim()}:{},...r.entryName.trim()?{entryName:r.entryName.trim()}:{},...Object.keys(i).length?{rename:i}:{},copyEnv:r.copyEnv,allowLocalHttp:r.allowLocalHttp,strictEgress:r.strictEgress,relativeConfig:r.relativeConfig,...r.outDir.trim()?{outDir:r.outDir.trim()}:{},...r.id.trim()?{id:r.id.trim()}:{}}}var bt={done:null,undo:null};function xt({open:e,onClose:t}){let n=()=>{bt.done=null,bt.undo=null,t()};return(0,Q.jsx)(v,{open:e,onClose:n,title:`Connect an app`,subtitle:`Put your toolbox between one of your AI apps and the servers it uses.`,width:880,children:e&&(0,Q.jsx)(St,{onClose:n})})}function St({onClose:e}){let{nav:t,reload:n}=J(),[r,a]=(0,Z.useState)(0),[o,s]=(0,Z.useState)(``),c=(0,Z.useRef)(!1),u=O(o.trim(),450),d=B(()=>we.clients(u||void 0),[u]);(0,Z.useEffect)(()=>{d.data&&!c.current&&!o&&s(d.data.projectDir)},[d.data]);let[f,p]=(0,Z.useState)(null),h=d.data?.clients.find(e=>e.scope===f)??null,[g,_]=(0,Z.useState)(vt),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(bt.undo),S=e=>{bt.undo=e,x(e)},C=(0,Z.useMemo)(()=>h?yt(h.scope,d.data?.projectDir??``,h.projectScoped,g):null,[h,d.data?.projectDir,g]),w=JSON.stringify(C),[T,E]=(0,Z.useState)(null),D=r>=2&&C&&T?.key!==w;(0,Z.useEffect)(()=>{if(r<2||!C||T?.key===w)return;let e=!0;return we.plan(C).then(t=>e&&E({key:w,data:t,error:null})).catch(t=>e&&E({key:w,data:null,error:W(t)})),()=>{e=!1}},[r,w]);let[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(null),[N,F]=(0,Z.useState)(bt.done),I=()=>{C&&(A(!0),M(null),we.apply(C).then(e=>{bt.done=e,F(e)}).catch(e=>{if(e instanceof m&&e.status===409){M({text:`A toolbox with that name is already in the console. Choose another name and try again.`,idTaken:!0});return}let t=e.detail;t?.report&&E({key:w,data:t.report,error:null}),M({text:W(e),blocking:t?.blocking})}).finally(()=>A(!1)))};if(N)return(0,Q.jsx)(It,{result:N,onClose:()=>{e(),n()},onOpen:r=>{e(),n(),ue(i(t,`/`,{server:r}))}});let L=T?.key===w?T:null,R=!!L?.data&&L.data.blocking.length>0,z=r===0?!!h&&h.exists&&!h.error&&(h.serverCount>0||h.alreadyAdopted):r===1||!!L?.data&&!R;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(ae,{steps:_t,step:r,onStep:e=>a(Math.max(0,e)),canNext:z&&!k,nextLabel:r===2?`Review and connect`:`Continue`,finishLabel:h?`Connect ${G(h.scope)}`:`Connect app`,onFinish:I,busy:k||!!D,children:[r===0&&(0,Q.jsx)(Ct,{clients:d,projectDir:o,onProjectDir:e=>{c.current=!0,s(e)},scope:f,onScope:p,onUndo:S,onAttach:y}),r===1&&h&&(0,Q.jsx)(Dt,{client:h,choices:g,onChange:_,found:L?.data?.serversFound??T?.data?.serversFound??[]}),r===2&&(D||!L?(0,Q.jsx)(Ot,{}):L.error?(0,Q.jsx)(l,{tone:`danger`,title:`The check could not finish`,role:`alert`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:()=>E(null),children:`Check again`}),children:L.error}):(0,Q.jsx)(At,{plan:L.data,app:G(h.scope)})),r===3&&L?.data&&h&&(0,Q.jsx)(Ft,{plan:L.data,client:h,error:j,id:g.id,onId:e=>_({...g,id:e})})]}),(0,Q.jsx)(Lt,{client:v,onClose:()=>y(null),onDone:()=>d.reload()}),(0,Q.jsx)(lt,{client:b,projectDir:d.data?.projectDir,onClose:()=>S(null),onDone:()=>{d.reload(),n()}})]})}function Ct({clients:e,projectDir:t,onProjectDir:n,scope:r,onScope:i,onUndo:a,onAttach:s}){let u=e.data?.clients??[],d=e.error&&!e.data?null:e.error;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`Pick the app whose tools you want your toolbox to check. The servers it already uses keep working; they are reached through your toolbox instead of directly.`}),(0,Q.jsx)(o,{label:`Project folder`,help:`Some apps keep a server list per project. This is the project they are read from. Use the full path.`,error:d?W(d):null,children:(0,Q.jsx)(f,{value:t,onChange:n,mono:!0,placeholder:`/Users/me/my-project`})}),e.error&&!e.data?(0,Q.jsx)(l,{tone:`danger`,title:`Your apps could not be checked`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:e.reload,children:`Check again`}),children:W(e.error)}):e.data?(0,Q.jsx)(`div`,{role:`radiogroup`,"aria-label":`App to connect`,className:`grid gap-3 sm:grid-cols-2`,children:[...u].sort((e,t)=>wt(e)-wt(t)).map(t=>(0,Q.jsx)(Et,{client:t,projectDir:e.data?.projectDir,selected:r===t.scope,onSelect:()=>i(t.scope),onUndo:()=>a(t),onAttach:()=>s(t)},t.scope))}):(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[0,1,2,3].map(e=>(0,Q.jsx)(`div`,{className:`rounded-[18px] border border-line p-4`,children:(0,Q.jsx)(c,{lines:3})},e))})]})}var wt=e=>e.error?3:e.alreadyAdopted?1:e.exists&&e.serverCount>0?0:Ae(e)?2:4,Tt=e=>!e.alreadyAdopted&&Ae(e)&&!(e.exists&&e.serverCount>0);function Et({client:t,projectDir:n,selected:i,onSelect:a,onUndo:o,onAttach:s}){let c=t.exists&&!t.error&&(t.serverCount>0||t.alreadyAdopted)&&!t.attachedTo,l=Tt(t),u=(0,Z.useId)(),d=Be(t),f=t.error?{tone:`bad`,text:`Can't be read`}:!t.exists&&!l?{tone:`neutral`,text:`Not found`}:t.alreadyAdopted?{tone:`ok`,text:`Connected`}:t.serverCount===0?{tone:`neutral`,text:`No servers yet`}:{tone:`warn`,text:`Not protected`};return(0,Q.jsxs)(`div`,{className:U(`flex min-w-0 flex-col gap-2 rounded-[18px] border-[1.5px] p-4 transition-colors`,i?`border-primary bg-ok-tint`:`border-line`,!c&&`bg-sunken/40`),children:[(0,Q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":i,"aria-labelledby":`${u}-name`,"aria-describedby":`${u}-status ${u}-desc`,disabled:!c,onClick:a,className:`flex min-w-0 flex-col items-start gap-1 text-left disabled:cursor-not-allowed`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full items-start gap-2`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:U(`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-full border-[1.5px]`,i?`border-primary bg-primary text-white`:`border-[var(--soft)]`,!c&&`opacity-40`),children:i&&(0,Q.jsx)(g,{name:`check`,size:12,strokeWidth:3})}),(0,Q.jsx)(`span`,{id:`${u}-name`,className:U(`min-w-0 flex-1 text-[15px] font-semibold`,!c&&`text-soft`),children:d}),(0,Q.jsx)(`span`,{id:`${u}-status`,children:(0,Q.jsx)(e,{tone:f.tone,children:f.text})})]}),(0,Q.jsx)(`span`,{id:`${u}-desc`,className:`pl-7 text-[13px] text-soft`,children:t.error?K(Y(t.error)):l?`It has no servers yet. Connect it to your toolbox, then add servers there.`:t.exists?t.alreadyAdopted?t.servers?ke(t.servers,je(t)):Se(t.serverCount):t.serverCount===0?`The app has no servers set up, so there is nothing to protect yet.`:`${r(t.serverCount,`server`)} set up, reached directly with nothing checking them.`:`This app's settings file isn't on this computer.`}),t.exists&&(0,Q.jsx)(`span`,{className:`pl-7`,children:(0,Q.jsx)(q,{children:t.path})})]}),l&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`plug`,onClick:s,children:`Connect it to your toolbox`})}),t.attachedTo&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(rt,{client:t,...n?{projectDir:n}:{}})}),t.canRevert&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:o,children:`Undo connection`})})]})}function Dt({client:t,choices:n,onChange:r,found:i}){let a=(e,t)=>r({...n,[e]:t}),s=Ne(t.scope);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:`You can switch at any time on the Protection settings page.`,children:[`How it starts `,(0,Q.jsx)(w,{term:`watchOnly`})]}),(0,Q.jsx)(Me,{label:`How it starts`,value:n.mode,onChange:e=>a(`mode`,e),options:[{value:`observe`,title:E.observe.label,badge:(0,Q.jsx)(e,{tone:`ok`,children:`Recommended for day one`}),body:`Nothing breaks while you settle in. Every call runs, and the activity log shows what would have been blocked or held, so you can adjust before turning protection on.`},{value:`enforce`,title:E.enforce.label,body:`Rules apply from the first call. Blocked calls stop and changes wait for you, which can interrupt work until the rules fit.`}]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:`What happens to a call no rule mentions.`,children:[`How careful the toolbox is `,(0,Q.jsx)(w,{term:`defaultStance`})]}),(0,Q.jsx)(Me,{label:`How careful the toolbox is`,columns:3,value:n.posture,onChange:e=>a(`posture`,e),options:Object.keys(V).map(e=>({value:e,title:V[e].label,body:V[e].explain}))})]}),(0,Q.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(o,{label:(0,Q.jsxs)(Q.Fragment,{children:[`Tools nobody has labelled yet `,(0,Q.jsx)(w,{term:`unknownTools`})]}),help:`A tool that hasn't said whether it only looks, makes changes or deletes.`,children:(0,Q.jsx)(h,{label:`Tools nobody has labelled yet`,value:n.onUnclassified,onChange:e=>a(`onUnclassified`,e),options:[{value:`approve`,label:`Ask me first`},{value:`deny`,label:`Block them`}]})}),(0,Q.jsx)(p,{checked:n.packs,onChange:e=>a(`packs`,e),label:`Use ready-made rules for servers your toolbox knows`,description:`For well-known servers such as file system and GitHub, sensible rules are filled in for each tool so you start with less to decide.`}),(0,Q.jsx)(p,{checked:s&&n.mode===`enforce`&&n.clientAllow,onChange:e=>a(`clientAllow`,e),disabled:!s||n.mode!==`enforce`,label:`Don't ask me twice`,description:s?n.mode===`enforce`?`Claude Code asks before each tool call, and your toolbox asks too when a rule says so. This stops Claude Code asking about your toolbox's tools, so you answer once.`:`Available when protecting. While it only watches, your toolbox never asks, so Claude Code's own question is the only one left.`:`Only Claude Code has this setting. ${G(t.scope)} keeps asking in its own way.`})]}),(0,Q.jsxs)(Ee,{title:`More options`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Toolbox name`,technical:`name`,optional:!0,help:`Shown in the console and in the activity log.`,children:(0,Q.jsx)(f,{value:n.gatewayName,onChange:e=>a(`gatewayName`,e),mono:!0,placeholder:`claude-code`})}),(0,Q.jsx)(o,{label:`Name in the app's server list`,optional:!0,technical:`entry name`,help:`What your toolbox is called inside the app.`,children:(0,Q.jsx)(f,{value:n.entryName,onChange:e=>a(`entryName`,e),mono:!0,placeholder:`hmcp`})})]}),(0,Q.jsx)(o,{label:`Rename servers`,optional:!0,help:i.length?`Found in the app: ${i.join(`, `)}. New names use lower-case letters, digits and underscores.`:`The name in the app on the left, the name in your toolbox on the right. Lower-case letters, digits and underscores.`,children:(0,Q.jsx)(me,{value:n.rename,onChange:e=>a(`rename`,e),keyLabel:`Name in the app`,valueLabel:`Name in your toolbox`,addLabel:`Add a rename`})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(p,{checked:n.copyEnv,onChange:e=>a(`copyEnv`,e),label:`Copy keys into the toolbox's settings file`,description:`Gives each server its own copy of the values it needs, such as access keys.`}),n.copyEnv&&(0,Q.jsx)(l,{tone:`warn`,title:`This writes passwords and keys into a file`,children:`The toolbox's settings file will hold them in plain text, outside your locked keys. Anyone who can read that file can read them, so don't share it or put it anywhere others can see. Leave this off unless a server was left out because of its values.`})]}),(0,Q.jsx)(p,{checked:n.allowLocalHttp,onChange:e=>a(`allowLocalHttp`,e),label:`Allow servers on this computer`,description:`Lets your toolbox reach web servers on this computer or your local network. This adds to your allowed addresses for every web server this toolbox reaches, not just one.`}),(0,Q.jsx)(p,{checked:n.strictEgress,onChange:e=>a(`strictEgress`,e),label:`Strict allowed addresses`,description:`Each remote server may be reached only at its exact address and port, rather than anywhere on its host.`}),(0,Q.jsx)(p,{checked:n.relativeConfig,onChange:e=>a(`relativeConfig`,e),label:`Point to the toolbox's settings file by a relative path`,description:`Useful when the project folder is shared or moved, so the app finds the toolbox's settings file wherever the folder lives.`}),(0,Q.jsx)(o,{label:`Folder for the toolbox's files`,optional:!0,help:`A full path. By default they go in a .hmcp folder in the project, or in your home folder for apps that aren't per project.`,children:(0,Q.jsx)(f,{value:n.outDir,onChange:e=>a(`outDir`,e),mono:!0,placeholder:`/Users/me/my-project/.hmcp`})})]})]})}function Ot(){let[e,t]=(0,Z.useState)(0);return(0,Z.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]),(0,Q.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex flex-col items-center gap-4 py-14 text-center`,children:[(0,Q.jsx)(`span`,{className:`grid h-14 w-14 place-items-center rounded-full bg-ok-tint text-ok`,children:(0,Q.jsx)(oe,{size:26})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[17px] font-medium`,children:`Starting each server to see its tools…`}),(0,Q.jsxs)(`p`,{className:`mt-1 text-[13.5px] text-soft`,children:[`This can take up to about 40 seconds. Nothing is changed yet. `,e>2&&(0,Q.jsxs)(`span`,{className:`tnum`,children:[`(`,e,` s)`]})]})]})]})}var kt=[{key:`run`,label:`Runs freely`,icon:`check`,tone:`ok`},{key:`ask`,label:`Asks first`,icon:`clock`,tone:`warn`},{key:`blocked`,label:`Blocked`,icon:`x`,tone:`bad`},{key:`hidden`,label:`Hidden`,icon:`eye-off`,tone:`neutral`}];function At({plan:t,app:n}){let i=t.starting?.mode!==`enforce`,a=t.tools.filter(e=>e.injection);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[t.blocking.length>0&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`This can't be connected yet`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:t.blocking.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))})}),t.status===`already-adopted`&&t.blocking.length===0&&(0,Q.jsx)(l,{tone:`info`,title:`${n} already goes through your toolbox`,children:`Connecting again only applies the change you chose.`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:t.existingGateway?`New servers are added to the toolbox this app already uses.`:void 0,children:[`Servers (`,t.upstreams.length,`)`]}),t.upstreams.length===0?(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`No server can go through your toolbox.`}):(0,Q.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:t.upstreams.map(t=>(0,Q.jsxs)(`li`,{className:`flex min-w-0 gap-3 rounded-2xl bg-sunken/60 p-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-full bg-surface text-muted`,children:(0,Q.jsx)(g,{name:t.transport===`http`?`external`:`server`,size:17})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`mono text-[13.5px] font-semibold`,children:t.name}),t.originalName!==t.name&&(0,Q.jsxs)(`span`,{className:`text-[12px] text-soft`,children:[`was `,t.originalName]}),t.alreadyFronted&&(0,Q.jsx)(e,{children:`Already connected`})]}),(0,Q.jsx)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:t.transport===`http`?`Remote server · ${t.url}`:`Runs on this computer · ${[t.command,...t.args].join(` `)}`}),(t.envNames.length>0||t.passEnv.length>0||t.headerNames.length>0)&&(0,Q.jsxs)(`span`,{className:`mt-0.5 block text-[12px] text-soft`,children:[`Uses `,(0,Q.jsx)(`span`,{className:`mono`,children:[...t.envNames,...t.passEnv,...t.headerNames].join(`, `)})]}),t.warnings.map(e=>(0,Q.jsx)(`span`,{className:`mt-1 block text-[12.5px] text-warn`,children:K(Y(e))},e))]})]},t.name))}),(t.skipped.length>0||t.malformed.length>0)&&(0,Q.jsxs)(`div`,{className:`mt-4`,children:[(0,Q.jsxs)(`p`,{className:`mb-2 text-[13.5px] font-semibold`,children:[`Left out (`,t.skipped.length+t.malformed.length,`)`]}),(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[t.skipped.map(e=>{let t=Ge(e.reason,e.remedy);return(0,Q.jsxs)(`li`,{className:`rounded-2xl border border-line p-3 text-[13.5px]`,children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:t.reason}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-soft`,children:t.remedy})]},e.name)}),t.malformed.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-2xl border border-line p-3 text-[13.5px]`,children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),(0,Q.jsxs)(`p`,{className:`mt-1 text-muted`,children:[`Its entry in the app's settings could not be read: `,K(Y(e.message))]})]},e.name))]})]})]}),t.probeFailures.length>0&&(0,Q.jsxs)(l,{tone:`danger`,title:`Some servers didn't start or answer`,children:[(0,Q.jsx)(`ul`,{className:`mt-1 space-y-1`,children:t.probeFailures.map(e=>(0,Q.jsxs)(`li`,{children:[(0,Q.jsx)(`code`,{className:`mono`,children:e.upstream}),`: `,K(Y(e.message))]},e.upstream))}),(0,Q.jsx)(`p`,{className:`mt-1`,children:`Check that each one works in the app on its own, then go back a step and check again.`})]}),t.tools.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:i?`For now it only watches, so every call runs. This is what will happen once you turn protection on.`:`What happens to each tool from the first call.`,children:[`Tools (`,t.tools.length,`)`]}),(0,Q.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:kt.map(e=>{let n=t.tools.filter(t=>t.verdict===e.key);return n.length===0?null:(0,Q.jsx)(Nt,{label:e.label,icon:e.icon,tone:e.tone,tools:n},e.key)})})]}),(a.length>0||t.findings.length>0||t.namesTooLong.length>0||t.withheld.length>0)&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Worth a look`}),(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2 text-[13.5px]`,children:[a.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl bg-warn-tint p-3`,children:[(0,Q.jsx)(g,{name:`warning`,size:17,className:`mt-0.5 shrink-0 text-warn`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` has hidden instructions in its description.`,` `,e.hidden?`The tool will be hidden from your AI app.`:`Your toolbox will deal with them as set in its options.`]})]},`inj-${e.name}`)),jt(t.findings).map(e=>(0,Q.jsx)(Mt,{group:e},e.ruleId)),t.namesTooLong.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`warning`,size:17,className:`mt-0.5 shrink-0 text-warn`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` has a name too long for `,n,` (`,e.length,` of `,e.limit,` letters), so it won't be offered. A shorter server name under More options leaves more room.`]})]},`long-${e.name}`)),t.withheld.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`eye-off`,size:17,className:`mt-0.5 shrink-0 text-soft`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` won't be offered: `,K(Y(e.reason))]})]},`w-${e.name}`))]})]}),t.packs.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Ready-made rules`}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.packs.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 rounded-2xl bg-ok-tint p-3 text-[13.5px]`,children:[(0,Q.jsx)(g,{name:`shield-check`,size:18,className:`shrink-0 text-ok`}),(0,Q.jsxs)(`span`,{children:[e.packLabel,` rules for `,(0,Q.jsx)(`code`,{className:`mono`,children:e.upstreamName}),`: `,r(e.rules.length,`rule`),e.unmatched.length>0&&(0,Q.jsxs)(`span`,{className:`text-soft`,children:[` · `,e.unmatched.length,` not used by this server`]})]})]},e.upstreamName))})]}),t.warnings.length>0&&(0,Q.jsx)(l,{tone:`warn`,title:`Before you connect`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:t.warnings.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))})}),t.files&&(0,Q.jsx)(Pt,{plan:t})]})}function jt(e){let t=new Map;for(let n of e)t.set(n.ruleId,[...t.get(n.ruleId)??[],n]);return[...t.entries()].map(([e,t])=>({ruleId:e,high:t.some(e=>e.severity===`high`),items:t})).sort((e,t)=>Number(t.high)-Number(e.high))}function Mt({group:e}){let[t,n]=(0,Z.useState)(!1);return(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`shield`,size:17,className:U(`mt-0.5 shrink-0`,e.high?`text-bad`:`text-warn`)}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:M(e.ruleId)}),(0,Q.jsx)(`span`,{className:`mono text-[11.5px] text-soft`,children:e.ruleId}),e.items.length>1&&(0,Q.jsxs)(`span`,{className:`text-soft`,children:[`· `,e.items.length,` places`]}),e.ruleId in F&&(0,Q.jsx)(w,{term:e.ruleId})]}),(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,className:`-ml-3`,"aria-expanded":t,onClick:()=>n(!t),children:t?`Hide details`:`Show details`}),t&&(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5 text-[13px] text-muted`,children:e.items.map((e,t)=>(0,Q.jsx)(`li`,{className:`break-words`,children:K(Y(e.message))},t))})]})]})}function Nt({label:t,icon:n,tone:r,tools:i}){let[a,o]=(0,Z.useState)(i.length<=8),s=a?i:i.slice(0,8);return(0,Q.jsxs)(`div`,{className:`rounded-[18px] border border-line p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(e,{tone:r,icon:n,children:t}),(0,Q.jsx)(`span`,{className:`tnum text-[13px] text-soft`,children:i.length})]}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:s.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 border-b border-faint py-1.5 last:border-b-0`,children:[(0,Q.jsx)(C,{effect:e.effect}),(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 truncate text-[12.5px]`,title:e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[12px] text-soft`,title:e.decidedBy,children:xe(e.decidedBy)})]},e.name))}),!a&&(0,Q.jsxs)(P,{size:`sm`,variant:`ghost`,className:`mt-1`,onClick:()=>o(!0),children:[`Show all `,i.length,` tools`]})]})}function Pt({plan:e}){let t=e.files,n=[[`The app's settings, changed to use your toolbox`,t.clientConfig],[`Backup of the app's settings`,t.wholeFileBackup],[`Record used to undo the connection`,t.backupRecord],[`The toolbox's settings file`,t.gatewayConfig],[t.policyKept?`Protection settings (kept as they are)`:`Protection settings`,t.policy],[`Claude Code permission for “Don't ask me twice”`,t.clientSettings]];return(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Files that will be written`}),(0,Q.jsx)(`dl`,{className:`flex flex-col gap-2 text-[13px]`,children:n.filter(([,e])=>e).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`grid gap-x-4 sm:grid-cols-[240px_1fr]`,children:[(0,Q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(q,{children:t})})]},e))})]})}function Ft({plan:e,client:t,error:n,id:i,onId:a}){let s=G(t.scope),c=e.starting?.mode!==`enforce`,u=e.upstreams.filter(e=>!e.alreadyFronted).length,d=[[`plug`,u>0?`${r(u,`server`)} in ${t.label} will go through your toolbox.`:`The change you chose is applied to your toolbox.`],[`file`,`A backup of the app's settings is kept, so you can undo this here at any time.`],[c?`eye`:`shield-check`,c?`For now it only watches: everything runs, and the activity log shows what would have been stopped.`:`It starts protecting: your rules apply from the first call.`],[`refresh`,`${s} has to be restarted afterwards to pick up your toolbox.`]];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{children:`When you connect`}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-3`,children:d.map(([e,t])=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-3 text-[14.5px]`,children:[(0,Q.jsx)(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-full bg-ok-tint text-ok`,children:(0,Q.jsx)(g,{name:e,size:17})}),(0,Q.jsx)(`span`,{className:`pt-1.5`,children:t})]},t))}),n&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`It wasn't connected`,children:n.blocking?.length?(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:n.blocking.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))}):n.text}),n?.idTaken&&(0,Q.jsx)(o,{label:`Toolbox name in the console`,technical:`id`,help:`Lower-case letters, digits, dashes and underscores.`,children:(0,Q.jsx)(f,{value:i,onChange:a,mono:!0,placeholder:`claude-code-2`})})]})}function It({result:e,onClose:t,onOpen:n}){let r=G(e.scope),i=e.applied;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(R,{steps:_t,current:_t.length}),(0,Q.jsxs)(b,{icon:`check`,title:`Done. Restart ${r} so it picks up your toolbox.`,actions:(0,Q.jsxs)(Q.Fragment,{children:[e.registryId&&(0,Q.jsx)(P,{variant:`primary`,icon:`arrow-right`,onClick:()=>n(e.registryId),children:`Open this toolbox`}),(0,Q.jsx)(P,{onClick:t,children:`Close`})]}),children:[i.replaced.length>0?`${i.replaced.join(`, `)} now ${i.replaced.length===1?`goes`:`go`} through your toolbox.`:`Your toolbox is set up as you chose.`,` `,e.starting?.mode===`enforce`?`It is protecting from the first call.`:`For now it only watches, so nothing is blocked yet.`]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-[18px] bg-sunken/60 p-4 text-[13px]`,children:[(0,Q.jsx)(`p`,{className:`font-semibold`,children:`What was backed up`}),i.wholeFileBackup&&(0,Q.jsxs)(`p`,{children:[`A copy of the app's settings as they were: `,(0,Q.jsx)(q,{children:i.wholeFileBackup})]}),(0,Q.jsxs)(`p`,{children:[`What's needed to undo it: `,(0,Q.jsx)(q,{children:i.backupRecord})]}),i.clientAllowAdded&&(0,Q.jsx)(`p`,{children:`Claude Code won't ask a second time about your toolbox's tools.`})]}),i.literalSecretsInBackup&&(0,Q.jsx)(l,{tone:`warn`,title:`The backups hold a password or key`,children:`A server you connected had a key written out in the app's settings, so both backup files contain it. Keep them private.`}),e.warning&&(0,Q.jsx)(l,{tone:`warn`,children:K(Y(e.warning))})]})}function Lt({client:e,onClose:t,onDone:n}){let{servers:r,serverId:i,nav:a}=J(),c=r.filter(e=>e.ok),[l,u]=(0,Z.useState)(null),d=l??(c.some(e=>e.id===i)?i:c[0]?.id??null);return e?(0,Q.jsx)(le,{open:!0,onClose:t,title:`Connect ${G(e.scope)} to your toolbox`,width:600,footer:(0,Q.jsx)(P,{onClick:t,children:`Close`}),children:d?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[c.length>1&&(0,Q.jsx)(o,{label:`Which toolbox`,children:(0,Q.jsx)(h,{label:`Which toolbox`,value:d,onChange:u,options:c.map(e=>({value:e.id,label:e.label}))})}),(0,Q.jsx)(pt,{gatewayId:d,scope:e.scope,onDone:n},d)]}):(0,Q.jsxs)(b,{icon:`server`,title:`You don't have a toolbox yet`,compact:!0,children:[`Adding your first server sets one up. Then come back here and connect `,G(e.scope),`.`,(0,Q.jsx)(`span`,{className:`mt-4 block`,children:(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:()=>ue(s(a,{connect:null,add:`server`})),children:`Add a server`})})]})}):null}var Rt={done:null,label:``};function zt({open:e,onClose:t}){let{reload:n}=J(),r=()=>{let e=!!Rt.done;Rt.done=null,t(),e&&n()},[i,a]=(0,Z.useState)(`new`);return(0,Q.jsx)(v,{open:e,onClose:r,title:`Create a toolbox`,subtitle:`Set up a toolbox yourself, server by server.`,width:760,children:e&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(h,{label:`How to add it`,value:i,onChange:a,options:[{value:`new`,label:`Start from nothing`},{value:`existing`,label:`Use a toolbox settings file I have`}]}),i===`new`?(0,Q.jsx)(Bt,{onClose:r}):(0,Q.jsx)(Ht,{onClose:r})]})})}function Bt({onClose:e}){let{nav:t,reload:n}=J(),r=H(),[a,s]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)(`observe`),[m,g]=(0,Z.useState)(`approve-writes`),[_,v]=(0,Z.useState)(`approve`),[y,b]=(0,Z.useState)(``),[x,S]=(0,Z.useState)([at()]),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(Rt.done),F=/^[a-z0-9][a-z0-9_-]{0,63}$/.test(a)?null:`Use lower-case letters, digits, dashes and underscores, starting with a letter or digit.`,I=x.map((e,t)=>mt(e,x.filter((e,n)=>n!==t).map(e=>e.name.trim()))),L=!F&&I.every(e=>!e);return j?(0,Q.jsx)(Vt,{result:j,label:Rt.label,onClose:e,onOpen:()=>{e(),ue(i(t,`/`,{server:j.id}))}}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsxs)(`section`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Name`,technical:`name`,help:`Also the name of its folder.`,error:k?F:null,children:(0,Q.jsx)(f,{value:a,onChange:s,mono:!0,placeholder:`work-tools`})}),(0,Q.jsx)(o,{label:`Label in the console`,optional:!0,children:(0,Q.jsx)(f,{value:c,onChange:u,placeholder:`Work tools`})})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{children:[`How it starts `,(0,Q.jsx)(w,{term:`watchOnly`})]}),(0,Q.jsx)(Me,{label:`How it starts`,value:d,onChange:p,options:[{value:`observe`,title:E.observe.label,body:`Recommended to begin with. Every call runs, and the log shows what would have been stopped.`},{value:`enforce`,title:E.enforce.label,body:E.enforce.explain}]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{children:[`How careful the toolbox is `,(0,Q.jsx)(w,{term:`defaultStance`})]}),(0,Q.jsx)(Me,{label:`How careful the toolbox is`,columns:3,value:m,onChange:g,options:Object.keys(V).map(e=>({value:e,title:V[e].label,body:V[e].explain}))})]}),(0,Q.jsxs)(`section`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:(0,Q.jsxs)(Q.Fragment,{children:[`Tools nobody has labelled yet `,(0,Q.jsx)(w,{term:`unknownTools`})]}),children:(0,Q.jsx)(h,{label:`Tools nobody has labelled yet`,value:_,onChange:v,options:[{value:`approve`,label:`Ask me first`},{value:`deny`,label:`Block them`}]})}),(0,Q.jsx)(o,{label:`Folder for its files`,optional:!0,help:`A full path. By default, a folder named after it in your home folder.`,children:(0,Q.jsx)(f,{value:y,onChange:b,mono:!0,placeholder:`~/.hmcp/gateways/work-tools`})})]}),(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(X,{sub:`The servers this toolbox sits in front of. A toolbox needs at least one.`,children:[`Connected servers `,(0,Q.jsx)(w,{term:`connectedServer`})]}),x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`rounded-[18px] border border-line p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-[14.5px] font-semibold`,children:[`Server `,t+1]}),x.length>1&&(0,Q.jsx)(N,{icon:`trash`,label:`Remove server ${t+1}`,size:34,onClick:()=>S(x.filter((e,n)=>n!==t))})]}),(0,Q.jsx)(it,{value:e,onChange:e=>S(x.map((n,r)=>r===t?e:n)),literalWarning:!0}),k&&I[t]&&(0,Q.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] font-medium text-bad`,children:I[t]})]},t)),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{icon:`plus`,onClick:()=>S([...x,at()]),children:`Add another server`})})]}),D&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`The toolbox wasn't created`,children:D}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:e,disabled:C,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:()=>{A(!0),L&&(T(!0),O(null),we.createGateway({name:a,...c.trim()?{label:c.trim()}:{},mode:d,posture:m,onUnclassified:_,...y.trim()?{outDir:y.trim()}:{},upstreams:x.map(ot)}).then(e=>{Rt.done=e,Rt.label=c.trim()||a,M(e),r.show(`ok`,`${c.trim()||a} was created.`)}).catch(e=>{let t=e.detail;O(W(e)+(Array.isArray(t)?` ${t.map(e=>K(Y(e.message))).join(` `)}`:``))}).finally(()=>T(!1)))},loading:C,children:`Create toolbox`})]})]})}function Vt({result:e,label:t,onClose:n,onOpen:r}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(b,{icon:`check`,title:`${t} is ready`,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{variant:`secondary`,icon:`arrow-right`,onClick:r,children:`Open this toolbox`}),(0,Q.jsx)(P,{variant:`ghost`,onClick:n,children:`Close`})]}),children:`Its protection settings start the way you chose. Connect your AI app to it next: one click, then restart the app once.`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Connect your AI app`}),(0,Q.jsx)(pt,{gatewayId:e.id,onDone:()=>void 0})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-[18px] bg-sunken/60 p-4 text-[13px]`,children:[(0,Q.jsxs)(`p`,{children:[`Settings file: `,(0,Q.jsx)(q,{children:e.configPath})]}),(0,Q.jsxs)(`p`,{children:[`Protection settings: `,(0,Q.jsx)(q,{children:e.policyPath})]})]}),e.warnings.map(e=>(0,Q.jsxs)(l,{tone:`warn`,children:[K(Y(e)),` If one is a password or key, keep that file private.`]},e)),e.warning&&(0,Q.jsx)(l,{tone:`warn`,children:K(Y(e.warning))})]})}function Ht({onClose:e}){let{nav:t,reload:n}=J(),r=H(),[a,s]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),g=()=>{p(!0),h(null),_.addServer({kind:`gateway`,...a.trim()?{label:a.trim()}:{},config_path:c.trim()}).then(o=>{n(),r.show(`ok`,`${a.trim()||`The toolbox`} was added to the console.`),e(),ue(i(t,`/`,{server:o.id}))}).catch(e=>h(W(e))).finally(()=>p(!1))};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`For a toolbox you already set up. The console reads its settings file and nothing else: it doesn't start the toolbox or change the file.`}),(0,Q.jsx)(o,{label:`Label in the console`,optional:!0,help:`Left empty, it's named after the toolbox.`,children:(0,Q.jsx)(f,{value:a,onChange:s,placeholder:`Work tools`})}),(0,Q.jsx)(o,{label:`Settings file`,technical:`gateway.yaml`,help:`The full path to its settings file.`,children:(0,Q.jsx)(f,{value:c,onChange:u,mono:!0,placeholder:`/Users/me/.hmcp/gateways/work/gateway.yaml`,onEnter:g})}),m&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:m}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:e,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:g,loading:d,disabled:!c.trim(),children:`Add toolbox`})]})]})}function Ut(){return document.cookie.match(/(?:^|;\s*)hmcp_csrf=([^;]+)/)?.[1]??``}async function Wt(e,t={}){let n={...t.headers??{}};t.method&&t.method!==`GET`&&(n[`Content-Type`]=`application/json`,n[`X-HMCP-CSRF`]=Ut());let r=await fetch(e,{...t,headers:n}),i=await r.text(),a=i?JSON.parse(i):null;if(!r.ok){let e=a?.error??{code:`unknown`,message:r.statusText};throw new m(r.status,e.code,e.message)}return a}var Gt=e=>({method:`POST`,body:JSON.stringify(e)}),Kt=(e,t)=>`/api/v1/servers/${encodeURIComponent(e.gatewayId)}/github/${encodeURIComponent(e.upstream)}/${t}`,qt={doors:()=>Wt(`/api/v1/github-doors`),claudeCode:e=>Wt(`/api/v1/github-doors/claude-code`,Gt({scope:`user`,close:e,confirm:!0})),confirm:(e,t)=>Wt(`/api/v1/github-doors/confirm`,Gt({door:e,done:t})),setChanges:(e,t)=>Wt(Kt(e,`changes`),Gt({allow:t,expectedDigest:e.digest,confirm:!0})),check:e=>Wt(Kt(e,`check`),Gt({}))},Jt=`Make hmcp the only way to change GitHub`,Yt=`hmcp can ask you before each GitHub change only when the change goes through it. These are the other ways a change could reach GitHub from this computer.`,Xt=`Claude Code enforces these rules, but a prefix rule makes a way around them much harder, not impossible. For a guarantee, also log gh out and remove saved GitHub git credentials.`,Zt=`Your GitHub server can only look. To let Claude make changes through hmcp, switch it below, or edit it and choose 'Look and make changes'.`,Qt=`Not checked yet — press Check it works to see what each change will meet.`,$t=`Once it's switched, press Check it works to see what each change will meet.`,en=`Let Claude change GitHub through hmcp`,tn=`Back to only looking`,nn=`Your GitHub server can make changes.`,rn=`For a company: a Claude Team/Enterprise admin can block connector tools for everyone, and a GitHub organisation owner can restrict which apps may reach the organisation's repositories (Organisation settings → Third-party access).`,an=e=>V[e]?.label??e;function on(e){if(e===null)return`What happens to a change couldn't be worked out, because this toolbox's protection settings can't be read.`;if(e.kind===`unchecked`)return Qt;if(e.kind===`no-changes`)return`It doesn't offer any tools that make changes.`;let t;switch(e.kind){case`waits`:t=`Each change waits for you to say yes`;break;case`refused`:t=`Changes will be refused while the toolbox is set to “${an(e.posture)}”; switch to “Ask before changes” to allow them with approval`;break;case`partly-refused`:t=`Some changes are refused under your toolbox's settings (${(e.tools??[]).join(`, `)}); the rest wait for you to say yes`;break;case`runs`:t=`Some changes run without asking you: ${(e.tools??[]).join(`, `)}. Change them to “Ask me first” on the Tools page`;break;case`observe`:t=`Changes run without asking while the toolbox only watches`}return e.preApproved?`${t}, but a pre-approval lets some changes run without asking.`:`${t}.`}function sn(e){return e.state===`open`?{label:`Open`,tone:`bad`}:e.state===`unknown`?{label:`Can't check`,tone:`warn`}:e.state===`harder`?{label:`Made harder`,tone:`neutral`}:e.confirmed?{label:`Closed (you confirmed)`,tone:`ok`}:{label:`Closed (checked)`,tone:`ok`}}function cn(){let e=H(),t=B(()=>qt.doors(),[]),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)({}),o=t.data;if(!o||o.servers.length===0)return null;let s=(n,i,a)=>{r(n),i().then(()=>{e.show(`ok`,a),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))};return(0,Q.jsx)(re,{title:Jt,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:Yt}),o.servers.map(o=>(0,Q.jsx)(ln,{server:o,busy:n,check:i[`${o.gatewayId}/${o.upstream}`]??null,onSwitch:n=>{r(`switch:${o.upstream}`),qt.setChanges(o,n).then(r=>{let i=r.servers.find(e=>e.gatewayId===o.gatewayId&&e.upstream===o.upstream);e.show(`ok`,n?`Claude can now change GitHub through hmcp. ${on(i?.changes??null)}`:`Your GitHub server can only look again.`),r.note&&e.show(`info`,r.note),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))},onCheck:()=>{r(`check:${o.upstream}`),qt.check(o).then(e=>{a(t=>({...t,[`${o.gatewayId}/${o.upstream}`]:e})),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))}},`${o.gatewayId}/${o.upstream}`)),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:o.doors.map(e=>(0,Q.jsx)(un,{door:e,busy:n,onBlock:e=>s(`claude-code`,()=>qt.claudeCode(e),e?`GitHub is blocked in Claude Code. Restart Claude Code to be sure it's applied.`:`The block was taken out of Claude Code's settings.`),onConfirm:t=>s(`confirm:${e.id}`,()=>qt.confirm(e.id,t),t?`Noted as done.`:`Noted as not done yet.`)},e.id))}),(0,Q.jsx)(l,{tone:`info`,children:Xt}),(0,Q.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:rn})]})})}function ln({server:e,busy:t,check:n,onSwitch:r,onCheck:i}){let a=We()(e.upstream,e.gatewayId);return e.access===null?null:(0,Q.jsxs)(`div`,{className:`rounded-2xl bg-sunken/60 px-4 py-3 text-[14px]`,children:[(0,Q.jsxs)(`p`,{className:`font-medium`,children:[a,` in `,e.gatewayLabel,pe(e.upstream,a)&&(0,Q.jsx)(`span`,{className:`ml-2 font-mono text-[12px] font-normal text-soft`,children:e.upstream})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:e.access===`readonly`?Zt:nn}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:e.access===`readonly`?$t:on(e.changes)}),(0,Q.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:e.access===`readonly`?(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`shield-check`,loading:t===`switch:${e.upstream}`,onClick:()=>r(!0),children:en}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`check`,loading:t===`check:${e.upstream}`,onClick:i,children:`Check it works`}),(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`eye`,loading:t===`switch:${e.upstream}`,onClick:()=>r(!1),children:tn})]})}),n&&(0,Q.jsxs)(`div`,{className:`mt-3`,children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:n.lines.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Q.jsx)(g,{name:e.ok?`check`:`warning`,size:17,className:e.ok?`mt-0.5 shrink-0 text-ok`:`mt-0.5 shrink-0 text-bad`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,children:e.ok?`Passed: `:`Needs a look: `}),e.text]})]},e.text))}),(0,Q.jsx)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:n.note})]})]})}function un({door:t,busy:n,onBlock:r,onConfirm:i}){let a=sn(t),o=t.links!==void 0;return(0,Q.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-faint py-3 last:border-b-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[15px] font-medium`,children:t.label}),(0,Q.jsx)(e,{tone:a.tone,children:a.label})]}),(0,Q.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:t.detail}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.links.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center sm:gap-3`,children:[(0,Q.jsx)(T,{href:e.url,external:!0,size:`sm`,icon:`external`,className:`shrink-0`,children:e.label}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:e.press})]},e.url))}),t.why&&(0,Q.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:t.why}),(0,Q.jsx)(se,{checked:t.confirmed===!0,disabled:n===`confirm:${t.id}`,onChange:i,label:`I've done this`})]}):t.state!==`closed`&&t.fix.length>0&&(0,Q.jsx)(`ol`,{className:`ml-5 list-decimal text-[13px] text-muted`,children:t.fix.map(e=>(0,Q.jsx)(`li`,{children:e},e))}),t.id===`claude-code-terminal`&&t.state===`harder`&&(0,Q.jsx)(`p`,{className:`text-[13px] text-muted`,children:`Claude Code enforces these rules, but a prefix rule makes a way around them much harder, not impossible. For a guarantee, also log gh out and remove saved GitHub git credentials.`}),t.id===`claude-code-terminal`&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.state!==`closed`&&t.state!==`harder`&&(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`lock`,loading:n===`claude-code`,onClick:()=>r(!0),children:`Block GitHub in Claude Code (all projects)`}),t.undoable?.includes(`user`)&&(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`refresh`,loading:n===`claude-code`,onClick:()=>r(!1),children:`Undo`})]})]})}function dn({servers:t,serverId:n}){let r=H(),i=B(()=>we.guard(),[],3e4),[a,o]=(0,Z.useState)(!1),s=t.filter(e=>e.ok),c=s.find(e=>e.id===n)??s[0];if(!c)return null;let u=i.data?.installed===!0,d=u?s.find(e=>e.id===i.data?.serverId):void 0,f=e=>{o(!0),we.setGuard(e,c.id).then(t=>{r.show(`ok`,`${e?`Turned on`:`Turned off`}. ${t.restartHint}`),t.warning&&r.show(`warn`,t.warning),i.reload()}).catch(e=>r.show(`bad`,W(e))).finally(()=>o(!1))};return(0,Q.jsx)(re,{title:`Guard every Claude Code tool with hmcp`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`Every tool Claude Code uses — connectors, plugins, the terminal and file edits — is checked by your toolbox first. Restart Claude Code after turning this on.`}),(0,Q.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[`Reading web pages counts as looking, so it runs without asking. A web address can carry information out, and the guard does not stop that unless a rule names `,(0,Q.jsx)(`code`,{className:`mono`,children:`claude-code__WebFetch`}),`.`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(e,{tone:u?i.data?.changedByHand?`warn`:`ok`:`neutral`,icon:`shield`,children:u?`On, checked by ${d?.label??`a toolbox`}${i.data?.changedByHand?` (changed by hand)`:``}`:`Off`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-soft`,children:`All projects`})]}),i.error&&(0,Q.jsx)(l,{tone:`warn`,children:i.error}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{size:`sm`,variant:u?`ghost`:`primary`,loading:a,onClick:()=>f(!u),children:u?`Turn off`:`Turn on, checked by ${c.label}`})})]})})}function fn(e){return B(()=>et(e),[e],3e3)}function pn(e){return e?e.externallyRunning?{label:`Run by an AI app`,tone:`ok`}:e.state===`running`?{label:`Running here`,tone:`ok`}:e.state===`starting`?{label:`Starting`,tone:`warn`}:e.state===`exited`?{label:e.exitCode===0?`Stopped`:`Stopped with an error`,tone:e.exitCode===0?`neutral`:`bad`}:{label:`Not running`,tone:`neutral`}:{label:`Checking`,tone:`neutral`}}function mn({token:e,url:t,onClose:n}){return(0,Q.jsx)(le,{open:!!e,onClose:n,dismissable:!1,title:`Copy the password now`,description:`Copy this now; it won't be shown again. Your AI app needs it to connect.`,width:560,footer:(0,Q.jsx)(P,{variant:`primary`,onClick:n,children:`I've copied it`}),children:e&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 text-[14px]`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-2xl bg-sunken p-3`,children:[(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[13px] break-all`,children:e}),(0,Q.jsx)(Pe,{text:e,label:`Copy password`})]}),(0,Q.jsxs)(`p`,{className:`text-muted`,children:[`In your AI app's server settings, add a header named `,(0,Q.jsx)(`code`,{className:`mono`,children:`Authorization`}),` with the value`,` `,(0,Q.jsx)(`code`,{className:`mono`,children:`Bearer`}),`, a space, then this password.`,t&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`The server's address is `,(0,Q.jsx)(q,{children:t})]})]})]})})}function hn({id:n,label:r}){let i=fn(n),{reload:s}=J(),u=H(),[d,f]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(`127.0.0.1`),[E,O]=(0,Z.useState)([]),[k,A]=(0,Z.useState)([]),[j,M]=(0,Z.useState)(!0),[N,F]=(0,Z.useState)(null),I=(e,t=!1)=>{f(e),v(null),(e===`start`?Te(n,{...S===null?{}:{port:S},host:w,...E.length?{allowHosts:E}:{},...k.length?{allowOrigins:k}:{},requireToken:j,...t?{acknowledged:{loosens:!0}}:{}}).then(e=>e.token&&b({token:e.token,url:e.http?.url??null})):e===`stop`?Ke(n):Oe(n)).then(()=>{u.show(`ok`,e===`start`?`${r} started.`:e===`stop`?`${r} stopped.`:`${r} restarted.`),i.reload(),s()}).catch(n=>{e===`start`&&!t&&n instanceof m&&n.needsLoosenAck?F(Ze(n)):v(W(n))}).finally(()=>f(null))};if(i.error&&!i.data)return(0,Q.jsx)(l,{tone:`danger`,title:`Whether your toolbox is running could not be read`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:i.reload,children:`Try again`}),children:W(i.error)});let L=i.data;if(!L)return(0,Q.jsx)(c,{lines:4});let R=pn(L),z=L.state===`running`||L.state===`starting`;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-11 w-11 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:`power`,size:20})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-[16px] font-semibold`,children:[r,` `,(0,Q.jsx)(e,{tone:R.tone,children:R.label})]}),(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:L.externallyRunning?`Started by an AI app on this computer.`:z&&L.startedAt?`Started ${x(L.startedAt)} by this console.`:L.state===`exited`?`It stopped${L.exitCode===null?L.signal?` (${L.signal})`:``:` with exit code ${L.exitCode}`}.`:`Nothing is running it at the moment.`})]}),z&&L.managed&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(P,{icon:`refresh`,onClick:()=>I(`restart`),loading:d===`restart`,disabled:!!d,children:`Restart toolbox`}),(0,Q.jsx)(P,{variant:`danger`,icon:`stop`,onClick:()=>I(`stop`),loading:d===`stop`,disabled:!!d,children:`Stop toolbox`})]})]}),_&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:_}),L.externallyRunning?(0,Q.jsx)(l,{tone:`info`,title:`An AI app runs this toolbox`,children:`The app starts the toolbox itself when it opens and stops it when it closes, so it can't be started or stopped here. To restart the toolbox, for example after changing its settings, quit and reopen the app.`}):z&&L.http?(0,Q.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(X,{sub:`Add this as a server in your AI app's settings. The app then reaches every tool through your toolbox.`,children:`Web address`}),L.http.url&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-2xl bg-sunken p-3`,children:[(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[13px] break-all`,children:L.http.url}),(0,Q.jsx)(Pe,{text:L.http.url,label:`Copy address`})]}),(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:L.http.tokenRequired?`A password is required. It was shown once when the toolbox started; restarting keeps the same one.`:`No password is required, so any program on this computer can reach it.`})]}):(0,Q.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{sub:`Runs your toolbox from this console, so AI apps on this computer can reach it at a web address.`,children:`Start toolbox`}),(0,Q.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Port`,optional:!0,help:`Leave empty to use 7878.`,children:(0,Q.jsx)(a,{value:S,onChange:C,min:1,max:65535})}),(0,Q.jsx)(o,{label:`Address`,help:`This computer only. Your toolbox is never reachable from other computers.`,children:(0,Q.jsx)(h,{label:`Address`,size:`sm`,value:w,onChange:T,options:[{value:`127.0.0.1`,label:`127.0.0.1`},{value:`localhost`,label:`localhost`},{value:`::1`,label:`::1`}]})})]}),(0,Q.jsx)(p,{checked:j,onChange:M,label:`Require a password`,description:`Your AI app must send it to connect, so other programs on this computer can't use your toolbox's tools.`}),(0,Q.jsxs)(Ee,{title:`More options`,children:[(0,Q.jsx)(o,{label:`Other names this computer is reached by`,optional:!0,help:`Only if your app uses a name other than the address above.`,children:(0,Q.jsx)(t,{value:E,onChange:O,placeholder:`my-machine.local`})}),(0,Q.jsx)(o,{label:`Web pages allowed to call it`,optional:!0,help:`Only for an AI app that runs in a browser. Scheme, host and port, such as http://localhost:3000.`,children:(0,Q.jsx)(t,{value:k,onChange:A,placeholder:`http://localhost:3000`})})]}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{variant:`primary`,icon:`play`,onClick:()=>I(`start`),loading:d===`start`,children:`Start toolbox`})})]}),(L.managed||L.log.length>0)&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`What it has written`}),(0,Q.jsx)(ne,{lines:L.log,height:260,label:`${r} output`,empty:`Nothing yet.`})]}),(0,Q.jsx)(mn,{token:y?.token??null,url:y?.url??null,onClose:()=>b(null)}),(0,Q.jsx)(D,{open:!!N,title:`Start a toolbox more can reach?`,onCancel:()=>F(null),confirmLabel:`Start toolbox anyway`,busy:d===`start`,consequences:N??[],onConfirm:()=>{F(null),I(`start`,!0)},children:`Besides AI apps on this computer, your toolbox will also answer the callers listed below.`})]})}function gn({id:e,tab:t,onTab:n,onClose:r,replaceKeyFor:i,onOpened:a}){let{servers:o}=J(),s=o.find(t=>t.id===e);return(0,Q.jsx)(v,{open:!!e,onClose:r,title:s?`${s.label} settings`:`Toolbox settings`,subtitle:`Its connected servers, options, and whether it is running.`,width:820,children:e&&(0,Q.jsx)(_n,{id:e,label:s?.label??e,tab:t,onTab:n,replaceKeyFor:i??null,onOpened:a},e)})}function _n({id:e,label:t,tab:n,onTab:r,replaceKeyFor:i,onOpened:a}){let o=B(()=>Re(e),[e]),s=fn(e),u=H(),{reload:f}=J(),p=Ie(e),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(!1),j=o.data,M=!!j?.broken,N=M&&(n===`servers`||n===`options`)?`file`:n,F=(e,t,n=`Save a change that lets more through?`,r)=>{if(!j)return Promise.resolve(!1);let i=e=>{u.show(`ok`,t),g(Date.now()),v(e.restartNeeded!==!1),o.reload(),p.reload(),f()};return e(j.digest).then(e=>(i(e),!0)).catch(t=>t instanceof m&&t.needsLoosenAck?new Promise(a=>{O(null),C({title:n,body:r,reasons:Ze(t),run:()=>e(j.digest,{loosens:!0}).then(e=>{i(e),a(!0)})})}):(De(t)?b(!0):u.show(`bad`,W(t)),!1))},I=s.data,L=!!I&&(I.externallyRunning||I.state===`running`||I.state===`starting`),R=p.data,z=!!R?.processes.some(e=>e.refusal),ee=L&&(R&&R.running?z||!R.applied&&(h===null||Date.now()-h>6e3):_||j&&!j.broken&&j.restartNeededFor.length>0),te=M?[{id:`file`,label:`Settings file`},{id:`run`,label:`Run`}]:[{id:`servers`,label:`Connected servers`,count:j?.config?.upstreams.length},{id:`options`,label:`Toolbox options`},{id:`run`,label:`Run`},{id:`file`,label:`Settings file`}];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[ee&&(0,Q.jsxs)(l,{tone:`warn`,role:`status`,title:`Restart needed for changes to take effect`,actions:I?.managed&&!I.externallyRunning?(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`refresh`,loading:k,onClick:()=>{A(!0),Oe(e).then(()=>{u.show(`ok`,`${t} restarted with the new settings.`),g(null),s.reload(),o.reload()}).catch(e=>u.show(`bad`,W(e))).finally(()=>A(!1))},children:`Restart toolbox`}):void 0,children:[z&&j&&j.restartNeededFor.length>0?`${j.restartNeededFor[0]}`:z?`The running toolbox can only take this change when it starts again. `:`The running toolbox hasn't picked up this change. `,z&&j&&j.restartNeededFor.length>0?``:I?.externallyRunning?`An AI app runs it: quit that app completely and open it again.`:`It still uses the old settings until it restarts.`]}),y&&(0,Q.jsx)(l,{tone:`warn`,title:`This changed since you opened it. Reload and try again.`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:()=>{b(!1),o.reload()},children:`Reload settings`})}),j?.broken&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`This toolbox's settings file can't be loaded`,children:j.broken}),(0,Q.jsx)(ie,{items:te,value:N,onChange:r,label:`Toolbox settings`}),(0,Q.jsx)(`div`,{role:`tabpanel`,id:S(N),"aria-labelledby":d(N),children:N===`run`?(0,Q.jsx)(hn,{id:e,label:t}):o.error&&!j?(0,Q.jsx)(l,{tone:`danger`,title:`The toolbox's settings file could not be read`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:o.reload,children:`Try again`}),children:W(o.error)}):j?N===`file`?(0,Q.jsx)(Cn,{id:e,file:j,write:F}):j.broken===null&&N===`servers`?(0,Q.jsx)(vn,{id:e,file:j,write:F,live:R??null,running:L,onReload:()=>{g(Date.now()),o.reload(),p.reload(),f()},start:i?{kind:`replace-key`,server:i}:void 0,onStarted:a}):j.broken===null?(0,Q.jsx)(xn,{id:e,file:j,write:F},j.digest):null:(0,Q.jsx)(c,{lines:6})}),(0,Q.jsx)(D,{open:!!x,title:x?.title??``,onCancel:()=>C(null),confirmLabel:`Save anyway`,busy:w,error:E,consequences:x?.reasons,onConfirm:()=>{x&&(T(!0),x.run().then(()=>C(null)).catch(e=>O(W(e))).finally(()=>T(!1)))},children:x?.body??`This change lets more through than before, so it needs your confirmation.`})]})}function vn({id:t,file:n,write:r,live:a,running:o,onReload:s,start:c,onStarted:l}){let u=n.config.upstreams,{nav:d}=J(),f=H(),p=tt(),[m,h]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(()=>{if(c?.kind===`by-hand`)return{original:null,draft:at()};let e=c?u.find(e=>e.name===c.server):void 0;return e&&c?.kind===`replace-key`&&he(e)?null:e?{original:e.name,draft:ct(e)}:null}),[x,S]=(0,Z.useState)(()=>{let e=c?.kind===`replace-key`?u.find(e=>e.name===c.server):void 0;return e?he(e):null});(0,Z.useEffect)(()=>{c&&l?.()},[]);let[C,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(null),A=Qe(t);if(y){let e=u.map(e=>e.name).filter(e=>e!==y.original),i=mt(y.draft,e);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{sub:y.original?`Values shown as kept secret stay as they are unless you type a new one.`:void 0,children:y.original?`Edit ${y.original}`:`Add a server`}),(0,Q.jsx)(it,{value:y.draft,onChange:e=>b({...y,draft:e}),nameLocked:!!y.original,secret:n.keptSecret,literalWarning:!0}),C&&i&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-[13px] font-medium text-bad`,children:i}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:()=>b(null),disabled:E,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`check`,onClick:()=>{T(!0),!i&&(D(!0),bn(ot(y.draft),n.keptSecret).then(e=>r((n,r)=>y.original?ge(t,y.original,e,n,r):nt(t,e,n,r),y.original?`${e.name} was saved.`:`${e.name} was added.`,`Save this server?`)).then(e=>e&&b(null)).catch(e=>f.show(`bad`,W(e))).finally(()=>D(!1)))},loading:E,children:y.original?`Save server`:`Add server`})]})]})}if(_)return(0,Q.jsx)(ut,{gatewayId:t,fixUpstream:_,onCancel:()=>{ft(),v(null)},onDone:e=>{ft(),v(null),f.show(`ok`,`${e.upstreamName} was saved.`),s()}});if(m)return(0,Q.jsx)(ut,{gatewayId:t,onCancel:()=>{ft(),h(!1)},onDone:e=>{h(!1),f.show(`ok`,`${e.upstreamName} was added.`),s()}});let j=u.length===1;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Q.jsxs)(`p`,{className:`text-[13.5px] text-soft`,children:[`The servers this toolbox sits in front of. `,(0,Q.jsx)(w,{term:`connectedServer`})]}),(0,Q.jsxs)(`span`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`edit`,onClick:()=>{T(!1),b({original:null,draft:at()})},children:`Add one by hand`}),(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`plus`,onClick:()=>h(!0),children:`Add a server`})]})]}),(0,Q.jsx)(ze,{id:t,upstreams:u,digest:n.digest,onMoved:s}),(0,Q.jsx)(Ve,{secret:x,onClose:()=>S(null),onSaved:()=>{S(null),f.show(`ok`,`The new key is saved. The server is tried again with it.`),s()}}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:u.map(n=>{let r=Ue(a,n.name),c=(A.data??[]).find(e=>e.server===n.name),l=r&&r.state===`connected`&&c?{...r,state:`failed`,problem:Le(n,c)}:r,u=o&&!!a?.running&&!!l&&(l.state===`failed`||l.state===`needs-sign-in`),f=!u&&He(n,p.data??null);return(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 rounded-[18px] border border-line p-3.5`,children:[(0,Q.jsx)(`span`,{className:`grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:n.transport===`http`?`external`:`server`,size:18})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`code`,{className:`mono text-[14px] font-semibold`,children:n.name}),(0,Q.jsx)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:n.transport===`http`?`Remote server · ${n.url}`:`Runs on this computer · ${[n.command,...n.args??[]].join(` `)}`}),(0,Q.jsx)(`span`,{className:`mt-1 block`,role:`status`,children:(0,Q.jsx)(Je,{live:a,running:o,state:l})})]}),n.on_injection&&(0,Q.jsx)(e,{children:be[n.on_injection].label}),(0,Q.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`edit`,onClick:()=>{T(!1),b({original:n.name,draft:ct(n)})},children:`Edit`}),(0,Q.jsx)(N,{icon:`trash`,label:j?`${n.name} is the only server and can't be removed`:`Remove ${n.name}`,size:36,disabled:j,onClick:()=>k(n.name)})]}),u&&l&&(0,Q.jsx)(qe,{gatewayId:t,upstream:n,state:l,onEdit:e=>{if(e===`choose-folder`||e===`replace-key`||e===`sign-in`){let t=l.problem?.detail?.path;v({upstream:n,action:e,...t?{path:t}:{}})}else T(!1),b({original:n.name,draft:ct(n)})},onFixed:s,onAllowAddress:()=>ue(i(d,`/protection`,{server:t}))}),f&&(0,Q.jsx)(qe,{gatewayId:t,upstream:n,state:{name:n.name,state:`needs-sign-in`,since:``,attempts:0,tool_count:0},onEdit:e=>e===`sign-in`?v({upstream:n,action:e}):b({original:n.name,draft:ct(n)}),onFixed:s,onAllowAddress:()=>void 0})]},n.name)})}),j&&(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:`A toolbox needs at least one server, so the last one can't be removed. Add another first, or remove the whole toolbox from the console.`}),(0,Q.jsx)(le,{open:!!O,onClose:()=>k(null),tone:`danger`,title:`Remove ${O}?`,description:yn(u.find(e=>e.name===O)),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{variant:`secondary`,onClick:()=>k(null),disabled:E,children:`Keep server`}),(0,Q.jsx)(P,{variant:`danger`,loading:E,onClick:()=>{let e=O;D(!0),r(n=>$e(t,e,n),`${e} was removed.`).then(()=>k(null)).finally(()=>D(!1))},children:`Remove server`})]})})]})}function yn(e){let t=[...Object.values(e?.env??{}),...Object.values(e?.headers??{}),e?.oauth].map(e=>e&&typeof e==`object`&&typeof e.secret==`string`?e.secret:null).filter(e=>e!==null),n=[...new Set(t)];return`Your AI app loses this server's tools, and the protection rules made for them are removed too.`+(n.length>0?` Its locked ${n.length===1?`key`:`keys`} (${n.join(`, `)}) ${n.length===1?`stays`:`stay`} saved; remove ${n.length===1?`it`:`them`} under Settings & help, Locked keys, if you no longer need ${n.length===1?`it`:`them`}.`:``)}async function bn(e,t){let r=async r=>{if(!r)return r;let i={};for(let[a,o]of Object.entries(r))if(typeof o==`string`&&o!==``&&o!==t&&!/\$\{[^}]*\}/.test(o)&&Fe(a)){let t=/^(Bearer|Basic|Token) /i.exec(o)?.[0],r=t?o.slice(t.length):o,s=await n.createSecret({label:`${e.name} ${a}`,value:r});i[a]=t?{secret:s.name,prefix:t}:{secret:s.name}}else i[a]=o;return i},i=await r(e.env),a=await r(e.headers);return{...e,...i?{env:i}:{},...a?{headers:a}:{}}}function $({title:e,help:t,technical:n,children:r,onSave:i,dirty:a,busy:o,onReset:s}){return(0,Q.jsxs)(`div`,{className:`grid gap-3 border-b border-faint py-5 first:pt-0 last:border-b-0 md:grid-cols-[1fr_minmax(0,300px)]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-2 text-[14.5px] font-semibold`,children:[e,` `,(0,Q.jsx)(`code`,{className:`mono text-[11.5px] font-normal text-soft`,children:n})]}),(0,Q.jsx)(`div`,{className:`mt-1 text-[13px] text-soft`,children:t})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[r,(i||s)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[s&&(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:s,disabled:o,children:`Use the default`}),i&&(0,Q.jsx)(P,{size:`sm`,variant:`primary`,onClick:i,disabled:!a,loading:o,children:`Save setting`})]})]})]})}function xn({id:e,file:t,write:n}){let r=t.config,i=(t.text??``).match(/^(\w+):/gm)?.map(e=>e.slice(0,-1))??[],[o,s]=(0,Z.useState)(null),c=(t,r,i,a)=>(s(t),n((n,i)=>ve(e,t,r,n,i),i,a).finally(()=>s(null))),[l,u]=(0,Z.useState)(r.name),[d,m]=(0,Z.useState)(r.connect_timeout_ms/1e3),[h,_]=(0,Z.useState)(r.on_injection),[v,y]=(0,Z.useState)(Object.entries(r.injection_overrides)),[b,x]=(0,Z.useState)(r.max_tool_name_length??null),S=r.notify===void 0?`auto`:r.notify?`on`:`off`,C=Object.fromEntries(v.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t]));return(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)($,{title:`Name`,technical:`name`,help:(0,Q.jsx)(Q.Fragment,{children:`Shown in the activity log and to your AI app. Renaming moves the toolbox to a new identity: tools you turned off, pre-approvals and reviewed tool changes are stored under the old name and stop applying, so it counts as loosening.`}),dirty:l.trim()!==r.name&&!!l.trim(),busy:o===`name`,onSave:()=>c(`name`,l.trim(),`The toolbox was renamed.`,`Rename this toolbox?`),children:(0,Q.jsx)(f,{value:l,onChange:u,mono:!0,"aria-label":`Toolbox name`})}),(0,Q.jsx)($,{title:`Time to wait for each server to start`,technical:`connect_timeout_ms`,help:`Your toolbox connects every server before serving any tool. A slow server gets this long before the toolbox gives up and says which one failed.`,dirty:d!==null&&d*1e3!==r.connect_timeout_ms,busy:o===`connect_timeout_ms`,onSave:()=>c(`connect_timeout_ms`,Math.round(d*1e3),`The start-up wait was saved.`),onReset:i.includes(`connect_timeout_ms`)?()=>c(`connect_timeout_ms`,null,`The start-up wait is back to 20 seconds.`):void 0,children:(0,Q.jsx)(a,{value:d,onChange:m,min:1,unit:`seconds`,"aria-label":`Seconds to wait`})}),(0,Q.jsx)($,{title:(0,Q.jsxs)(Q.Fragment,{children:[`Hidden instructions in tool descriptions `,(0,Q.jsx)(w,{term:`HMCP005`})]}),technical:`on_injection`,help:be[h].explain+` Each server can have its own setting too.`,dirty:h!==r.on_injection,busy:o===`on_injection`,onSave:()=>c(`on_injection`,h,`Hidden-instruction handling was saved.`,`Handle hidden instructions less strictly?`),children:(0,Q.jsx)(I,{value:h,onChange:_,"aria-label":`Hidden instructions`,options:[`strip`,`deny`,`annotate`].map(e=>({value:e,label:be[e].label}))})}),(0,Q.jsx)($,{title:`Descriptions you checked`,technical:`injection_overrides`,help:`For a tool whose description was flagged by mistake. Name the tool as your AI app sees it, such as files__read_file.`,dirty:JSON.stringify(C)!==JSON.stringify(r.injection_overrides),busy:o===`injection_overrides`,onSave:()=>c(`injection_overrides`,C,`Checked descriptions were saved.`,`Trust these descriptions?`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[v.map(([e,t],n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(f,{value:e,onChange:e=>y(v.map((t,r)=>r===n?[e,t[1]]:t)),mono:!0,"aria-label":`Tool ${n+1}`,placeholder:`files__read_file`}),(0,Q.jsx)(N,{icon:`trash`,label:`Remove ${e||`row ${n+1}`}`,size:34,onClick:()=>y(v.filter((e,t)=>t!==n))})]},n)).flatMap((e,t)=>[e,(0,Q.jsx)(I,{value:v[t][1],onChange:e=>y(v.map((n,r)=>r===t?[n[0],e]:n)),"aria-label":`How to treat tool ${t+1}`,options:[`accept`,`annotate`,`strip`,`deny`].map(e=>({value:e,label:be[e].label}))},`m${t}`)]),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`plus`,onClick:()=>y([...v,[``,`accept`]]),children:`Add a tool`})})]})}),(0,Q.jsx)($,{title:`Put the server's name in front of each tool`,technical:`namespace`,help:`Tools are shown as server__tool, so two servers can't offer look-alike tools. Turning it off renames every tool, so rules and switches naming them stop applying.`,children:(0,Q.jsx)(p,{checked:r.namespace,disabled:o===`namespace`,onChange:e=>c(`namespace`,e,e?`Tool names now include the server.`:`Tool names no longer include the server.`,`Rename every tool?`),label:r.namespace?`On`:`Off`})}),(0,Q.jsx)($,{title:`Apply protection changes without a restart`,technical:`policy_reload`,help:`When the protection settings file changes, the running toolbox picks it up straight away. A file with a mistake is ignored and the old settings stay in force.`,children:(0,Q.jsx)(p,{checked:r.policy_reload,disabled:o===`policy_reload`,onChange:e=>c(`policy_reload`,e,e?`Protection changes now apply straight away.`:`Protection changes now wait for a restart.`),label:r.policy_reload?`On`:`Off`})}),(0,Q.jsx)($,{title:`Longest tool name`,technical:`max_tool_name_length`,help:`AI services refuse a request if any tool name is too long, which breaks every tool at once. A tool with a longer name is held back instead. Empty means no limit.`,dirty:(b??void 0)!==r.max_tool_name_length,busy:o===`max_tool_name_length`,onSave:()=>c(`max_tool_name_length`,b,b?`The name limit was saved.`:`The name limit was removed.`),children:(0,Q.jsx)(a,{value:b,onChange:x,min:1,unit:`letters`,"aria-label":`Longest tool name`})}),(0,Q.jsx)($,{title:`Desktop notifications`,technical:`notify`,help:`Show a notification on this computer when a call waits for you. Automatic means on when an app runs the toolbox on this computer, off when it serves over a web address.`,children:(0,Q.jsx)(I,{value:S,"aria-label":`Desktop notifications`,onChange:e=>c(`notify`,e===`auto`?null:e===`on`,`Notification setting saved.`),options:[{value:`auto`,label:`Automatic`},{value:`on`,label:`On`},{value:`off`,label:`Off`}]})}),(0,Q.jsxs)(`div`,{className:`mt-2 rounded-[18px] bg-sunken/60 p-4`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-[14.5px] font-semibold`,children:[(0,Q.jsx)(g,{name:`lock`,size:17}),` Settings the console can't change`]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-soft`,children:`These decide what the console itself may do. If the console could change them, it could give itself permission, so they can only be changed by editing the file outside the console.`}),(0,Q.jsxs)(`dl`,{className:`mt-3 grid gap-2 text-[13.5px] sm:grid-cols-2`,children:[(0,Q.jsx)(Sn,{term:`Console may change protection rules`,technical:`policy_writes`,on:t.guarded.policy_writes}),(0,Q.jsx)(Sn,{term:`Console may reverse an existing decision`,technical:`policy_overrides`,on:t.guarded.policy_overrides})]})]})]})}function Sn({term:t,technical:n,on:r}){return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-2xl bg-surface px-3 py-2.5`,children:[(0,Q.jsxs)(`dt`,{children:[t,(0,Q.jsx)(`code`,{className:`mono block text-[11.5px] text-soft`,children:n})]}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(e,{tone:r?`ok`:`neutral`,children:r?`Allowed`:`Not allowed`})})]})}function Cn({id:e,file:t,write:n}){let[i,a]=(0,Z.useState)(t.text??``),[o,s]=(0,Z.useState)(null),[c,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{a(t.text??``),s(null)},[t.digest]),t.text===null)return(0,Q.jsxs)(b,{icon:`file`,title:`This file has to be fixed in a text editor`,children:[`It isn't readable as a settings file at all, so the console can't show it. Open it in a text editor, fix it, then reopen these settings.`,(0,Q.jsx)(`span`,{className:`mt-2 block`,children:(0,Q.jsx)(q,{children:t.path})})]});let h=()=>{u(!0),m(null),_e(e,i).then(s).catch(e=>m(W(e))).finally(()=>u(!1))},g=()=>{f(!0),n((t,n)=>ye(e,i,t,n),t.broken?`The settings file was repaired.`:`The settings file was saved.`,t.broken?`Save the repaired settings file?`:`Save the edited settings file?`,t.broken?`This file couldn't be loaded, so the console can't compare what your fix changes. Check it carefully before saving.`:void 0).finally(()=>f(!1))},_=i!==t.text,v=o&&_;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`p`,{className:`text-[13.5px] text-soft`,children:[`The toolbox's whole settings file, for changes the forms don't cover. Keys in your locked keys appear only by name. A key still written out in the file shows as `,(0,Q.jsx)(`code`,{className:`mono`,children:`[kept secret]`}),`; leave that marker and the stored value is kept. The protection-settings entry and the two settings the console can't change are refused here.`,(0,Q.jsx)(`span`,{className:`mt-1 block`,children:(0,Q.jsx)(q,{children:t.path})})]}),(0,Q.jsx)(ee,{value:i,onChange:e=>{a(e),s(null)},label:`Settings file`,rows:18,error:o&&!o.valid?o.error:null}),p&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:p}),v&&o.valid&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{children:`What changes`}),(0,Q.jsx)(j,{before:t.text??``,after:i,label:`Changes to the settings file`}),t.broken?(0,Q.jsx)(l,{tone:`warn`,title:`Saving needs your confirmation`,children:`This file couldn't be loaded, so the console can't compare what your fix changes.`}):o.loosens.length>0&&(0,Q.jsx)(l,{tone:`warn`,title:`This lets more through`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc pl-5`,children:o.loosens.map(e=>(0,Q.jsx)(`li`,{children:e},e))})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:()=>{a(t.text??``),s(null)},disabled:!_,children:`Undo my edits`}),v&&o.valid?(0,Q.jsx)(P,{variant:`primary`,icon:`check`,onClick:g,loading:d,children:t.broken?`Save repaired file`:`Save settings file`}):(0,Q.jsx)(P,{variant:`primary`,onClick:h,loading:c,disabled:!_,children:`Check changes`})]}),(0,Q.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[`Changes to servers reach a running toolbox straight away; anything else applies the next time it starts. `,r(i.split(`
|
|
1
|
+
import{$ as e,A as t,At as n,B as r,Ct as i,D as a,E as o,Et as s,G as c,H as l,It as u,J as d,M as f,N as p,Nt as m,O as h,Ot as g,Pt as _,S as v,St as y,U as b,V as x,Y as S,Z as C,_ as w,_t as T,at as E,b as D,bt as O,c as k,et as A,f as j,ft as M,gt as N,ht as P,it as F,k as I,kt as L,l as R,lt as z,m as ee,mt as te,p as ne,pt as re,q as ie,s as B,st as V,u as ae,vt as oe,w as se,wt as ce,x as le,xt as ue,y as H,yt as U,z as de}from"./kit-BHB_ha4i.js";import{r as fe,t as pe}from"./server-name-D9u6r07i.js";import{$ as me,$t as he,An as ge,Cn as _e,Dn as ve,En as ye,Ft as be,Gt as xe,Ht as Se,It as Ce,Kt as W,Mn as we,On as Te,Q as Ee,Qt as De,Rt as G,Tn as Oe,Ut as ke,Vt as Ae,Wt as je,X as Me,Xt as Ne,Z as Pe,Zt as Fe,_ as Ie,an as Le,bn as Re,cn as K,d as ze,en as Be,et as q,f as Ve,g as He,h as Ue,hn as We,in as Ge,kn as Ke,m as qe,mn as J,p as Je,qt as Ye,rn as Y,s as Xe,tn as Ze,tt as X,v as Qe,wn as $e,xn as et,y as tt,yn as nt}from"./index-2otwle61.js";import{a as rt,c as it,d as at,f as ot,i as st,l as ct,n as lt,o as ut,r as dt,s as ft,t as pt,u as mt}from"./AttachApp-CuSl69fx.js";import{m as ht,p as gt}from"./connect-app-words-B_5RQcK_.js";var Z=u(),Q=L(),_t=[`Choose an app`,`Choose how it starts`,`Check what will happen`,`Connect`],vt={mode:`observe`,posture:`approve-writes`,onUnclassified:`approve`,packs:!0,clientAllow:!1,gatewayName:``,entryName:``,rename:[],copyEnv:!1,allowLocalHttp:!1,strictEgress:!1,relativeConfig:!1,outDir:``,id:``};function yt(e,t,n,r){let i=Object.fromEntries(r.rename.filter(([e,t])=>e.trim()&&t.trim()).map(([e,t])=>[e.trim(),t.trim()]));return{scope:e,...n&&t?{projectDir:t}:{},mode:r.mode,posture:r.posture,onUnclassified:r.onUnclassified,packs:r.packs,...Ne(e)&&r.mode===`enforce`?{clientAllow:r.clientAllow}:{},...r.gatewayName.trim()?{gatewayName:r.gatewayName.trim()}:{},...r.entryName.trim()?{entryName:r.entryName.trim()}:{},...Object.keys(i).length?{rename:i}:{},copyEnv:r.copyEnv,allowLocalHttp:r.allowLocalHttp,strictEgress:r.strictEgress,relativeConfig:r.relativeConfig,...r.outDir.trim()?{outDir:r.outDir.trim()}:{},...r.id.trim()?{id:r.id.trim()}:{}}}var bt={done:null,undo:null};function xt({open:e,onClose:t}){let n=()=>{bt.done=null,bt.undo=null,t()};return(0,Q.jsx)(v,{open:e,onClose:n,title:`Connect an app`,subtitle:`Put your toolbox between one of your AI apps and the servers it uses.`,width:880,children:e&&(0,Q.jsx)(St,{onClose:n})})}function St({onClose:e}){let{nav:t,reload:n}=J(),[r,a]=(0,Z.useState)(0),[o,s]=(0,Z.useState)(``),c=(0,Z.useRef)(!1),u=O(o.trim(),450),d=B(()=>we.clients(u||void 0),[u]);(0,Z.useEffect)(()=>{d.data&&!c.current&&!o&&s(d.data.projectDir)},[d.data]);let[f,p]=(0,Z.useState)(null),h=d.data?.clients.find(e=>e.scope===f)??null,[g,_]=(0,Z.useState)(vt),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(bt.undo),S=e=>{bt.undo=e,x(e)},C=(0,Z.useMemo)(()=>h?yt(h.scope,d.data?.projectDir??``,h.projectScoped,g):null,[h,d.data?.projectDir,g]),w=JSON.stringify(C),[T,E]=(0,Z.useState)(null),D=r>=2&&C&&T?.key!==w;(0,Z.useEffect)(()=>{if(r<2||!C||T?.key===w)return;let e=!0;return we.plan(C).then(t=>e&&E({key:w,data:t,error:null})).catch(t=>e&&E({key:w,data:null,error:W(t)})),()=>{e=!1}},[r,w]);let[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(null),[N,F]=(0,Z.useState)(bt.done),I=()=>{C&&(A(!0),M(null),we.apply(C).then(e=>{bt.done=e,F(e)}).catch(e=>{if(e instanceof m&&e.status===409){M({text:`A toolbox with that name is already in the console. Choose another name and try again.`,idTaken:!0});return}let t=e.detail;t?.report&&E({key:w,data:t.report,error:null}),M({text:W(e),blocking:t?.blocking})}).finally(()=>A(!1)))};if(N)return(0,Q.jsx)(It,{result:N,onClose:()=>{e(),n()},onOpen:r=>{e(),n(),ue(i(t,`/`,{server:r}))}});let L=T?.key===w?T:null,R=!!L?.data&&L.data.blocking.length>0,z=r===0?!!h&&h.exists&&!h.error&&(h.serverCount>0||h.alreadyAdopted):r===1||!!L?.data&&!R;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(ae,{steps:_t,step:r,onStep:e=>a(Math.max(0,e)),canNext:z&&!k,nextLabel:r===2?`Review and connect`:`Continue`,finishLabel:h?`Connect ${G(h.scope)}`:`Connect app`,onFinish:I,busy:k||!!D,children:[r===0&&(0,Q.jsx)(Ct,{clients:d,projectDir:o,onProjectDir:e=>{c.current=!0,s(e)},scope:f,onScope:p,onUndo:S,onAttach:y}),r===1&&h&&(0,Q.jsx)(Dt,{client:h,choices:g,onChange:_,found:L?.data?.serversFound??T?.data?.serversFound??[]}),r===2&&(D||!L?(0,Q.jsx)(Ot,{}):L.error?(0,Q.jsx)(l,{tone:`danger`,title:`The check could not finish`,role:`alert`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:()=>E(null),children:`Check again`}),children:L.error}):(0,Q.jsx)(At,{plan:L.data,app:G(h.scope)})),r===3&&L?.data&&h&&(0,Q.jsx)(Ft,{plan:L.data,client:h,error:j,id:g.id,onId:e=>_({...g,id:e})})]}),(0,Q.jsx)(Lt,{client:v,onClose:()=>y(null),onDone:()=>d.reload()}),(0,Q.jsx)(lt,{client:b,projectDir:d.data?.projectDir,onClose:()=>S(null),onDone:()=>{d.reload(),n()}})]})}function Ct({clients:e,projectDir:t,onProjectDir:n,scope:r,onScope:i,onUndo:a,onAttach:s}){let u=e.data?.clients??[],d=e.error&&!e.data?null:e.error;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`Pick the app whose tools you want your toolbox to check. The servers it already uses keep working; they are reached through your toolbox instead of directly.`}),(0,Q.jsx)(o,{label:`Project folder`,help:`Some apps keep a server list per project. This is the project they are read from. Use the full path.`,error:d?W(d):null,children:(0,Q.jsx)(f,{value:t,onChange:n,mono:!0,placeholder:`/Users/me/my-project`})}),e.error&&!e.data?(0,Q.jsx)(l,{tone:`danger`,title:`Your apps could not be checked`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:e.reload,children:`Check again`}),children:W(e.error)}):e.data?(0,Q.jsx)(`div`,{role:`radiogroup`,"aria-label":`App to connect`,className:`grid gap-3 sm:grid-cols-2`,children:[...u].sort((e,t)=>wt(e)-wt(t)).map(t=>(0,Q.jsx)(Et,{client:t,projectDir:e.data?.projectDir,selected:r===t.scope,onSelect:()=>i(t.scope),onUndo:()=>a(t),onAttach:()=>s(t)},t.scope))}):(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[0,1,2,3].map(e=>(0,Q.jsx)(`div`,{className:`rounded-[18px] border border-line p-4`,children:(0,Q.jsx)(c,{lines:3})},e))})]})}var wt=e=>e.error?3:e.alreadyAdopted?1:e.exists&&e.serverCount>0?0:Ae(e)?2:4,Tt=e=>!e.alreadyAdopted&&Ae(e)&&!(e.exists&&e.serverCount>0);function Et({client:t,projectDir:n,selected:i,onSelect:a,onUndo:o,onAttach:s}){let c=t.exists&&!t.error&&(t.serverCount>0||t.alreadyAdopted)&&!t.attachedTo,l=Tt(t),u=(0,Z.useId)(),d=Be(t),f=t.error?{tone:`bad`,text:`Can't be read`}:!t.exists&&!l?{tone:`neutral`,text:`Not found`}:t.alreadyAdopted?{tone:`ok`,text:`Connected`}:t.serverCount===0?{tone:`neutral`,text:`No servers yet`}:{tone:`warn`,text:`Not protected`};return(0,Q.jsxs)(`div`,{className:U(`flex min-w-0 flex-col gap-2 rounded-[18px] border-[1.5px] p-4 transition-colors`,i?`border-primary bg-ok-tint`:`border-line`,!c&&`bg-sunken/40`),children:[(0,Q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":i,"aria-labelledby":`${u}-name`,"aria-describedby":`${u}-status ${u}-desc`,disabled:!c,onClick:a,className:`flex min-w-0 flex-col items-start gap-1 text-left disabled:cursor-not-allowed`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full items-start gap-2`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:U(`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-full border-[1.5px]`,i?`border-primary bg-primary text-white`:`border-[var(--soft)]`,!c&&`opacity-40`),children:i&&(0,Q.jsx)(g,{name:`check`,size:12,strokeWidth:3})}),(0,Q.jsx)(`span`,{id:`${u}-name`,className:U(`min-w-0 flex-1 text-[15px] font-semibold`,!c&&`text-soft`),children:d}),(0,Q.jsx)(`span`,{id:`${u}-status`,children:(0,Q.jsx)(e,{tone:f.tone,children:f.text})})]}),(0,Q.jsx)(`span`,{id:`${u}-desc`,className:`pl-7 text-[13px] text-soft`,children:t.error?K(Y(t.error)):l?`It has no servers yet. Connect it to your toolbox, then add servers there.`:t.exists?t.alreadyAdopted?t.servers?ke(t.servers,je(t)):Se(t.serverCount):t.serverCount===0?`The app has no servers set up, so there is nothing to protect yet.`:`${r(t.serverCount,`server`)} set up, reached directly with nothing checking them.`:`This app's settings file isn't on this computer.`}),t.exists&&(0,Q.jsx)(`span`,{className:`pl-7`,children:(0,Q.jsx)(q,{children:t.path})})]}),l&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`plug`,onClick:s,children:`Connect it to your toolbox`})}),t.attachedTo&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(rt,{client:t,...n?{projectDir:n}:{}})}),t.canRevert&&(0,Q.jsx)(`div`,{className:`pl-7`,children:(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:o,children:`Undo connection`})})]})}function Dt({client:t,choices:n,onChange:r,found:i}){let a=(e,t)=>r({...n,[e]:t}),s=Ne(t.scope);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:`You can switch at any time on the Protection settings page.`,children:[`How it starts `,(0,Q.jsx)(w,{term:`watchOnly`})]}),(0,Q.jsx)(Me,{label:`How it starts`,value:n.mode,onChange:e=>a(`mode`,e),options:[{value:`observe`,title:E.observe.label,badge:(0,Q.jsx)(e,{tone:`ok`,children:`Recommended for day one`}),body:`Nothing breaks while you settle in. Every call runs, and the activity log shows what would have been blocked or held, so you can adjust before turning protection on.`},{value:`enforce`,title:E.enforce.label,body:`Rules apply from the first call. Blocked calls stop and changes wait for you, which can interrupt work until the rules fit.`}]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:`What happens to a call no rule mentions.`,children:[`How careful the toolbox is `,(0,Q.jsx)(w,{term:`defaultStance`})]}),(0,Q.jsx)(Me,{label:`How careful the toolbox is`,columns:3,value:n.posture,onChange:e=>a(`posture`,e),options:Object.keys(V).map(e=>({value:e,title:V[e].label,body:V[e].explain}))})]}),(0,Q.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(o,{label:(0,Q.jsxs)(Q.Fragment,{children:[`Tools nobody has labelled yet `,(0,Q.jsx)(w,{term:`unknownTools`})]}),help:`A tool that hasn't said whether it only looks, makes changes or deletes.`,children:(0,Q.jsx)(h,{label:`Tools nobody has labelled yet`,value:n.onUnclassified,onChange:e=>a(`onUnclassified`,e),options:[{value:`approve`,label:`Ask me first`},{value:`deny`,label:`Block them`}]})}),(0,Q.jsx)(p,{checked:n.packs,onChange:e=>a(`packs`,e),label:`Use ready-made rules for servers your toolbox knows`,description:`For well-known servers such as file system and GitHub, sensible rules are filled in for each tool so you start with less to decide.`}),(0,Q.jsx)(p,{checked:s&&n.mode===`enforce`&&n.clientAllow,onChange:e=>a(`clientAllow`,e),disabled:!s||n.mode!==`enforce`,label:`Don't ask me twice`,description:s?n.mode===`enforce`?`Claude Code asks before each tool call, and your toolbox asks too when a rule says so. This stops Claude Code asking about your toolbox's tools, so you answer once.`:`Available when protecting. While it only watches, your toolbox never asks, so Claude Code's own question is the only one left.`:`Only Claude Code has this setting. ${G(t.scope)} keeps asking in its own way.`})]}),(0,Q.jsxs)(Ee,{title:`More options`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Toolbox name`,technical:`name`,optional:!0,help:`Shown in the console and in the activity log.`,children:(0,Q.jsx)(f,{value:n.gatewayName,onChange:e=>a(`gatewayName`,e),mono:!0,placeholder:`claude-code`})}),(0,Q.jsx)(o,{label:`Name in the app's server list`,optional:!0,technical:`entry name`,help:`What your toolbox is called inside the app.`,children:(0,Q.jsx)(f,{value:n.entryName,onChange:e=>a(`entryName`,e),mono:!0,placeholder:`hmcp`})})]}),(0,Q.jsx)(o,{label:`Rename servers`,optional:!0,help:i.length?`Found in the app: ${i.join(`, `)}. New names use lower-case letters, digits and underscores.`:`The name in the app on the left, the name in your toolbox on the right. Lower-case letters, digits and underscores.`,children:(0,Q.jsx)(me,{value:n.rename,onChange:e=>a(`rename`,e),keyLabel:`Name in the app`,valueLabel:`Name in your toolbox`,addLabel:`Add a rename`})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(p,{checked:n.copyEnv,onChange:e=>a(`copyEnv`,e),label:`Copy keys into the toolbox's settings file`,description:`Gives each server its own copy of the values it needs, such as access keys.`}),n.copyEnv&&(0,Q.jsx)(l,{tone:`warn`,title:`This writes passwords and keys into a file`,children:`The toolbox's settings file will hold them in plain text, outside your locked keys. Anyone who can read that file can read them, so don't share it or put it anywhere others can see. Leave this off unless a server was left out because of its values.`})]}),(0,Q.jsx)(p,{checked:n.allowLocalHttp,onChange:e=>a(`allowLocalHttp`,e),label:`Allow servers on this computer`,description:`Lets your toolbox reach web servers on this computer or your local network. This adds to your allowed addresses for every web server this toolbox reaches, not just one.`}),(0,Q.jsx)(p,{checked:n.strictEgress,onChange:e=>a(`strictEgress`,e),label:`Strict allowed addresses`,description:`Each remote server may be reached only at its exact address and port, rather than anywhere on its host.`}),(0,Q.jsx)(p,{checked:n.relativeConfig,onChange:e=>a(`relativeConfig`,e),label:`Point to the toolbox's settings file by a relative path`,description:`Useful when the project folder is shared or moved, so the app finds the toolbox's settings file wherever the folder lives.`}),(0,Q.jsx)(o,{label:`Folder for the toolbox's files`,optional:!0,help:`A full path. By default they go in a .hmcp folder in the project, or in your home folder for apps that aren't per project.`,children:(0,Q.jsx)(f,{value:n.outDir,onChange:e=>a(`outDir`,e),mono:!0,placeholder:`/Users/me/my-project/.hmcp`})})]})]})}function Ot(){let[e,t]=(0,Z.useState)(0);return(0,Z.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]),(0,Q.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex flex-col items-center gap-4 py-14 text-center`,children:[(0,Q.jsx)(`span`,{className:`grid h-14 w-14 place-items-center rounded-full bg-ok-tint text-ok`,children:(0,Q.jsx)(oe,{size:26})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[17px] font-medium`,children:`Starting each server to see its tools…`}),(0,Q.jsxs)(`p`,{className:`mt-1 text-[13.5px] text-soft`,children:[`This can take up to about 40 seconds. Nothing is changed yet. `,e>2&&(0,Q.jsxs)(`span`,{className:`tnum`,children:[`(`,e,` s)`]})]})]})]})}var kt=[{key:`run`,label:`Runs freely`,icon:`check`,tone:`ok`},{key:`ask`,label:`Asks first`,icon:`clock`,tone:`warn`},{key:`blocked`,label:`Blocked`,icon:`x`,tone:`bad`},{key:`hidden`,label:`Hidden`,icon:`eye-off`,tone:`neutral`}];function At({plan:t,app:n}){let i=t.starting?.mode!==`enforce`,a=t.tools.filter(e=>e.injection);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[t.blocking.length>0&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`This can't be connected yet`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:t.blocking.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))})}),t.status===`already-adopted`&&t.blocking.length===0&&(0,Q.jsx)(l,{tone:`info`,title:`${n} already goes through your toolbox`,children:`Connecting again only applies the change you chose.`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:t.existingGateway?`New servers are added to the toolbox this app already uses.`:void 0,children:[`Servers (`,t.upstreams.length,`)`]}),t.upstreams.length===0?(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`No server can go through your toolbox.`}):(0,Q.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:t.upstreams.map(t=>(0,Q.jsxs)(`li`,{className:`flex min-w-0 gap-3 rounded-2xl bg-sunken/60 p-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-full bg-surface text-muted`,children:(0,Q.jsx)(g,{name:t.transport===`http`?`external`:`server`,size:17})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`mono text-[13.5px] font-semibold`,children:t.name}),t.originalName!==t.name&&(0,Q.jsxs)(`span`,{className:`text-[12px] text-soft`,children:[`was `,t.originalName]}),t.alreadyFronted&&(0,Q.jsx)(e,{children:`Already connected`})]}),(0,Q.jsx)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:t.transport===`http`?`Remote server · ${t.url}`:`Runs on this computer · ${[t.command,...t.args].join(` `)}`}),(t.envNames.length>0||t.passEnv.length>0||t.headerNames.length>0)&&(0,Q.jsxs)(`span`,{className:`mt-0.5 block text-[12px] text-soft`,children:[`Uses `,(0,Q.jsx)(`span`,{className:`mono`,children:[...t.envNames,...t.passEnv,...t.headerNames].join(`, `)})]}),t.warnings.map(e=>(0,Q.jsx)(`span`,{className:`mt-1 block text-[12.5px] text-warn`,children:K(Y(e))},e))]})]},t.name))}),(t.skipped.length>0||t.malformed.length>0)&&(0,Q.jsxs)(`div`,{className:`mt-4`,children:[(0,Q.jsxs)(`p`,{className:`mb-2 text-[13.5px] font-semibold`,children:[`Left out (`,t.skipped.length+t.malformed.length,`)`]}),(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[t.skipped.map(e=>{let t=Ge(e.reason,e.remedy);return(0,Q.jsxs)(`li`,{className:`rounded-2xl border border-line p-3 text-[13.5px]`,children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:t.reason}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-soft`,children:t.remedy})]},e.name)}),t.malformed.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-2xl border border-line p-3 text-[13.5px]`,children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),(0,Q.jsxs)(`p`,{className:`mt-1 text-muted`,children:[`Its entry in the app's settings could not be read: `,K(Y(e.message))]})]},e.name))]})]})]}),t.probeFailures.length>0&&(0,Q.jsxs)(l,{tone:`danger`,title:`Some servers didn't start or answer`,children:[(0,Q.jsx)(`ul`,{className:`mt-1 space-y-1`,children:t.probeFailures.map(e=>(0,Q.jsxs)(`li`,{children:[(0,Q.jsx)(`code`,{className:`mono`,children:e.upstream}),`: `,K(Y(e.message))]},e.upstream))}),(0,Q.jsx)(`p`,{className:`mt-1`,children:`Check that each one works in the app on its own, then go back a step and check again.`})]}),t.tools.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{sub:i?`For now it only watches, so every call runs. This is what will happen once you turn protection on.`:`What happens to each tool from the first call.`,children:[`Tools (`,t.tools.length,`)`]}),(0,Q.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:kt.map(e=>{let n=t.tools.filter(t=>t.verdict===e.key);return n.length===0?null:(0,Q.jsx)(Nt,{label:e.label,icon:e.icon,tone:e.tone,tools:n},e.key)})})]}),(a.length>0||t.findings.length>0||t.namesTooLong.length>0||t.withheld.length>0)&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Worth a look`}),(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2 text-[13.5px]`,children:[a.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl bg-warn-tint p-3`,children:[(0,Q.jsx)(g,{name:`warning`,size:17,className:`mt-0.5 shrink-0 text-warn`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` has hidden instructions in its description.`,` `,e.hidden?`The tool will be hidden from your AI app.`:`Your toolbox will deal with them as set in its options.`]})]},`inj-${e.name}`)),jt(t.findings).map(e=>(0,Q.jsx)(Mt,{group:e},e.ruleId)),t.namesTooLong.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`warning`,size:17,className:`mt-0.5 shrink-0 text-warn`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` has a name too long for `,n,` (`,e.length,` of `,e.limit,` letters), so it won't be offered. A shorter server name under More options leaves more room.`]})]},`long-${e.name}`)),t.withheld.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`eye-off`,size:17,className:`mt-0.5 shrink-0 text-soft`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`mono font-semibold`,children:e.name}),` won't be offered: `,K(Y(e.reason))]})]},`w-${e.name}`))]})]}),t.packs.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Ready-made rules`}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.packs.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 rounded-2xl bg-ok-tint p-3 text-[13.5px]`,children:[(0,Q.jsx)(g,{name:`shield-check`,size:18,className:`shrink-0 text-ok`}),(0,Q.jsxs)(`span`,{children:[e.packLabel,` rules for `,(0,Q.jsx)(`code`,{className:`mono`,children:e.upstreamName}),`: `,r(e.rules.length,`rule`),e.unmatched.length>0&&(0,Q.jsxs)(`span`,{className:`text-soft`,children:[` · `,e.unmatched.length,` not used by this server`]})]})]},e.upstreamName))})]}),t.warnings.length>0&&(0,Q.jsx)(l,{tone:`warn`,title:`Before you connect`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:t.warnings.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))})}),t.files&&(0,Q.jsx)(Pt,{plan:t})]})}function jt(e){let t=new Map;for(let n of e)t.set(n.ruleId,[...t.get(n.ruleId)??[],n]);return[...t.entries()].map(([e,t])=>({ruleId:e,high:t.some(e=>e.severity===`high`),items:t})).sort((e,t)=>Number(t.high)-Number(e.high))}function Mt({group:e}){let[t,n]=(0,Z.useState)(!1);return(0,Q.jsxs)(`li`,{className:`flex gap-2 rounded-2xl border border-line p-3`,children:[(0,Q.jsx)(g,{name:`shield`,size:17,className:U(`mt-0.5 shrink-0`,e.high?`text-bad`:`text-warn`)}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:M(e.ruleId)}),(0,Q.jsx)(`span`,{className:`mono text-[11.5px] text-soft`,children:e.ruleId}),e.items.length>1&&(0,Q.jsxs)(`span`,{className:`text-soft`,children:[`· `,e.items.length,` places`]}),e.ruleId in F&&(0,Q.jsx)(w,{term:e.ruleId})]}),(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,className:`-ml-3`,"aria-expanded":t,onClick:()=>n(!t),children:t?`Hide details`:`Show details`}),t&&(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5 text-[13px] text-muted`,children:e.items.map((e,t)=>(0,Q.jsx)(`li`,{className:`break-words`,children:K(Y(e.message))},t))})]})]})}function Nt({label:t,icon:n,tone:r,tools:i}){let[a,o]=(0,Z.useState)(i.length<=8),s=a?i:i.slice(0,8);return(0,Q.jsxs)(`div`,{className:`rounded-[18px] border border-line p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(e,{tone:r,icon:n,children:t}),(0,Q.jsx)(`span`,{className:`tnum text-[13px] text-soft`,children:i.length})]}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:s.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 border-b border-faint py-1.5 last:border-b-0`,children:[(0,Q.jsx)(C,{effect:e.effect}),(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 truncate text-[12.5px]`,title:e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[12px] text-soft`,title:e.decidedBy,children:xe(e.decidedBy)})]},e.name))}),!a&&(0,Q.jsxs)(P,{size:`sm`,variant:`ghost`,className:`mt-1`,onClick:()=>o(!0),children:[`Show all `,i.length,` tools`]})]})}function Pt({plan:e}){let t=e.files,n=[[`The app's settings, changed to use your toolbox`,t.clientConfig],[`Backup of the app's settings`,t.wholeFileBackup],[`Record used to undo the connection`,t.backupRecord],[`The toolbox's settings file`,t.gatewayConfig],[t.policyKept?`Protection settings (kept as they are)`:`Protection settings`,t.policy],[`Claude Code permission for “Don't ask me twice”`,t.clientSettings]];return(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Files that will be written`}),(0,Q.jsx)(`dl`,{className:`flex flex-col gap-2 text-[13px]`,children:n.filter(([,e])=>e).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`grid gap-x-4 sm:grid-cols-[240px_1fr]`,children:[(0,Q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(q,{children:t})})]},e))})]})}function Ft({plan:e,client:t,error:n,id:i,onId:a}){let s=G(t.scope),c=e.starting?.mode!==`enforce`,u=e.upstreams.filter(e=>!e.alreadyFronted).length,d=[[`plug`,u>0?`${r(u,`server`)} in ${t.label} will go through your toolbox.`:`The change you chose is applied to your toolbox.`],[`file`,`A backup of the app's settings is kept, so you can undo this here at any time.`],[c?`eye`:`shield-check`,c?`For now it only watches: everything runs, and the activity log shows what would have been stopped.`:`It starts protecting: your rules apply from the first call.`],[`refresh`,`${s} has to be restarted afterwards to pick up your toolbox.`]];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{children:`When you connect`}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-3`,children:d.map(([e,t])=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-3 text-[14.5px]`,children:[(0,Q.jsx)(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-full bg-ok-tint text-ok`,children:(0,Q.jsx)(g,{name:e,size:17})}),(0,Q.jsx)(`span`,{className:`pt-1.5`,children:t})]},t))}),n&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`It wasn't connected`,children:n.blocking?.length?(0,Q.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-5`,children:n.blocking.map(e=>(0,Q.jsx)(`li`,{children:K(Y(e))},e))}):n.text}),n?.idTaken&&(0,Q.jsx)(o,{label:`Toolbox name in the console`,technical:`id`,help:`Lower-case letters, digits, dashes and underscores.`,children:(0,Q.jsx)(f,{value:i,onChange:a,mono:!0,placeholder:`claude-code-2`})})]})}function It({result:e,onClose:t,onOpen:n}){let r=G(e.scope),i=e.applied;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(R,{steps:_t,current:_t.length}),(0,Q.jsxs)(b,{icon:`check`,title:`Done. Restart ${r} so it picks up your toolbox.`,actions:(0,Q.jsxs)(Q.Fragment,{children:[e.registryId&&(0,Q.jsx)(P,{variant:`primary`,icon:`arrow-right`,onClick:()=>n(e.registryId),children:`Open this toolbox`}),(0,Q.jsx)(P,{onClick:t,children:`Close`})]}),children:[i.replaced.length>0?`${i.replaced.join(`, `)} now ${i.replaced.length===1?`goes`:`go`} through your toolbox.`:`Your toolbox is set up as you chose.`,` `,e.starting?.mode===`enforce`?`It is protecting from the first call.`:`For now it only watches, so nothing is blocked yet.`]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-[18px] bg-sunken/60 p-4 text-[13px]`,children:[(0,Q.jsx)(`p`,{className:`font-semibold`,children:`What was backed up`}),i.wholeFileBackup&&(0,Q.jsxs)(`p`,{children:[`A copy of the app's settings as they were: `,(0,Q.jsx)(q,{children:i.wholeFileBackup})]}),(0,Q.jsxs)(`p`,{children:[`What's needed to undo it: `,(0,Q.jsx)(q,{children:i.backupRecord})]}),i.clientAllowAdded&&(0,Q.jsx)(`p`,{children:`Claude Code won't ask a second time about your toolbox's tools.`})]}),i.literalSecretsInBackup&&(0,Q.jsx)(l,{tone:`warn`,title:`The backups hold a password or key`,children:`A server you connected had a key written out in the app's settings, so both backup files contain it. Keep them private.`}),e.warning&&(0,Q.jsx)(l,{tone:`warn`,children:K(Y(e.warning))})]})}function Lt({client:e,onClose:t,onDone:n}){let{servers:r,serverId:i,nav:a}=J(),c=r.filter(e=>e.ok),[l,u]=(0,Z.useState)(null),d=l??(c.some(e=>e.id===i)?i:c[0]?.id??null);return e?(0,Q.jsx)(le,{open:!0,onClose:t,title:`Connect ${G(e.scope)} to your toolbox`,width:600,footer:(0,Q.jsx)(P,{onClick:t,children:`Close`}),children:d?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[c.length>1&&(0,Q.jsx)(o,{label:`Which toolbox`,children:(0,Q.jsx)(h,{label:`Which toolbox`,value:d,onChange:u,options:c.map(e=>({value:e.id,label:e.label}))})}),(0,Q.jsx)(pt,{gatewayId:d,scope:e.scope,onDone:n},d)]}):(0,Q.jsxs)(b,{icon:`server`,title:`You don't have a toolbox yet`,compact:!0,children:[`Adding your first server sets one up. Then come back here and connect `,G(e.scope),`.`,(0,Q.jsx)(`span`,{className:`mt-4 block`,children:(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:()=>ue(s(a,{connect:null,add:`server`})),children:`Add a server`})})]})}):null}var Rt={done:null,label:``};function zt({open:e,onClose:t}){let{reload:n}=J(),r=()=>{let e=!!Rt.done;Rt.done=null,t(),e&&n()},[i,a]=(0,Z.useState)(`new`);return(0,Q.jsx)(v,{open:e,onClose:r,title:`Create a toolbox`,subtitle:`Set up a toolbox yourself, server by server.`,width:760,children:e&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(h,{label:`How to add it`,value:i,onChange:a,options:[{value:`new`,label:`Start from nothing`},{value:`existing`,label:`Use a toolbox settings file I have`}]}),i===`new`?(0,Q.jsx)(Bt,{onClose:r}):(0,Q.jsx)(Ht,{onClose:r})]})})}function Bt({onClose:e}){let{nav:t,reload:n}=J(),r=H(),[a,s]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)(`observe`),[m,g]=(0,Z.useState)(`approve-writes`),[_,v]=(0,Z.useState)(`approve`),[y,b]=(0,Z.useState)(``),[x,S]=(0,Z.useState)([at()]),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(Rt.done),F=/^[a-z0-9][a-z0-9_-]{0,63}$/.test(a)?null:`Use lower-case letters, digits, dashes and underscores, starting with a letter or digit.`,I=x.map((e,t)=>mt(e,x.filter((e,n)=>n!==t).map(e=>e.name.trim()))),L=!F&&I.every(e=>!e);return j?(0,Q.jsx)(Vt,{result:j,label:Rt.label,onClose:e,onOpen:()=>{e(),ue(i(t,`/`,{server:j.id}))}}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsxs)(`section`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Name`,technical:`name`,help:`Also the name of its folder.`,error:k?F:null,children:(0,Q.jsx)(f,{value:a,onChange:s,mono:!0,placeholder:`work-tools`})}),(0,Q.jsx)(o,{label:`Label in the console`,optional:!0,children:(0,Q.jsx)(f,{value:c,onChange:u,placeholder:`Work tools`})})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{children:[`How it starts `,(0,Q.jsx)(w,{term:`watchOnly`})]}),(0,Q.jsx)(Me,{label:`How it starts`,value:d,onChange:p,options:[{value:`observe`,title:E.observe.label,body:`Recommended to begin with. Every call runs, and the log shows what would have been stopped.`},{value:`enforce`,title:E.enforce.label,body:E.enforce.explain}]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(X,{children:[`How careful the toolbox is `,(0,Q.jsx)(w,{term:`defaultStance`})]}),(0,Q.jsx)(Me,{label:`How careful the toolbox is`,columns:3,value:m,onChange:g,options:Object.keys(V).map(e=>({value:e,title:V[e].label,body:V[e].explain}))})]}),(0,Q.jsxs)(`section`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:(0,Q.jsxs)(Q.Fragment,{children:[`Tools nobody has labelled yet `,(0,Q.jsx)(w,{term:`unknownTools`})]}),children:(0,Q.jsx)(h,{label:`Tools nobody has labelled yet`,value:_,onChange:v,options:[{value:`approve`,label:`Ask me first`},{value:`deny`,label:`Block them`}]})}),(0,Q.jsx)(o,{label:`Folder for its files`,optional:!0,help:`A full path. By default, a folder named after it in your home folder.`,children:(0,Q.jsx)(f,{value:y,onChange:b,mono:!0,placeholder:`~/.hmcp/gateways/work-tools`})})]}),(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(X,{sub:`The servers this toolbox sits in front of. A toolbox needs at least one.`,children:[`Connected servers `,(0,Q.jsx)(w,{term:`connectedServer`})]}),x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`rounded-[18px] border border-line p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-[14.5px] font-semibold`,children:[`Server `,t+1]}),x.length>1&&(0,Q.jsx)(N,{icon:`trash`,label:`Remove server ${t+1}`,size:34,onClick:()=>S(x.filter((e,n)=>n!==t))})]}),(0,Q.jsx)(it,{value:e,onChange:e=>S(x.map((n,r)=>r===t?e:n)),literalWarning:!0}),k&&I[t]&&(0,Q.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] font-medium text-bad`,children:I[t]})]},t)),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{icon:`plus`,onClick:()=>S([...x,at()]),children:`Add another server`})})]}),D&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`The toolbox wasn't created`,children:D}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:e,disabled:C,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:()=>{A(!0),L&&(T(!0),O(null),we.createGateway({name:a,...c.trim()?{label:c.trim()}:{},mode:d,posture:m,onUnclassified:_,...y.trim()?{outDir:y.trim()}:{},upstreams:x.map(ot)}).then(e=>{Rt.done=e,Rt.label=c.trim()||a,M(e),r.show(`ok`,`${c.trim()||a} was created.`)}).catch(e=>{let t=e.detail;O(W(e)+(Array.isArray(t)?` ${t.map(e=>K(Y(e.message))).join(` `)}`:``))}).finally(()=>T(!1)))},loading:C,children:`Create toolbox`})]})]})}function Vt({result:e,label:t,onClose:n,onOpen:r}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(b,{icon:`check`,title:`${t} is ready`,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{variant:`secondary`,icon:`arrow-right`,onClick:r,children:`Open this toolbox`}),(0,Q.jsx)(P,{variant:`ghost`,onClick:n,children:`Close`})]}),children:`Its protection settings start the way you chose. Connect your AI app to it next: one click, then restart the app once.`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`Connect your AI app`}),(0,Q.jsx)(pt,{gatewayId:e.id,onDone:()=>void 0})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-[18px] bg-sunken/60 p-4 text-[13px]`,children:[(0,Q.jsxs)(`p`,{children:[`Settings file: `,(0,Q.jsx)(q,{children:e.configPath})]}),(0,Q.jsxs)(`p`,{children:[`Protection settings: `,(0,Q.jsx)(q,{children:e.policyPath})]})]}),e.warnings.map(e=>(0,Q.jsxs)(l,{tone:`warn`,children:[K(Y(e)),` If one is a password or key, keep that file private.`]},e)),e.warning&&(0,Q.jsx)(l,{tone:`warn`,children:K(Y(e.warning))})]})}function Ht({onClose:e}){let{nav:t,reload:n}=J(),r=H(),[a,s]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),g=()=>{p(!0),h(null),_.addServer({kind:`gateway`,...a.trim()?{label:a.trim()}:{},config_path:c.trim()}).then(o=>{n(),r.show(`ok`,`${a.trim()||`The toolbox`} was added to the console.`),e(),ue(i(t,`/`,{server:o.id}))}).catch(e=>h(W(e))).finally(()=>p(!1))};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`For a toolbox you already set up. The console reads its settings file and nothing else: it doesn't start the toolbox or change the file.`}),(0,Q.jsx)(o,{label:`Label in the console`,optional:!0,help:`Left empty, it's named after the toolbox.`,children:(0,Q.jsx)(f,{value:a,onChange:s,placeholder:`Work tools`})}),(0,Q.jsx)(o,{label:`Settings file`,technical:`gateway.yaml`,help:`The full path to its settings file.`,children:(0,Q.jsx)(f,{value:c,onChange:u,mono:!0,placeholder:`/Users/me/.hmcp/gateways/work/gateway.yaml`,onEnter:g})}),m&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:m}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:e,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`plus`,onClick:g,loading:d,disabled:!c.trim(),children:`Add toolbox`})]})]})}function Ut(){return document.cookie.match(/(?:^|;\s*)hmcp_csrf=([^;]+)/)?.[1]??``}async function Wt(e,t={}){let n={...t.headers??{}};t.method&&t.method!==`GET`&&(n[`Content-Type`]=`application/json`,n[`X-HMCP-CSRF`]=Ut());let r=await fetch(e,{...t,headers:n}),i=await r.text(),a=i?JSON.parse(i):null;if(!r.ok){let e=a?.error??{code:`unknown`,message:r.statusText};throw new m(r.status,e.code,e.message)}return a}var Gt=e=>({method:`POST`,body:JSON.stringify(e)}),Kt=(e,t)=>`/api/v1/servers/${encodeURIComponent(e.gatewayId)}/github/${encodeURIComponent(e.upstream)}/${t}`,qt={doors:()=>Wt(`/api/v1/github-doors`),claudeCode:e=>Wt(`/api/v1/github-doors/claude-code`,Gt({scope:`user`,close:e,confirm:!0})),confirm:(e,t)=>Wt(`/api/v1/github-doors/confirm`,Gt({door:e,done:t})),setChanges:(e,t)=>Wt(Kt(e,`changes`),Gt({allow:t,expectedDigest:e.digest,confirm:!0})),check:e=>Wt(Kt(e,`check`),Gt({}))},Jt=`Make hmcp the only way to change GitHub`,Yt=`hmcp can ask you before each GitHub change only when the change goes through it. These are the other ways a change could reach GitHub from this computer.`,Xt=`Claude Code enforces these rules, but a prefix rule makes a way around them much harder, not impossible. For a guarantee, also log gh out and remove saved GitHub git credentials.`,Zt=`Your GitHub server can only look. To let Claude make changes through hmcp, switch it below, or edit it and choose 'Look and make changes'.`,Qt=`Not checked yet — press Check it works to see what each change will meet.`,$t=`Once it's switched, press Check it works to see what each change will meet.`,en=`Let Claude change GitHub through hmcp`,tn=`Back to only looking`,nn=`Your GitHub server can make changes.`,rn=`For a company: a Claude Team/Enterprise admin can block connector tools for everyone, and a GitHub organisation owner can restrict which apps may reach the organisation's repositories (Organisation settings → Third-party access).`,an=e=>V[e]?.label??e;function on(e){if(e===null)return`What happens to a change couldn't be worked out, because this toolbox's protection settings can't be read.`;if(e.kind===`unchecked`)return Qt;if(e.kind===`no-changes`)return`It doesn't offer any tools that make changes.`;let t;switch(e.kind){case`waits`:t=`Each change waits for you to say yes`;break;case`refused`:t=`Changes will be refused while the toolbox is set to “${an(e.posture)}”; switch to “Ask before changes” to allow them with approval`;break;case`partly-refused`:t=`Some changes are refused under your toolbox's settings (${(e.tools??[]).join(`, `)}); the rest wait for you to say yes`;break;case`runs`:t=`Some changes run without asking you: ${(e.tools??[]).join(`, `)}. Change them to “Ask me first” on the Tools page`;break;case`observe`:t=`Changes run without asking while the toolbox only watches`}return e.preApproved?`${t}, but a pre-approval lets some changes run without asking.`:`${t}.`}function sn(e){return e.state===`open`?{label:`Open`,tone:`bad`}:e.state===`unknown`?{label:`Can't check`,tone:`warn`}:e.state===`harder`?{label:`Made harder`,tone:`neutral`}:e.confirmed?{label:`Closed (you confirmed)`,tone:`ok`}:{label:`Closed (checked)`,tone:`ok`}}function cn(){let e=H(),t=B(()=>qt.doors(),[]),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)({}),o=t.data;if(!o||o.servers.length===0)return null;let s=(n,i,a)=>{r(n),i().then(()=>{e.show(`ok`,a),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))};return(0,Q.jsx)(re,{title:Jt,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:Yt}),o.servers.map(o=>(0,Q.jsx)(ln,{server:o,busy:n,check:i[`${o.gatewayId}/${o.upstream}`]??null,onSwitch:n=>{r(`switch:${o.upstream}`),qt.setChanges(o,n).then(r=>{let i=r.servers.find(e=>e.gatewayId===o.gatewayId&&e.upstream===o.upstream);e.show(`ok`,n?`Claude can now change GitHub through hmcp. ${on(i?.changes??null)}`:`Your GitHub server can only look again.`),r.note&&e.show(`info`,r.note),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))},onCheck:()=>{r(`check:${o.upstream}`),qt.check(o).then(e=>{a(t=>({...t,[`${o.gatewayId}/${o.upstream}`]:e})),t.reload()}).catch(t=>e.show(`bad`,W(t))).finally(()=>r(null))}},`${o.gatewayId}/${o.upstream}`)),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:o.doors.map(e=>(0,Q.jsx)(un,{door:e,busy:n,onBlock:e=>s(`claude-code`,()=>qt.claudeCode(e),e?`GitHub is blocked in Claude Code. Restart Claude Code to be sure it's applied.`:`The block was taken out of Claude Code's settings.`),onConfirm:t=>s(`confirm:${e.id}`,()=>qt.confirm(e.id,t),t?`Noted as done.`:`Noted as not done yet.`)},e.id))}),(0,Q.jsx)(l,{tone:`info`,children:Xt}),(0,Q.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:rn})]})})}function ln({server:e,busy:t,check:n,onSwitch:r,onCheck:i}){let a=We()(e.upstream,e.gatewayId);return e.access===null?null:(0,Q.jsxs)(`div`,{className:`rounded-2xl bg-sunken/60 px-4 py-3 text-[14px]`,children:[(0,Q.jsxs)(`p`,{className:`font-medium`,children:[a,` in `,e.gatewayLabel,pe(e.upstream,a)&&(0,Q.jsx)(`span`,{className:`ml-2 font-mono text-[12px] font-normal text-soft`,children:e.upstream})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:e.access===`readonly`?Zt:nn}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted`,children:e.access===`readonly`?$t:on(e.changes)}),(0,Q.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:e.access===`readonly`?(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`shield-check`,loading:t===`switch:${e.upstream}`,onClick:()=>r(!0),children:en}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`check`,loading:t===`check:${e.upstream}`,onClick:i,children:`Check it works`}),(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`eye`,loading:t===`switch:${e.upstream}`,onClick:()=>r(!1),children:tn})]})}),n&&(0,Q.jsxs)(`div`,{className:`mt-3`,children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:n.lines.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Q.jsx)(g,{name:e.ok?`check`:`warning`,size:17,className:e.ok?`mt-0.5 shrink-0 text-ok`:`mt-0.5 shrink-0 text-bad`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,children:e.ok?`Passed: `:`Needs a look: `}),e.text]})]},e.text))}),(0,Q.jsx)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:n.note})]})]})}function un({door:t,busy:n,onBlock:r,onConfirm:i}){let a=sn(t),o=t.links!==void 0;return(0,Q.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-faint py-3 last:border-b-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[15px] font-medium`,children:t.label}),(0,Q.jsx)(e,{tone:a.tone,children:a.label})]}),(0,Q.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:t.detail}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.links.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center sm:gap-3`,children:[(0,Q.jsx)(T,{href:e.url,external:!0,size:`sm`,icon:`external`,className:`shrink-0`,children:e.label}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:e.press})]},e.url))}),t.why&&(0,Q.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:t.why}),(0,Q.jsx)(se,{checked:t.confirmed===!0,disabled:n===`confirm:${t.id}`,onChange:i,label:`I've done this`})]}):t.state!==`closed`&&t.fix.length>0&&(0,Q.jsx)(`ol`,{className:`ml-5 list-decimal text-[13px] text-muted`,children:t.fix.map(e=>(0,Q.jsx)(`li`,{children:e},e))}),t.id===`claude-code-terminal`&&t.state===`harder`&&(0,Q.jsx)(`p`,{className:`text-[13px] text-muted`,children:`Claude Code enforces these rules, but a prefix rule makes a way around them much harder, not impossible. For a guarantee, also log gh out and remove saved GitHub git credentials.`}),t.id===`claude-code-terminal`&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.state!==`closed`&&t.state!==`harder`&&(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`lock`,loading:n===`claude-code`,onClick:()=>r(!0),children:`Block GitHub in Claude Code (all projects)`}),t.undoable?.includes(`user`)&&(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`refresh`,loading:n===`claude-code`,onClick:()=>r(!1),children:`Undo`})]})]})}function dn({servers:t,serverId:n}){let r=H(),i=B(()=>we.guard(),[],3e4),[a,o]=(0,Z.useState)(!1),s=t.filter(e=>e.ok),c=s.find(e=>e.id===n)??s[0];if(!c)return null;let u=i.data?.installed===!0,d=u?s.find(e=>e.id===i.data?.serverId):void 0,f=e=>{o(!0),we.setGuard(e,c.id).then(t=>{r.show(`ok`,`${e?`Turned on`:`Turned off`}. ${t.restartHint}`),t.warning&&r.show(`warn`,t.warning),i.reload()}).catch(e=>r.show(`bad`,W(e))).finally(()=>o(!1))};return(0,Q.jsx)(re,{title:`Guard every Claude Code tool with hmcp`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`Every tool Claude Code uses — connectors, plugins, the terminal and file edits — is checked by your toolbox first. Restart Claude Code after turning this on.`}),(0,Q.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[`Reading web pages counts as looking, so it runs without asking. A web address can carry information out, and the guard does not stop that unless a rule names `,(0,Q.jsx)(`code`,{className:`mono`,children:`claude-code__WebFetch`}),`.`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(e,{tone:u?i.data?.changedByHand?`warn`:`ok`:`neutral`,icon:`shield`,children:u?`On, checked by ${d?.label??`a toolbox`}${i.data?.changedByHand?` (changed by hand)`:``}`:`Off`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-soft`,children:`All projects`})]}),i.error&&(0,Q.jsx)(l,{tone:`warn`,children:i.error}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{size:`sm`,variant:u?`ghost`:`primary`,loading:a,onClick:()=>f(!u),children:u?`Turn off`:`Turn on, checked by ${c.label}`})})]})})}function fn(e){return B(()=>et(e),[e],3e3)}function pn(e){return e?e.externallyRunning?{label:`Run by an AI app`,tone:`ok`}:e.state===`running`?{label:`Running here`,tone:`ok`}:e.state===`starting`?{label:`Starting`,tone:`warn`}:e.state===`exited`?{label:e.exitCode===0?`Stopped`:`Stopped with an error`,tone:e.exitCode===0?`neutral`:`bad`}:{label:`Not running`,tone:`neutral`}:{label:`Checking`,tone:`neutral`}}function mn({token:e,url:t,onClose:n}){return(0,Q.jsx)(le,{open:!!e,onClose:n,dismissable:!1,title:`Copy the password now`,description:`Copy this now; it won't be shown again. Your AI app needs it to connect.`,width:560,footer:(0,Q.jsx)(P,{variant:`primary`,onClick:n,children:`I've copied it`}),children:e&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 text-[14px]`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-2xl bg-sunken p-3`,children:[(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[13px] break-all`,children:e}),(0,Q.jsx)(Pe,{text:e,label:`Copy password`})]}),(0,Q.jsxs)(`p`,{className:`text-muted`,children:[`In your AI app's server settings, add a header named `,(0,Q.jsx)(`code`,{className:`mono`,children:`Authorization`}),` with the value`,` `,(0,Q.jsx)(`code`,{className:`mono`,children:`Bearer`}),`, a space, then this password.`,t&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`The server's address is `,(0,Q.jsx)(q,{children:t})]})]})]})})}function hn({id:n,label:r}){let i=fn(n),{reload:s}=J(),u=H(),[d,f]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(`127.0.0.1`),[E,O]=(0,Z.useState)([]),[k,A]=(0,Z.useState)([]),[j,M]=(0,Z.useState)(!0),[N,F]=(0,Z.useState)(null),I=(e,t=!1)=>{f(e),v(null),(e===`start`?Te(n,{...S===null?{}:{port:S},host:w,...E.length?{allowHosts:E}:{},...k.length?{allowOrigins:k}:{},requireToken:j,...t?{acknowledged:{loosens:!0}}:{}}).then(e=>e.token&&b({token:e.token,url:e.http?.url??null})):e===`stop`?Ke(n):Oe(n)).then(()=>{u.show(`ok`,e===`start`?`${r} started.`:e===`stop`?`${r} stopped.`:`${r} restarted.`),i.reload(),s()}).catch(n=>{e===`start`&&!t&&n instanceof m&&n.needsLoosenAck?F(Ze(n)):v(W(n))}).finally(()=>f(null))};if(i.error&&!i.data)return(0,Q.jsx)(l,{tone:`danger`,title:`Whether your toolbox is running could not be read`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:i.reload,children:`Try again`}),children:W(i.error)});let L=i.data;if(!L)return(0,Q.jsx)(c,{lines:4});let R=pn(L),z=L.state===`running`||L.state===`starting`;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-11 w-11 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:`power`,size:20})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-[16px] font-semibold`,children:[r,` `,(0,Q.jsx)(e,{tone:R.tone,children:R.label})]}),(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:L.externallyRunning?`Started by an AI app on this computer.`:z&&L.startedAt?`Started ${x(L.startedAt)} by this console.`:L.state===`exited`?`It stopped${L.exitCode===null?L.signal?` (${L.signal})`:``:` with exit code ${L.exitCode}`}.`:`Nothing is running it at the moment.`})]}),z&&L.managed&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(P,{icon:`refresh`,onClick:()=>I(`restart`),loading:d===`restart`,disabled:!!d,children:`Restart toolbox`}),(0,Q.jsx)(P,{variant:`danger`,icon:`stop`,onClick:()=>I(`stop`),loading:d===`stop`,disabled:!!d,children:`Stop toolbox`})]})]}),_&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:_}),L.externallyRunning?(0,Q.jsx)(l,{tone:`info`,title:`An AI app runs this toolbox`,children:`The app starts the toolbox itself when it opens and stops it when it closes, so it can't be started or stopped here. To restart the toolbox, for example after changing its settings, quit and reopen the app.`}):z&&L.http?(0,Q.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(X,{sub:`Add this as a server in your AI app's settings. The app then reaches every tool through your toolbox.`,children:`Web address`}),L.http.url&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-2xl bg-sunken p-3`,children:[(0,Q.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[13px] break-all`,children:L.http.url}),(0,Q.jsx)(Pe,{text:L.http.url,label:`Copy address`})]}),(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:L.http.tokenRequired?`A password is required. It was shown once when the toolbox started; restarting keeps the same one.`:`No password is required, so any program on this computer can reach it.`})]}):(0,Q.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{sub:`Runs your toolbox from this console, so AI apps on this computer can reach it at a web address.`,children:`Start toolbox`}),(0,Q.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,Q.jsx)(o,{label:`Port`,optional:!0,help:`Leave empty to use 7878.`,children:(0,Q.jsx)(a,{value:S,onChange:C,min:1,max:65535})}),(0,Q.jsx)(o,{label:`Address`,help:`This computer only. Your toolbox is never reachable from other computers.`,children:(0,Q.jsx)(h,{label:`Address`,size:`sm`,value:w,onChange:T,options:[{value:`127.0.0.1`,label:`127.0.0.1`},{value:`localhost`,label:`localhost`},{value:`::1`,label:`::1`}]})})]}),(0,Q.jsx)(p,{checked:j,onChange:M,label:`Require a password`,description:`Your AI app must send it to connect, so other programs on this computer can't use your toolbox's tools.`}),(0,Q.jsxs)(Ee,{title:`More options`,children:[(0,Q.jsx)(o,{label:`Other names this computer is reached by`,optional:!0,help:`Only if your app uses a name other than the address above.`,children:(0,Q.jsx)(t,{value:E,onChange:O,placeholder:`my-machine.local`})}),(0,Q.jsx)(o,{label:`Web pages allowed to call it`,optional:!0,help:`Only for an AI app that runs in a browser. Scheme, host and port, such as http://localhost:3000.`,children:(0,Q.jsx)(t,{value:k,onChange:A,placeholder:`http://localhost:3000`})})]}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{variant:`primary`,icon:`play`,onClick:()=>I(`start`),loading:d===`start`,children:`Start toolbox`})})]}),(L.managed||L.log.length>0)&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(X,{children:`What it has written`}),(0,Q.jsx)(ne,{lines:L.log,height:260,label:`${r} output`,empty:`Nothing yet.`})]}),(0,Q.jsx)(mn,{token:y?.token??null,url:y?.url??null,onClose:()=>b(null)}),(0,Q.jsx)(D,{open:!!N,title:`Start a toolbox more can reach?`,onCancel:()=>F(null),confirmLabel:`Start toolbox anyway`,busy:d===`start`,consequences:N??[],onConfirm:()=>{F(null),I(`start`,!0)},children:`Besides AI apps on this computer, your toolbox will also answer the callers listed below.`})]})}function gn({id:e,tab:t,onTab:n,onClose:r,replaceKeyFor:i,onOpened:a}){let{servers:o}=J(),s=o.find(t=>t.id===e);return(0,Q.jsx)(v,{open:!!e,onClose:r,title:s?`${s.label} settings`:`Toolbox settings`,subtitle:`Its connected servers, options, and whether it is running.`,width:820,children:e&&(0,Q.jsx)(_n,{id:e,label:s?.label??e,tab:t,onTab:n,replaceKeyFor:i??null,onOpened:a},e)})}function _n({id:e,label:t,tab:n,onTab:r,replaceKeyFor:i,onOpened:a}){let o=B(()=>Re(e),[e]),s=fn(e),u=H(),{reload:f}=J(),p=Ie(e),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(!1),j=o.data,M=!!j?.broken,N=M&&(n===`servers`||n===`options`)?`file`:n,F=(e,t,n=`Save a change that lets more through?`,r)=>{if(!j)return Promise.resolve(!1);let i=e=>{u.show(`ok`,t),g(Date.now()),v(e.restartNeeded!==!1),o.reload(),p.reload(),f()};return e(j.digest).then(e=>(i(e),!0)).catch(t=>t instanceof m&&t.needsLoosenAck?new Promise(a=>{O(null),C({title:n,body:r,reasons:Ze(t),run:()=>e(j.digest,{loosens:!0}).then(e=>{i(e),a(!0)})})}):(De(t)?b(!0):u.show(`bad`,W(t)),!1))},I=s.data,L=!!I&&(I.externallyRunning||I.state===`running`||I.state===`starting`),R=p.data,z=!!R?.processes.some(e=>e.refusal),ee=L&&(R&&R.running?z||!R.applied&&(h===null||Date.now()-h>6e3):_||j&&!j.broken&&j.restartNeededFor.length>0),te=M?[{id:`file`,label:`Settings file`},{id:`run`,label:`Run`}]:[{id:`servers`,label:`Connected servers`,count:j?.config?.upstreams.length},{id:`options`,label:`Toolbox options`},{id:`run`,label:`Run`},{id:`file`,label:`Settings file`}];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[ee&&(0,Q.jsxs)(l,{tone:`warn`,role:`status`,title:`Restart needed for changes to take effect`,actions:I?.managed&&!I.externallyRunning?(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`refresh`,loading:k,onClick:()=>{A(!0),Oe(e).then(()=>{u.show(`ok`,`${t} restarted with the new settings.`),g(null),s.reload(),o.reload()}).catch(e=>u.show(`bad`,W(e))).finally(()=>A(!1))},children:`Restart toolbox`}):void 0,children:[z&&j&&j.restartNeededFor.length>0?`${j.restartNeededFor[0]}`:z?`The running toolbox can only take this change when it starts again. `:`The running toolbox hasn't picked up this change. `,z&&j&&j.restartNeededFor.length>0?``:I?.externallyRunning?`An AI app runs it: quit that app completely and open it again.`:`It still uses the old settings until it restarts.`]}),y&&(0,Q.jsx)(l,{tone:`warn`,title:`This changed since you opened it. Reload and try again.`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:()=>{b(!1),o.reload()},children:`Reload settings`})}),j?.broken&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,title:`This toolbox's settings file can't be loaded`,children:j.broken}),(0,Q.jsx)(ie,{items:te,value:N,onChange:r,label:`Toolbox settings`}),(0,Q.jsx)(`div`,{role:`tabpanel`,id:S(N),"aria-labelledby":d(N),children:N===`run`?(0,Q.jsx)(hn,{id:e,label:t}):o.error&&!j?(0,Q.jsx)(l,{tone:`danger`,title:`The toolbox's settings file could not be read`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:o.reload,children:`Try again`}),children:W(o.error)}):j?N===`file`?(0,Q.jsx)(Cn,{id:e,file:j,write:F}):j.broken===null&&N===`servers`?(0,Q.jsx)(vn,{id:e,file:j,write:F,live:R??null,running:L,onReload:()=>{g(Date.now()),o.reload(),p.reload(),f()},start:i?{kind:`replace-key`,server:i}:void 0,onStarted:a}):j.broken===null?(0,Q.jsx)(xn,{id:e,file:j,write:F},j.digest):null:(0,Q.jsx)(c,{lines:6})}),(0,Q.jsx)(D,{open:!!x,title:x?.title??``,onCancel:()=>C(null),confirmLabel:`Save anyway`,busy:w,error:E,consequences:x?.reasons,onConfirm:()=>{x&&(T(!0),x.run().then(()=>C(null)).catch(e=>O(W(e))).finally(()=>T(!1)))},children:x?.body??`This change lets more through than before, so it needs your confirmation.`})]})}function vn({id:t,file:n,write:r,live:a,running:o,onReload:s,start:c,onStarted:l}){let u=n.config.upstreams,{nav:d}=J(),f=H(),p=tt(),[m,h]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(()=>{if(c?.kind===`by-hand`)return{original:null,draft:at()};let e=c?u.find(e=>e.name===c.server):void 0;return e&&c?.kind===`replace-key`&&he(e)?null:e?{original:e.name,draft:ct(e)}:null}),[x,S]=(0,Z.useState)(()=>{let e=c?.kind===`replace-key`?u.find(e=>e.name===c.server):void 0;return e?he(e):null});(0,Z.useEffect)(()=>{c&&l?.()},[]);let[C,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(null),A=Qe(t);if(y){let e=u.map(e=>e.name).filter(e=>e!==y.original),i=mt(y.draft,e);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(X,{sub:y.original?`Values shown as kept secret stay as they are unless you type a new one.`:void 0,children:y.original?`Edit ${y.original}`:`Add a server`}),(0,Q.jsx)(it,{value:y.draft,onChange:e=>b({...y,draft:e}),nameLocked:!!y.original,secret:n.keptSecret,literalWarning:!0}),C&&i&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-[13px] font-medium text-bad`,children:i}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2 border-t border-faint pt-5`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:()=>b(null),disabled:E,children:`Cancel`}),(0,Q.jsx)(P,{variant:`primary`,icon:`check`,onClick:()=>{T(!0),!i&&(D(!0),bn(ot(y.draft),n.keptSecret).then(e=>r((n,r)=>y.original?ge(t,y.original,e,n,r):nt(t,e,n,r),y.original?`${e.name} was saved.`:`${e.name} was added.`,`Save this server?`)).then(e=>e&&b(null)).catch(e=>f.show(`bad`,W(e))).finally(()=>D(!1)))},loading:E,children:y.original?`Save server`:`Add server`})]})]})}if(_)return(0,Q.jsx)(ut,{gatewayId:t,fixUpstream:_,onCancel:()=>{ft(),v(null)},onDone:e=>{ft(),v(null),f.show(`ok`,`${e.upstreamName} was saved.`),s()}});if(m)return(0,Q.jsx)(ut,{gatewayId:t,onCancel:()=>{ft(),h(!1)},onDone:e=>{h(!1),f.show(`ok`,`${e.upstreamName} was added.`),s()}});let j=u.length===1;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Q.jsxs)(`p`,{className:`text-[13.5px] text-soft`,children:[`The servers this toolbox sits in front of. `,(0,Q.jsx)(w,{term:`connectedServer`})]}),(0,Q.jsxs)(`span`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`edit`,onClick:()=>{T(!1),b({original:null,draft:at()})},children:`Add one by hand`}),(0,Q.jsx)(P,{size:`sm`,variant:`primary`,icon:`plus`,onClick:()=>h(!0),children:`Add a server`})]})]}),(0,Q.jsx)(ze,{id:t,upstreams:u,digest:n.digest,onMoved:s}),(0,Q.jsx)(Ve,{secret:x,onClose:()=>S(null),onSaved:()=>{S(null),f.show(`ok`,`The new key is saved. The server is tried again with it.`),s()}}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:u.map(n=>{let r=Ue(a,n.name),c=(A.data??[]).find(e=>e.server===n.name),l=r&&r.state===`connected`&&c?{...r,state:`failed`,problem:Le(n,c)}:r,u=o&&!!a?.running&&!!l&&(l.state===`failed`||l.state===`needs-sign-in`),f=!u&&He(n,p.data??null);return(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 rounded-[18px] border border-line p-3.5`,children:[(0,Q.jsx)(`span`,{className:`grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:n.transport===`http`?`external`:`server`,size:18})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`code`,{className:`mono text-[14px] font-semibold`,children:n.name}),(0,Q.jsx)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:n.transport===`http`?`Remote server · ${n.url}`:`Runs on this computer · ${[n.command,...n.args??[]].join(` `)}`}),(0,Q.jsx)(`span`,{className:`mt-1 block`,role:`status`,children:(0,Q.jsx)(Je,{live:a,running:o,state:l})})]}),n.on_injection&&(0,Q.jsx)(e,{children:be[n.on_injection].label}),(0,Q.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`edit`,onClick:()=>{T(!1),b({original:n.name,draft:ct(n)})},children:`Edit`}),(0,Q.jsx)(N,{icon:`trash`,label:j?`${n.name} is the only server and can't be removed`:`Remove ${n.name}`,size:36,disabled:j,onClick:()=>k(n.name)})]}),u&&l&&(0,Q.jsx)(qe,{gatewayId:t,upstream:n,state:l,onEdit:e=>{if(e===`choose-folder`||e===`replace-key`||e===`sign-in`){let t=l.problem?.detail?.path;v({upstream:n,action:e,...t?{path:t}:{}})}else T(!1),b({original:n.name,draft:ct(n)})},onFixed:s,onAllowAddress:()=>ue(i(d,`/protection`,{server:t}))}),f&&(0,Q.jsx)(qe,{gatewayId:t,upstream:n,state:{name:n.name,state:`needs-sign-in`,since:``,attempts:0,tool_count:0},onEdit:e=>e===`sign-in`?v({upstream:n,action:e}):b({original:n.name,draft:ct(n)}),onFixed:s,onAllowAddress:()=>void 0})]},n.name)})}),j&&(0,Q.jsx)(`p`,{className:`text-[13px] text-soft`,children:`A toolbox needs at least one server, so the last one can't be removed. Add another first, or remove the whole toolbox from the console.`}),(0,Q.jsx)(le,{open:!!O,onClose:()=>k(null),tone:`danger`,title:`Remove ${O}?`,description:yn(u.find(e=>e.name===O)),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{variant:`secondary`,onClick:()=>k(null),disabled:E,children:`Keep server`}),(0,Q.jsx)(P,{variant:`danger`,loading:E,onClick:()=>{let e=O;D(!0),r(n=>$e(t,e,n),`${e} was removed.`).then(()=>k(null)).finally(()=>D(!1))},children:`Remove server`})]})})]})}function yn(e){let t=[...Object.values(e?.env??{}),...Object.values(e?.headers??{}),e?.oauth].map(e=>e&&typeof e==`object`&&typeof e.secret==`string`?e.secret:null).filter(e=>e!==null),n=[...new Set(t)];return`Your AI app loses this server's tools, and the protection rules made for them are removed too.`+(n.length>0?` Its locked ${n.length===1?`key`:`keys`} (${n.join(`, `)}) ${n.length===1?`stays`:`stay`} saved; remove ${n.length===1?`it`:`them`} under Settings & help, Locked keys, if you no longer need ${n.length===1?`it`:`them`}.`:``)}async function bn(e,t){let r=async r=>{if(!r)return r;let i={};for(let[a,o]of Object.entries(r))if(typeof o==`string`&&o!==``&&o!==t&&!/\$\{[^}]*\}/.test(o)&&Fe(a)){let t=/^(Bearer|Basic|Token) /i.exec(o)?.[0],r=t?o.slice(t.length):o,s=await n.createSecret({label:`${e.name} ${a}`,value:r});i[a]=t?{secret:s.name,prefix:t}:{secret:s.name}}else i[a]=o;return i},i=await r(e.env),a=await r(e.headers);return{...e,...i?{env:i}:{},...a?{headers:a}:{}}}function $({title:e,help:t,technical:n,children:r,onSave:i,dirty:a,busy:o,onReset:s}){return(0,Q.jsxs)(`div`,{className:`grid gap-3 border-b border-faint py-5 first:pt-0 last:border-b-0 md:grid-cols-[1fr_minmax(0,300px)]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-2 text-[14.5px] font-semibold`,children:[e,` `,(0,Q.jsx)(`code`,{className:`mono text-[11.5px] font-normal text-soft`,children:n})]}),(0,Q.jsx)(`div`,{className:`mt-1 text-[13px] text-soft`,children:t})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[r,(i||s)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[s&&(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:s,disabled:o,children:`Use the default`}),i&&(0,Q.jsx)(P,{size:`sm`,variant:`primary`,onClick:i,disabled:!a,loading:o,children:`Save setting`})]})]})]})}function xn({id:e,file:t,write:n}){let r=t.config,i=(t.text??``).match(/^(\w+):/gm)?.map(e=>e.slice(0,-1))??[],[o,s]=(0,Z.useState)(null),c=(t,r,i,a)=>(s(t),n((n,i)=>ve(e,t,r,n,i),i,a).finally(()=>s(null))),[l,u]=(0,Z.useState)(r.name),[d,m]=(0,Z.useState)(r.connect_timeout_ms/1e3),[h,_]=(0,Z.useState)(r.on_injection),[v,y]=(0,Z.useState)(Object.entries(r.injection_overrides)),[b,x]=(0,Z.useState)(r.max_tool_name_length??null),S=r.notify===void 0?`auto`:r.notify?`on`:`off`,C=Object.fromEntries(v.filter(([e])=>e.trim()).map(([e,t])=>[e.trim(),t]));return(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)($,{title:`Name`,technical:`name`,help:(0,Q.jsx)(Q.Fragment,{children:`Shown in the activity log and to your AI app. Renaming moves the toolbox to a new identity: tools you turned off, pre-approvals and reviewed tool changes are stored under the old name and stop applying, so it counts as loosening.`}),dirty:l.trim()!==r.name&&!!l.trim(),busy:o===`name`,onSave:()=>c(`name`,l.trim(),`The toolbox was renamed.`,`Rename this toolbox?`),children:(0,Q.jsx)(f,{value:l,onChange:u,mono:!0,"aria-label":`Toolbox name`})}),(0,Q.jsx)($,{title:`Time to wait for each server to start`,technical:`connect_timeout_ms`,help:`Your toolbox connects every server before serving any tool. A slow server gets this long before the toolbox gives up and says which one failed.`,dirty:d!==null&&d*1e3!==r.connect_timeout_ms,busy:o===`connect_timeout_ms`,onSave:()=>c(`connect_timeout_ms`,Math.round(d*1e3),`The start-up wait was saved.`),onReset:i.includes(`connect_timeout_ms`)?()=>c(`connect_timeout_ms`,null,`The start-up wait is back to 20 seconds.`):void 0,children:(0,Q.jsx)(a,{value:d,onChange:m,min:1,unit:`seconds`,"aria-label":`Seconds to wait`})}),(0,Q.jsx)($,{title:(0,Q.jsxs)(Q.Fragment,{children:[`Hidden instructions in tool descriptions `,(0,Q.jsx)(w,{term:`HMCP005`})]}),technical:`on_injection`,help:be[h].explain+` Each server can have its own setting too.`,dirty:h!==r.on_injection,busy:o===`on_injection`,onSave:()=>c(`on_injection`,h,`Hidden-instruction handling was saved.`,`Handle hidden instructions less strictly?`),children:(0,Q.jsx)(I,{value:h,onChange:_,"aria-label":`Hidden instructions`,options:[`strip`,`deny`,`annotate`].map(e=>({value:e,label:be[e].label}))})}),(0,Q.jsx)($,{title:`Descriptions you checked`,technical:`injection_overrides`,help:`For a tool whose description was flagged by mistake. Name the tool as your AI app sees it, such as files__read_file.`,dirty:JSON.stringify(C)!==JSON.stringify(r.injection_overrides),busy:o===`injection_overrides`,onSave:()=>c(`injection_overrides`,C,`Checked descriptions were saved.`,`Trust these descriptions?`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[v.map(([e,t],n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(f,{value:e,onChange:e=>y(v.map((t,r)=>r===n?[e,t[1]]:t)),mono:!0,"aria-label":`Tool ${n+1}`,placeholder:`files__read_file`}),(0,Q.jsx)(N,{icon:`trash`,label:`Remove ${e||`row ${n+1}`}`,size:34,onClick:()=>y(v.filter((e,t)=>t!==n))})]},n)).flatMap((e,t)=>[e,(0,Q.jsx)(I,{value:v[t][1],onChange:e=>y(v.map((n,r)=>r===t?[n[0],e]:n)),"aria-label":`How to treat tool ${t+1}`,options:[`accept`,`annotate`,`strip`,`deny`].map(e=>({value:e,label:be[e].label}))},`m${t}`)]),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`plus`,onClick:()=>y([...v,[``,`accept`]]),children:`Add a tool`})})]})}),(0,Q.jsx)($,{title:`Put the server's name in front of each tool`,technical:`namespace`,help:`Tools are shown as server__tool, so two servers can't offer look-alike tools. Turning it off renames every tool, so rules and switches naming them stop applying.`,children:(0,Q.jsx)(p,{checked:r.namespace,disabled:o===`namespace`,onChange:e=>c(`namespace`,e,e?`Tool names now include the server.`:`Tool names no longer include the server.`,`Rename every tool?`),label:r.namespace?`On`:`Off`})}),(0,Q.jsx)($,{title:`Apply protection changes without a restart`,technical:`policy_reload`,help:`When the protection settings file changes, the running toolbox picks it up straight away. A file with a mistake is ignored and the old settings stay in force.`,children:(0,Q.jsx)(p,{checked:r.policy_reload,disabled:o===`policy_reload`,onChange:e=>c(`policy_reload`,e,e?`Protection changes now apply straight away.`:`Protection changes now wait for a restart.`),label:r.policy_reload?`On`:`Off`})}),(0,Q.jsx)($,{title:`Longest tool name`,technical:`max_tool_name_length`,help:`AI services refuse a request if any tool name is too long, which breaks every tool at once. A tool with a longer name is held back instead. Empty means no limit.`,dirty:(b??void 0)!==r.max_tool_name_length,busy:o===`max_tool_name_length`,onSave:()=>c(`max_tool_name_length`,b,b?`The name limit was saved.`:`The name limit was removed.`),children:(0,Q.jsx)(a,{value:b,onChange:x,min:1,unit:`letters`,"aria-label":`Longest tool name`})}),(0,Q.jsx)($,{title:`Desktop notifications`,technical:`notify`,help:`Show a notification on this computer when a call waits for you. Automatic means on when an app runs the toolbox on this computer, off when it serves over a web address.`,children:(0,Q.jsx)(I,{value:S,"aria-label":`Desktop notifications`,onChange:e=>c(`notify`,e===`auto`?null:e===`on`,`Notification setting saved.`),options:[{value:`auto`,label:`Automatic`},{value:`on`,label:`On`},{value:`off`,label:`Off`}]})}),(0,Q.jsxs)(`div`,{className:`mt-2 rounded-[18px] bg-sunken/60 p-4`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-[14.5px] font-semibold`,children:[(0,Q.jsx)(g,{name:`lock`,size:17}),` Settings the console can't change`]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-soft`,children:`These decide what the console itself may do. If the console could change them, it could give itself permission, so they can only be changed by editing the file outside the console.`}),(0,Q.jsxs)(`dl`,{className:`mt-3 grid gap-2 text-[13.5px] sm:grid-cols-2`,children:[(0,Q.jsx)(Sn,{term:`Console may change protection rules`,technical:`policy_writes`,on:t.guarded.policy_writes}),(0,Q.jsx)(Sn,{term:`Console may reverse an existing decision`,technical:`policy_overrides`,on:t.guarded.policy_overrides})]})]})]})}function Sn({term:t,technical:n,on:r}){return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-2xl bg-surface px-3 py-2.5`,children:[(0,Q.jsxs)(`dt`,{children:[t,(0,Q.jsx)(`code`,{className:`mono block text-[11.5px] text-soft`,children:n})]}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(e,{tone:r?`ok`:`neutral`,children:r?`Allowed`:`Not allowed`})})]})}function Cn({id:e,file:t,write:n}){let[i,a]=(0,Z.useState)(t.text??``),[o,s]=(0,Z.useState)(null),[c,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{a(t.text??``),s(null)},[t.digest]),t.text===null)return(0,Q.jsxs)(b,{icon:`file`,title:`This file has to be fixed in a text editor`,children:[`It isn't readable as a settings file at all, so the console can't show it. Open it in a text editor, fix it, then reopen these settings.`,(0,Q.jsx)(`span`,{className:`mt-2 block`,children:(0,Q.jsx)(q,{children:t.path})})]});let h=()=>{u(!0),m(null),_e(e,i).then(s).catch(e=>m(W(e))).finally(()=>u(!1))},g=()=>{f(!0),n((t,n)=>ye(e,i,t,n),t.broken?`The settings file was repaired.`:`The settings file was saved.`,t.broken?`Save the repaired settings file?`:`Save the edited settings file?`,t.broken?`This file couldn't be loaded, so the console can't compare what your fix changes. Check it carefully before saving.`:void 0).finally(()=>f(!1))},_=i!==t.text,v=o&&_;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`p`,{className:`text-[13.5px] text-soft`,children:[`The toolbox's whole settings file, for changes the forms don't cover. Keys in your locked keys appear only by name. A key still written out in the file shows as `,(0,Q.jsx)(`code`,{className:`mono`,children:`[kept secret]`}),`; leave that marker and the stored value is kept. The protection-settings entry and the two settings the console can't change are refused here.`,(0,Q.jsx)(`span`,{className:`mt-1 block`,children:(0,Q.jsx)(q,{children:t.path})})]}),(0,Q.jsx)(ee,{value:i,onChange:e=>{a(e),s(null)},label:`Settings file`,rows:18,error:o&&!o.valid?o.error:null}),p&&(0,Q.jsx)(l,{tone:`danger`,role:`alert`,children:p}),v&&o.valid&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{children:`What changes`}),(0,Q.jsx)(j,{before:t.text??``,after:i,label:`Changes to the settings file`}),t.broken?(0,Q.jsx)(l,{tone:`warn`,title:`Saving needs your confirmation`,children:`This file couldn't be loaded, so the console can't compare what your fix changes.`}):o.loosens.length>0&&(0,Q.jsx)(l,{tone:`warn`,title:`This lets more through`,children:(0,Q.jsx)(`ul`,{className:`mt-1 list-disc pl-5`,children:o.loosens.map(e=>(0,Q.jsx)(`li`,{children:e},e))})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,Q.jsx)(P,{variant:`ghost`,onClick:()=>{a(t.text??``),s(null)},disabled:!_,children:`Undo my edits`}),v&&o.valid?(0,Q.jsx)(P,{variant:`primary`,icon:`check`,onClick:g,loading:d,children:t.broken?`Save repaired file`:`Save settings file`}):(0,Q.jsx)(P,{variant:`primary`,onClick:h,loading:c,disabled:!_,children:`Check changes`})]}),(0,Q.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[`Changes to servers reach a running toolbox straight away; anything else applies the next time it starts. `,r(i.split(`
|
|
2
2
|
`).length,`line`),`.`]})]})}var wn={ok:`bg-ok`,warn:`bg-warn`,bad:`bg-bad`,neutral:`bg-soft`};function Tn(){let{nav:e,servers:t,serverId:n,reload:r}=J(),i=H(),a=e.query,o=(...t)=>ce(s(e,Object.fromEntries(t.map(e=>[e,null])))),c=a.get(`manage`),l=a.get(`tab`)??`servers`,u=t.filter(e=>e.ok),d=u.filter(e=>e.running).length,f=u.filter(e=>e.enforcement===`enforce`).length,p=u.reduce((e,t)=>e+(t.upstreams?.length??0),0),m=u.reduce((e,t)=>e+(t.toolCount??0),0);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(k,{title:`Connections`,subtitle:`The toolboxes that protect your AI apps, and the apps and servers they connect.`,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(T,{href:s(e,{connect:`1`}),variant:`primary`,icon:`plug`,children:ht}),(0,Q.jsx)(T,{href:s(e,{add:`server`}),icon:`plus`,children:`Add a server`}),(0,Q.jsx)(T,{href:s(e,{add:`1`}),variant:`ghost`,icon:`shield`,children:`Create a toolbox`})]})}),t.length===0?(0,Q.jsx)(kn,{}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 lg:gap-5`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:gap-4 xl:grid-cols-4 lg:gap-5`,children:[(0,Q.jsx)(te,{tone:`hero`,title:`Toolboxes`,value:u.length,sub:u.length?`${f} protecting · ${u.length-f} watch-only`:`None can be loaded`}),(0,Q.jsx)(te,{title:`Running now`,value:d,sub:d===u.length?`All of them`:`${u.length-d} not running`}),(0,Q.jsx)(te,{title:`Connected servers`,value:p,sub:`The servers your toolboxes hold`}),(0,Q.jsx)(te,{title:`Tools`,value:de(m),sub:`Offered to your AI apps`})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`gateways-h`,children:[(0,Q.jsx)(`h2`,{id:`gateways-h`,className:`sr-only`,children:`Toolboxes`}),(0,Q.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 2xl:grid-cols-3 lg:gap-5`,children:t.map(e=>e.ok?(0,Q.jsx)(An,{server:e},e.id):(0,Q.jsx)(jn,{server:e},e.id))})]}),(0,Q.jsx)(cn,{}),(0,Q.jsx)(dn,{servers:t,serverId:n}),(0,Q.jsx)(Pn,{servers:t})]}),(0,Q.jsx)(On,{open:a.get(`connect`)===`1`,onClose:()=>o(`connect`)}),(0,Q.jsx)(xt,{open:a.get(`connect`)===`advanced`,onClose:()=>o(`connect`)}),(0,Q.jsx)(zt,{open:a.get(`add`)===`1`,onClose:()=>o(`add`)}),(0,Q.jsx)(Dn,{open:a.get(`add`)===`server`,gatewayId:En(a.get(`gateway`),n,u),onClose:()=>o(`add`,`gateway`),onDone:(e,t)=>{o(`add`,`gateway`),i.show(`ok`,t?`${e} was added, and your toolbox was set up.`:`${e} was added.`),r()}}),(0,Q.jsx)(gn,{id:c&&t.some(e=>e.id===c)?c:null,tab:l,onTab:t=>ce(s(e,{tab:t})),onClose:()=>o(`manage`,`tab`,`key`),replaceKeyFor:a.get(`key`),onOpened:()=>o(`key`)})]})}function En(e,t,n){return e&&n.some(t=>t.id===e)?e:t&&n.some(e=>e.id===t)?t:n[0]?.id??null}function Dn({open:e,gatewayId:t,onClose:n,onDone:r}){let{servers:i}=J(),a=i.find(e=>e.id===t)?.label;return(0,Q.jsx)(v,{open:e,onClose:()=>{ft(),n()},title:`Add a server`,subtitle:a?`It joins ${a}. You test it before anything is saved.`:`You test it before anything is saved.`,width:920,children:e&&(0,Q.jsx)(ut,{gatewayId:t,onCancel:n,onDone:e=>r(e.upstreamName,e.created)})})}function On({open:e,onClose:t}){let{nav:n,reload:r}=J();return(0,Z.useEffect)(()=>{e||st()},[e]),(0,Q.jsx)(v,{open:e,onClose:()=>{st(),t()},title:ht,subtitle:gt,width:880,children:e&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(dt,{toolsHref:(e,t)=>i(n,`/tools`,{server:e,app:t}),protect:e=>({href:i(n,`/protection`,{server:e})}),addServer:{href:s(n,{connect:null,add:`server`})},onConnected:r,onUndone:r}),(0,Q.jsxs)(`details`,{className:`rounded-[18px] border border-line p-4`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[14px] font-semibold select-none`,children:`Advanced`}),(0,Q.jsx)(`p`,{className:`mt-2 text-[13.5px] text-muted`,children:`For one project folder only, a different toolbox, Roo Code, or adding your toolbox to an app without moving its servers.`}),(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(T,{href:s(n,{connect:`advanced`}),size:`sm`,icon:`settings`,children:`Connect step by step`})})]})]})})}function kn(){let{nav:e}=J();return(0,Q.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[1.2fr_1fr] lg:gap-5`,children:[(0,Q.jsxs)(re,{tone:`hero`,className:`flex flex-col p-7 md:p-8`,children:[(0,Q.jsx)(`span`,{className:`grid h-12 w-12 place-items-center rounded-full bg-white/15`,children:(0,Q.jsx)(g,{name:`shield-check`,size:24})}),(0,Q.jsx)(`h2`,{className:`display mt-5 text-[30px] md:text-[36px]`,children:`Give your AI app its first tools`}),(0,Q.jsx)(`p`,{className:`mt-2 max-w-lg text-[15px] text-on-hero-soft`,children:`Your toolbox sits between your AI app and the servers that give it tools, and decides what runs, what waits for you, and what is blocked. The getting-started guide walks you through it in a few minutes.`}),(0,Q.jsxs)(`div`,{className:`mt-7 flex flex-wrap gap-2.5`,children:[(0,Q.jsx)(T,{href:`/start`,variant:`on-hero`,icon:`arrow-right`,children:`Start the guide`}),(0,Q.jsx)(T,{href:s(e,{connect:`1`}),variant:`on-hero`,icon:`plug`,className:`!bg-transparent !text-white ring-1 ring-white/50`,children:ht})]}),(0,Q.jsxs)(`p`,{className:`mt-4 text-[13px] text-on-hero-soft`,children:[`No servers in your app yet?`,` `,(0,Q.jsx)(`a`,{href:s(e,{add:`server`}),onClick:y,className:`font-semibold text-white underline underline-offset-2`,children:`Add a server`}),` `,`and your toolbox is made with it.`]})]}),(0,Q.jsx)(re,{title:`How it works`,children:(0,Q.jsx)(`ol`,{className:`flex flex-col gap-4`,children:[[`Connect your AI app`,`Pick Claude Desktop, Claude Code, Codex, the ChatGPT desktop app, Cursor, VS Code or another app. The servers it already has move into your toolbox in one click. Restart the app once.`],[`Add a server`,`Want more tools? Pick one from the list, such as Files on this computer or GitHub. You're walked through it, and you test it before anything is saved.`],[`Decide what needs you`,`Tools that only look run freely. Changes wait for you to say yes, and you can adjust that any time.`]].map(([e,t],n)=>(0,Q.jsxs)(`li`,{className:`flex gap-3.5`,children:[(0,Q.jsx)(`span`,{className:`tnum grid h-9 w-9 shrink-0 place-items-center rounded-full bg-ok-tint text-[14px] font-bold text-ok`,children:n+1}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`block text-[15px] font-medium`,children:e}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[13.5px] text-soft`,children:t})]})]},e))})})]})}function An({server:t}){let{nav:n,reload:a}=J(),o=H(),c=B(()=>et(t.id),[t.id],15e3),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),m=c.data,h=m?pn(m):t.running?{label:`Running`,tone:`ok`}:{label:`Not running`,tone:`neutral`},_=E[t.enforcement??`enforce`],v=t.upstreams??[],b=!!m?.managed&&(m.state===`running`||m.state===`starting`),x=e=>s(n,{manage:t.id,tab:e}),S=Ie(t.id),C=Qe(t.id),D=Ye(S.data?.upstreams??[],!!S.data?.running,C.data??[]);return(0,Q.jsxs)(`article`,{className:`card flex min-w-0 flex-col gap-5 p-6`,children:[(0,Q.jsxs)(`header`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:`shield`,size:20})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`h3`,{className:`truncate text-[19px] leading-tight font-medium tracking-[-0.02em]`,title:t.id,children:t.label}),t.configPath&&(0,Q.jsx)(`p`,{className:`mono mt-1 truncate text-[12px] text-soft`,title:t.configPath,children:t.configPath})]}),(0,Q.jsx)(N,{icon:`trash`,label:`Remove ${t.label} from the console`,size:36,onClick:()=>p(!0)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(e,{tone:h.tone,icon:`power`,children:h.label}),(0,Q.jsx)(e,{tone:_.tone,icon:t.enforcement===`observe`?`eye`:`shield-check`,title:_.explain,children:_.label}),t.posture&&t.posture in V&&(0,Q.jsx)(e,{children:V[t.posture].label})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-2 gap-3`,children:[(0,Q.jsxs)(`div`,{className:`rounded-2xl bg-sunken/60 px-4 py-3`,children:[(0,Q.jsx)(`dt`,{className:`text-[12.5px] text-soft`,children:`Tools`}),(0,Q.jsx)(`dd`,{className:`display tnum text-[28px]`,children:t.toolCount??`–`})]}),(0,Q.jsxs)(`div`,{className:`rounded-2xl bg-sunken/60 px-4 py-3`,children:[(0,Q.jsxs)(`dt`,{className:`text-[12.5px] text-soft`,children:[`Connected servers `,(0,Q.jsx)(w,{term:`connectedServer`})]}),(0,Q.jsx)(`dd`,{className:`display tnum text-[28px]`,children:v.length})]})]}),v.length>0&&(0,Q.jsx)(`ul`,{className:`-mt-2 flex flex-wrap gap-1.5`,"aria-label":`Its servers`,children:v.map(e=>{let n=S.data?.running?Ue(S.data,e):null,r=n?.state===`connected`&&(C.data??[]).some(t=>t.server===e),i=r?`bad`:n?Ce[n.state].tone:null;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded-full bg-sunken px-2.5 py-0.5 text-[12px]`,children:[i&&(0,Q.jsx)(`span`,{"aria-hidden":!0,className:U(`h-2 w-2 rounded-full`,wn[i])}),(0,Q.jsx)(`span`,{title:e,children:fe(e,t.displayNames)}),r?(0,Q.jsx)(`span`,{className:`text-muted`,children:`· calls failing`}):n&&n.state!==`connected`&&(0,Q.jsxs)(`span`,{className:`text-muted`,children:[`· `,Ce[n.state].label.toLowerCase()]}),n&&!r&&(0,Q.jsxs)(`span`,{className:`sr-only`,children:[`: `,Ce[n.state].label]})]},e)})}),D&&(0,Q.jsxs)(`p`,{className:U(`-mt-2 flex flex-wrap items-center gap-x-2 text-[13px] font-medium`,D.tone===`bad`?`text-bad`:D.tone===`warn`?`text-warn`:`text-ok`),children:[D.text,D.fix&&(0,Q.jsxs)(`a`,{href:x(`servers`),onClick:y,className:`underline underline-offset-2`,children:[`Fix `,D.fix]})]}),t.toolCount===null&&(0,Q.jsx)(`p`,{className:`-mt-2 text-[12.5px] text-soft`,children:t.provisionalToolCount?`${r(t.provisionalToolCount,`tool`)} found when its servers were tested. They're counted for real once the toolbox has run.`:`Tools are counted once the toolbox has run.`}),t.tenantError&&(0,Q.jsx)(l,{tone:`warn`,children:K(Y(t.tenantError))}),m?.externallyRunning&&(0,Q.jsx)(`p`,{className:`-mt-2 text-[12.5px] text-soft`,children:`An AI app runs this toolbox. Restarting the app restarts it.`}),(0,Q.jsxs)(`div`,{className:`mt-auto flex flex-wrap gap-2 border-t border-faint pt-4`,children:[(0,Q.jsx)(T,{href:i(n,`/`,{server:t.id}),variant:`primary`,size:`sm`,iconRight:`arrow-right`,children:`Open`}),(0,Q.jsx)(T,{href:x(`servers`),size:`sm`,icon:`settings`,children:`Settings`}),b?(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`stop`,loading:u,onClick:()=>{d(!0),Ke(t.id).then(()=>{o.show(`ok`,`${t.label} stopped.`),c.reload(),a()}).catch(e=>o.show(`bad`,W(e))).finally(()=>d(!1))},children:`Stop toolbox`}):!m?.externallyRunning&&(0,Q.jsx)(T,{href:x(`run`),size:`sm`,variant:`ghost`,icon:`play`,children:`Start toolbox`})]}),(0,Q.jsx)(Mn,{server:f?t:null,onClose:()=>p(!1)})]})}function jn({server:t}){let{nav:n}=J(),[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`article`,{className:`card flex min-w-0 flex-col gap-4 border-[1.5px] border-bad/40 p-6`,children:[(0,Q.jsxs)(`header`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-bad-tint text-bad`,children:(0,Q.jsx)(g,{name:`warning`,size:20})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`h3`,{className:`truncate text-[19px] leading-tight font-medium tracking-[-0.02em]`,title:t.id,children:t.label}),t.configPath&&(0,Q.jsx)(`p`,{className:`mono mt-1 truncate text-[12px] text-soft`,title:t.configPath,children:t.configPath})]}),(0,Q.jsx)(e,{tone:`bad`,children:`Can't be loaded`})]}),(0,Q.jsx)(`p`,{className:`text-[14px] text-muted`,children:`The console couldn't read this toolbox, so it can't show or protect anything for it.`}),(0,Q.jsx)(`p`,{className:`rounded-2xl bg-sunken/60 px-4 py-3 text-[13px] break-words text-muted`,children:K(Y(t.error??`No reason was given.`))}),(0,Q.jsxs)(`div`,{className:`mt-auto flex flex-wrap gap-2 border-t border-faint pt-4`,children:[(0,Q.jsx)(T,{href:s(n,{manage:t.id,tab:`file`}),size:`sm`,variant:`primary`,icon:`edit`,children:`Fix toolbox settings file`}),(0,Q.jsx)(P,{size:`sm`,variant:`ghost`,icon:`trash`,onClick:()=>i(!0),children:`Remove from console`})]}),(0,Q.jsx)(Mn,{server:r?t:null,onClose:()=>i(!1)})]})}function Mn({server:e,onClose:t}){let{reload:n}=J(),r=H(),[i,a]=(0,Z.useState)(!1);return e?(0,Q.jsx)(le,{open:!0,onClose:t,tone:`danger`,dismissable:!i,title:`Remove ${e.label} from the console?`,description:`The console stops showing it. Nothing is deleted.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{variant:`secondary`,onClick:t,disabled:i,children:`Keep it`}),(0,Q.jsx)(P,{variant:`danger`,loading:i,onClick:()=>{a(!0),_.removeServer(e.id).then(()=>{r.show(`ok`,`${e.label} was removed from the console.`),t(),n()}).catch(e=>r.show(`bad`,W(e))).finally(()=>a(!1))},children:`Remove from console`})]}),children:(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2 text-[14px] text-muted`,children:[(0,Q.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Q.jsx)(g,{name:`file`,size:17,className:`mt-0.5 shrink-0 text-soft`}),`Its files on this computer are kept: the toolbox's settings file, its protection settings, waiting calls and the activity log.`]}),(0,Q.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Q.jsx)(g,{name:`power`,size:17,className:`mt-0.5 shrink-0 text-soft`}),`If this console was running it, it is stopped. If an AI app runs it, it keeps running and keeps protecting that app.`]}),(0,Q.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Q.jsx)(g,{name:`plus`,size:17,className:`mt-0.5 shrink-0 text-soft`}),`You can add it back later with Create a toolbox, using its settings file.`]})]})}):null}var Nn={"connect.apply":`App connected`,"connect.revert":`Connection undone`,"connect.create":`Toolbox created`,"gateway.setting":`Toolbox option changed`,"gateway.upstream.add":`Server added`,"gateway.upstream.update":`Server changed`,"gateway.upstream.remove":`Server removed`,"gateway.file":`Toolbox settings file edited`,"gateway.process.start":`Toolbox started`,"gateway.process.stop":`Toolbox stopped`,"policy.reload":`Protection settings reloaded`,"exposure.disable":`Tool turned off`,"exposure.enable":`Tool turned back on`,"approval.decide":`Call answered`,"standing_grant.create":`Pre-approval given`,"standing_grant.revoke":`Pre-approval withdrawn`,"github.claude-code.block":`GitHub blocked in Claude Code`,"github.claude-code.unblock":`GitHub block in Claude Code undone`,"github.changes.on":`GitHub changes switched on`,"github.changes.off":`GitHub set back to only looking`};function Pn({servers:e}){let{nav:t}=J(),[n,r]=(0,Z.useState)(`noteworthy`),a=e.filter(e=>e.ok).map(e=>e.id).join(`,`),o=B(()=>a?_.combinedAudit({servers:a,limit:`12`,...n===`noteworthy`?{noteworthy:`1`}:{}}):Promise.resolve(null),[a,n],3e4),s=t=>e.find(e=>e.id===t)?.label??t??`A toolbox`,u=o.data;return(0,Q.jsx)(re,{title:`Recent activity across toolboxes`,actions:(0,Q.jsx)(h,{label:`Which activity`,size:`sm`,value:n,onChange:r,options:[{value:`noteworthy`,label:`Needs a look`},{value:`all`,label:`All`}]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[u?.sharedPaths.map(e=>(0,Q.jsx)(l,{tone:`info`,title:`${e.servers.map(s).join(` and `)} share one activity log`,children:`That's how they were set up, and it's safe: the tamper check covers them together. Give each toolbox its own log only if you want to check them apart.`},e.path)),u?.broken.map(e=>(0,Q.jsxs)(l,{tone:`info`,children:[s(e.id),`'s activity couldn't be read: `,K(Y(e.error))]},e.id)),o.error&&!u?(0,Q.jsx)(l,{tone:`danger`,title:`Activity could not be loaded`,actions:(0,Q.jsx)(P,{size:`sm`,icon:`refresh`,onClick:o.reload,children:`Try again`}),children:W(o.error)}):o.loading&&!u?(0,Q.jsx)(c,{lines:5,height:18}):!u||u.records.length===0?(0,Q.jsx)(b,{icon:`activity`,title:n===`noteworthy`?`Nothing needs a look`:`No activity yet`,compact:!0,children:n===`noteworthy`?`No blocked, held or failed calls lately.`:`Calls appear here once an AI app uses a toolbox's tools.`}):(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:u.records.map(e=>(0,Q.jsx)(Fn,{record:e,gateway:s(e.serverId),href:i(t,`/activity`,{server:e.serverId??``,seq:String(e.seq)})},`${e.serverId}-${e.seq}-${e.id}`))})]})})}function Fn({record:t,gateway:n,href:r}){let i=t.tool.startsWith(`(`)||Nn[t.rule_id]!==void 0,a=i?Nn[t.rule_id]??`Console change`:Xe(t.tool).label;return(0,Q.jsx)(`li`,{className:`border-b border-faint last:border-b-0`,children:(0,Q.jsxs)(`a`,{href:r,onClick:y,className:`-mx-2 flex items-center gap-3 rounded-2xl px-2 py-2.5 transition-colors hover:bg-faint`,children:[(0,Q.jsx)(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-full bg-sunken text-muted`,children:(0,Q.jsx)(g,{name:i?`settings`:`tool`,size:17})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[14px] font-medium`,title:i?void 0:t.tool,children:a}),(0,Q.jsxs)(`span`,{className:`block truncate text-[12.5px] text-soft`,children:[n,` · `,x(t.ts)]})]}),!i&&(0,Q.jsx)(`span`,{className:`shrink-0`,children:t.observe?(0,Q.jsxs)(e,{tone:`neutral`,title:`Watch-only: it ran anyway`,children:[`Would be: `,z(t.decision)]}):(0,Q.jsx)(A,{decision:t.decision})})]})})}export{Tn as ConnectionsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,A as t,B as n,D as r,E as i,G as a,H as o,I as s,It as c,K as l,L as u,M as d,Nt as ee,O as te,Pt as f,S as p,T as ne,U as m,V as h,Z as g,_,bt as re,c as v,gt as y,ht as b,j as ie,k as x,kt as S,mt as C,pt as w,rt as T,s as E,w as D,x as O,y as k}from"./kit-BHB_ha4i.js";import{c as A,i as j,l as M,o as N,pn as P,s as F}from"./index-DywhXnhV.js";var I=c(),L=S(),R=[{value:`max`,label:`is at most`},{value:`min`,label:`is at least`},{value:`enum`,label:`is one of`},{value:`maxLength`,label:`has at most N characters`},{value:`maxItems`,label:`has at most N items`},{value:`within`,label:`is a path inside the folder`},{value:`host`,label:`is a web address on`}],z=(e=``)=>({arg:e,kind:`max`,value:``,values:[]});function B(e,t){if(t===`number`||t===`integer`){let t=Number(e);return Number.isFinite(t)?t:e}if(t===`boolean`)return e===`true`||e!==`false`&&e;if(t===`string`)return e;if(e===`true`||e===`false`)return e===`true`;let n=Number(e);return e.trim()!==``&&Number.isFinite(n)?n:e}function V(e,t={}){let n={};for(let r of e){let e=r.arg.trim();if(!e)return{constraints:n,error:`Each limit needs the name of an input.`};let i=n[e]??={},a=Number(r.value),o=r.value.trim()!==``&&Number.isFinite(a);switch(r.kind){case`max`:case`min`:if(!o)return{constraints:n,error:`Give a number for the limit on ${e}.`};i[r.kind]=a;break;case`maxLength`:case`maxItems`:if(!o||!Number.isInteger(a)||a<+(r.kind===`maxLength`))return{constraints:n,error:`Give a whole number for the limit on ${e}.`};i[r.kind]=a;break;case`enum`:if(r.values.length===0)return{constraints:n,error:`List at least one allowed value for ${e}.`};i.enum=r.values.map(n=>B(n,t[e]));break;case`within`:if(!/^(\/|[a-zA-Z]:[\\/])/.test(r.value.trim()))return{constraints:n,error:`The folder for ${e} must be a full path, starting with /.`};i.within=r.value.trim();break;case`host`:if(r.values.length===0)return{constraints:n,error:`List at least one website for ${e}.`};i.host=r.values}}return{constraints:n,error:null}}function H({rows:e,onChange:n,argNames:r,disabled:i}){let a=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[e.map((o,s)=>(0,L.jsxs)(`div`,{className:`grid gap-2 rounded-2xl border border-line p-3 sm:grid-cols-[minmax(0,9rem)_minmax(0,14rem)_minmax(0,1fr)_auto] sm:items-start`,children:[r&&r.length>0?(0,L.jsx)(x,{"aria-label":`Input for limit ${s+1}`,value:o.arg,onChange:e=>a(s,{arg:e}),disabled:i,options:[{value:``,label:`Choose input`},...r.map(e=>({value:e,label:e}))]}):(0,L.jsx)(d,{"aria-label":`Input for limit ${s+1}`,value:o.arg,onChange:e=>a(s,{arg:e}),placeholder:`input name`,mono:!0,disabled:i}),(0,L.jsx)(x,{"aria-label":`Kind of limit ${s+1}`,value:o.kind,onChange:e=>a(s,{kind:e}),options:R,disabled:i}),o.kind===`enum`||o.kind===`host`?(0,L.jsx)(t,{"aria-label":`Allowed values for limit ${s+1}`,value:o.values,onChange:e=>a(s,{values:e}),placeholder:o.kind===`host`?`example.com, then Enter`:`a value, then Enter`,disabled:i}):(0,L.jsx)(d,{"aria-label":`Value for limit ${s+1}`,value:o.value,onChange:e=>a(s,{value:e}),placeholder:o.kind===`within`?`/home/me/projects`:`a number`,mono:o.kind===`within`,disabled:i}),(0,L.jsx)(y,{icon:`trash`,label:`Remove limit ${s+1}`,size:40,onClick:()=>n(e.filter((e,t)=>t!==s)),disabled:i})]},s)),(0,L.jsx)(b,{size:`sm`,variant:`secondary`,icon:`plus`,onClick:()=>n([...e,z(r?.length===1?r[0]:``)]),disabled:i,children:`Add input limit`})]})}var U=`__pattern__`;function W(e){let t;return/matches a family of tools/.test(e)?{uses:`A pattern covers several tools, so it also needs a use limit or an input limit.`}:(t=/may not last longer than (\d+) days/.exec(e))?{ttl:`The longest a pre-approval can last is ${t[1]} days.`}:/expires_at is in the past/.test(e)?{ttl:`Choose how long it should last.`}:/unclosed brace/.test(e)?{tool:`This pattern has a { without a matching }.`}:(t=/constraint "(.+?)" is not a usable argument path/.exec(e))?{limits:`"${t[1]}" is not an input name that can be checked.`}:/within must be an absolute path/.test(e)?{limits:`A folder must be a full path, starting with /.`}:/"reason"/.test(e)?{reason:`Say why you are adding this. It is kept in the activity log.`}:/"tool_match"/.test(e)?{tool:`Choose a tool, or type a pattern.`}:/"max_uses"/.test(e)?{uses:`Use a whole number of 1 or more, or choose no limit.`}:{general:N(e)}}function G({open:e,onClose:t,serverId:n,tenant:s,tools:c,ttlMax:l,onCreated:te}){let[m,h]=(0,I.useState)(``),[g,v]=(0,I.useState)(``),[y,S]=(0,I.useState)(``),[C,w]=(0,I.useState)([]),[E,O]=(0,I.useState)(3600),[k,A]=(0,I.useState)(20),[j,M]=(0,I.useState)(!1),[P,R]=(0,I.useState)(``),[z,B]=(0,I.useState)(!1),[G,K]=(0,I.useState)({}),[q,J]=(0,I.useState)(!1);(0,I.useEffect)(()=>{e&&(h(``),v(``),S(``),w([]),O(3600),A(20),M(!1),R(``),B(!1),K({}))},[e]);let Y=m===U,X=(Y?g:m).trim(),Z=Y?void 0:c?.find(e=>e.name===m),Q=V(C,(0,I.useMemo)(()=>Object.fromEntries((Z?.args??[]).map(e=>[e.name,e.type??``])),[Z])),oe={tool_match:X,effect:y||null,constraints:Q.constraints,ttl_seconds:E??0,max_uses:j?null:k},se=JSON.stringify(oe),ce=re(se,250),[$,le]=(0,I.useState)(null),[ue,de]=(0,I.useState)(null),[fe,pe]=(0,I.useState)(!1);(0,I.useEffect)(()=>{if(!e)return;let t=JSON.parse(ce);if(!t.tool_match||Q.error||!t.ttl_seconds){le(null),de(null);return}let r=!0;return pe(!0),f.previewGrant(n,{...t,reason:`preview`},s).then(e=>{r&&(le(e),de(null))}).catch(e=>{if(!r)return;le(null);let t=W(e.message);de(Object.values(t)[0]??N(e.message))}).finally(()=>r&&pe(!1)),()=>{r=!1}},[ce,e,n,s]);let me=$?.tools.filter(e=>e.covers)??[],he=y===`destructive`||me.some(e=>e.effect===`destructive`)||Z?.effect===`destructive`;async function ge(){let e={};if(X||(e.tool=Y?`Type a pattern.`:`Choose a tool.`),E===null?e.ttl=`Choose how long it should last.`:l!==void 0&&E>l&&(e.ttl=`The longest a pre-approval can last is ${u(l)}.`),!j&&(k===null||k<1||!Number.isInteger(k))&&(e.uses=`Use a whole number of 1 or more, or choose no limit.`),Q.error&&(e.limits=Q.error),P.trim()||(e.reason=`Say why you are adding this. It is kept in the activity log.`),K(e),!(Object.keys(e).length>0)){J(!0);try{te(await f.createGrant(n,{...oe,reason:P.trim()},s))}catch(e){K(e instanceof ee&&e.status===422?W(e.message):{general:N(e.message)})}finally{J(!1)}}}let _e=[{value:``,label:c===null?`Loading tools…`:`Choose a tool`},...(c??[]).map(e=>({value:e.name,label:`${F(e.name).label} · ${e.name}`})),{value:U,label:`Several tools, by pattern…`}];return(0,L.jsx)(p,{open:e,onClose:()=>!q&&t(),width:640,title:`Add pre-approval`,subtitle:`Let a kind of call run without asking you, for a limited time.`,footer:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(b,{variant:`ghost`,onClick:t,disabled:q,children:`Cancel`}),(0,L.jsx)(b,{variant:`primary`,icon:`check`,loading:q,disabled:he&&!z,onClick:ge,children:`Save pre-approval`})]}),children:(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsx)(i,{label:`Which tool`,error:G.tool,children:(0,L.jsx)(x,{value:m,onChange:h,options:_e})}),Y&&(0,L.jsx)(i,{label:`Tool pattern`,error:G.tool,help:`Use * for any run of characters. For example notes__* covers every tool from the notes server. A pattern also needs a use limit or an input limit.`,children:(0,L.jsx)(d,{value:g,onChange:v,placeholder:`notes__create_*`,mono:!0,autoFocus:!0})}),(0,L.jsx)(i,{label:`Only when the tool`,help:`Leave this on any to go by what each tool does already.`,children:(0,L.jsx)(x,{value:y,onChange:S,options:[{value:``,label:`Any`},{value:`read`,label:T.read.label},{value:`write`,label:T.write.label},{value:`destructive`,label:T.destructive.label}]})}),(0,L.jsx)(i,{label:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Input limits `,(0,L.jsx)(_,{term:`limits`})]}),optional:!0,error:G.limits,help:`Calls covered by this must stay inside every limit you add.`,children:(0,L.jsx)(H,{rows:C,onChange:w,argNames:Z?Z.args.map(e=>e.name):null,disabled:q})}),(0,L.jsx)(i,{label:`For how long`,error:G.ttl,help:l?`Up to ${u(l)}.`:void 0,children:(0,L.jsx)(ne,{value:E,onChange:O,label:`For how long`,max:l})}),(0,L.jsx)(i,{label:`Up to how many calls`,error:G.uses,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,L.jsx)(r,{value:j?null:k,onChange:A,min:1,step:1,unit:`calls`,disabled:j,className:`w-40`}),(0,L.jsx)(D,{checked:j,onChange:M,label:`No limit`})]})}),(0,L.jsx)(i,{label:`Reason`,error:G.reason,help:`Kept in the activity log with your name.`,children:(0,L.jsx)(ie,{value:P,onChange:R,rows:2,placeholder:`For example: tidying notes this week, agreed with the team`})}),(0,L.jsxs)(`section`,{"aria-live":`polite`,className:`space-y-3 rounded-2xl bg-sunken/70 p-4`,children:[(0,L.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:`What this would cover`}),X?Q.error?(0,L.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`Finish the input limits to see what this would cover.`}):ue?(0,L.jsx)(`p`,{className:`text-[13.5px] text-warn`,children:ue}):$?(0,L.jsx)(ae,{preview:$,covered:me,byPattern:Y}):fe&&(0,L.jsx)(a,{lines:3}):(0,L.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`Choose a tool to see which calls this would let through.`})]}),he&&(0,L.jsxs)(`div`,{className:`space-y-3 rounded-2xl bg-bad-tint p-4`,children:[(0,L.jsx)(`p`,{className:`text-[13.5px]`,children:`This covers a tool that deletes. Calls to it would run without asking you, within the limits above.`}),(0,L.jsx)(D,{checked:z,onChange:B,label:`I understand deletes will run without asking.`})]}),G.general&&(0,L.jsx)(o,{tone:`danger`,title:`The pre-approval was not saved`,role:`alert`,children:G.general})]})})}function ae({preview:e,covered:t,byPattern:r}){if(!e.surfaceKnown)return(0,L.jsxs)(`p`,{className:`text-[13.5px] text-warn`,children:[`Can't tell which tools this covers right now.`,` `,e.surfaceUnknownWhy?N(e.surfaceUnknownWhy):`The toolbox has not reported its tools.`]});let i=e.tools.length-t.length;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:t.length===0?`This covers none of the tools this toolbox has right now.`:`It covers ${n(t.length,`tool`)} until ${A(e.expiresAt)}.`}),t.length>0&&(0,L.jsx)(`ul`,{className:`space-y-2.5`,children:t.map(e=>(0,L.jsxs)(`li`,{className:`rounded-xl bg-surface px-3 py-2.5`,children:[(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,L.jsx)(g,{effect:e.effect}),(0,L.jsx)(`span`,{className:`text-[14px] font-medium`,children:F(e.name).label}),(0,L.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.name})]}),e.heldBounds.length>0&&(0,L.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Calls that break your rule's limit on `,e.heldBounds.join(`, `),` still ask you. Add a limit for`,` `,e.heldBounds.length===1?`it`:`them`,` here to cover those too.`]}),e.unknownArgsHeld&&(0,L.jsx)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:`Calls that send an input your rule does not mention still ask you.`})]},e.name))}),(0,L.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[i>0&&`${n(i,`other tool`)} ${i===1?`is`:`are`} not covered. `,r&&`A tool added later that fits the pattern would be covered too. `,`It never lets through anything your rules block.`]})]})}var K={active:{label:`Active`,tone:`ok`},expired:{label:`Expired`,tone:`neutral`},exhausted:{label:`Used up`,tone:`neutral`},revoked:{label:`Revoked`,tone:`bad`}};function q(){let{serverId:t,tenant:n,nav:r,reload:i}=P(),c=k(),u=M(3e4),d=r.query.get(`grant`)??r.query.get(`id`),[p,ne]=(0,I.useState)(r.query.get(`id`)?`all`:`active`),_=E(()=>f.grants(t,n,{state:p}),[t,n,p],15e3),re=E(()=>f.tools(t,n),[t,n]),y=E(()=>f.redaction(),[]),[ie,x]=(0,I.useState)(!1),[S,T]=(0,I.useState)(null),[D,R]=(0,I.useState)(!1),[z,B]=(0,I.useState)(null),V=_.data??[],H=V.filter(e=>e.state===`active`&&e.expiresAt>u),U=H.reduce((e,t)=>e+t.uses,0),W=H.reduce((e,t)=>e===null||t.expiresAt<e?t.expiresAt:e,null);async function ae(){if(S){R(!0),B(null);try{let e=await f.revokeGrant(t,S.id,n);e.warning?c.show(`warn`,`Revoked, but ${N(e.warning).replace(/^The grant was revoked but /i,``)}`):c.show(`ok`,`Pre-approval revoked. Calls it covered will ask you again.`),T(null),_.reload(),i()}catch(e){e instanceof ee&&(e.status===409||e.status===404)?(c.show(`warn`,`This pre-approval had already ended.`),T(null),_.reload()):B(N(e.message))}finally{R(!1)}}}return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(v,{title:`Pre-approvals`,subtitle:`Let a kind of call run without asking you, until a time or a number of uses runs out. A pre-approval can never allow something your rules block.`,actions:(0,L.jsx)(b,{variant:`primary`,icon:`plus`,onClick:()=>x(!0),children:`Add pre-approval`})}),(0,L.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,L.jsx)(C,{tone:`hero`,title:`Active now`,value:H.length,loading:_.data===null&&!_.error,sub:H.length?`Each one ends by itself`:`Every held call asks you`}),(0,L.jsx)(C,{title:`Calls let through`,value:U,loading:_.data===null&&!_.error,sub:`By the active pre-approvals so far`}),(0,L.jsx)(C,{title:`Ends soonest`,value:W===null?`None`:h(W,u),loading:_.data===null&&!_.error,sub:W===null?`Nothing is active`:`At ${A(W)}`})]}),(0,L.jsxs)(w,{className:`mt-6`,title:`Your pre-approvals`,actions:(0,L.jsx)(te,{label:`Show`,size:`sm`,value:p,onChange:ne,options:[{value:`active`,label:`Active`},{value:`all`,label:`All`}]}),children:[_.error&&(0,L.jsx)(`div`,{className:`mb-4`,children:(0,L.jsx)(o,{tone:`danger`,title:`Could not load pre-approvals`,actions:(0,L.jsx)(b,{size:`sm`,icon:`refresh`,onClick:_.reload,children:`Try again`}),children:N(_.error)})}),_.data===null?!_.error&&(0,L.jsx)(a,{lines:4,height:20}):(0,L.jsx)(l,{caption:`Pre-approvals`,columns:[{key:`tools`,header:`Which tools`,width:`w-[15rem]`,cell:e=>{let t=/[*?{]/.test(e.toolMatch);return(0,L.jsxs)(`span`,{className:`flex min-w-0 items-start gap-2.5`,children:[(0,L.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,L.jsx)(g,{effect:e.effect})}),(0,L.jsxs)(`span`,{className:`min-w-0`,children:[(0,L.jsx)(`span`,{className:`block font-medium`,children:t?`Tools matching a pattern`:F(e.toolMatch).label}),(0,L.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.toolMatch}),e.effect&&(0,L.jsxs)(`span`,{className:`block text-[12px] text-soft`,children:[`Only tools that: `,J[e.effect]??e.effect]})]})]})}},{key:`limits`,header:`Limits`,cell:e=>{let t=j(e.constraints);return e.olderVersion&&t.length===0?(0,L.jsx)(`span`,{className:`text-soft`,children:`Only a call with no inputs at all`}):t.length===0?(0,L.jsx)(`span`,{className:`text-soft`,children:`No input limits`}):(0,L.jsx)(`ul`,{className:`space-y-0.5 text-[13px]`,children:t.map(([e,t])=>(0,L.jsxs)(`li`,{children:[(0,L.jsx)(`code`,{className:`mono text-[12px]`,children:e}),` `,t]},e))})}},{key:`uses`,header:`Uses`,cell:e=>(0,L.jsx)(Y,{grant:e})},{key:`expires`,header:`Expires`,cell:e=>(0,L.jsxs)(`span`,{className:`block`,children:[(0,L.jsx)(`span`,{className:`block`,children:e.state===`active`?h(e.expiresAt,u):e.state===`expired`?`Ended`:`–`}),(0,L.jsx)(`span`,{className:`block text-[12px] text-soft`,children:s(e.expiresAt)})]})},{key:`reason`,header:`Reason`,cell:e=>(0,L.jsxs)(`span`,{className:`block max-w-[18rem] min-w-0`,children:[(0,L.jsx)(`span`,{className:`block break-words`,children:e.reason}),(0,L.jsxs)(`span`,{className:`block text-[12px] text-soft`,children:[`Added by `,e.createdBy,` `,h(Math.min(e.createdAt,u),u),e.revokedBy&&`. Revoked by ${e.revokedBy}`]})]})},{key:`state`,header:`State`,cell:t=>{let n=K[t.state]??{label:t.state,tone:`neutral`};return t.olderVersion&&t.state===`active`?(0,L.jsxs)(`span`,{className:`block max-w-[12rem]`,children:[(0,L.jsx)(e,{tone:`warn`,children:`Needs approving again`}),(0,L.jsx)(`span`,{className:`mt-1 block text-[12px] text-soft`,children:`Made by an older version. Approve the next call with "don't ask again" to remember it.`})]}):(0,L.jsx)(e,{tone:n.tone,children:n.label})}},{key:`act`,header:`Action`,align:`right`,cell:e=>e.state===`active`?(0,L.jsx)(b,{size:`sm`,variant:`secondary`,onClick:()=>(B(null),T(e)),children:`Revoke`}):(0,L.jsx)(`span`,{className:`text-soft`,children:`–`})}],rows:V,rowKey:e=>e.id,selectedKey:d,empty:(0,L.jsx)(m,{icon:`key`,title:p===`active`?`No active pre-approvals`:`No pre-approvals yet`,actions:(0,L.jsx)(b,{variant:`primary`,icon:`plus`,onClick:()=>x(!0),children:`Add pre-approval`}),children:`Without one, every call your rules hold waits for you on the Waiting for you page. You can also add one while approving a call there.`})})]}),(0,L.jsx)(G,{open:ie,onClose:()=>x(!1),serverId:t,tenant:n,tools:re.data,ttlMax:y.data?.grantTtlMaxSeconds,onCreated:e=>{x(!1),c.show(`ok`,`Pre-approval saved. It ends ${h(e.expiresAt)}.`),_.reload(),i()}}),(0,L.jsx)(O,{open:S!==null,onClose:()=>!D&&T(null),dismissable:!D,tone:`danger`,title:`Revoke this pre-approval?`,description:`Calls it covered will ask you again from now on. This cannot be undone, but you can add a new one.`,footer:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(b,{variant:`secondary`,onClick:()=>T(null),disabled:D,children:`Keep it`}),(0,L.jsx)(b,{variant:`danger`,loading:D,onClick:ae,children:`Revoke pre-approval`})]}),children:S&&(0,L.jsxs)(`div`,{className:`space-y-2 text-[14px]`,children:[(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`code`,{className:`mono`,children:S.toolMatch}),`, `,S.uses,` of`,` `,S.maxUses===null?`unlimited`:S.maxUses,` uses, ends `,h(S.expiresAt),`.`]}),(0,L.jsx)(`p`,{className:`text-soft`,children:S.reason}),z&&(0,L.jsx)(`p`,{role:`alert`,className:`font-medium text-bad`,children:z})]})})]})}var J={read:`look only`,write:`make changes`,destructive:`delete`};function Y({grant:e}){if(e.maxUses===null)return(0,L.jsxs)(`span`,{className:`block`,children:[(0,L.jsx)(`span`,{className:`tnum block`,children:n(e.uses,`use`)}),(0,L.jsx)(`span`,{className:`block text-[12px] text-soft`,children:`no limit`})]});let t=Math.min(100,Math.round(e.uses/Math.max(1,e.maxUses)*100));return(0,L.jsxs)(`span`,{className:`block w-28`,children:[(0,L.jsxs)(`span`,{className:`tnum block text-[13.5px]`,children:[e.uses,` of `,e.maxUses,` used`]}),(0,L.jsx)(`span`,{className:`mt-1.5 block h-1.5 overflow-hidden rounded-full bg-sunken`,role:`meter`,"aria-label":`Uses`,"aria-valuemin":0,"aria-valuemax":e.maxUses,"aria-valuenow":e.uses,children:(0,L.jsx)(`span`,{className:`block h-full rounded-full ${t>=100?`bg-soft`:`bg-primary`}`,style:{width:`${t}%`}})})]})}export{q as PreApprovalsPage};
|
|
1
|
+
import{$ as e,A as t,B as n,D as r,E as i,G as a,H as o,I as s,It as c,K as l,L as u,M as d,Nt as ee,O as te,Pt as f,S as p,T as ne,U as m,V as h,Z as g,_,bt as re,c as v,gt as y,ht as b,j as ie,k as x,kt as S,mt as C,pt as w,rt as T,s as E,w as D,x as O,y as k}from"./kit-BHB_ha4i.js";import{c as A,i as j,l as M,o as N,pn as P,s as F}from"./index-2otwle61.js";var I=c(),L=S(),R=[{value:`max`,label:`is at most`},{value:`min`,label:`is at least`},{value:`enum`,label:`is one of`},{value:`maxLength`,label:`has at most N characters`},{value:`maxItems`,label:`has at most N items`},{value:`within`,label:`is a path inside the folder`},{value:`host`,label:`is a web address on`}],z=(e=``)=>({arg:e,kind:`max`,value:``,values:[]});function B(e,t){if(t===`number`||t===`integer`){let t=Number(e);return Number.isFinite(t)?t:e}if(t===`boolean`)return e===`true`||e!==`false`&&e;if(t===`string`)return e;if(e===`true`||e===`false`)return e===`true`;let n=Number(e);return e.trim()!==``&&Number.isFinite(n)?n:e}function V(e,t={}){let n={};for(let r of e){let e=r.arg.trim();if(!e)return{constraints:n,error:`Each limit needs the name of an input.`};let i=n[e]??={},a=Number(r.value),o=r.value.trim()!==``&&Number.isFinite(a);switch(r.kind){case`max`:case`min`:if(!o)return{constraints:n,error:`Give a number for the limit on ${e}.`};i[r.kind]=a;break;case`maxLength`:case`maxItems`:if(!o||!Number.isInteger(a)||a<+(r.kind===`maxLength`))return{constraints:n,error:`Give a whole number for the limit on ${e}.`};i[r.kind]=a;break;case`enum`:if(r.values.length===0)return{constraints:n,error:`List at least one allowed value for ${e}.`};i.enum=r.values.map(n=>B(n,t[e]));break;case`within`:if(!/^(\/|[a-zA-Z]:[\\/])/.test(r.value.trim()))return{constraints:n,error:`The folder for ${e} must be a full path, starting with /.`};i.within=r.value.trim();break;case`host`:if(r.values.length===0)return{constraints:n,error:`List at least one website for ${e}.`};i.host=r.values}}return{constraints:n,error:null}}function H({rows:e,onChange:n,argNames:r,disabled:i}){let a=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[e.map((o,s)=>(0,L.jsxs)(`div`,{className:`grid gap-2 rounded-2xl border border-line p-3 sm:grid-cols-[minmax(0,9rem)_minmax(0,14rem)_minmax(0,1fr)_auto] sm:items-start`,children:[r&&r.length>0?(0,L.jsx)(x,{"aria-label":`Input for limit ${s+1}`,value:o.arg,onChange:e=>a(s,{arg:e}),disabled:i,options:[{value:``,label:`Choose input`},...r.map(e=>({value:e,label:e}))]}):(0,L.jsx)(d,{"aria-label":`Input for limit ${s+1}`,value:o.arg,onChange:e=>a(s,{arg:e}),placeholder:`input name`,mono:!0,disabled:i}),(0,L.jsx)(x,{"aria-label":`Kind of limit ${s+1}`,value:o.kind,onChange:e=>a(s,{kind:e}),options:R,disabled:i}),o.kind===`enum`||o.kind===`host`?(0,L.jsx)(t,{"aria-label":`Allowed values for limit ${s+1}`,value:o.values,onChange:e=>a(s,{values:e}),placeholder:o.kind===`host`?`example.com, then Enter`:`a value, then Enter`,disabled:i}):(0,L.jsx)(d,{"aria-label":`Value for limit ${s+1}`,value:o.value,onChange:e=>a(s,{value:e}),placeholder:o.kind===`within`?`/home/me/projects`:`a number`,mono:o.kind===`within`,disabled:i}),(0,L.jsx)(y,{icon:`trash`,label:`Remove limit ${s+1}`,size:40,onClick:()=>n(e.filter((e,t)=>t!==s)),disabled:i})]},s)),(0,L.jsx)(b,{size:`sm`,variant:`secondary`,icon:`plus`,onClick:()=>n([...e,z(r?.length===1?r[0]:``)]),disabled:i,children:`Add input limit`})]})}var U=`__pattern__`;function W(e){let t;return/matches a family of tools/.test(e)?{uses:`A pattern covers several tools, so it also needs a use limit or an input limit.`}:(t=/may not last longer than (\d+) days/.exec(e))?{ttl:`The longest a pre-approval can last is ${t[1]} days.`}:/expires_at is in the past/.test(e)?{ttl:`Choose how long it should last.`}:/unclosed brace/.test(e)?{tool:`This pattern has a { without a matching }.`}:(t=/constraint "(.+?)" is not a usable argument path/.exec(e))?{limits:`"${t[1]}" is not an input name that can be checked.`}:/within must be an absolute path/.test(e)?{limits:`A folder must be a full path, starting with /.`}:/"reason"/.test(e)?{reason:`Say why you are adding this. It is kept in the activity log.`}:/"tool_match"/.test(e)?{tool:`Choose a tool, or type a pattern.`}:/"max_uses"/.test(e)?{uses:`Use a whole number of 1 or more, or choose no limit.`}:{general:N(e)}}function G({open:e,onClose:t,serverId:n,tenant:s,tools:c,ttlMax:l,onCreated:te}){let[m,h]=(0,I.useState)(``),[g,v]=(0,I.useState)(``),[y,S]=(0,I.useState)(``),[C,w]=(0,I.useState)([]),[E,O]=(0,I.useState)(3600),[k,A]=(0,I.useState)(20),[j,M]=(0,I.useState)(!1),[P,R]=(0,I.useState)(``),[z,B]=(0,I.useState)(!1),[G,K]=(0,I.useState)({}),[q,J]=(0,I.useState)(!1);(0,I.useEffect)(()=>{e&&(h(``),v(``),S(``),w([]),O(3600),A(20),M(!1),R(``),B(!1),K({}))},[e]);let Y=m===U,X=(Y?g:m).trim(),Z=Y?void 0:c?.find(e=>e.name===m),Q=V(C,(0,I.useMemo)(()=>Object.fromEntries((Z?.args??[]).map(e=>[e.name,e.type??``])),[Z])),oe={tool_match:X,effect:y||null,constraints:Q.constraints,ttl_seconds:E??0,max_uses:j?null:k},se=JSON.stringify(oe),ce=re(se,250),[$,le]=(0,I.useState)(null),[ue,de]=(0,I.useState)(null),[fe,pe]=(0,I.useState)(!1);(0,I.useEffect)(()=>{if(!e)return;let t=JSON.parse(ce);if(!t.tool_match||Q.error||!t.ttl_seconds){le(null),de(null);return}let r=!0;return pe(!0),f.previewGrant(n,{...t,reason:`preview`},s).then(e=>{r&&(le(e),de(null))}).catch(e=>{if(!r)return;le(null);let t=W(e.message);de(Object.values(t)[0]??N(e.message))}).finally(()=>r&&pe(!1)),()=>{r=!1}},[ce,e,n,s]);let me=$?.tools.filter(e=>e.covers)??[],he=y===`destructive`||me.some(e=>e.effect===`destructive`)||Z?.effect===`destructive`;async function ge(){let e={};if(X||(e.tool=Y?`Type a pattern.`:`Choose a tool.`),E===null?e.ttl=`Choose how long it should last.`:l!==void 0&&E>l&&(e.ttl=`The longest a pre-approval can last is ${u(l)}.`),!j&&(k===null||k<1||!Number.isInteger(k))&&(e.uses=`Use a whole number of 1 or more, or choose no limit.`),Q.error&&(e.limits=Q.error),P.trim()||(e.reason=`Say why you are adding this. It is kept in the activity log.`),K(e),!(Object.keys(e).length>0)){J(!0);try{te(await f.createGrant(n,{...oe,reason:P.trim()},s))}catch(e){K(e instanceof ee&&e.status===422?W(e.message):{general:N(e.message)})}finally{J(!1)}}}let _e=[{value:``,label:c===null?`Loading tools…`:`Choose a tool`},...(c??[]).map(e=>({value:e.name,label:`${F(e.name).label} · ${e.name}`})),{value:U,label:`Several tools, by pattern…`}];return(0,L.jsx)(p,{open:e,onClose:()=>!q&&t(),width:640,title:`Add pre-approval`,subtitle:`Let a kind of call run without asking you, for a limited time.`,footer:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(b,{variant:`ghost`,onClick:t,disabled:q,children:`Cancel`}),(0,L.jsx)(b,{variant:`primary`,icon:`check`,loading:q,disabled:he&&!z,onClick:ge,children:`Save pre-approval`})]}),children:(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsx)(i,{label:`Which tool`,error:G.tool,children:(0,L.jsx)(x,{value:m,onChange:h,options:_e})}),Y&&(0,L.jsx)(i,{label:`Tool pattern`,error:G.tool,help:`Use * for any run of characters. For example notes__* covers every tool from the notes server. A pattern also needs a use limit or an input limit.`,children:(0,L.jsx)(d,{value:g,onChange:v,placeholder:`notes__create_*`,mono:!0,autoFocus:!0})}),(0,L.jsx)(i,{label:`Only when the tool`,help:`Leave this on any to go by what each tool does already.`,children:(0,L.jsx)(x,{value:y,onChange:S,options:[{value:``,label:`Any`},{value:`read`,label:T.read.label},{value:`write`,label:T.write.label},{value:`destructive`,label:T.destructive.label}]})}),(0,L.jsx)(i,{label:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Input limits `,(0,L.jsx)(_,{term:`limits`})]}),optional:!0,error:G.limits,help:`Calls covered by this must stay inside every limit you add.`,children:(0,L.jsx)(H,{rows:C,onChange:w,argNames:Z?Z.args.map(e=>e.name):null,disabled:q})}),(0,L.jsx)(i,{label:`For how long`,error:G.ttl,help:l?`Up to ${u(l)}.`:void 0,children:(0,L.jsx)(ne,{value:E,onChange:O,label:`For how long`,max:l})}),(0,L.jsx)(i,{label:`Up to how many calls`,error:G.uses,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,L.jsx)(r,{value:j?null:k,onChange:A,min:1,step:1,unit:`calls`,disabled:j,className:`w-40`}),(0,L.jsx)(D,{checked:j,onChange:M,label:`No limit`})]})}),(0,L.jsx)(i,{label:`Reason`,error:G.reason,help:`Kept in the activity log with your name.`,children:(0,L.jsx)(ie,{value:P,onChange:R,rows:2,placeholder:`For example: tidying notes this week, agreed with the team`})}),(0,L.jsxs)(`section`,{"aria-live":`polite`,className:`space-y-3 rounded-2xl bg-sunken/70 p-4`,children:[(0,L.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:`What this would cover`}),X?Q.error?(0,L.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`Finish the input limits to see what this would cover.`}):ue?(0,L.jsx)(`p`,{className:`text-[13.5px] text-warn`,children:ue}):$?(0,L.jsx)(ae,{preview:$,covered:me,byPattern:Y}):fe&&(0,L.jsx)(a,{lines:3}):(0,L.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`Choose a tool to see which calls this would let through.`})]}),he&&(0,L.jsxs)(`div`,{className:`space-y-3 rounded-2xl bg-bad-tint p-4`,children:[(0,L.jsx)(`p`,{className:`text-[13.5px]`,children:`This covers a tool that deletes. Calls to it would run without asking you, within the limits above.`}),(0,L.jsx)(D,{checked:z,onChange:B,label:`I understand deletes will run without asking.`})]}),G.general&&(0,L.jsx)(o,{tone:`danger`,title:`The pre-approval was not saved`,role:`alert`,children:G.general})]})})}function ae({preview:e,covered:t,byPattern:r}){if(!e.surfaceKnown)return(0,L.jsxs)(`p`,{className:`text-[13.5px] text-warn`,children:[`Can't tell which tools this covers right now.`,` `,e.surfaceUnknownWhy?N(e.surfaceUnknownWhy):`The toolbox has not reported its tools.`]});let i=e.tools.length-t.length;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:t.length===0?`This covers none of the tools this toolbox has right now.`:`It covers ${n(t.length,`tool`)} until ${A(e.expiresAt)}.`}),t.length>0&&(0,L.jsx)(`ul`,{className:`space-y-2.5`,children:t.map(e=>(0,L.jsxs)(`li`,{className:`rounded-xl bg-surface px-3 py-2.5`,children:[(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,L.jsx)(g,{effect:e.effect}),(0,L.jsx)(`span`,{className:`text-[14px] font-medium`,children:F(e.name).label}),(0,L.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.name})]}),e.heldBounds.length>0&&(0,L.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Calls that break your rule's limit on `,e.heldBounds.join(`, `),` still ask you. Add a limit for`,` `,e.heldBounds.length===1?`it`:`them`,` here to cover those too.`]}),e.unknownArgsHeld&&(0,L.jsx)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:`Calls that send an input your rule does not mention still ask you.`})]},e.name))}),(0,L.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[i>0&&`${n(i,`other tool`)} ${i===1?`is`:`are`} not covered. `,r&&`A tool added later that fits the pattern would be covered too. `,`It never lets through anything your rules block.`]})]})}var K={active:{label:`Active`,tone:`ok`},expired:{label:`Expired`,tone:`neutral`},exhausted:{label:`Used up`,tone:`neutral`},revoked:{label:`Revoked`,tone:`bad`}};function q(){let{serverId:t,tenant:n,nav:r,reload:i}=P(),c=k(),u=M(3e4),d=r.query.get(`grant`)??r.query.get(`id`),[p,ne]=(0,I.useState)(r.query.get(`id`)?`all`:`active`),_=E(()=>f.grants(t,n,{state:p}),[t,n,p],15e3),re=E(()=>f.tools(t,n),[t,n]),y=E(()=>f.redaction(),[]),[ie,x]=(0,I.useState)(!1),[S,T]=(0,I.useState)(null),[D,R]=(0,I.useState)(!1),[z,B]=(0,I.useState)(null),V=_.data??[],H=V.filter(e=>e.state===`active`&&e.expiresAt>u),U=H.reduce((e,t)=>e+t.uses,0),W=H.reduce((e,t)=>e===null||t.expiresAt<e?t.expiresAt:e,null);async function ae(){if(S){R(!0),B(null);try{let e=await f.revokeGrant(t,S.id,n);e.warning?c.show(`warn`,`Revoked, but ${N(e.warning).replace(/^The grant was revoked but /i,``)}`):c.show(`ok`,`Pre-approval revoked. Calls it covered will ask you again.`),T(null),_.reload(),i()}catch(e){e instanceof ee&&(e.status===409||e.status===404)?(c.show(`warn`,`This pre-approval had already ended.`),T(null),_.reload()):B(N(e.message))}finally{R(!1)}}}return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(v,{title:`Pre-approvals`,subtitle:`Let a kind of call run without asking you, until a time or a number of uses runs out. A pre-approval can never allow something your rules block.`,actions:(0,L.jsx)(b,{variant:`primary`,icon:`plus`,onClick:()=>x(!0),children:`Add pre-approval`})}),(0,L.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,L.jsx)(C,{tone:`hero`,title:`Active now`,value:H.length,loading:_.data===null&&!_.error,sub:H.length?`Each one ends by itself`:`Every held call asks you`}),(0,L.jsx)(C,{title:`Calls let through`,value:U,loading:_.data===null&&!_.error,sub:`By the active pre-approvals so far`}),(0,L.jsx)(C,{title:`Ends soonest`,value:W===null?`None`:h(W,u),loading:_.data===null&&!_.error,sub:W===null?`Nothing is active`:`At ${A(W)}`})]}),(0,L.jsxs)(w,{className:`mt-6`,title:`Your pre-approvals`,actions:(0,L.jsx)(te,{label:`Show`,size:`sm`,value:p,onChange:ne,options:[{value:`active`,label:`Active`},{value:`all`,label:`All`}]}),children:[_.error&&(0,L.jsx)(`div`,{className:`mb-4`,children:(0,L.jsx)(o,{tone:`danger`,title:`Could not load pre-approvals`,actions:(0,L.jsx)(b,{size:`sm`,icon:`refresh`,onClick:_.reload,children:`Try again`}),children:N(_.error)})}),_.data===null?!_.error&&(0,L.jsx)(a,{lines:4,height:20}):(0,L.jsx)(l,{caption:`Pre-approvals`,columns:[{key:`tools`,header:`Which tools`,width:`w-[15rem]`,cell:e=>{let t=/[*?{]/.test(e.toolMatch);return(0,L.jsxs)(`span`,{className:`flex min-w-0 items-start gap-2.5`,children:[(0,L.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,L.jsx)(g,{effect:e.effect})}),(0,L.jsxs)(`span`,{className:`min-w-0`,children:[(0,L.jsx)(`span`,{className:`block font-medium`,children:t?`Tools matching a pattern`:F(e.toolMatch).label}),(0,L.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.toolMatch}),e.effect&&(0,L.jsxs)(`span`,{className:`block text-[12px] text-soft`,children:[`Only tools that: `,J[e.effect]??e.effect]})]})]})}},{key:`limits`,header:`Limits`,cell:e=>{let t=j(e.constraints);return e.olderVersion&&t.length===0?(0,L.jsx)(`span`,{className:`text-soft`,children:`Only a call with no inputs at all`}):t.length===0?(0,L.jsx)(`span`,{className:`text-soft`,children:`No input limits`}):(0,L.jsx)(`ul`,{className:`space-y-0.5 text-[13px]`,children:t.map(([e,t])=>(0,L.jsxs)(`li`,{children:[(0,L.jsx)(`code`,{className:`mono text-[12px]`,children:e}),` `,t]},e))})}},{key:`uses`,header:`Uses`,cell:e=>(0,L.jsx)(Y,{grant:e})},{key:`expires`,header:`Expires`,cell:e=>(0,L.jsxs)(`span`,{className:`block`,children:[(0,L.jsx)(`span`,{className:`block`,children:e.state===`active`?h(e.expiresAt,u):e.state===`expired`?`Ended`:`–`}),(0,L.jsx)(`span`,{className:`block text-[12px] text-soft`,children:s(e.expiresAt)})]})},{key:`reason`,header:`Reason`,cell:e=>(0,L.jsxs)(`span`,{className:`block max-w-[18rem] min-w-0`,children:[(0,L.jsx)(`span`,{className:`block break-words`,children:e.reason}),(0,L.jsxs)(`span`,{className:`block text-[12px] text-soft`,children:[`Added by `,e.createdBy,` `,h(Math.min(e.createdAt,u),u),e.revokedBy&&`. Revoked by ${e.revokedBy}`]})]})},{key:`state`,header:`State`,cell:t=>{let n=K[t.state]??{label:t.state,tone:`neutral`};return t.olderVersion&&t.state===`active`?(0,L.jsxs)(`span`,{className:`block max-w-[12rem]`,children:[(0,L.jsx)(e,{tone:`warn`,children:`Needs approving again`}),(0,L.jsx)(`span`,{className:`mt-1 block text-[12px] text-soft`,children:`Made by an older version. Approve the next call with "don't ask again" to remember it.`})]}):(0,L.jsx)(e,{tone:n.tone,children:n.label})}},{key:`act`,header:`Action`,align:`right`,cell:e=>e.state===`active`?(0,L.jsx)(b,{size:`sm`,variant:`secondary`,onClick:()=>(B(null),T(e)),children:`Revoke`}):(0,L.jsx)(`span`,{className:`text-soft`,children:`–`})}],rows:V,rowKey:e=>e.id,selectedKey:d,empty:(0,L.jsx)(m,{icon:`key`,title:p===`active`?`No active pre-approvals`:`No pre-approvals yet`,actions:(0,L.jsx)(b,{variant:`primary`,icon:`plus`,onClick:()=>x(!0),children:`Add pre-approval`}),children:`Without one, every call your rules hold waits for you on the Waiting for you page. You can also add one while approving a call there.`})})]}),(0,L.jsx)(G,{open:ie,onClose:()=>x(!1),serverId:t,tenant:n,tools:re.data,ttlMax:y.data?.grantTtlMaxSeconds,onCreated:e=>{x(!1),c.show(`ok`,`Pre-approval saved. It ends ${h(e.expiresAt)}.`),_.reload(),i()}}),(0,L.jsx)(O,{open:S!==null,onClose:()=>!D&&T(null),dismissable:!D,tone:`danger`,title:`Revoke this pre-approval?`,description:`Calls it covered will ask you again from now on. This cannot be undone, but you can add a new one.`,footer:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(b,{variant:`secondary`,onClick:()=>T(null),disabled:D,children:`Keep it`}),(0,L.jsx)(b,{variant:`danger`,loading:D,onClick:ae,children:`Revoke pre-approval`})]}),children:S&&(0,L.jsxs)(`div`,{className:`space-y-2 text-[14px]`,children:[(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`code`,{className:`mono`,children:S.toolMatch}),`, `,S.uses,` of`,` `,S.maxUses===null?`unlimited`:S.maxUses,` uses, ends `,h(S.expiresAt),`.`]}),(0,L.jsx)(`p`,{className:`text-soft`,children:S.reason}),z&&(0,L.jsx)(`p`,{role:`alert`,className:`font-medium text-bad`,children:z})]})})]})}var J={read:`look only`,write:`make changes`,destructive:`delete`};function Y({grant:e}){if(e.maxUses===null)return(0,L.jsxs)(`span`,{className:`block`,children:[(0,L.jsx)(`span`,{className:`tnum block`,children:n(e.uses,`use`)}),(0,L.jsx)(`span`,{className:`block text-[12px] text-soft`,children:`no limit`})]});let t=Math.min(100,Math.round(e.uses/Math.max(1,e.maxUses)*100));return(0,L.jsxs)(`span`,{className:`block w-28`,children:[(0,L.jsxs)(`span`,{className:`tnum block text-[13.5px]`,children:[e.uses,` of `,e.maxUses,` used`]}),(0,L.jsx)(`span`,{className:`mt-1.5 block h-1.5 overflow-hidden rounded-full bg-sunken`,role:`meter`,"aria-label":`Uses`,"aria-valuemin":0,"aria-valuemax":e.maxUses,"aria-valuenow":e.uses,children:(0,L.jsx)(`span`,{className:`block h-full rounded-full ${t>=100?`bg-soft`:`bg-primary`}`,style:{width:`${t}%`}})})]})}export{q as PreApprovalsPage};
|