hmcp-web 0.2.0 → 0.2.2

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.
@@ -0,0 +1,4 @@
1
+ import{$ as e,A as t,B as n,Ct as r,D as i,E as a,Et as o,G as s,H as c,I 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 _,Q as v,S as y,U as b,V as x,Y as S,Z as C,_ as w,_t as ee,bt as te,c as ne,d as re,et as T,f as ie,ft as ae,gt as oe,ht as E,k as se,kt as D,lt as ce,ot as O,pt as k,q as le,rt as A,s as ue,st as j,w as M,wt as de,x as N,y as P,yt as F}from"./kit-DRVm92_t.js";import{_n as fe,bn as I,fn as L,gn as pe,pn as R,s as z,un as me}from"./index-CTvq_isK.js";var B=u(),V=[`allow`,`approve`,`deny`,`unlabelled`,`off`,`changed`],he={allow:`Runs freely`,approve:`Asks you first`,deny:`Blocked`,unlabelled:`Not labelled`,off:`Turned off`,changed:`Changed`};function ge(e){return e!==null&&V.includes(e)}function H(e){return e.exposure.disabled?`off`:e.effect===null&&!e.reclassifiedTo?`unlabelled`:e.verdict.kind}function U(e){let t=e.reclassifiedTo??e.effect;return t===`read`||t===`write`||t===`destructive`?t:null}function W(e){return e.standingGrants.some(e=>e.covers)}function _e(e){if(e.exposure.disabled)return`Turned off. Your AI can't see it, and every call to it is blocked.`;if(e.hiddenByPolicy)return`Hidden from your AI, because its description carried hidden instructions.`;let t=e.effect===null&&!e.reclassifiedTo;if(e.unreachable)return`Asks you first, but approvals are switched off, so it can never run.`;if(t)return e.verdict.kind===`approve`?`Asks you first, because nobody has said what it does yet.`:`Blocked, because nobody has said what it does yet.`;if(e.verdict.kind===`deny`)return`Blocked. Your AI can see it, but every call to it is refused.`;let n=e.bounds,r=De(e,n);return r.length>0?`Every call ${n.unknownArgs===`approve`?`asks you first`:`is blocked`}, because ${we(r)} ${r.length===1?`is`:`are`} required and its limits don't mention ${r.length===1?`it`:`them`}.`:e.verdict.kind===`approve`?n?n.onViolation===`approve`?`Asks you first before it runs. Its inputs also have limits, listed below.`:`Asks you first before it runs, and a call that breaks the limits below is blocked.`:`Asks you first before it runs.`:n?`Runs freely while its inputs stay within the limits below. A call outside them ${G(n.onViolation)}.`:`Runs freely, without asking anyone.`}function G(e){return e===`approve`?`asks you first`:`is blocked`}function K(e,t){let n=[];return t&&n.push({key:`changed`,text:`Changed`,tone:`warn`}),e.injection&&e.injection.length>0&&n.push({key:`inj`,text:`Hidden instructions found`,tone:`bad`}),e.unreachable&&n.push({key:`unreach`,text:`Can never run`,tone:`bad`}),e.bounds&&n.push({key:`bounds`,text:`Has limits`,tone:`neutral`}),e.unboundedInputs.length>0&&n.push({key:`unbounded`,text:`Some inputs unlimited`,tone:`neutral`}),W(e)&&n.push({key:`grant`,text:`Pre-approved`,tone:`ok`}),n}function ve(e,t){let{ruleId:n,reason:r,kind:i}=e,a=i===`allow`?`runs freely`:i===`approve`?`asks you first`:`is blocked`;return n===`exposure.disabled`?`Someone turned this tool off.`:n.startsWith(`tenant.`)?`The customer check stopped it: ${J(r)}`:n===`defaults.on_unclassified`?`Nobody has said what it does, and your setting for unlabelled tools is that they ${i===`approve`?`ask you first`:`are blocked`}.`:n===`defaults.mode`?t?`No rule mentions it, so your default stance decides. ${j[t].explain}`:`No rule mentions it, so your default stance decides.`:/^rule ".*" \(.*\) says (allow|approve|deny) for /.test(r)?`A rule in your protection settings says it ${a}.`:`A rule in your protection settings says it ${a}, because: “${r}”`}var ye={policy:`A rule in your protection settings says what it does.`,annotation:`The connected server describes it this way. Nothing in your settings overrides it.`,name:`Guessed from the tool's name.`,unclassified:`Nobody has said what it does.`},q={max:`At most`,min:`At least`,enum:`Must be one of`,maxLength:`Longest text`,maxItems:`Most items`,within:`Must stay inside folder`,host:`Allowed websites`};function be(e){return e===`number`||e===`integer`?[`max`,`min`,`enum`]:e===`string`?[`enum`,`maxLength`,`within`,`host`]:e===`array`?[`maxItems`]:e===`boolean`?[`enum`]:[`max`,`min`,`enum`,`maxLength`,`maxItems`,`within`,`host`]}function xe(e){return e.pattern!==void 0||e.coerce!==void 0||e.required!==void 0}function Se(e){let t=[];if(e.min!==void 0&&t.push(`at least ${e.min}`),e.max!==void 0&&t.push(`at most ${e.max}`),e.maxLength!==void 0&&t.push(`at most ${e.maxLength} characters`),e.maxItems!==void 0&&t.push(`at most ${e.maxItems} items`),e.sum_max!==void 0&&t.push(`${e.sum_max} in total`),e.count_max!==void 0&&t.push(`in at most ${e.count_max} places`),e.enum&&t.push(`one of ${e.enum.map(String).join(`, `)}`),e.const===null?t.push(`only empty (null)`):e.const!==void 0&&t.push(`exactly ${String(e.const)}`),e.within&&t.push(`inside ${typeof e.within==`string`?e.within:e.within.join(` or `)}`),e.host&&t.push(`a web address on ${e.host.join(`, `)}`),e.pattern&&t.push(`matching a pattern set in the settings file`),Object.keys(e).every(e=>e===`optional`))return`may be any value`;let n=t.length?`must be ${t.join(`, `)}`:`is limited`;return e.optional?`${n}, or left out`:n}function Ce(e){return e?e.paths.map(t=>`${t} ${Se(e.constraints[t]??{})}`):[]}function we(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`}function Te(e){return/^[^.[\]]*/.exec(e)[0]}function Ee(e,t){let n=[];for(let r of e.args){if(t.includes(r.name))continue;let e=t.filter(e=>Te(e)===r.name);n.push({name:r.name,required:r.required&&e.length===0,only:e.length>0?e:null,list:r.type===`array`})}return[...n.filter(e=>e.required),...n.filter(e=>!e.required&&!e.only),...n.filter(e=>e.only)]}function De(e,t){return!t||t.unknownArgs===`allow`?[]:Ee(e,t.paths).filter(e=>e.required).map(e=>e.name)}var Oe={allow:`Anything else the tool is sent is let through without a check.`,approve:`A call sending anything else asks you first.`,deny:`A call sending anything else is blocked.`};function J(e){let t=e.split(/(?<=[.;])\s+/).filter(e=>!/\b(hmcp-gateway|hmcp|npx)\s+[a-z]/i.test(e)&&!/(^|\s)--[a-z][\w-]*/.test(e)),n=(t.length?t:[`The toolbox refused this change.`]).join(` `).replace(/`/g,``);return n.charAt(0).toUpperCase()+n.slice(1)}function Y(e){return J(e instanceof Error?e.message:String(e))}function ke(e){return e instanceof m&&e.status===409}var Ae=`This changed since you opened it. Reload and try again.`;function je(e,t=64){return e.split(`
2
+ `).map(e=>{let n=[],r=``;for(let i of e.split(/\s+/))r&&r.length+i.length+1>t?(n.push(r),r=i):r=r?`${r} ${i}`:i;return n.push(r),n.join(`
3
+ `)}).join(`
4
+ `)}var X=D(),Me={effect:`What it does (looks, changes or deletes)`,description:`Its description`,"input schema":`The inputs it takes`,annotations:`The hints its server gives about it`};function Ne(e){return e.previousKnown?e.changes.length===0?[`Its details changed.`]:e.changes.map(e=>Me[e]??e):[`Something changed, but the earlier version wasn't kept, so the toolbox can't show what.`]}function Pe({serverId:e,data:t,error:r,loading:i,reload:a,onAccepted:o}){let l=P(),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(!1),[m,h]=(0,B.useState)(null),[g,_]=(0,B.useState)(!1);async function v(t){p(!0);try{let n=t?await R(e,t):await L(e);l.show(`ok`,n.accepted.length===1?`Accepted the change to ${n.accepted[0]}.`:`Accepted ${n.accepted.length} changed tools.`),d(null),n.restartNeeded&&(h(`checking`),pe(e).then(h,()=>h(null))),a(),o()}catch(e){l.show(`bad`,`Not accepted. ${Y(e)}`)}finally{p(!1)}}async function y(){_(!0);try{let t=await I(e);l.show(`ok`,`The toolbox restarted. Accepted tools are available again.`),t.warning&&l.show(`warn`,J(t.warning)),h(null),a(),o()}catch(e){l.show(`bad`,`The toolbox didn't restart. ${Y(e)}`)}finally{_(!1)}}if(r&&!t)return(0,X.jsx)(c,{tone:`danger`,title:`Changed tools couldn't be loaded`,actions:(0,X.jsx)(E,{size:`sm`,icon:`refresh`,onClick:a,children:`Try again`}),children:Y(r)});if(!t)return(0,X.jsx)(k,{children:(0,X.jsx)(s,{lines:5})});let S=t.changed;return(0,X.jsxs)(`div`,{className:`space-y-5`,children:[m&&(0,X.jsx)(c,{tone:`warn`,title:`Restart the toolbox to bring accepted tools back`,actions:m!==`checking`&&m.managed&&(0,X.jsx)(E,{variant:`primary`,size:`sm`,icon:`refresh`,loading:g,onClick:()=>void y(),children:`Restart gateway`}),children:m===`checking`?`Checking how this toolbox is running…`:m.managed?`Some accepted tools were held back from your AI. They come back once the toolbox restarts.`:m.externalHint?`Some accepted tools were held back from your AI. ${J(m.externalHint.replace(/\s+--\s+/g,`, `))}`:`Some accepted tools were held back from your AI. They come back the next time the AI app that runs this toolbox starts it again, so restart that app.`}),!t.live&&(0,X.jsx)(c,{tone:`warn`,title:`The toolbox isn't running, so changes can't be checked right now`,children:`The list below is what it reported last time. Changes can be accepted once it is running again.`}),(0,X.jsxs)(k,{title:(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[`Changed tools `,(0,X.jsx)(w,{term:`changedTools`})]}),actions:S.length>1&&(0,X.jsx)(E,{size:`sm`,variant:`primary`,icon:`check`,disabled:!t.live,onClick:()=>d({tool:null}),children:`Accept all`}),children:[(0,X.jsx)(`p`,{className:`-mt-2 mb-4 text-[13.5px] text-soft`,children:t.onToolChange===`deny`?`A changed tool is held back from your AI until you accept it.`:`A changed tool keeps working, and the change is noted in the activity log until you accept it.`}),S.length===0?(0,X.jsx)(b,{icon:`shield-check`,title:`No tools have changed`,compact:!0,children:`Every tool matches what was accepted before. The toolbox checks again each time it starts and when a connected server updates its list.`}):(0,X.jsx)(`ul`,{className:`space-y-3`,children:S.map(e=>(0,X.jsx)(Fe,{change:e,live:t.live,loading:i,onAccept:()=>d({tool:e.tool})},e.tool))})]}),t.pins.length>0&&(0,X.jsx)(k,{padded:!1,children:(0,X.jsxs)(`details`,{className:`group p-6`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-pointer items-center justify-between gap-3 text-[17px] font-medium tracking-[-0.015em]`,children:[`Reviewed tools`,(0,X.jsx)(`span`,{className:`text-[13px] font-normal text-soft`,children:n(t.pins.length,`tool`)})]}),(0,X.jsx)(`p`,{className:`mt-2 text-[13.5px] text-soft`,children:`The version of each tool that was last accepted. A tool is compared against this every time the toolbox sees it.`}),(0,X.jsx)(`ul`,{className:`mt-3 divide-y divide-faint`,children:t.pins.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-0.5 py-2.5`,children:[(0,X.jsx)(`code`,{className:`font-mono text-[13.5px] break-all`,children:e.tool}),(0,X.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[`Accepted `,x(e.pinnedAt),` by `,e.pinnedBy,(0,X.jsx)(`span`,{className:`ml-2 font-mono text-[11px]`,children:e.digest.slice(0,12)})]})]},e.tool))})]})}),(0,X.jsx)(N,{open:u!==null,onClose:()=>d(null),title:u?.tool?`Accept the change to ${u.tool}?`:`Accept all ${S.length} changed tools?`,description:`Accepting means you've looked at what changed and you're fine with it. The new version becomes the one future changes are compared against.`,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(E,{variant:`secondary`,onClick:()=>d(null),disabled:f,children:`Cancel`}),(0,X.jsx)(E,{variant:`primary`,icon:`check`,loading:f,onClick:()=>void v(u?.tool??null),children:u?.tool?`Accept change`:`Accept all`})]}),children:(0,X.jsxs)(`p`,{className:`text-[14px] text-muted`,children:[`Accepting doesn't change what the tool is allowed to do. Your rules still decide that.`,t.onToolChange===`deny`&&` A tool that was held back becomes available again after the toolbox restarts.`]})})]})}function Fe({change:t,live:n,loading:r,onAccept:i}){let a=t.was;return(0,X.jsxs)(`li`,{className:`rounded-[20px] border border-line p-4 sm:p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`font-mono text-[14.5px] font-medium break-all`,children:t.tool}),t.withheld?(0,X.jsx)(e,{tone:`bad`,icon:`lock`,children:`Held back until reviewed`}):(0,X.jsx)(e,{tone:`warn`,icon:`refresh`,children:`Changed`})]}),(0,X.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Noticed `,x(t.detectedAt),` · last accepted `,x(t.pinnedAt),` by `,t.pinnedBy]})]}),(0,X.jsx)(E,{size:`sm`,variant:`primary`,icon:`check`,onClick:i,disabled:!n||r,children:`Accept change`})]}),(0,X.jsx)(`ul`,{className:`mt-3 space-y-1`,children:Ne(t).map(e=>(0,X.jsxs)(`li`,{className:`flex gap-2 text-[13.5px]`,children:[(0,X.jsx)(`span`,{className:`mt-[8px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),e]},e))}),a&&(0,X.jsxs)(`details`,{className:`mt-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`See what changed`}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-4`,children:[a.effect!==t.now.effect&&(0,X.jsxs)(`p`,{className:`text-[13.5px]`,children:[`What it does: `,(0,X.jsx)(`strong`,{children:A[a.effect??`unknown`].label}),` →`,` `,(0,X.jsx)(`strong`,{children:A[t.now.effect??`unknown`].label})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Description`}),(0,X.jsx)(ie,{before:je(a.description),after:je(t.now.description),label:`Description of ${t.tool}, before and after`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Inputs`}),(0,X.jsx)(ie,{before:JSON.stringify(a.inputSchema??{},null,2),after:JSON.stringify(t.now.inputSchema??{},null,2),label:`Inputs of ${t.tool}, before and after`})]}),JSON.stringify(a.annotations)!==JSON.stringify(t.now.annotations)&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Hints from its server`}),(0,X.jsx)(ie,{before:JSON.stringify(a.annotations??{},null,2),after:JSON.stringify(t.now.annotations??{},null,2),label:`Hints for ${t.tool}, before and after`})]})]})]})]})}function Ie(e){return e?e.surface.neverPublished?`This toolbox hasn't reported its tools yet. Start it once, then you can turn tools off here.`:e.surface.live?null:`The toolbox isn't running, so this list can't be confirmed as current. Start the toolbox to turn tools on or off.`:null}function Le(e){let t=P(),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(null),o=Ie(e.protection);async function s(n,i,a){r(n.name);try{let r=await _.setExposure(e.serverId,n.name,i,a,e.tenant);return t.show(`ok`,i?`${n.name} is turned off. Your AI can't see it or use it.`:`${n.name} is back on. The normal rules decide what it may do.`),r.warning&&t.show(`warn`,Y(r.warning)),e.onChanged(),!0}catch(e){return t.show(`bad`,`${n.name} was not changed. ${Y(e)}`),!1}finally{r(null)}}function c(e,t,n=``){let r=U(e);!t&&(r===`write`||r===`destructive`)?a({tool:e,reason:n}):s(e,t,n)}let l=i,u=l?l.tool.verdict.kind===`allow`?`run freely, without asking anyone`:l.tool.verdict.kind===`approve`?`ask you first every time`:`still be blocked`:``;return{blocked:o,busy:e=>n===e,set:c,dialog:(0,X.jsx)(N,{open:l!==null,onClose:()=>a(null),title:l?`Turn ${l.tool.name} back on?`:``,description:`Turning a tool on doesn't allow it. It goes back to following your normal rules.`,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(E,{variant:`secondary`,onClick:()=>a(null),children:`Keep it off`}),(0,X.jsx)(E,{variant:`primary`,icon:`power`,loading:n===l?.tool.name,onClick:async()=>{l&&await s(l.tool,!1,l.reason)&&a(null)},children:`Turn tool on`})]}),children:l&&(0,X.jsxs)(`div`,{className:`space-y-3 text-[14px] text-muted`,children:[(0,X.jsxs)(`p`,{children:[`This tool `,U(l.tool)===`destructive`?`deletes things`:`makes changes`,`. Under your rules today it would `,(0,X.jsx)(`strong`,{className:`text-ink`,children:u}),` (`,ce(l.tool.verdict.kind),`).`]}),(0,X.jsx)(`p`,{children:`The change is written to the activity log and takes effect on the next call.`})]})})}}var Re=[{value:`deny`,label:`Block them`,hint:`A tool nobody has labelled can't run at all until someone says what it does.`,icon:`x`},{value:`approve`,label:`Ask me first`,hint:`Each call to an unlabelled tool waits for you to approve it, so a new tool is a question rather than a wall.`,icon:`clock`}];function ze({open:e,serverId:t,tenant:n,protection:r,onClose:i,onSaved:a,onReload:o}){let s=P(),l=r.onUnclassified===`approve`?`approve`:`deny`,[u,d]=(0,B.useState)(l),[f,p]=(0,B.useState)(!1),[m,h]=(0,B.useState)(null),v=r.policyWrite,y=r.surface.unclassifiedCount;async function b(){p(!0),h(null);try{let e=await _.setUnclassifiedPosture(t,u,v.digest,n);s.show(`ok`,u===`approve`?`Unlabelled tools now ask you first. The toolbox applies this within about a second.`:`Unlabelled tools are now blocked. The toolbox applies this within about a second.`),e.warning&&s.show(`warn`,J(e.warning)),a(),i()}catch(e){h({text:ke(e)?Ae:Y(e),stale:ke(e)})}finally{p(!1)}}return(0,X.jsx)(N,{open:e,onClose:i,title:`What happens to unlabelled tools`,description:(0,X.jsxs)(X.Fragment,{children:[`A tool is unlabelled when nobody has said whether it looks, makes changes or deletes.`,` `,y>0?`${y===1?`One tool on this toolbox is`:`${y} tools on this toolbox are`} unlabelled right now.`:`Every tool on this toolbox is labelled right now, so this only affects tools that appear later.`]}),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[m?.stale&&(0,X.jsx)(E,{variant:`ghost`,icon:`refresh`,className:`mr-auto`,onClick:()=>{h(null),o()},children:`Reload`}),(0,X.jsx)(E,{variant:`secondary`,onClick:i,disabled:f,children:`Cancel`}),(0,X.jsx)(E,{variant:`primary`,onClick:()=>void b(),disabled:!v.ok||u===l,loading:f,children:`Save setting`})]}),children:(0,X.jsxs)(`div`,{className:`space-y-4 text-[14px]`,children:[(0,X.jsx)(`div`,{role:`radiogroup`,"aria-label":`What happens to unlabelled tools`,className:`space-y-2`,children:Re.map(e=>{let t=u===e.value;return(0,X.jsxs)(`label`,{className:F(`flex cursor-pointer gap-3 rounded-[18px] border-[1.5px] p-4 transition-colors has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--focus)]`,t?`border-primary bg-ok-tint`:`border-line hover:border-[var(--soft)]`),children:[(0,X.jsx)(`input`,{type:`radio`,name:`unlabelled`,checked:t,onChange:()=>d(e.value),className:`sr-only`}),(0,X.jsx)(g,{name:e.icon,size:20,strokeWidth:2,className:F(`mt-0.5 shrink-0`,t?`text-ok`:`text-soft`)}),(0,X.jsxs)(`span`,{className:`min-w-0`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold`,children:[e.label,e.value===l&&(0,X.jsx)(`span`,{className:`text-[12px] font-medium text-soft`,children:`current setting`})]}),(0,X.jsx)(`span`,{className:`mt-0.5 block text-[13px] text-soft`,children:e.hint})]})]},e.value)})}),(0,X.jsxs)(`p`,{className:`text-[13px] text-soft`,children:[`Either way, nothing unlabelled runs without you. Labelling a tool, from its panel, is how it starts following your normal rules. `,(0,X.jsx)(`code`,{className:`font-mono text-[11.5px]`,children:`defaults.on_unclassified`})]}),!v.ok&&(0,X.jsx)(c,{tone:`warn`,title:`This toolbox's settings can't be changed from here`,children:J(v.why??`The settings file is not writable.`)}),m&&(0,X.jsx)(`p`,{role:`alert`,className:`text-[13.5px] font-medium text-bad`,children:m.text})]})})}var Be=[`max`,`min`,`enum`,`maxLength`,`maxItems`,`within`,`host`];function Ve(e){let t={};for(let[n,r]of Object.entries(e??{})){let e={},i={};for(let[t,n]of Object.entries(r))Be.includes(t)?e[t]=t===`enum`?n.map(String):n:t!==`optional`&&(i[t]=n);let a=Object.keys(e).length===0&&Object.keys(i).length===0;t[n]={values:e,optional:r.optional===!0,carried:i,...a?{any:a}:{}}}return t}function He(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function Ue(e){return Object.values(e).some(e=>Object.values(e.values).some(He))}function We(e,t){return e.map(e=>(t===`number`||t===`integer`)&&e.trim()!==``&&!Number.isNaN(Number(e))?Number(e):t===`boolean`&&(e===`true`||e===`false`)?e===`true`:e)}function Ge(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=t.args.find(e=>e.name===r)?.type,a={...i.carried};for(let[t,n]of Object.entries(i.values))He(n)||(a[t]=t===`enum`?We(n,e):t===`within`?n.trim():n);(Object.keys(a).length!==0||i.any)&&(i.optional&&(a.optional=!0),n[r]=a)}return n}function Ke(e,t,n,r=!1){return t?e??n:r?`allow`:e??`allow`}function qe(e,t){return e.required?`required: every call sends it, so every call would ${t===`approve`?`ask you first`:`be blocked`}`:e.only?`only ${we(e.only)} ${e.only.length===1?`has a limit`:`have limits`}, so anything else inside it, or an empty ${e.list?`list`:`one`}, is caught too`:`a call that sends it ${t===`approve`?`asks you first`:`is blocked`}`}function Je({tool:e,draft:t,setDraft:n,onViolation:r,setOnViolation:i,unknownArgs:o,setUnknownArgs:s,approvalsOff:c=!1,hadLimits:l=!1}){let[u,d]=(0,B.useState)(``),p=[...new Set([...e.args.map(e=>e.name),...Object.keys(t)])],m=Object.keys(Ge(t,e)),g=m.length>0,_=Ke(o,g,r,l),v=_===`allow`?[]:Ee(e,m),y=e=>n({...t,[e]:{values:{},optional:!1,carried:{},any:!0}}),b=e=>{let r={...t};delete r[e],n(r)},x=(e,r)=>{let i=t[e]??{values:{},optional:!1,carried:{}};n({...t,[e]:r(i)})},S=(e,t,n)=>x(e,e=>{let r={...e.values};return n===void 0?delete r[t]:r[t]=n,{...e,values:r}});return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[p.length===0&&(0,X.jsx)(`p`,{className:`rounded-2xl bg-sunken p-4 text-[13.5px] text-soft`,children:`This tool takes no inputs, so there is nothing to limit.`}),(0,X.jsx)(`ul`,{className:`space-y-3`,children:p.map(n=>{let r=e.args.find(e=>e.name===n),i=t[n],a=Object.keys(i?.values??{}),o=be(r?.type).filter(e=>!a.includes(e));return(0,X.jsxs)(`li`,{className:`rounded-2xl border border-line p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`code`,{className:`font-mono text-[13.5px] font-medium break-all`,children:n}),(0,X.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[r?.type??`any type`,` · `,r?r.required?`required`:`optional`:`nested input`]})]}),r?.description&&(0,X.jsx)(`p`,{className:`mt-0.5 line-clamp-2 text-[12.5px] text-soft`,children:r.description}),a.length>0&&(0,X.jsx)(`div`,{className:`mt-3 space-y-2.5`,children:a.map(e=>(0,X.jsx)(Ye,{path:n,limit:e,value:i.values[e]??null,onChange:t=>S(n,e,t),onRemove:()=>S(n,e,void 0)},e))}),i?.any&&a.length===0&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 text-[13px] text-soft`,children:[`Any value is let through.`,(0,X.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>b(n),children:`Undo`})]}),Object.keys(i?.carried??{}).length>0&&(0,X.jsxs)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:[`Also kept as written in the settings file:`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:Object.keys(i.carried).join(`, `)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[o.length>0&&(0,X.jsx)(se,{"aria-label":`Add a limit to ${n}`,value:``,className:`w-56`,onChange:e=>{e&&S(n,e,e===`enum`||e===`host`?[]:e===`within`?``:null)},options:[{value:``,label:`Add a limit…`},...o.map(e=>({value:e,label:q[e]}))]}),a.length>0&&r&&!r.required&&(0,X.jsx)(M,{checked:i?.optional===!0,onChange:e=>x(n,t=>({...t,optional:e})),label:`It's fine to leave this input out`})]})]},n)})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,X.jsx)(a,{label:`Limit a nested input`,className:`min-w-0 flex-1 basis-56`,children:(0,X.jsx)(f,{value:u,onChange:d,mono:!0,placeholder:`items[].qty`,onEnter:()=>C()})}),(0,X.jsx)(E,{icon:`plus`,disabled:u.trim()===``||p.includes(u.trim()),onClick:C,children:`Add input`})]}),(0,X.jsx)(`p`,{className:`mt-1.5 text-[12.5px] text-soft`,children:`For a value inside a list or object, such as items[].qty.`})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)(a,{label:`If a call breaks a limit`,technical:`on_violation`,children:(0,X.jsx)(h,{label:`If a call breaks a limit`,value:r,onChange:i,options:[{value:`deny`,label:`Block it`},{value:`approve`,label:`Ask me`}]})}),(g||_!==`allow`)&&(0,X.jsx)(a,{label:`Anything else the tool is sent`,technical:`unknown_args`,help:`Inputs your limits don't mention. Letting them through means an extra input like force: true isn't checked.`,children:(0,X.jsx)(h,{label:`Anything else the tool is sent`,value:_,onChange:s,options:[{value:`deny`,label:`Block it`},{value:`approve`,label:`Ask me first`},{value:`allow`,label:`Let it through`}]})})]}),_===`approve`&&c&&(0,X.jsx)(`p`,{className:`text-[13px] font-medium text-warn`,children:`Approvals are switched off on this toolbox, so “Ask me first” means refused for now.`}),v.length>0&&(_===`deny`||_===`approve`)&&(0,X.jsxs)(`div`,{className:`rounded-2xl bg-sunken p-4`,children:[(0,X.jsx)(`p`,{className:`text-[13px] font-semibold`,children:`What this catches`}),!g&&(0,X.jsx)(`p`,{className:`mt-1 text-[13px] text-muted`,children:`There are no limits, so every call that sends any input is caught.`}),(0,X.jsx)(`ul`,{className:`mt-2 space-y-2`,children:v.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-2 text-[13px]`,children:[(0,X.jsxs)(`span`,{className:e.required?`font-medium text-warn`:`text-muted`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:e.name}),` — `,qe(e,_)]}),(0,X.jsx)(E,{size:`sm`,onClick:()=>y(e.name),children:`Allow any value`})]},e.name))})]})]});function C(){let e=u.trim();e&&!p.includes(e)&&(n({...t,[e]:{values:{max:null},optional:!1,carried:{}}}),d(``))}}function Ye({path:e,limit:n,value:r,onChange:a,onRemove:o}){let s=`${q[n]} (${e})`,c;return c=n===`enum`||n===`host`?(0,X.jsx)(t,{"aria-label":s,value:r??[],onChange:a,placeholder:n===`host`?`example.com, or .example.com for every address under it`:`Type a value and press Enter`,validate:n===`host`?e=>/[\s/:]/.test(e)?`Type just the website name, such as example.com`:null:void 0}):n===`within`?(0,X.jsx)(f,{"aria-label":s,value:r??``,onChange:a,mono:!0,placeholder:`/Users/you/project`}):(0,X.jsx)(i,{"aria-label":s,value:r??null,onChange:a,min:n===`maxLength`?1:n===`maxItems`?0:void 0,step:n===`maxLength`||n===`maxItems`?1:void 0,unit:n===`maxLength`?`chars`:n===`maxItems`?`items`:void 0}),(0,X.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-start gap-x-2 gap-y-1 sm:grid-cols-[176px_1fr_auto] sm:items-center`,children:[(0,X.jsx)(`span`,{className:`col-span-2 text-[13px] font-semibold sm:col-span-1`,children:q[n]}),(0,X.jsx)(`div`,{className:`min-w-0`,children:c}),(0,X.jsx)(oe,{icon:`x`,label:`Remove ${q[n].toLowerCase()} from ${e}`,size:34,onClick:o})]})}var Xe=[{value:`read`,label:`Looks only`,hint:`Reads or looks things up. Changes nothing.`,icon:`eye`},{value:`write`,label:`Makes changes`,hint:`Creates, edits, sends or adds something.`,icon:`edit`},{value:`destructive`,label:`Deletes`,hint:`Removes something, or does what can't be undone.`,icon:`trash`}],Ze=[{value:`allow`,label:`Run freely`,hint:`Nobody is asked.`,icon:`check`},{value:`approve`,label:`Ask me first`,hint:`Every call waits for you to approve it.`,icon:`clock`},{value:`deny`,label:`Block it`,hint:`Every call is refused.`,icon:`x`}];function Qe({open:e,serverId:t,tenant:n,tool:r,protection:i,onClose:o,onSaved:s}){let l=P(),[u,d]=(0,B.useState)(U(r)),[p,m]=(0,B.useState)(U(r)===null?null:r.verdict.kind),[h,g]=(0,B.useState)(``),[v,y]=(0,B.useState)(!1),[b,x]=(0,B.useState)(()=>Ve(r.bounds?.constraints)),[S,C]=(0,B.useState)(r.bounds?.onViolation??`deny`),[ee,ne]=(0,B.useState)(r.bounds?.unknownArgs??null),[T,ie]=(0,B.useState)(!1),[ae,oe]=(0,B.useState)(!1),[se,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)(null),[le,A]=(0,B.useState)(null),[ue,j]=(0,B.useState)(0),[M,de]=(0,B.useState)(!1),[F,fe]=(0,B.useState)(null),[I,L]=(0,B.useState)(null),pe=Object.values((O?.preview.bounds??r.bounds)?.constraints??{}).some(e=>xe(e)),R=(0,B.useMemo)(()=>{if(!u||!p)return null;let e={tool:r.name,effect:u,decision:p};return h.trim()&&(e.reason=h.trim()),v&&Object.assign(e,tt(r,b,S,ee)),e},[r,u,p,h,v,b,S,ee]),z=te(R?JSON.stringify(R):``,350);(0,B.useEffect)(()=>{if(!e||!z){k(null);return}let r=!0;return A(null),_.toolRulePreview(t,JSON.parse(z),n).then(e=>{r&&(k({key:z,preview:e}),v||(x(Ve(e.bounds?.constraints)),C(e.bounds?.onViolation??`deny`),ne(e.bounds?.unknownArgs??null)))}).catch(e=>r&&A(Y(e))),()=>{r=!1}},[e,z,t,n,ue]);let me=R?JSON.stringify(R):``,V=O&&O.key===me?O.preview:null,he=V!==null,ge=O?.preview??null,H=ge?ge.bounds:r.bounds,W=V?.overriddenReason!=null,_e=W&&V?.overridesAllowed===!1,G=V?.dropsBounds!=null,K=u===`destructive`&&p===`allow`,ve=v&&Ue(b),ye=V?.writable.ok===!1,q=V!==null&&he&&!le&&!M&&!ye&&!_e&&!ve&&(!W||T)&&(!G||ae)&&(!K||se);async function be(){if(V&&R){de(!0),fe(null);try{let e=await _.setToolRule(t,{...R,expectedDigest:V.expectedDigest,acknowledged:{...W?{overrideDeny:V.overriddenReason.ruleId}:{},...G?{dropBounds:!0}:{},...K?{destructiveAllow:!0}:{}}},n);L({yaml:e.yaml,reloads:V.reloads}),l.show(`ok`,`Saved what ${r.name} may do.`),e.warning&&l.show(`warn`,J(e.warning)),s()}catch(e){ke(e)?(fe({text:Ae,stale:!0}),k(null),j(e=>e+1)):fe({text:Y(e),stale:!1})}finally{de(!1)}}}if(I)return(0,X.jsx)(N,{open:e,onClose:o,title:`Saved`,width:600,footer:(0,X.jsx)(E,{variant:`primary`,onClick:o,children:`Close`}),children:(0,X.jsxs)(`div`,{className:`space-y-4 text-[14px]`,children:[(0,X.jsxs)(`p`,{className:`text-muted`,children:[`The rule for `,(0,X.jsx)(`code`,{className:`font-mono text-ink`,children:r.name}),` is in your protection settings.`,` `,I.reloads?`The running gateway applies it within about a second. No restart is needed.`:`This toolbox only reads its settings when it starts, so restart it to apply this.`]}),(0,X.jsxs)(`details`,{className:`group`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show what was written`}),(0,X.jsx)(`div`,{className:`mt-2`,children:(0,X.jsx)(re,{label:`The rule that was written`,children:I.yaml})})]})]})});let Se=V?.approvalsReachable===!1;return(0,X.jsx)(N,{open:e,onClose:o,title:(0,X.jsxs)(X.Fragment,{children:[`Change what `,(0,X.jsx)(`span`,{className:`font-mono text-[0.9em]`,children:r.name}),` may do`]}),description:`Your answer is saved as a rule in your protection settings.`,width:720,footer:(0,X.jsxs)(X.Fragment,{children:[F?.stale&&(0,X.jsx)(E,{variant:`ghost`,icon:`refresh`,onClick:()=>j(e=>e+1),className:`mr-auto`,children:`Reload preview`}),(0,X.jsx)(E,{variant:`secondary`,onClick:o,disabled:M,children:`Cancel`}),(0,X.jsx)(E,{variant:`primary`,onClick:()=>void be(),disabled:!q,loading:M,children:`Save rule`})]}),children:(0,X.jsxs)(`div`,{className:`space-y-6 pb-1 text-[14px]`,children:[i?.tenant&&(0,X.jsx)(c,{tone:`info`,title:`This applies to every customer`,children:`A rule changes the protection settings, which every customer of this toolbox shares. Turning a tool off is the only change kept for one customer.`}),r.injection&&r.injection.length>0&&(0,X.jsx)(c,{tone:`danger`,title:`Judge this tool by its name and inputs`,children:`Its description carried hidden instructions written to steer whoever reads it, so it isn't repeated here.`}),(0,X.jsx)(nt,{legend:`What does this tool do?`,name:`rule-effect`,value:u,onChange:d,options:Xe}),(0,X.jsx)(nt,{legend:`What should happen when your AI uses it?`,name:`rule-decision`,value:p,onChange:m,options:Ze.map(e=>e.value===`approve`&&Se?{...e,disabled:!0,hint:`Approvals are switched off on this toolbox, so nobody could answer.`}:e)}),(0,X.jsxs)(`section`,{className:`rounded-[20px] bg-sunken/60 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`h3`,{className:`flex items-center gap-2 text-[15px] font-semibold`,children:[`Limits on its inputs `,(0,X.jsx)(w,{term:`limits`})]}),(0,X.jsx)(`p`,{className:`mt-1 text-[13px] text-soft`,children:pe?`These limits include one written into the settings file by hand that can't be edited here. They are kept exactly as they are.`:v?`Set the values this tool may be called with.`:H?$e(H,ge?.carriedFrom??null):`None. Every input is passed on as your AI sends it.`})]}),!v&&!pe&&(0,X.jsx)(E,{size:`sm`,icon:H?`edit`:`plus`,onClick:()=>y(!0),children:H?`Edit limits`:`Add limits on its inputs`})]}),v&&(0,X.jsxs)(`div`,{className:`mt-4`,children:[(0,X.jsx)(Je,{tool:r,draft:b,setDraft:x,onViolation:S,setOnViolation:C,unknownArgs:ee,setUnknownArgs:ne,approvalsOff:Se,hadLimits:et(r)}),ve&&(0,X.jsx)(`p`,{className:`mt-3 text-[13px] font-medium text-warn`,children:`Fill in every limit you added, or remove it.`})]})]}),(0,X.jsx)(a,{label:`Reason`,optional:!0,help:`Saved with the rule and in the activity log. When a call is blocked, your AI is told this reason.`,children:(0,X.jsx)(f,{value:h,onChange:g,placeholder:`For example: finance signs these off by hand`})}),(0,X.jsx)(rt,{tool:r,preview:V,loading:R!==null&&V===null&&!le,error:le,incomplete:R===null}),V&&he&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[ye&&(0,X.jsx)(c,{tone:`warn`,title:`This toolbox's settings can't be changed from here`,children:J(V.writable.why??`The settings file is not writable.`)}),_e?(0,X.jsxs)(c,{tone:`info`,title:`This toolbox doesn't allow reversing a rule from here`,children:[`The rule `,(0,X.jsx)(`code`,{className:`font-mono`,children:V.overriddenReason.ruleId}),` stays as it is. It can only be changed in the settings file itself.`]}):W&&(0,X.jsxs)(ot,{title:`This reverses a rule somebody wrote`,checked:T,onChange:ie,label:`Reverse the rule ${V.overriddenReason.ruleId} anyway`,children:[`The rule `,(0,X.jsx)(`code`,{className:`font-mono`,children:V.overriddenReason.ruleId}),` says`,` `,(0,X.jsx)(`strong`,{children:ce(V.overriddenReason.decision).toLowerCase()}),` for this tool`,V.overriddenReason.reason?(0,X.jsxs)(X.Fragment,{children:[`, because: “`,V.overriddenReason.reason,`”`]}):`.`]}),G&&(0,X.jsxs)(ot,{title:`This removes the limits on its inputs`,checked:ae,onChange:oe,label:`Remove the limits on its inputs`,children:[`Today: `,Ce(V.currentBounds).join(`; `)||`limited`,`. After this, nothing checks what the tool is called with.`]}),K&&(0,X.jsx)(ot,{title:`Your AI could delete things without asking`,checked:se,onChange:D,label:`Let a tool that deletes things run with nobody asked`,children:`“Ask me first” keeps it just as usable, with you approving each call.`})]}),F&&(0,X.jsx)(c,{tone:`danger`,role:`alert`,title:F.stale?`Not saved`:`The toolbox refused this change`,children:F.text})]})})}function $e(e,t){let n=Ce(e);return n.length===0?`No limits on its inputs. ${Oe[e.unknownArgs]}`:t?`Carried over from the rule ${t}, which governs it today: ${n.join(`; `)}.`:`Kept as they are: ${n.join(`; `)}.`}function et(e){return(e.bounds?.paths.length??0)>0}function tt(e,t,n,r){let i=Ge(t,e);return{args:i,on_violation:n,unknown_args:Ke(r,Object.keys(i).length>0,n,et(e))}}function nt({legend:e,name:t,value:n,onChange:r,options:i}){return(0,X.jsxs)(`fieldset`,{children:[(0,X.jsx)(`legend`,{className:`mb-2.5 text-[15px] font-semibold`,children:e}),(0,X.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:i.map(e=>{let i=n===e.value;return(0,X.jsxs)(`label`,{className:F(`relative flex cursor-pointer flex-col gap-1 rounded-[18px] border-[1.5px] p-3.5 transition-colors has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--focus)]`,i?`border-primary bg-ok-tint`:`border-line hover:border-[var(--soft)]`,e.disabled&&`cursor-not-allowed opacity-55`),children:[(0,X.jsx)(`input`,{type:`radio`,name:t,value:e.value,checked:i,disabled:e.disabled,onChange:()=>r(e.value),className:`sr-only`}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold`,children:[(0,X.jsx)(g,{name:e.icon,size:17,strokeWidth:2,className:i?`text-ok`:`text-soft`}),e.label,i&&(0,X.jsx)(g,{name:`check`,size:16,strokeWidth:2.4,className:`ml-auto text-ok`})]}),(0,X.jsx)(`span`,{className:`text-[12.5px] leading-snug text-soft`,children:e.hint})]},e.value)})})]})}function rt({tool:e,preview:t,loading:n,error:r,incomplete:i}){return(0,X.jsxs)(`section`,{"aria-live":`polite`,className:`rounded-[20px] border-[1.5px] border-line p-4`,children:[(0,X.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:`What changes`}),i?(0,X.jsx)(`p`,{className:`mt-2 text-[13.5px] text-soft`,children:`Answer both questions above to see what changes.`}):r?(0,X.jsx)(`p`,{role:`alert`,className:`mt-2 text-[13.5px] font-medium text-bad`,children:r}):n||!t?(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(s,{lines:3})}):(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,X.jsx)(`span`,{className:`text-[13px] text-soft`,children:`Now`}),(0,X.jsx)(T,{decision:t.current.kind}),(0,X.jsx)(g,{name:`arrow-right`,size:18,className:`text-soft`,label:`becomes`}),(0,X.jsx)(`span`,{className:`text-[13px] text-soft`,children:`After`}),(0,X.jsx)(T,{decision:t.verdict.kind})]}),(0,X.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:it(e,t)}),(0,X.jsx)(at,{preview:t}),(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the rule that will be written`}),(0,X.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,X.jsx)(re,{label:`The rule that will be written`,children:t.yaml}),t.policyPath&&(0,X.jsx)(`p`,{className:`font-mono text-[11.5px] break-all text-soft`,children:t.policyPath})]})]})]})]})}function it(e,t){let n=e.name,r=t.verdict.kind===`deny`?[]:De(e,t.bounds);if(t.bounds&&r.length>0){let e=r.length===1;return`After saving, every call to ${n} ${t.bounds.unknownArgs===`approve`?`will ask you first`:`will be blocked`}, because ${we(r)} ${e?`is`:`are`} required and your limits don't mention ${e?`it`:`them`}.`}let i=`After saving, every call to ${n} ${t.verdict.kind===`allow`?`runs freely`:t.verdict.kind===`approve`?`asks you first`:`is blocked`}`;if(t.bounds&&t.verdict.kind!==`deny`){let e=Ce(t.bounds);i+=e.length>0?` while its inputs stay within limits (${e.join(`; `)}). A call outside them ${G(t.bounds.onViolation)}.`:`.`,i+=` ${Oe[t.bounds.unknownArgs]}`}else i+=`.`;return t.verdict.kind!==`deny`&&t.currentBounds&&t.currentBounds.unknownArgs!==`allow`&&(t.bounds?.unknownArgs??`allow`)===`allow`&&(i+=` Anything else the tool is sent will now be let through.`),i}function at({preview:e}){let t=[];return e.loosens&&t.push({key:`loosens`,tone:`warn`,text:`This lets your AI do more with this tool than it can today. The safety check will point this out if a tool that changes or deletes things runs without asking.`}),e.overridden&&t.push({key:`overridden`,tone:`warn`,text:J(e.overridden)}),e.nameContradiction&&t.push({key:`name`,tone:`warn`,text:J(e.nameContradiction)}),e.strandedRule&&t.push({key:`stranded`,tone:`info`,text:(0,X.jsxs)(X.Fragment,{children:[`The rule `,(0,X.jsx)(`code`,{className:`font-mono`,children:e.strandedRule}),` no longer applies to any tool after this. It stays in your settings, and undoing this change brings it back.`]})}),e.reloads||t.push({key:`reload`,tone:`info`,text:`This toolbox only reads its settings when it starts, so this applies after a restart.`}),t.length===0?null:(0,X.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,X.jsxs)(`li`,{className:F(`flex gap-2.5 rounded-2xl px-3.5 py-2.5 text-[13px]`,e.tone===`warn`?`bg-warn-tint`:`bg-info-tint`),children:[(0,X.jsx)(g,{name:e.tone===`warn`?`warning`:`info`,size:16,strokeWidth:2,className:F(`mt-0.5 shrink-0`,e.tone===`warn`?`text-warn`:`text-soft`)}),(0,X.jsx)(`span`,{className:`text-ink`,children:e.text})]},e.key))})}function ot({title:e,children:t,checked:n,onChange:r,label:i}){return(0,X.jsxs)(`div`,{className:`rounded-[18px] border-[1.5px] border-bad/45 bg-bad-tint/50 p-4`,children:[(0,X.jsxs)(`p`,{className:`flex items-center gap-2 font-semibold text-bad`,children:[(0,X.jsx)(g,{name:`warning`,size:17,strokeWidth:2}),e]}),(0,X.jsx)(`div`,{className:`mt-1 text-[13.5px] text-muted`,children:t}),(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(M,{checked:n,onChange:r,label:i})})]})}var st=[`read`,`write`,`destructive`,`unsure`,`off`],ct={read:`Looks at things`,write:`Makes changes`,destructive:`Deletes or overwrites`,unsure:`We're not sure what it does`,off:`Turned off`};function Z(e){let t=H(e);return t===`off`?`off`:t===`unlabelled`?`unsure`:U(e)??`unsure`}function lt(e){return st.map(t=>({key:t,tools:e.filter(e=>Z(e)===t)})).filter(e=>e.tools.length>0)}function ut(e){return`${e} ${e===1?`tool`:`tools`}`}function dt(e,t){if(e.exposure.disabled)return`off`;if(t.withheld?.has(e.name))return`held`;if(e.hiddenByPolicy)return`hidden`;let n=e.verdict.kind,r=W(e);return t.observe?n===`allow`?`allow`:n===`deny`?`would-deny`:e.unreachable&&!r?`would-never`:`would-approve`:n===`deny`?`deny`:n===`approve`?r?t.approvalsOff?`granted-only`:`granted`:e.unreachable||t.approvalsOff?`never`:`approve`:e.bounds?`limited`:`allow`}var ft={off:`Turned off`,held:`Held back: it changed since you approved it`,hidden:`Hidden: had hidden instructions`,never:`Can never run`,deny:`Blocked`,approve:`Asks you first`,granted:`Pre-approved within limits`,"granted-only":`Pre-approved calls only; others can never run`,limited:`Runs within limits`,allow:`Runs freely`,"would-deny":`Would be blocked`,"would-approve":`Would ask you first`,"would-never":`Would never run`},pt=new Set([`off`,`held`,`hidden`,`never`,`deny`]);function mt(e,t){return pt.has(dt(e,t))}function ht(e,t){return ft[dt(e,t)]}function gt(e,t){let n=dt(e,t);return n===`allow`||n===`limited`?`ok`:n===`approve`||n===`granted`||n===`granted-only`?`warn`:n===`off`||n.startsWith(`would-`)?`soft`:`bad`}var _t=[`allow`,`limited`,`granted`,`granted-only`,`approve`,`would-approve`,`would-never`,`would-deny`,`never`,`deny`,`held`,`hidden`,`off`],vt={allow:[`runs freely`,`run freely`],limited:[`runs within limits`,`run within limits`],granted:[`pre-approved`,`pre-approved`],"granted-only":[`runs only pre-approved calls`,`run only pre-approved calls`],approve:[`asks you first`,`ask you first`],"would-approve":[`would ask you first`,`would ask you first`],"would-never":[`would never run`,`would never run`],"would-deny":[`would be blocked`,`would be blocked`],never:[`can never run`,`can never run`],deny:[`blocked`,`blocked`],held:[`held back`,`held back`],hidden:[`hidden`,`hidden`],off:[`turned off`,`turned off`]},yt=(e,t)=>e.map(e=>dt(e,t));function bt(e){let t=new Set(e);return t.size===1?[...t][0]:null}function xt(e,t){let n=new Map;for(let r of yt(e,t))n.set(r,(n.get(r)??0)+1);return _t.filter(e=>n.has(e)).map(e=>{let t=n.get(e);return`${t} ${vt[e][t===1?0:1]}`}).join(`, `)}var St=e=>e.every(e=>e===`allow`||e.startsWith(`would-`));function Ct(e,t){let n=t?`it`:`they`;switch(e){case`allow`:return`, so ${n} ${t?`runs`:`run`} freely`;case`approve`:return`, so ${n} ${t?`asks`:`ask`} you first`;case`deny`:return t?`, so it's blocked`:`, so they're blocked`;case`never`:return`, so ${n} can never run`;case`would-approve`:return`. ${t?`It runs`:`They run`} for now, and would ask you first`;case`would-deny`:return`. ${t?`It runs`:`They run`} for now, and would be blocked`;default:return null}}function wt(e,t,n){let r=t.length===1;if(e===`off`)return r?`Your AI can't see it or use it`:`Your AI can't see or use these`;let i=yt(t,n),a=bt(i);if(e===`unsure`){let e=r?`We're not sure what this does`:`We're not sure what these do`,i=a?Ct(a,r):null;return i?`${e}${i}`:a?`${e}. ${ft[a]}`:`${e}. Mixed: ${xt(t,n)}`}let o=n.observe&&St(i)&&i.some(e=>e.startsWith(`would-`));return a?o?`Runs for now; ${ft[a].toLowerCase()}`:ft[a]:`${o?`Runs for now. `:``}Mixed: ${xt(t,n)}`}var Tt=[`inj`,`unreach`,`changed`,`bounds`,`unbounded`,`grant`],Et={inj:e=>`${e} with hidden instructions`,unreach:e=>`${e} can never run`,changed:e=>`${e} changed`,bounds:e=>`${e} ${e===1?`has`:`have`} limits`,unbounded:e=>`${e} ${e===1?`input`:`inputs`} unlimited`,grant:e=>`${e} pre-approved`};function Dt(e,t){let n=new Map;for(let r of e)for(let e of K(r,t.has(r.name))){let t=e.key===`unbounded`?r.unboundedInputs.length:1;n.set(e.key,{n:(n.get(e.key)?.n??0)+t,tone:e.tone})}return Tt.filter(e=>n.has(e)).map(e=>({key:e,text:Et[e](n.get(e).n),tone:n.get(e).tone}))}function Q(e,t,n,r=0){let i=[];return e&&i.push(e===1?`the one tool that's turned off`:`the ${e} tools that are turned off`),r&&i.push(r===1?`the one tool held back because it changed`:`the ${r} tools held back because they changed`),t&&i.push(t===1?`the one tool hidden for carrying hidden instructions`:`the ${t} tools hidden for carrying hidden instructions`),n&&i.push(n===1?`the one tool we're not sure about`:`the ${n} tools we're not sure about`),i.length?`Apart from ${i.join(` and `)}, `:``}function Ot(e,t){let n=e.length,r=e.filter(e=>e.verdict.ruleId.startsWith(`tenant.`)).length,i=e.filter(e=>e.verdict.ruleId===`defaults.mode`).length;return r===n?`, because the toolbox needs to know which customer each call is for`:r>0?`, because of the customer check and your other settings`:i===n?t?`, because your default stance is “${j[t].label}”`:`, because of your default stance`:i===0?` by rules in your protection settings`:`, because of your default stance and your rules`}function kt(e){let t=bt(e.map(e=>e.bounds?.onViolation??null));return t?`a call outside them ${G(t)}`:`what happens outside them depends on the tool`}function At(e,t,n){let r=t.filter(e=>Z(e)===`off`),i=t.filter(e=>Z(e)!==`off`),a=i.filter(e=>n.withheld?.has(e.name)),o=i.filter(e=>!n.withheld?.has(e.name)),s=o.filter(e=>e.hiddenByPolicy),c=o.filter(e=>!e.hiddenByPolicy&&Z(e)===`unsure`),l=o.filter(e=>!e.hiddenByPolicy&&Z(e)!==`unsure`),u=e=>dt(e,n),d=(e,t)=>e?t:t[0].toUpperCase()+t.slice(1);if(l.length===0&&c.length===0)return s.length===0&&a.length===0?`Every tool from ${e} is turned off.`:r.length===0&&a.length===0?`Every tool from ${e} is hidden, because their descriptions carried hidden instructions.`:`Nothing from ${e} can run: its tools are turned off, hidden or held back.`;if(n.observe){let t=Q(r.length,s.length,0,a.length);return`${t}${d(t,`everything`)} from ${e} runs for now, because your toolbox is only watching.`}if(l.length===0){let t=Q(r.length,s.length,0,a.length),n=bt(c.map(u)),i=n===`allow`||n===`approve`||n===`deny`||n===`never`?Ct(n,!1):null;return`${t}${d(t,`we're`)} not sure what ${e}'s tools do${i??` yet`}.`}let f=l.map(u),p=bt(f),m=e=>c.filter(t=>!e(u(t))).length;if(f.every(e=>e===`deny`||e===`never`)){let t=Q(0,0,m(e=>pt.has(e)));return p===`deny`?`${t}${d(t,`everything`)} from ${e} is blocked${Ot(l,n.stance)}.`:p===`never`?`${t}${d(t,`everything`)} from ${e} would ask you first, but approvals are switched off, so none of it can run.`:`${t}${d(t,`nothing`)} from ${e} can run: ${xt(l,n)}.`}let h=l.filter(e=>Z(e)===`read`),g=l.filter(e=>Z(e)!==`read`),_=bt(h.map(u)),v=bt(g.map(u)),y=_===`allow`?`can look at things freely`:_===`limited`?`can look at things within limits you set (${kt(h)})`:null,b=g.length===0?``:v===`approve`?`; anything that changes something asks you first`:v===`granted`?`; anything that changes something asks you first, apart from calls you pre-approved`:v===`granted-only`?`; anything that changes something runs only if you pre-approved it, because approvals are switched off`:v===`deny`?`; anything that changes something is blocked`:v===`never`?`; anything that changes something can never run, because approvals are switched off`:null;if(h.length>0&&y&&b!==null)return`${Q(r.length,s.length,c.length,a.length)}${e} ${y}${b}.`;if(p===`allow`||p===`approve`){let t=Q(r.length,s.length,m(e=>e===p),a.length),i=p===`allow`?`runs freely, without asking you`:`asks you first`;return`${t}${d(t,`everything`)} from ${e} ${i}${Ot(l,n.stance)}.`}if(p===`limited`){let t=Q(r.length,s.length,c.length,a.length);return`${t}${d(t,`everything`)} from ${e} runs freely within limits you set; ${kt(l)}.`}if(p===`granted`){let t=Q(r.length,s.length,c.length,a.length);return`${t}${d(t,`everything`)} from ${e} asks you first, apart from calls you pre-approved.`}if(p===`granted-only`){let t=Q(r.length,s.length,c.length,a.length);return`${t}${d(t,`everything`)} from ${e} runs only calls you pre-approved, because approvals are switched off.`}return`${Q(r.length,s.length,c.length,a.length)}${e}'s tools are mixed: ${xt(l,n)}.`}function jt(e,t){let n=t.trim().toLowerCase();return!n||`${z(e.name).label} ${e.name} ${e.description}`.toLowerCase().includes(n)}function Mt(e,t,n,r=[],i=new Set){let a=t.trim()!==``,o=new Set(e.map(e=>e.upstream));if(!a)for(let e of r)o.add(e);return[...o].sort((e,t)=>e.localeCompare(t)).flatMap(r=>{let a=e.filter(e=>e.upstream===r);if(a.length===0)return[{name:r,why:``,groups:[]}];let o=a.filter(e=>jt(e,t)).sort((e,t)=>e.name.localeCompare(t.name));if(o.length===0)return[];let s=lt(o).map(e=>{let t=Dt(e.tools,i);return{key:e.key,label:ct[e.key],count:ut(e.tools.length),status:wt(e.key,e.tools,n),flags:t,urgent:t.some(e=>e.tone===`bad`),tools:e.tools}});return[{name:r,why:At(r,a,n),groups:s}]})}function Nt({tools:e,changed:t,selected:n,onOpen:r,exposure:i}){return(0,X.jsx)(`ul`,{className:`divide-y divide-faint`,children:e.map(e=>(0,X.jsx)(Ft,{tool:e,changed:t.has(e.name),selected:n===e.name,onOpen:()=>r(e.name),exposure:i},e.name))})}var Pt={read:`bg-ok-tint`,write:`bg-warn-tint`,destructive:`bg-bad-tint`,unknown:`bg-sunken`};function Ft({tool:t,changed:n,selected:r,onOpen:i,exposure:a}){let o=H(t),s=U(t),c=t.exposure.disabled;return(0,X.jsxs)(`li`,{onClick:i,className:F(`-mx-3 flex cursor-pointer flex-wrap items-center gap-x-4 gap-y-2 rounded-2xl px-3 py-3.5 transition-colors hover:bg-faint/70 sm:flex-nowrap`,r&&`bg-faint`),children:[(0,X.jsx)(`span`,{className:F(`grid h-11 w-11 shrink-0 place-items-center rounded-full`,Pt[s??`unknown`],c&&`opacity-50`),title:A[s??`unknown`].label,children:(0,X.jsx)(C,{effect:s})}),(0,X.jsxs)(`div`,{className:F(`min-w-0 flex-1 basis-[calc(100%-64px)] sm:basis-auto`,c&&`opacity-70`),children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`max-w-full truncate rounded font-mono text-[14px] font-medium text-ink hover:underline`,"aria-label":`Open ${t.name}`,children:t.name}),(0,X.jsxs)(`span`,{className:`truncate text-[12.5px] text-soft`,children:[`on `,t.upstream]})]}),(0,X.jsx)(`p`,{className:`mt-0.5 line-clamp-1 text-[13px] text-soft`,children:zt(t.description)||(0,X.jsx)(`span`,{className:`italic`,children:`No description`})}),(0,X.jsx)(Rt,{tool:t,changed:n})]}),(0,X.jsxs)(`div`,{className:`ml-[60px] flex min-w-0 flex-wrap items-center gap-2 sm:ml-0 sm:shrink-0 sm:flex-nowrap`,children:[o===`off`?(0,X.jsx)(e,{tone:`neutral`,icon:`power`,children:`Turned off`}):o===`unlabelled`?(0,X.jsx)(e,{tone:t.verdict.kind===`approve`?`warn`:`bad`,icon:`help`,title:`Nobody has said what this tool does yet`,children:t.verdict.kind===`approve`?`Not labelled · asks`:`Not labelled · blocked`}):(0,X.jsx)(T,{decision:t.verdict.kind}),(0,X.jsx)(It,{tool:t,exposure:a})]})]})}function It({tool:e,exposure:t}){let n=e.exposure.disabled;return(0,X.jsx)(E,{size:`sm`,variant:`ghost`,icon:`power`,loading:t.busy(e.name),disabled:t.blocked!==null,title:t.blocked??void 0,onClick:r=>{r.stopPropagation(),t.set(e,!n)},"aria-label":`${n?`Turn on`:`Turn off`} ${e.name}`,className:`justify-center sm:w-[104px]`,children:n?`Turn on`:`Turn off`})}var Lt={changed:`refresh`,inj:`warning`,unreach:`lock`,bounds:`sliders`,unbounded:`info`,grant:`key`};function Rt({tool:t,changed:n}){let r=K(t,n);return r.length===0?null:(0,X.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:r.map(t=>(0,X.jsx)(e,{tone:t.tone,icon:Lt[t.key],className:`py-0 text-[11.5px]`,children:t.text},t.key))})}function zt(e){let t=/^\[description withheld by hmcp-gateway: it contained text that ([^\]]+)\]/.exec(e);return t?`Description hidden from your AI: it contained text that ${t[1]}.`:e}function Bt({protection:e,tools:t,query:n,onClearQuery:r,changed:i,selected:a,onOpen:o,exposure:c,configured:l,withheld:u,connectionsHref:d,onPosture:f}){let[p,m]=(0,B.useState)(()=>new Map),h=e?.defaults.mode??null,_=e?.enforcement===`observe`,v=e?.approvals?.mode===`deny`,y=(0,B.useMemo)(()=>({observe:_,approvalsOff:v,withheld:u}),[_,v,u]),x=(0,B.useMemo)(()=>Mt(t,n,{stance:h,...y},l,i),[t,n,h,y,l,i]);if(!e)return(0,X.jsx)(k,{children:(0,X.jsxs)(`div`,{className:`space-y-5`,"aria-busy":!0,children:[(0,X.jsx)(s,{lines:2}),(0,X.jsx)(s,{lines:3})]})});if(t.length===0)return(0,X.jsx)(k,{children:(0,X.jsx)(b,{icon:`tool`,title:`No tools yet`,children:e.surface.neverPublished?`Start the toolbox once and the tools its connected servers offer will appear here.`:`The connected servers on this toolbox don't offer any tools.`})});if(x.length===0)return(0,X.jsx)(k,{children:(0,X.jsx)(b,{icon:`search`,title:`No tools match`,compact:!0,actions:(0,X.jsx)(E,{onClick:r,children:`Clear search`}),children:`Nothing on this toolbox matches what you typed.`})});let S=n.trim()!==``;return(0,X.jsx)(`div`,{className:`space-y-5`,children:x.map(e=>(0,X.jsx)(k,{title:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,X.jsx)(g,{name:`server`,size:20,className:`text-soft`}),e.name]}),children:e.groups.length===0?(0,X.jsxs)(`p`,{className:`text-[14.5px] text-muted`,children:[`No tools listed yet. If it should have some, it may not have connected:`,` `,(0,X.jsx)(`a`,{href:d,className:`font-semibold underline underline-offset-2`,children:`check it on Connections`}),`.`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-[14.5px] text-muted`,children:e.why}),(0,X.jsx)(`ul`,{className:`mt-3 divide-y divide-faint`,children:e.groups.map(t=>{let n=`${e.name}\n${t.key}`,r=S||(p.get(n)??t.urgent);return(0,X.jsx)(Vt,{group:t,open:r,forced:S,onToggle:()=>m(e=>new Map(e).set(n,!r)),changed:i,selected:a,onOpen:o,exposure:c,status:y,onPosture:f},t.key)})})]})},e.name))})}function Vt({group:t,open:n,forced:r,onToggle:i,changed:a,selected:o,onOpen:s,exposure:c,status:l,onPosture:u}){let d=(0,B.useId)(),f=t.key===`read`||t.key===`write`||t.key===`destructive`?t.key:null;return(0,X.jsxs)(`li`,{className:`py-1`,children:[(0,X.jsxs)(`div`,{className:`-mx-3 flex items-center gap-2`,children:[(0,X.jsxs)(`button`,{type:`button`,"aria-expanded":n,disabled:r,"aria-controls":d,title:r?`Every group is open while you search. Clear the search to fold them.`:void 0,onClick:i,className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1 rounded-2xl px-3 py-3 text-left transition-colors enabled:hover:bg-faint/70`,children:[(0,X.jsx)(g,{name:`chevron`,size:18,className:F(`shrink-0 text-soft transition-transform`,!n&&`-rotate-90`)}),(0,X.jsx)(`span`,{className:F(`grid h-9 w-9 shrink-0 place-items-center rounded-full`,Pt[f??`unknown`]),children:t.key===`off`?(0,X.jsx)(g,{name:`power`,size:16,className:`text-soft`}):(0,X.jsx)(C,{effect:f})}),(0,X.jsx)(`span`,{className:`font-semibold text-ink`,children:t.label}),(0,X.jsx)(`span`,{className:`tnum text-[13px] text-soft`,children:t.count}),(0,X.jsx)(`span`,{className:`basis-full pl-[66px] text-[13.5px] text-muted sm:ml-auto sm:basis-auto sm:pl-0 sm:text-right`,children:t.status}),t.flags.length>0&&(0,X.jsx)(`span`,{className:`flex basis-full flex-wrap gap-1.5 pl-[66px]`,children:t.flags.map(t=>(0,X.jsx)(e,{tone:t.tone,icon:Lt[t.key],className:`py-0 text-[11.5px]`,children:t.text},t.key))})]}),t.key===`unsure`&&(0,X.jsx)(E,{size:`sm`,variant:`ghost`,onClick:u,"aria-label":`Change what happens to tools we're not sure about`,children:`Change`})]}),(0,X.jsx)(`ul`,{id:d,hidden:!n,className:`mb-2 divide-y divide-faint pl-8`,children:t.tools.map(e=>(0,X.jsx)(Ut,{tool:e,changed:a.has(e.name),selected:o===e.name,onOpen:()=>s(e.name),exposure:c,status:l},e.name))})]})}var Ht={ok:`text-ok`,warn:`text-warn`,bad:`text-bad`,soft:`text-soft`};function Ut({tool:e,changed:t,selected:n,onOpen:r,exposure:i,status:a}){let o=z(e.name).label;return(0,X.jsxs)(`li`,{onClick:r,className:F(`-mx-3 flex cursor-pointer flex-wrap items-center gap-x-4 gap-y-2 rounded-2xl px-3 py-3 transition-colors hover:bg-faint/70 sm:flex-nowrap`,n&&`bg-faint`),children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 basis-full sm:basis-auto`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r()},className:`max-w-full truncate rounded text-left text-[14.5px] font-medium text-ink hover:underline`,"aria-label":`Open ${o} (${e.name})`,children:o}),(0,X.jsx)(`span`,{className:`block truncate font-mono text-[12px] text-soft`,children:e.name}),(0,X.jsx)(Rt,{tool:e,changed:t})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:F(`text-[13.5px] font-semibold`,Ht[gt(e,a)]),children:ht(e,a)}),mt(e,a)?(0,X.jsx)(E,{size:`sm`,variant:`ghost`,icon:`sliders`,onClick:e=>{e.stopPropagation(),r()},"aria-label":`Change what ${o} may do`,title:e.name,className:`justify-center sm:w-[104px]`,children:`Change`}):(0,X.jsx)(It,{tool:e,exposure:i})]})]})}function Wt({name:e,serverId:t,tenant:n,protection:r,listTool:i,version:a,nav:o,exposure:l,ruleBlocked:u,onClose:d,onEditRule:f,onPosture:p,onChanged:m}){let{data:h,error:g,loading:v,reload:b}=ue(()=>e?_.tool(t,e,n):Promise.resolve(null),[t,e,n,a]),x=h&&h.name===e?h:null,S=x??i;return(0,X.jsx)(y,{open:e!==null,onClose:d,width:620,title:(0,X.jsx)(`span`,{className:`font-mono text-[18px] break-all`,children:e}),subtitle:S?(0,X.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,X.jsx)(C,{effect:U(S),withLabel:!0}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,X.jsxs)(`span`,{children:[`on `,(0,X.jsx)(`span`,{className:`font-medium text-muted`,children:S.upstream})]}),(0,X.jsx)(w,{term:`connectedServer`})]}):void 0,children:g&&!S?(0,X.jsx)(c,{tone:`danger`,title:`This tool couldn't be loaded`,actions:(0,X.jsx)(E,{size:`sm`,icon:`refresh`,onClick:b,children:`Try again`}),children:Y(g)}):S?(0,X.jsxs)(`div`,{className:`space-y-8`,children:[(0,X.jsx)(Gt,{tool:S}),(0,X.jsx)(Kt,{tool:S,protection:r,serverId:t,tenant:n,ruleBlocked:u,onEditRule:()=>f(S),onPosture:p,onChanged:m}),(0,X.jsx)(Yt,{tool:S}),(0,X.jsx)(Xt,{tool:S,loading:v&&!x}),(0,X.jsx)(Zt,{tool:S,nav:o}),(0,X.jsx)(Qt,{tool:x,loading:v&&!x,nav:o}),(0,X.jsx)($t,{tool:S,exposure:l,perCustomer:!!r?.tenant},S.name)]}):(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(s,{height:20,lines:3}),(0,X.jsx)(s,{height:40}),(0,X.jsx)(s,{lines:4})]})})}function $({title:e,aside:t,children:n}){return(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`header`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`h3`,{className:`flex items-center gap-2 text-[16px] font-semibold tracking-[-0.01em]`,children:e}),t]}),n]})}function Gt({tool:e}){let t=e.rawDescription!==e.description,n=e.injection??[],r=n.length>0&&!e.hiddenByPolicy&&!t;return(0,X.jsxs)($,{title:t?`What your AI is told about it`:`What ${e.upstream} says about it`,children:[(0,X.jsx)(`p`,{className:`text-[14.5px] whitespace-pre-wrap text-ink`,children:e.description||(0,X.jsx)(`span`,{className:`text-soft italic`,children:`The connected server gave no description.`})}),(0,X.jsx)(`p`,{className:`mt-1.5 text-[12.5px] text-soft`,children:`This is the description your AI sees.`}),n.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsxs)(c,{tone:r?`info`:`danger`,title:e.hiddenByPolicy?`Hidden instructions found, so the tool is hidden`:r?`Hidden instructions found, and accepted after review`:`Hidden instructions found and removed`,children:[`The connected server's description contained text aimed at your AI rather than at you, such as telling it to ignore its rules.`,` `,e.hiddenByPolicy?`The toolbox keeps this tool away from your AI entirely.`:r?`Someone reviewed it and chose to pass the text through unchanged. It doesn't change what the tool may do.`:`The toolbox changed the description before your AI saw it.`,(0,X.jsx)(`span`,{className:`mt-1.5 block font-mono text-[11.5px] text-soft`,children:n.map(e=>ae(e)===e?e:`${e} (${ae(e)})`).join(`, `)})]})}),t&&(0,X.jsxs)(`details`,{className:`mt-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`What ${e.upstream} originally said`}),(0,X.jsx)(`p`,{className:`mt-2 mb-2 text-[12.5px] text-soft`,children:`What the connected server sent (removed lines) and what your AI sees instead (added lines).`}),(0,X.jsx)(ie,{before:je(e.rawDescription),after:je(e.description),label:`Original and shown description`})]})]})}function Kt({tool:e,protection:t,serverId:n,tenant:r,ruleBlocked:i,onEditRule:a,onPosture:o,onChanged:s}){let[l,u]=(0,B.useState)(!1),d=e.effect===null&&!e.reclassifiedTo,f=e.exposure.disabled?`deny`:e.verdict.kind;return(0,X.jsxs)($,{title:`What it's allowed to do`,children:[(0,X.jsxs)(`div`,{className:`rounded-[20px] bg-sunken/70 p-5`,children:[(0,X.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,X.jsx)(T,{decision:f,label:e.exposure.disabled?`Turned off`:void 0})}),(0,X.jsx)(`p`,{className:`display mt-3 text-[22px] leading-snug`,children:_e(e)}),t?.enforcement===`observe`&&e.verdict.kind!==`allow`&&!e.exposure.disabled&&(0,X.jsx)(`p`,{className:`mt-1 text-[13.5px] text-muted`,children:`That starts once protection is on. Your toolbox is only watching now, so for the moment it runs.`}),!e.exposure.disabled&&(0,X.jsxs)(`dl`,{className:`mt-4 space-y-2 text-[13.5px]`,children:[(0,X.jsxs)(qt,{label:`Why`,children:[ve(e.verdict,t?.defaults.mode??null),(0,X.jsx)(`code`,{className:`mt-0.5 block font-mono text-[11.5px] break-all text-soft`,children:e.verdict.ruleId})]}),(0,X.jsxs)(qt,{label:`Labelled as`,children:[A[U(e)??`unknown`].label,`.`,` `,(0,X.jsx)(`span`,{className:`text-soft`,children:ye[e.effectSource]??e.effectSource}),e.reclassifiedTo&&e.effect&&(0,X.jsxs)(`span`,{className:`block text-[12.5px] text-soft`,children:[`The connected server calls it “`,A[e.effect]?.label??e.effect,`”; a rule changed that.`]})]}),e.consoleRule&&(0,X.jsx)(qt,{label:`Set by`,children:`You, from this console. Use “Undo my change” to remove it.`})]}),(0,X.jsxs)(`div`,{className:`mt-5 flex flex-wrap gap-2`,children:[(0,X.jsx)(E,{variant:`primary`,icon:`sliders`,onClick:a,disabled:i!==null,children:`Change what it may do`}),e.consoleRule&&(0,X.jsx)(E,{icon:`refresh`,onClick:()=>u(!0),disabled:i!==null,children:`Undo my change`}),d&&(0,X.jsx)(E,{variant:`ghost`,onClick:o,children:`Change the setting for unlabelled tools`})]}),i&&(0,X.jsx)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:i})]}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[t?.runtime.policyApplied===!1&&(0,X.jsxs)(c,{tone:`warn`,title:`The running gateway hasn't picked up the latest settings`,children:[`What's shown here is the settings file. The toolbox still uses the version it read when it started`,` `,t.runtime.startedAt?x(t.runtime.startedAt):`earlier`,`. Restart it to apply the newer one.`]}),e.boundsDrift&&(0,X.jsxs)(c,{tone:`info`,title:`These limits no longer match the rule they were copied from`,children:[`When this rule was saved it copied the limits from`,` `,(0,X.jsx)(`code`,{className:`font-mono text-[12px]`,children:e.boundsDrift.ruleId}),`. That rule has changed since:`,(0,X.jsx)(`ul`,{className:`mt-1.5 list-disc space-y-0.5 pl-5`,children:e.boundsDrift.differences.map(e=>(0,X.jsx)(`li`,{children:J(e)},e))}),(0,X.jsx)(`span`,{className:`mt-1.5 block`,children:`This tool still follows its own copy. Change what it may do to take the newer limits, or leave it if these are the ones you want.`})]})]}),l&&(0,X.jsx)(Jt,{serverId:n,tenant:r,tool:e,protection:t,onClose:()=>u(!1),onDone:()=>{u(!1),s()}})]})}function qt({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`grid gap-x-4 gap-y-0.5 sm:grid-cols-[110px_1fr]`,children:[(0,X.jsx)(`dt`,{className:`font-semibold text-soft`,children:e}),(0,X.jsx)(`dd`,{className:`min-w-0 text-ink`,children:t})]})}function Jt({serverId:e,tenant:t,tool:n,protection:r,onClose:i,onDone:a}){let o=P(),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(null),[p,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(0);(0,B.useEffect)(()=>{let r=!0;return u(null),_.clearPreview(e,n.name,t).then(e=>r&&u(e),e=>r&&f({text:Y(e),stale:!1})),()=>{r=!1}},[e,n.name,t,h]);async function v(){if(l){m(!0),f(null);try{let r=await _.clearToolRule(e,n.name,l.expectedDigest,t);o.show(`ok`,`Your change to ${n.name} is undone. The toolbox applies it within about a second.`),r.warning&&o.show(`warn`,J(r.warning)),a()}catch(e){f({text:ke(e)?Ae:Y(e),stale:ke(e)})}finally{m(!1)}}}let y=l?.verdict.kind===`allow`?`run freely`:l?.verdict.kind===`approve`?`ask you first`:`be blocked`;return(0,X.jsx)(N,{open:!0,onClose:i,title:`Undo your change to ${n.name}?`,description:`This removes the rule you saved here. The tool goes back to whatever your other settings say.`,footer:(0,X.jsxs)(X.Fragment,{children:[d?.stale&&(0,X.jsx)(E,{variant:`ghost`,icon:`refresh`,className:`mr-auto`,onClick:()=>{f(null),g(e=>e+1)},children:`Reload`}),(0,X.jsx)(E,{variant:`secondary`,onClick:i,disabled:p,children:`Keep my change`}),(0,X.jsx)(E,{variant:`primary`,onClick:()=>void v(),disabled:!l,loading:p,children:`Undo change`})]}),children:(0,X.jsxs)(`div`,{className:`space-y-3 text-[14px]`,children:[!l&&!d&&(0,X.jsx)(s,{lines:3}),l&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,X.jsx)(`span`,{className:`text-[13px] text-soft`,children:`Afterwards it will`}),(0,X.jsx)(T,{decision:l.verdict.kind})]}),(0,X.jsxs)(`p`,{className:`text-muted`,children:[`Every call to `,(0,X.jsx)(`code`,{className:`font-mono text-ink`,children:n.name}),` will `,y,l.verdict.ruleId.startsWith(`defaults.`)?`, by your default settings`:``,`.`,l.bounds?` Limits: ${Ce(l.bounds).join(`; `)}.`:``]}),l.becomesUnclassified&&(0,X.jsx)(c,{tone:`warn`,title:`Nothing else says what this tool does`,children:`Your change was the only label on this tool. Without it, it is treated as not labelled again.`}),r?.tenant&&(0,X.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`This affects every customer of this toolbox.`}),(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the rule being removed`}),(0,X.jsx)(`div`,{className:`mt-2`,children:(0,X.jsx)(re,{label:`The rule being removed`,children:l.yaml})})]})]}),d&&(0,X.jsx)(`p`,{role:`alert`,className:`text-[13.5px] font-medium text-bad`,children:d.text})]})})}function Yt({tool:e}){let t=e.bounds;return(0,X.jsx)($,{title:(0,X.jsxs)(X.Fragment,{children:[`Limits on its inputs `,(0,X.jsx)(w,{term:`limits`})]}),children:t?(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:t.paths.map((e,n)=>(0,X.jsxs)(`li`,{className:`flex gap-2.5 text-[14px]`,children:[(0,X.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--soft)]`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`code`,{className:`font-mono text-[13px] font-medium`,children:e}),` `,Ce(t)[n].slice(e.length+1)]})]},e))}),(0,X.jsxs)(`p`,{className:`text-[13px] text-soft`,children:[`A call that breaks a limit `,t.onViolation===`approve`?`asks you first`:`is blocked`,`.`,` `,Oe[t.unknownArgs]]}),e.unboundedInputs.length>0&&(0,X.jsxs)(`p`,{className:`text-[13px] text-ink`,children:[e.unboundedOpen?`Inputs with no limits include: `:`These inputs have no limits: `,e.unboundedInputs.map((e,t)=>(0,X.jsxs)(`span`,{children:[t>0&&`, `,(0,X.jsx)(`code`,{className:`font-mono text-[12.5px]`,children:e})]},e)),e.unboundedOpen&&` and any other input the tool accepts`,`. Set “Anything else the tool is sent” to block or ask to cover them.`]}),(0,X.jsx)(`p`,{className:`font-mono text-[11.5px] text-soft`,children:t.ruleId})]}):(0,X.jsx)(`p`,{className:`text-[14px] text-soft`,children:`No limits. Every input is passed on as your AI sends it.`})})}function Xt({tool:t,loading:n}){return(0,X.jsxs)($,{title:`Inputs`,children:[t.args.length===0?(0,X.jsx)(`p`,{className:`text-[14px] text-soft`,children:`This tool takes no inputs.`}):(0,X.jsx)(`ul`,{className:`divide-y divide-faint rounded-[18px] border border-line`,children:t.args.map(t=>(0,X.jsxs)(`li`,{className:`px-4 py-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,X.jsx)(`code`,{className:`font-mono text-[13.5px] font-medium break-all`,children:t.name}),(0,X.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[t.type??`any type`,t.format?`, ${t.format}`:``,` · `,t.required?`required`:`optional`]}),t.constrainedByRule&&(0,X.jsx)(e,{tone:`neutral`,icon:`sliders`,className:`py-0 text-[11.5px]`,children:`Limited`})]}),t.description&&(0,X.jsx)(`p`,{className:`mt-1 text-[13px] text-muted`,children:t.description}),t.enumValues&&(0,X.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Accepts: `,(0,X.jsx)(`span`,{className:`font-mono`,children:t.enumValues.join(`, `)})]}),t.defaultValue!==null&&(0,X.jsxs)(`p`,{className:t.defaultIsUrl?`mt-1 text-[12.5px] text-warn`:`mt-1 text-[12.5px] text-soft`,children:[`If left out: `,(0,X.jsx)(`span`,{className:`font-mono break-all`,children:t.defaultValue}),t.defaultIsUrl&&` (a web address the connected server contacts on its own; your network limits don't cover it)`]})]},t.name))}),t.schemaClosed===!1&&(0,X.jsx)(`p`,{className:`mt-2 text-[13px] text-warn`,children:`The connected server accepts inputs beyond the ones listed here, and passes them on as given.`}),(0,X.jsxs)(`details`,{className:`mt-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the full input definition`}),(0,X.jsx)(`div`,{className:`mt-2`,children:n?(0,X.jsx)(s,{lines:4}):(0,X.jsx)(re,{copy:!0,label:`Input definition`,children:JSON.stringify(t.inputSchema??{},null,2)})})]})]})}function Zt({tool:t,nav:n}){return(0,X.jsx)($,{title:(0,X.jsxs)(X.Fragment,{children:[`Pre-approvals that cover it `,(0,X.jsx)(w,{term:`preApproval`})]}),aside:(0,X.jsx)(ee,{href:r(n,`/pre-approvals`),size:`sm`,variant:`ghost`,iconRight:`arrow-right`,children:`Open pre-approvals`}),children:t.standingGrants.length===0?(0,X.jsx)(`p`,{className:`text-[14px] text-soft`,children:`None. When this tool asks first, you decide each call.`}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:t.standingGrants.map(t=>(0,X.jsxs)(`li`,{className:`rounded-[18px] border border-line px-4 py-3 text-[13.5px]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(e,{tone:t.covers?`ok`:`neutral`,icon:t.covers?`check`:`x`,children:t.covers?`Covers this tool`:`Doesn't apply`}),(0,X.jsxs)(`span`,{className:`text-soft`,children:[t.uses,` of `,t.maxUses??`unlimited`,` uses · ends `,x(t.expiresAt)]})]}),t.reason&&(0,X.jsx)(`p`,{className:`mt-1.5 text-ink`,children:t.reason}),!t.covers&&(0,X.jsx)(`p`,{className:`mt-1 text-soft`,children:J(t.why)}),t.covers&&t.heldBounds.length>0&&(0,X.jsxs)(`p`,{className:`mt-1 text-soft`,children:[`A call that breaks the limit on `,(0,X.jsx)(`span`,{className:`font-mono`,children:t.heldBounds.join(`, `)}),` still asks you, because this pre-approval doesn't limit that input.`]}),(0,X.jsx)(`p`,{className:`mt-1 font-mono text-[11.5px] text-soft`,children:t.grantId})]},t.grantId))})})}function Qt({tool:t,loading:n,nav:i}){let a=t?.activity??[];return(0,X.jsx)($,{title:`Recent activity`,aside:t&&(0,X.jsx)(ee,{href:r(i,`/activity`,{tool:t.name}),size:`sm`,variant:`ghost`,iconRight:`arrow-right`,children:`Open activity`}),children:n?(0,X.jsx)(s,{lines:3}):a.length===0?(0,X.jsx)(`p`,{className:`text-[14px] text-soft`,children:`Your AI hasn't used this tool yet.`}):(0,X.jsx)(`ul`,{className:`divide-y divide-faint`,children:a.map(t=>{let n=O[t.outcome];return(0,X.jsxs)(`li`,{className:`flex flex-wrap items-start gap-x-3 gap-y-1 py-2.5`,children:[(0,X.jsx)(`span`,{className:`w-24 shrink-0 text-[12.5px] text-soft`,title:l(t.ts),children:x(t.ts)}),(0,X.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(T,{decision:t.decision}),n&&(0,X.jsx)(e,{tone:n.tone,className:`py-0 text-[11.5px]`,children:n.label}),t.observe&&(0,X.jsx)(e,{tone:`neutral`,className:`py-0 text-[11.5px]`,children:`Watch-only`})]}),t.reason&&(0,X.jsx)(`span`,{className:`w-full text-[12.5px] text-soft sm:pl-[108px]`,children:J(t.reason)})]},t.id)})})})}function $t({tool:e,exposure:t,perCustomer:n}){let[r,i]=(0,B.useState)(``),o=e.exposure.disabled;return(0,X.jsx)($,{title:(0,X.jsxs)(X.Fragment,{children:[`Turn off this tool `,(0,X.jsx)(w,{term:`killSwitch`})]}),children:(0,X.jsxs)(`div`,{className:`space-y-4 rounded-[20px] border border-line p-5`,children:[(0,X.jsx)(p,{checked:o,onChange:n=>t.set(e,n,n?r.trim():``),disabled:t.blocked!==null||t.busy(e.name),label:o?`This tool is turned off`:`Turn off this tool`,description:o?`Your AI can't see it, and every call is blocked${e.exposure.setBy?`. Turned off by ${e.exposure.setBy}`:``}${e.exposure.setAt?` ${x(e.exposure.setAt)}`:``}.`:`Hides it from your AI and blocks every call, even in watch-only mode.`}),o&&e.exposure.reason&&(0,X.jsxs)(`p`,{className:`text-[13.5px] text-muted`,children:[`Reason given: `,(0,X.jsx)(`span`,{className:`text-ink`,children:e.exposure.reason})]}),!o&&(0,X.jsx)(a,{label:`Reason`,optional:!0,help:`Saved in the activity log with the change.`,children:(0,X.jsx)(f,{value:r,onChange:i,placeholder:`For example: misbehaving since the last update`,disabled:t.blocked!==null})}),(0,X.jsxs)(`p`,{className:`text-[12.5px] text-soft`,children:[`Turning it back on returns it to your normal rules. It never makes it allowed on its own`,e.exposure.policyWouldExpose?`.`:`: your rules block this tool anyway.`,n&&` This switch is kept separately for each customer.`]}),t.blocked&&(0,X.jsx)(c,{tone:`warn`,title:`Not available right now`,children:t.blocked})]})})}var en=`hmcp.tools.look`;function tn(){try{return localStorage.getItem(en)===`detailed`?`detailed`:`simple`}catch{return`simple`}}function nn(e){try{localStorage.setItem(en,e)}catch{}}var rn={allow:`allow`,approve:`approve`,deny:`deny`,unlabelled:`unclassified`,off:null,changed:null};function an(){let{server:e,serverId:t,tenant:i,nav:a,reload:l}=me(),u=ue(()=>_.protection(t,i),[t,i],3e4),f=ue(()=>fe(t),[t],3e4),[p,m]=(0,B.useState)(0),[g,v]=(0,B.useState)(``),[y,C]=(0,B.useState)(`any`),[w,te]=(0,B.useState)(null),[re,T]=(0,B.useState)(!1),[ie,ae]=(0,B.useState)(tn),oe=(0,B.useRef)(void 0);(0,B.useEffect)(()=>()=>clearTimeout(oe.current),[]);let D=u.data,ce=a.query.get(`tool`),O=a.query.get(`verdict`),A=ge(O)?O:null,j=a.query.get(`view`)===`changed`?`changed`:`all`,M=a.query.get(`list`),N=M===`detailed`||M===`simple`?M:ie,P=()=>{u.reload(),f.reload(),m(e=>e+1),l()},F=()=>{P(),clearTimeout(oe.current),oe.current=setTimeout(P,1500)},I=Le({serverId:t,tenant:i,protection:D,onChanged:P}),L=(0,B.useMemo)(()=>D?.tools??[],[D]),pe=(0,B.useMemo)(()=>e?.upstreams??[],[e]),R=(0,B.useMemo)(()=>new Set((f.data?.changed??[]).map(e=>e.tool)),[f.data]),z=(0,B.useMemo)(()=>new Set((f.data?.changed??[]).filter(e=>e.withheld).map(e=>e.tool)),[f.data]),W=(0,B.useMemo)(()=>{let e={allow:0,approve:0,deny:0,unlabelled:0,off:0,changed:0};for(let t of L)e[H(t)]++,R.has(t.name)&&e.changed++;return e},[L,R]),_e=(0,B.useMemo)(()=>{let e=g.trim().toLowerCase();return L.filter(t=>!((A===`changed`?!R.has(t.name):A!==null&&H(t)!==A)||y!==`any`&&U(t)!==y||e&&!`${t.name} ${t.description} ${t.upstream}`.toLowerCase().includes(e))).sort((e,t)=>e.upstream.localeCompare(t.upstream)||e.name.localeCompare(t.name))},[L,A,y,g,R]),G=D?D.surface.neverPublished?`Your toolbox hasn't run yet, so there's no list of its tools to set a rule on. Open your AI app once, then come back.`:D.policyWrite.ok?null:J(D.policyWrite.why??`This toolbox's settings can't be changed from here.`):null,K=f.data?.changed.length??0,ve=e=>de(o(a,{verdict:e})),ye=e=>de(o(a,{view:e===`changed`?e:null})),q=e=>de(o(a,{tool:e}));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ne,{title:`Tools`,subtitle:`Everything your AI can use through your toolbox, and what each one is allowed to do.`,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(E,{icon:`help`,onClick:()=>T(!0),disabled:!D,children:`What happens to unlabelled tools`}),K>0&&(0,X.jsxs)(E,{variant:`primary`,icon:`refresh`,onClick:()=>ye(`changed`),children:[`Review changed tools (`,K,`)`]})]})}),D?.enforcement===`observe`&&(0,X.jsx)(`div`,{className:`mb-5`,children:(0,X.jsx)(c,{tone:`warn`,title:`Only watching: every tool runs for now`,children:`Your toolbox isn't protecting you yet, so nothing below asks you first or is blocked today. The labels say what happens once protection is on.`})}),(0,X.jsxs)(`div`,{className:`mb-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsx)(le,{label:`Tool views`,value:j,onChange:ye,items:[{id:`all`,label:`All tools`,count:D?L.length:void 0},{id:`changed`,label:`Changed tools`,count:K}]}),j===`all`&&(0,X.jsx)(h,{label:`How to show tools`,size:`sm`,value:N,onChange:e=>{nn(e),ae(e),de(o(a,{list:e===`detailed`?e:null}))},options:[{value:`simple`,label:`Simple`},{value:`detailed`,label:`Detailed`}]})]}),(0,X.jsx)(`div`,{role:`tabpanel`,id:S(j),"aria-labelledby":d(j),className:`space-y-5`,children:j===`changed`?(0,X.jsx)(Pe,{serverId:t,data:f.data,error:f.error,loading:f.loading,reload:f.reload,onAccepted:P}):u.error&&!D?(0,X.jsx)(c,{tone:`danger`,title:`The tool list couldn't be loaded`,actions:(0,X.jsx)(E,{size:`sm`,icon:`refresh`,onClick:u.reload,children:`Try again`}),children:Y(u.error)}):(0,X.jsxs)(X.Fragment,{children:[D&&I.blocked&&(0,X.jsx)(c,{tone:`warn`,title:D.surface.neverPublished?`No tool list yet`:`The toolbox isn't running`,children:D.surface.neverPublished?`This toolbox hasn't reported which tools its connected servers offer. Start it once and they appear here.`:`This is the list it reported ${D.surface.publishedAt?x(D.surface.publishedAt):`last time`}. Start the toolbox to turn tools off or change their rules.`}),N===`simple`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(on,{value:g,onChange:v}),(0,X.jsx)(ee,{href:r(a,`/protection`,{focus:`stance`}),icon:`sliders`,children:`Change how careful to be (all servers)`})]}),(0,X.jsx)(Bt,{protection:D,tools:L,query:g,onClearQuery:()=>v(``),changed:R,selected:ce,onOpen:q,exposure:I,configured:pe,withheld:z,connectionsHref:r(a,`/connections`),onPosture:()=>T(!0)})]}):(0,X.jsxs)(k,{padded:!1,children:[(0,X.jsxs)(`div`,{className:`space-y-4 border-b border-faint p-5 sm:p-6`,children:[(0,X.jsx)(`div`,{role:`group`,"aria-label":`Show tools that`,className:`flex flex-wrap gap-2`,children:V.map(e=>(0,X.jsx)(sn,{label:he[e],count:D?W[e]:null,dot:rn[e],icon:e===`off`?`power`:e===`changed`?`refresh`:null,on:A===e,onClick:()=>ve(A===e?null:e)},e))}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,X.jsx)(on,{value:g,onChange:v}),(0,X.jsx)(se,{"aria-label":`Show tools by what they do`,value:y,onChange:C,className:`w-full sm:w-52`,options:[{value:`any`,label:`Any kind of tool`},{value:`read`,label:`Looks only`},{value:`write`,label:`Makes changes`},{value:`destructive`,label:`Deletes`}]})]})]}),(0,X.jsx)(`div`,{className:`px-5 pt-1 pb-3 sm:px-6`,children:D?L.length===0?(0,X.jsx)(b,{icon:`tool`,title:`No tools yet`,children:D.surface.neverPublished?`Start the toolbox once and the tools its connected servers offer will appear here.`:`The connected servers on this toolbox don't offer any tools.`}):_e.length===0?(0,X.jsx)(b,{icon:`search`,title:`No tools match`,compact:!0,actions:(0,X.jsx)(E,{onClick:()=>{v(``),C(`any`),ve(null)},children:`Clear filters`}),children:`Nothing on this toolbox matches what you picked.`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`sr-only`,"aria-live":`polite`,children:[n(_e.length,`tool`),` shown`]}),(0,X.jsx)(Nt,{tools:_e,changed:R,selected:ce,onOpen:q,exposure:I})]}):(0,X.jsx)(`div`,{className:`space-y-5 py-4`,"aria-busy":!0,children:[0,1,2,3].map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,X.jsx)(`span`,{className:`skeleton h-11 w-11 shrink-0 rounded-full`}),(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsx)(s,{lines:2})})]},e))})})]})]})}),(0,X.jsx)(Wt,{name:ce,serverId:t,tenant:i,protection:D,listTool:L.find(e=>e.name===ce)??null,version:p,nav:a,exposure:I,ruleBlocked:G,onClose:()=>q(null),onEditRule:te,onPosture:()=>T(!0),onChanged:F}),w&&(0,X.jsx)(Qe,{open:!0,serverId:t,tenant:i,tool:w,protection:D,onClose:()=>te(null),onSaved:F},w.name),D&&re&&(0,X.jsx)(ze,{open:!0,serverId:t,tenant:i,protection:D,onClose:()=>T(!1),onSaved:F,onReload:u.reload}),I.dialog]})}function on({value:e,onChange:t}){return(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-60`,children:[(0,X.jsx)(g,{name:`search`,size:18,className:`pointer-events-none absolute top-1/2 left-3.5 -translate-y-1/2 text-soft`}),(0,X.jsx)(f,{type:`search`,value:e,onChange:t,placeholder:`Search by name or description`,"aria-label":`Search tools by name or description`,className:`pl-10`})]})}function sn({label:e,count:t,dot:n,icon:r,on:i,onClick:a}){return(0,X.jsxs)(`button`,{type:`button`,"aria-pressed":i,onClick:a,className:F(`inline-flex h-10 items-center gap-2 rounded-full border-[1.5px] px-4 text-[13.5px] font-semibold transition-colors active:scale-[.98]`,i?`border-primary bg-primary text-white`:`border-line text-muted hover:border-[var(--soft)] hover:text-ink`),children:[n&&(i?(0,X.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-full bg-white`,"aria-hidden":!0}):(0,X.jsx)(v,{decision:n})),r&&(0,X.jsx)(g,{name:r,size:15,strokeWidth:2}),e,(0,X.jsx)(`span`,{className:F(`tnum rounded-full px-1.5 text-[12px]`,i?`bg-white/20`:`bg-faint`),children:t??`–`})]})}export{an as ToolsPage};