hmcp-web 0.2.1 → 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.
@@ -1 +0,0 @@
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,It as l,L as u,M as d,N as f,Nt as p,O as m,Ot as h,P as g,Pt as _,Q as v,R as y,U as b,Z as x,_ as S,_t as C,b as w,c as T,d as ee,et as E,f as te,gt as D,ht as O,it as ne,k,kt as A,m as j,mt as M,nt as N,pt as P,rt as F,s as I,st as L,tt as re,vt as R,w as z,wt as ie,x as ae,y as B,yt as V,z as oe}from"./kit-DRVm92_t.js";import{bn as H,gn as U,un as se}from"./index-DbHZ_SUd.js";var W=l(),G=A(),ce=(0,W.createContext)(null);function K(){let e=(0,W.useContext)(ce);if(!e)throw Error(`useWriter outside the Protection page`);return e}var le=new Set([`enforcement`,`defaults.mode`,`defaults.on_unclassified`,`approvals.mode`,`approvals.ttl_seconds`,`approvals.single_use`]),ue=[`egress.`],de=e=>le.has(e)||e===`egress`||ue.some(t=>e.startsWith(t));function q(e){if(/policy_overrides/.test(e))return`This toolbox only lets the console make settings stricter, so this change has to be made in the settings file by whoever manages the toolbox.`;if(/policy_writes/.test(e))return`This toolbox is set up to refuse changes from the console.`;if(/written inline/.test(e))return`These settings live inside the toolbox's own configuration, so the console can show them but not change them.`;if(/no tenant block/.test(e))return`This toolbox does not keep customers apart, so there is nothing to change here.`;if(/already /.test(e)&&/is already/.test(e))return`That is already the current setting.`;let t=e.replace(/`?(?:npx\s+)?hmcp(?:-gateway|-web)?\s[^`.;)]*`?/g,`the console`).replace(/\s--[a-z][\w-]*/g,``).replace(/`/g,``);return t=t.charAt(0).toUpperCase()+t.slice(1),t}var fe={enforcement:`Protection mode`,on_tool_change:`Changed tools`,"defaults.mode":`The default stance`,"defaults.on_unclassified":`Unlabelled tools`,"approvals.mode":`Where you're asked`,"approvals.ttl_seconds":`How long a request waits`,"approvals.single_use":`One approval per call`,tool_budget:`The tool limit`,"audit.enabled":`The activity log`,"audit.hash_chain":`The tamper check`,"audit.record_args":`Recording inputs`,"audit.on_failure":`What happens if the log can't be written`,"tenant.on_mismatch":`Wrong-customer handling`,"tenant.required":`Requiring a customer`},pe={"read-only":`Only let it look`,"approve-writes":`Ask before changes`,locked:`Lock everything`,enforce:`Protecting`,observe:`Watch-only`};function me(e){let t=/^([\w.]+) goes from (.+) to (.+)$/.exec(e);if(t&&(fe[t[1]]||/^(egress|results|audit)\./.test(t[1]))){let e=fe[t[1]]??`The setting ${t[1]}`,n=e=>{let t=e.replace(/^"|"$/g,``);return pe[t]??t};return`${e} goes from ${n(t[2])} to ${n(t[3])}`}return e.replace(/\bfrom allow\b/g,`from Runs freely`).replace(/\bfrom approve\b/g,`from Asks you first`).replace(/\bfrom deny\b/g,`from Blocked`).replace(/\bto allow\b/g,`to Runs freely`).replace(/\bto approve\b/g,`to Asks you first`).replace(/\bto deny\b/g,`to Blocked`).replace(/\bsays allow\b/g,`lets tools run freely`).replace(/\bsays approve\b/g,`asks you first`).replace(/\bsaid allow\b/g,`let tools run freely`).replace(/\bsaid approve\b/g,`asked you first`).replace(/\bsaid deny\b/g,`blocked them`).replace(/\ba write tool\b/g,`a tool that makes changes`).replace(/\ba destructive tool\b/g,`a tool that deletes`).replace(/\ba read tool\b/g,`a tool that only looks`).replace(/argument bounds/g,`input limits`).replace(/within bounds/g,`within limits`).replace(/the tenant block/g,`customers`).replace(/`/g,``)}function he({serverId:e,tenant:t,canWrite:n,canLoosen:r,digestRef:i,reloadsLive:a,onWritten:o,onReload:s,children:c}){let l=B(),[u,d]=(0,W.useState)(null),[f,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(null),[v,y]=(0,W.useState)(!1),b=(0,W.useRef)(o);b.current=o;let x=(0,W.useCallback)((e,t)=>{i.current=e.digest,l.show(`ok`,t||!a?`Saved. The toolbox applies it the next time it starts.`:`Saved. The toolbox applies it within a second.`),e.warning&&l.show(`warn`,q(e.warning)),b.current()},[i,a,l]),S=(0,W.useCallback)(async(e,t,n={})=>{let i=()=>new Promise(r=>{g(null),d({copy:t,resolve:r,run:async()=>{let t=await e({loosens:!0});n.done?.(t),x(t,n.restart??!1)}})});if(n.knownLoosens)return r?i():(l.show(`bad`,q(`policy_overrides`)),!1);try{let t=await e();return n.done?.(t),x(t,n.restart??!1),!0}catch(e){return e instanceof p&&e.needsLoosenAck?i():e instanceof p&&e.status===409?(y(!0),!1):(l.show(`bad`,q(e.message)),!1)}},[r,x,l]),C=(0,W.useCallback)((n,r)=>S(a=>_.setPolicySetting(e,n,r,i.current,a,t),_e(n,r),{restart:!de(n)}),[i,S,e,t]),T=async()=>{if(u){m(!0);try{await u.run(),u.resolve(!0),d(null)}catch(e){e instanceof p&&e.status===409?(u.resolve(!1),d(null),y(!0)):g(q(e.message))}finally{m(!1)}}},ee={serverId:e,tenant:t,canWrite:n,canLoosen:r,digest:()=>i.current,guarded:S,saveSetting:C};return(0,G.jsxs)(ce.Provider,{value:ee,children:[c,(0,G.jsx)(w,{open:u!==null,title:u?.copy.title??``,consequences:u?.copy.consequences??[],confirmLabel:u?.copy.confirmLabel??`Save setting`,busy:f,error:h,onCancel:()=>{u?.resolve(!1),d(null)},onConfirm:T,children:u?.copy.body}),(0,G.jsx)(ae,{open:v,onClose:()=>y(!1),title:`These settings changed since you opened them`,description:`This changed since you opened it. Reload and try again. Someone else, or the settings file itself, made a change in the meantime, and saving now could undo it.`,footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(O,{variant:`secondary`,onClick:()=>y(!1),children:`Close`}),(0,G.jsx)(O,{variant:`primary`,icon:`refresh`,onClick:()=>{y(!1),s()},children:`Reload settings`})]})})]})}var ge=e=>Array.isArray(e)?e.join(`, `):String(e);function _e(e,t){let n=(e,t,n=`Save setting`)=>({title:e,body:`This lets more through than your settings do now.`,consequences:[t],confirmLabel:n});switch(e){case`enforcement`:return{title:`Switch to watch-only?`,body:`Your rules stop being applied. The activity log keeps noting what they would have done, so you can review it later.`,consequences:[`Every call runs, including calls your rules block.`,`Nothing waits for your approval.`,`Tools you turned off stay off.`],confirmLabel:`Switch to watch-only`};case`on_tool_change`:return n(`Keep serving changed tools?`,`A tool whose description or inputs change keeps working before anyone reviews it.`,`Keep serving changed tools`);case`defaults.mode`:return n(`Change the default stance?`,t===`approve-writes`?`Tools no rule mentions can make changes and delete things, once you approve each call.`:`Tools no rule mentions can look at information without asking.`,`Change default stance`);case`defaults.on_unclassified`:return n(`Ask about unlabelled tools instead of blocking them?`,`A tool nobody has labelled can run once you approve the call.`,`Ask me instead`);case`results.on_injection`:return n(`Let more tool answers through?`,t===`allow`?`Answers that contain hidden instructions reach your AI app with no warning attached.`:`Answers that contain hidden instructions reach your AI app, marked as untrusted.`,`Change what happens`);case`results.on_secret`:return n(`Let more tool answers through?`,t===`allow`?`Answers that contain a password or key reach your AI app, and nothing is noted in the log.`:`Answers that contain a password or key reach your AI app. The log notes each one.`,`Change what happens`);case`approvals.mode`:return n(`Change how you're asked?`,t===`cli`?`Calls that need approval can run once someone approves them in the console, instead of being blocked.`:`Requests can be answered from inside the AI app, which is a window the AI app itself controls.`,`Change how you're asked`);case`approvals.ttl_seconds`:return n(`Let requests wait longer?`,`A request stays open longer, so a call can be approved later than before.`);case`approvals.single_use`:return n(`Let one approval cover several calls?`,`One approval can release more than one identical call.`,`Allow repeat use`);case`tool_budget`:return n(`Raise the tool limit?`,`Your AI app can be shown more tools at once, which makes them harder to review.`,`Raise tool limit`);case`egress.allow`:return n(`Allow more websites?`,`Connected servers can reach more of the internet. The list becomes: ${ge(t)||`none`}.`,`Allow these websites`);case`egress.methods`:return n(`Allow more request types?`,`Connected servers can send these request types: ${ge(t)}. Types other than GET and HEAD can change things on other websites.`,`Allow these request types`);case`egress.max_body_bytes`:return n(`Allow bigger answers?`,`Connected servers can receive larger answers from websites.`);case`egress.max_request_body_bytes`:return n(`Allow bigger requests?`,`Connected servers can send more data out to websites.`);case`egress.timeout_ms`:return n(`Wait longer for websites?`,`A slow website can hold a call open for longer.`);case`egress.max_redirects`:return n(`Follow more redirects?`,`A website can send a request on to another address, which is then checked against your list again.`);case`egress.block_private_ips`:return n(`Allow your private network?`,`Connected servers can reach this computer and other devices on your own network.`,`Allow private network`);case`egress.allow_http`:return n(`Allow unencrypted requests?`,`Connected servers can send requests that anyone on the network path can read or alter.`,`Allow unencrypted requests`);case`egress.allow_ip_literals`:return n(`Allow raw IP addresses?`,`Connected servers can reach an address written as numbers, such as 203.0.113.5, rather than a website name.`,`Allow IP addresses`);case`audit.enabled`:return n(`Turn off the activity log?`,`Calls stop being recorded, so you could not see or prove what your AI did.`,`Turn off activity log`);case`audit.hash_chain`:return n(`Turn off the tamper check?`,`If someone edits or removes a log entry, nothing would show it.`,`Turn off tamper check`);case`audit.record_args`:return n(`Stop recording inputs?`,`The log no longer shows what each call was asked to do.`,`Stop recording inputs`);case`audit.redact`:return n(`Stop hiding these inputs?`,`Inputs with the names you removed are written to the log as they are, which may include secrets.`,`Stop hiding them`);case`audit.on_failure`:return n(`Run calls the log can't record?`,`If the log can't be written, calls still run, and nothing records them.`,`Run them anyway`);case`tenant.on_mismatch`:return n(`Replace the wrong customer instead of blocking?`,`A call that names the wrong customer is quietly corrected rather than stopped, so you won't see the attempt as a block.`,`Replace instead`);case`tenant.required`:return n(`Let the toolbox start without a customer?`,`The toolbox can start, and serve calls, without knowing which customer it is for.`,`Allow it`)}}var ve=(0,W.createContext)(null);function J({id:e,title:t,intro:n,actions:r,children:i}){let a=(0,W.useContext)(ve)===e;return(0,G.jsx)(`div`,{id:e,className:V(`scroll-mt-6 rounded-[var(--radius-card)] transition-shadow duration-300`,a&&`shadow-[0_0_0_3px_var(--focus)]`),children:(0,G.jsxs)(P,{title:t,titleId:`${e}-title`,actions:r,children:[n&&(0,G.jsx)(`p`,{className:`-mt-2 mb-5 max-w-3xl text-[14px] text-soft`,children:n}),i]})})}function Y({label:e,explain:t,yamlKey:n,saving:r,wide:i,children:a}){let{canWrite:o}=K(),s=o&&!de(n);return(0,G.jsxs)(`div`,{className:V(`grid gap-4 border-t border-faint py-5 first:border-t-0 first:pt-0 last:pb-0`,!i&&`md:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] md:gap-8`),children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:e}),(0,G.jsx)(`div`,{className:`mt-1 max-w-xl text-[13.5px] text-soft`,children:t}),(0,G.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[(0,G.jsx)(`code`,{className:`mono text-[11.5px] text-soft`,children:n}),s&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[12px] text-soft`,children:[(0,G.jsx)(h,{name:`refresh`,size:12,strokeWidth:2}),`Applies after a restart`]}),r&&(0,G.jsxs)(`span`,{role:`status`,className:`inline-flex items-center gap-1.5 text-[12px] font-medium text-muted`,children:[(0,G.jsx)(R,{size:12}),`Saving`]})]})]}),(0,G.jsx)(`div`,{className:`min-w-0`,children:a})]})}function X({label:e,value:t,options:n,onChange:r,disabled:i,columns:a=2,size:o=`md`}){return(0,G.jsx)(`div`,{role:`radiogroup`,"aria-label":e,onKeyDown:e=>{let t=e.key===`ArrowRight`||e.key===`ArrowDown`?1:e.key===`ArrowLeft`||e.key===`ArrowUp`?-1:0;if(!t)return;e.preventDefault();let n=[...e.currentTarget.querySelectorAll(`[role=radio]`)];n[(n.indexOf(document.activeElement)+t+n.length)%n.length]?.focus()},className:V(`grid gap-3`,a===2&&`sm:grid-cols-2`,a===3&&`md:grid-cols-3`,a===4&&`sm:grid-cols-2 xl:grid-cols-4`),children:n.map(e=>{let n=e.value===t;return(0,G.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,tabIndex:n?0:-1,disabled:i,onClick:()=>!n&&r(e.value),className:V(`group relative flex h-full flex-col items-start rounded-[18px] border-[1.5px] text-left transition-[border-color,background-color,transform] duration-150 ease-[var(--ease-out)]`,o===`md`?`p-5`:`px-4 py-3.5`,n?`border-[var(--primary)] bg-ok-tint`:`border-line bg-surface hover:border-[var(--soft)]`,i?`cursor-not-allowed`:`active:scale-[.99]`,i&&!n&&`opacity-60`),children:[(0,G.jsxs)(`span`,{className:`flex w-full items-start gap-3`,children:[e.icon&&o===`md`&&(0,G.jsx)(`span`,{className:V(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,n?`bg-primary text-white`:`bg-sunken text-muted`),children:(0,G.jsx)(h,{name:e.icon,size:20})}),(0,G.jsx)(`span`,{className:V(`min-w-0 flex-1 font-semibold`,o===`md`?`pt-2 text-[16px]`:`text-[14px]`),children:e.title}),(0,G.jsx)(`span`,{"aria-hidden":!0,className:V(`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-full border-[1.5px]`,n?`border-[var(--primary)] bg-primary text-white`:`border-line`),children:n&&(0,G.jsx)(h,{name:`check`,size:12,strokeWidth:3})})]}),e.body&&(0,G.jsx)(`span`,{className:V(`block text-[13px] text-muted`,o===`md`?`mt-3`:`mt-1`),children:e.body})]},e.value)})})}function Z(e,t){let n=K(),[r,i]=(0,W.useState)(null);return{value:r??t,saving:r!==null,choose:async t=>{i(t),await n.saveSetting(e,t),i(null)},disabled:!n.canWrite||r!==null}}function Q({path:e,label:t,explain:n,checked:r,on:i,off:a}){let o=Z(e,r);return(0,G.jsx)(Y,{label:t,explain:n,yamlKey:e,saving:o.saving,children:(0,G.jsx)(`div`,{className:`rounded-2xl bg-sunken px-4 py-3`,children:(0,G.jsx)(f,{checked:o.value,onChange:e=>void o.choose(e),disabled:o.disabled,label:(0,G.jsx)(`span`,{className:`sr-only`,children:t}),description:(0,G.jsx)(`span`,{className:`text-[13.5px] font-medium text-ink`,children:o.value?i:a})})})})}function ye(e,t){let n=K(),[r,i]=(0,W.useState)(t),[a,o]=(0,W.useState)(!1),s=JSON.stringify(t),c=(0,W.useRef)(s);return(0,W.useEffect)(()=>{c.current!==s&&(c.current=s,i(t))},[s]),{draft:r,setDraft:i,dirty:JSON.stringify(r)!==s,saving:a,save:async(t=r)=>{o(!0),await n.saveSetting(e,t),o(!1)},reset:()=>i(t),disabled:!n.canWrite||a}}function be({dirty:e,saving:t,invalid:n,onSave:r,onReset:i}){return!e&&!t?null:(0,G.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,G.jsx)(O,{variant:`primary`,size:`sm`,icon:`check`,onClick:r,loading:t,disabled:n,children:`Save setting`}),(0,G.jsx)(O,{variant:`ghost`,size:`sm`,onClick:i,disabled:t,children:`Undo edit`})]})}function xe({children:e}){return(0,G.jsxs)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:[`Saved value: `,e]})}function $({path:e,label:t,explain:n,current:r,units:a,min:o=1,max:s,show:c}){let l=ye(e,r),u=()=>[...a].reverse().find(e=>r%e.size===0)??a[0],[d,f]=(0,W.useState)(u),[p,m]=(0,W.useState)(r/d.size),h=`${r}`,g=(0,W.useRef)(h);(0,W.useEffect)(()=>{if(g.current!==h){g.current=h;let e=u();f(e),m(r/e.size)}},[h]);let _=p===null?null:Math.round(p*d.size),v=_===null||!Number.isFinite(_)||_<o||s!==void 0&&_>s,y=_!==r,b=(0,W.useId)();return(0,G.jsxs)(Y,{label:t,explain:n,yamlKey:e,saving:l.saving,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(i,{id:b,"aria-label":t,value:p,onChange:m,min:0,disabled:l.disabled,className:`w-36`}),a.length>1?(0,G.jsx)(k,{"aria-label":`${t} unit`,value:d.label,onChange:e=>{let t=a.find(t=>t.label===e);_!==null&&m(Number((_/t.size).toFixed(3))),f(t)},options:a.map(e=>({value:e.label,label:e.label})),disabled:l.disabled,className:`w-28`}):(0,G.jsx)(`span`,{className:`text-[13.5px] text-soft`,children:a[0].label})]}),y&&v&&(0,G.jsx)(`p`,{role:`alert`,className:`mt-2 text-[12.5px] font-medium text-bad`,children:s===void 0?`Use a number of at least ${c(o)}.`:`Use a whole number from ${c(o)} to ${c(s)}.`}),(0,G.jsx)(xe,{children:c(r)}),(0,G.jsx)(be,{dirty:y,saving:l.saving,invalid:v,onSave:()=>_!==null&&void l.save(_),onReset:()=>{f(u()),m(r/u().size)}})]})}function Se(e,t){let n=`^`,r=0;for(let t of e)t===`*`?n+=`.*`:t===`?`?n+=`.`:t===`{`?(n+=`(?:`,r++):t===`}`&&r>0?(n+=`)`,r--):n+=t===`,`&&r>0?`|`:t.replace(/[.+^${}()|[\]\\]/g,`\\$&`);try{return RegExp(n+`$`).test(t)}catch{return!1}}function Ce({changes:t,reasons:n,live:r}){return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[t.length===0?(0,G.jsx)(`p`,{className:`rounded-2xl bg-sunken px-4 py-3 text-[13.5px] text-muted`,children:r?`No tool's outcome changes. Tools the toolbox serves today are decided the same way as before.`:`The toolbox is not reporting its tools right now, so the console cannot list which tools this affects.`}):(0,G.jsx)(`ul`,{className:`divide-y divide-[var(--faint)] rounded-2xl border border-line`,"aria-label":`What changes`,children:t.map(t=>(0,G.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3`,children:[(0,G.jsx)(`code`,{className:`mono min-w-0 flex-1 basis-40 text-[13px] break-all`,children:t.tool}),(0,G.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[t.before===t.after?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(E,{decision:t.after}),(0,G.jsx)(`span`,{className:`text-[12.5px] text-soft`,children:`with different input limits`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(E,{decision:t.before}),(0,G.jsx)(h,{name:`arrow-right`,size:16,className:`text-soft`,label:`becomes`}),(0,G.jsx)(E,{decision:t.after})]}),t.loosens&&(0,G.jsx)(e,{tone:`bad`,children:`Lets more through`})]})]},t.tool))}),n.length>0&&(0,G.jsxs)(`div`,{className:`rounded-2xl bg-bad-tint px-4 py-3 text-[13.5px]`,children:[(0,G.jsx)(`p`,{className:`font-semibold text-bad`,children:`This lets more through:`}),(0,G.jsx)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-5 text-ink`,children:n.map(e=>(0,G.jsx)(`li`,{children:me(e)},e))})]})]})}function we({live:e}){let t=K(),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,v]=(0,W.useState)(null),y=async()=>{l(!0),a(null);try{let e=await _.policyFile(t.serverId,t.tenant);r(e),d(e.text??``),p(null)}catch(e){a(q(e.message))}finally{l(!1)}},b=n?.text??``,x=u!==b,S=f?.text===u?f.result:null,C=!t.canWrite||!n?.writable.ok;return(0,G.jsx)(J,{id:`file`,title:`Edit settings file (advanced)`,intro:`Every setting on this page lives in one file. Edit it as text when you need something the controls above don't offer. The console checks your edit before saving, and a file with a mistake is never saved.`,children:n?n.text===null?(0,G.jsx)(c,{tone:`danger`,title:`The settings file could not be read`,children:n.readError?q(n.readError):`The toolbox's settings are written inside its own configuration, so there is no separate file to edit.`}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Text patterns (regular expressions) can't be added from here, because a badly written one can slow every call down. Patterns already in the file can stay or be removed.`}),(0,G.jsx)(j,{label:`Settings file`,value:u,onChange:d,readOnly:C,rows:20}),!C&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,G.jsx)(O,{onClick:async()=>{h(`preview`),v(null);try{p({text:u,result:await _.previewPolicyFile(t.serverId,u,t.tenant)})}catch(e){v(q(e.message))}finally{h(null)}},loading:m===`preview`,disabled:!x||m!==null,icon:`eye`,children:`Preview changes`}),(0,G.jsx)(O,{variant:`primary`,icon:`check`,onClick:async()=>{if(!S||!n)return;h(`save`);let e=await t.guarded(e=>_.writePolicyFile(t.serverId,u,S.expectedDigest,e,t.tenant),{title:`Save a settings file that lets more through?`,body:`After this change, some calls that are blocked or held today would run.`,consequences:S.loosenReasons.length?S.loosenReasons.map(me):[`Some settings would be less strict.`],confirmLabel:`Save file`},{knownLoosens:S.loosens});h(null),e&&await y()},loading:m===`save`,disabled:!S?.valid||m!==null,children:`Save file`}),(0,G.jsx)(O,{variant:`ghost`,onClick:()=>d(b),disabled:!x||m!==null,children:`Discard edits`})]}),g&&(0,G.jsx)(c,{tone:`danger`,children:g}),m===`preview`&&(0,G.jsx)(s,{lines:4,height:16}),S&&(0,G.jsx)(`div`,{className:`space-y-4 rounded-2xl border border-line p-4`,children:S.valid?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`mb-2 text-[14px] font-semibold`,children:`Lines you changed`}),(0,G.jsx)(te,{before:b,after:u,label:`Lines you changed`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`mb-2 text-[14px] font-semibold`,children:`What changes for your tools`}),(0,G.jsx)(Ce,{changes:S.changes,reasons:S.loosenReasons,live:e})]})]}):(0,G.jsx)(c,{tone:`danger`,title:`This file has a mistake, so it can't be saved`,role:`alert`,children:(0,G.jsx)(`pre`,{className:`mt-1 font-mono text-[12.5px] whitespace-pre-wrap`,children:q(S.error??``)})})}),x&&!S&&m===null&&(0,G.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`Preview your changes to save them.`})]}):(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsx)(O,{icon:`file`,onClick:y,loading:o,children:`Open settings file`}),i&&(0,G.jsx)(`div`,{className:`basis-full`,children:(0,G.jsx)(c,{tone:`danger`,actions:(0,G.jsx)(O,{size:`sm`,onClick:y,children:`Try again`}),children:i})})]})})}var Te={read:`only look`,write:`make changes`,destructive:`delete`},Ee={deny:`blocked`,approve:`held for you`},De={allow:`allowed`,approve:`held for you`,deny:`blocked`};function Oe(e,t){let n=[];return t.min!==void 0&&t.max!==void 0?n.push(`${t.min} to ${t.max}`):t.max===void 0?t.min!==void 0&&n.push(`at least ${t.min}`):n.push(`at most ${t.max}`),t.maxLength!==void 0&&n.push(`up to ${t.maxLength} characters`),t.maxItems!==void 0&&n.push(`up to ${t.maxItems} items`),t.enum&&n.push(`one of ${t.enum.map(String).join(`, `)}`),t.within&&n.push(`inside ${String(t.within)}`),Array.isArray(t.host)&&n.push(`only ${t.host.join(`, `)}`),t.pattern&&n.push(`matching a text pattern`),t.optional&&n.push(`may be left out`),`${e}: ${n.join(`, `)||`limited`}`}function ke(e,t){return{title:`Make a change that lets more through?`,body:`After this change, some calls that are blocked or held today would run.`,consequences:e.loosenReasons.length?e.loosenReasons.map(me):[`Some tools would be decided less strictly.`],confirmLabel:t}}function Ae({p:e,full:t,fullError:n}){let r=K(),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),l=(0,W.useMemo)(()=>new Map((t??[]).map(e=>[e.id,e])),[t]),u=e.rules,d=u.map(e=>e.id),f=e.surface.live,p=(e,t)=>{let n=[...d];[n[e],n[e+t]]=[n[e+t],n[e]],s({body:{op:`order`,order:n},title:`Move ${d[e]} ${t<0?`up`:`down`}?`,confirm:t<0?`Move rule up`:`Move rule down`})};return(0,G.jsxs)(J,{id:`rules`,title:`Rules`,intro:(0,G.jsxs)(G.Fragment,{children:[`Rules are checked from the top. The first rule that matches a tool decides what happens to it, so order matters. `,(0,G.jsx)(S,{term:`rule`})]}),actions:r.canWrite&&(0,G.jsx)(O,{variant:`primary`,size:`sm`,icon:`plus`,onClick:()=>a({mode:`add`}),disabled:!t,children:`Add rule`}),children:[n&&(0,G.jsx)(`div`,{className:`mb-4`,children:(0,G.jsxs)(c,{tone:`warn`,children:[`The rules could not be read in full, so they can't be edited right now. `,q(n)]})}),u.length===0?(0,G.jsx)(b,{compact:!0,icon:`list`,title:`No rules yet`,actions:r.canWrite&&(0,G.jsx)(O,{variant:`primary`,icon:`plus`,onClick:()=>a({mode:`add`}),disabled:!t,children:`Add rule`}),children:`Every call is decided by the default stance above. Add a rule to treat some tools differently.`}):(0,G.jsx)(`ol`,{className:`space-y-3`,"aria-label":`Rules, in the order they are checked`,children:u.map((e,t)=>(0,G.jsx)(je,{r:e,index:t,count:u.length,live:f,full:l.get(e.id),canEdit:r.canWrite&&l.has(e.id),onEdit:()=>a({mode:`edit`,rule:l.get(e.id)}),onDelete:()=>s({body:{op:`delete`,ruleId:e.id},title:`Delete ${e.id}?`,confirm:`Delete rule`}),onMove:e=>p(t,e)},e.id))}),i&&t&&(0,G.jsx)(Re,{rule:i.mode===`edit`?i.rule:null,rules:t,tools:e.tools.map(e=>e.name),live:f,onClose:()=>a(null)},i.mode===`edit`?i.rule.id:`add`),o&&(0,G.jsx)(Me,{...o,live:f,onClose:()=>s(null)})]})}function je({r:e,full:t,index:r,count:i,live:a,canEdit:o,onEdit:s,onDelete:c,onMove:l}){let[u,d]=(0,W.useState)(!1),f=u?e.matchedTools:e.matchedTools.slice(0,6),p=e.effect,m=t?.args?Object.entries(t.args).map(([e,t])=>Oe(e,t)):e.argConstraints;return(0,G.jsx)(`li`,{className:`rounded-[18px] border-[1.5px] border-line bg-surface p-4 sm:p-5`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-4 gap-y-3`,children:[(0,G.jsx)(`span`,{className:`tnum grid h-8 w-8 shrink-0 place-items-center rounded-full bg-sunken text-[13px] font-bold`,"aria-label":`Position ${r+1}`,children:r+1}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64`,children:[(0,G.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1.5 text-[15px] leading-snug`,children:[(0,G.jsx)(`code`,{className:`mono rounded-md bg-sunken px-1.5 py-0.5 text-[13px] break-all`,children:e.match}),p&&Te[p]&&(0,G.jsxs)(`span`,{children:[`that `,Te[p]]}),(0,G.jsx)(h,{name:`arrow-right`,size:16,className:`text-soft`,label:`then`}),(0,G.jsx)(E,{decision:e.decision})]}),(0,G.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[12.5px] text-soft`,children:[(0,G.jsx)(`code`,{className:`mono text-[11.5px]`,children:e.id}),p&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Labels them `,(0,G.jsx)(x,{effect:p,withLabel:!0})]})]}),e.reason&&(0,G.jsxs)(`p`,{className:`mt-2 text-[13.5px] text-muted`,children:[`“`,e.reason,`”`]}),m.length>0&&(0,G.jsxs)(`div`,{className:`mt-3 text-[13px]`,children:[(0,G.jsx)(`span`,{className:`text-soft`,children:`Input limits: `}),(0,G.jsx)(`span`,{className:`inline-flex flex-wrap gap-1.5 align-middle`,children:m.map(e=>(0,G.jsx)(`span`,{className:`rounded-md bg-sunken px-2 py-0.5 text-[12.5px] text-ink`,children:e},e))}),(0,G.jsxs)(`p`,{className:`mt-1 text-soft`,children:[`Calls outside the limits are`,` `,Ee[e.onViolation]??e.onViolation,`. Other inputs are`,` `,De[e.unknownArgs]??e.unknownArgs,`.`]})]}),(0,G.jsx)(`div`,{className:`mt-3 text-[13px]`,children:e.matchedTools.length===0?(0,G.jsx)(`span`,{className:`text-soft`,children:a?`Matches no tool the toolbox serves right now.`:`The toolbox is not reporting its tools, so matches are unknown.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-soft`,children:[`Applies to `,n(e.matchedTools.length,`tool`),`:`,` `]}),(0,G.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1.5 align-middle`,children:[f.map(e=>(0,G.jsx)(`code`,{className:`mono rounded-full border border-line px-2 py-0.5 text-[12px]`,children:e},e)),e.matchedTools.length>6&&(0,G.jsx)(`button`,{type:`button`,className:`text-[12.5px] font-semibold text-ink underline underline-offset-2`,onClick:()=>d(!u),children:u?`Show fewer`:`Show ${e.matchedTools.length-6} more`})]})]})}),e.shadowedBy&&(0,G.jsxs)(`p`,{className:`mt-3 flex items-start gap-1.5 text-[13px] text-warn`,children:[(0,G.jsx)(h,{name:`warning`,size:15,className:`mt-0.5 shrink-0`,strokeWidth:2}),(0,G.jsxs)(`span`,{children:[`Never used:`,` `,(0,G.jsx)(`code`,{className:`mono text-[12px]`,children:e.shadowedBy}),` is higher up and matches these tools first.`]})]})]}),o&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 max-sm:w-full max-sm:justify-end`,children:[(0,G.jsx)(D,{icon:`chevron`,className:`rotate-180`,label:`Move ${e.id} up`,size:36,variant:`soft`,disabled:r===0,onClick:()=>l(-1)}),(0,G.jsx)(D,{icon:`chevron`,label:`Move ${e.id} down`,size:36,variant:`soft`,disabled:r===i-1,onClick:()=>l(1)}),(0,G.jsx)(O,{size:`sm`,icon:`edit`,onClick:s,"aria-label":`Edit rule ${e.id}`,children:`Edit`}),(0,G.jsx)(D,{icon:`trash`,label:`Delete rule ${e.id}`,size:36,onClick:c})]})]})})}function Me({body:e,title:t,confirm:n,live:r,onClose:i}){let a=K(),[o,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{_.previewRules(a.serverId,e,a.tenant).then(l,e=>d(q(e.message)))},[]),(0,G.jsxs)(ae,{open:!0,onClose:i,title:t,width:600,description:e.op===`delete`?`The rule is removed from the settings file. Tools it decided fall through to the next matching rule, or to the default stance.`:`Rules are checked from the top, so moving one can change which rule decides a tool.`,footer:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(O,{variant:`secondary`,onClick:i,disabled:f,children:`Cancel`}),(0,G.jsx)(O,{variant:e.op===`delete`?`danger`:`primary`,onClick:async()=>{if(!o)return;p(!0);let t=await a.guarded(t=>e.op===`delete`?_.deleteRule(a.serverId,e.ruleId,o.expectedDigest,t,a.tenant):_.orderRules(a.serverId,e.order,o.expectedDigest,t,a.tenant),ke(o,n),{knownLoosens:o.loosens});p(!1),t&&i()},loading:f,disabled:!o,children:n})]}),children:[(0,G.jsx)(`h3`,{className:`mb-2 text-[14px] font-semibold`,children:`What changes`}),u?(0,G.jsx)(c,{tone:`danger`,children:u}):o?(0,G.jsx)(Ce,{changes:o.changes,reasons:o.loosenReasons,live:r}):(0,G.jsx)(s,{lines:3,height:18})]})}var Ne=[`max`,`min`,`maxLength`,`maxItems`,`enum`,`optional`],Pe=1;function Fe(e,t){let n={};for(let[e,r]of Object.entries(t))Ne.includes(e)||(n[e]=r);return{key:Pe++,path:e,max:t.max??null,min:t.min??null,maxLength:t.maxLength??null,maxItems:t.maxItems??null,values:(t.enum??[]).map(String),typed:t.enum??[],optional:!!t.optional,extra:n}}function Ie(e){let t={...e.extra};return e.max!==null&&(t.max=e.max),e.min!==null&&(t.min=e.min),e.maxLength!==null&&(t.maxLength=e.maxLength),e.maxItems!==null&&(t.maxItems=e.maxItems),e.values.length&&(t.enum=e.values.map(t=>e.typed.find(e=>String(e)===t)??t)),e.optional&&(t.optional=!0),t}var Le={pattern:`a text pattern`,coerce:`number conversion`,within:`a folder`,host:`allowed websites`,required:`required`,sum_max:`a total`,count_max:`a count`,const:`a fixed value`};function Re({rule:e,rules:t,tools:r,live:i,onClose:o}){let s=K(),l=e===null,[u,f]=(0,W.useState)(e?.id??``),[p,h]=(0,W.useState)(e?.match??``),[g,v]=(0,W.useState)(e?.effect??``),[y,b]=(0,W.useState)(e?.decision??`approve`),[x,C]=(0,W.useState)(()=>Object.entries(e?.args??{}).map(([e,t])=>Fe(e,t))),[w,T]=(0,W.useState)(e?.on_violation??`deny`),[E,te]=(0,W.useState)(e?.unknown_args??`allow`),[D,ne]=(0,W.useState)(e?.reason??``),[A,j]=(0,W.useState)(t.length),[M,N]=(0,W.useState)(null),[P,I]=(0,W.useState)(null),[L,R]=(0,W.useState)(!1),z=(0,W.useMemo)(()=>p.trim()?r.filter(e=>Se(p.trim(),e)):[],[p,r]),ie=l?u.trim()?/\s/.test(u)?`Use no spaces, for example ask-before-writes.`:t.some(e=>e.id===u.trim())?`Another rule already has this name.`:null:`Give the rule a short name.`:null,B=p.trim()?null:`Say which tools this rule is for.`,V=x.map(e=>e.path.trim()?x.filter(t=>t.path.trim()===e.path.trim()).length>1?`This input is listed twice.`:e.maxLength!==null&&(e.maxLength<1||!Number.isInteger(e.maxLength))?`Longest text must be a whole number of at least 1.`:e.maxItems!==null&&(e.maxItems<0||!Number.isInteger(e.maxItems))?`Most items must be a whole number.`:null:`Name the input.`),oe=!!ie||!!B||V.some(Boolean),H=()=>{let t={id:l?u.trim():e.id,match:p.trim(),decision:y};return g&&(t.effect=g),x.length?(t.args=Object.fromEntries(x.map(e=>[e.path.trim(),Ie(e)])),t.on_violation=w,t.unknown_args=E):l||(e.on_violation&&(t.on_violation=e.on_violation),e.unknown_args&&(t.unknown_args=e.unknown_args)),D.trim()&&(t.reason=D.trim()),t},U=e=>t=>{e(t),N(null),I(null)},se=async()=>{R(!0),I(null);try{let t=l?{op:`add`,rule:H(),index:A}:{op:`set`,ruleId:e.id,rule:H()};N(await _.previewRules(s.serverId,t,s.tenant))}catch(e){I(q(e.message))}finally{R(!1)}},ce=async()=>{if(!M)return;R(!0);let t=H(),n=await s.guarded(n=>l?_.addRule(s.serverId,t,M.expectedDigest,A,n,s.tenant):_.setRule(s.serverId,e.id,t,M.expectedDigest,n,s.tenant),ke(M,`Save rule`),{knownLoosens:M.loosens});R(!1),n&&o()},le=(e,t)=>U(C)(x.map(n=>n.key===e?{...n,...t}:n));return(0,G.jsx)(ae,{open:!0,onClose:o,dismissable:!L,width:720,title:l?`Add a rule`:`Edit rule`,description:M?`Check what this does to your tools, then save it.`:`Say which tools this is for and what should happen when your AI calls them.`,footer:M?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(O,{variant:`ghost`,icon:`arrow-left`,onClick:()=>N(null),disabled:L,children:`Back to the rule`}),(0,G.jsx)(O,{variant:`primary`,icon:`check`,onClick:ce,loading:L,children:`Save rule`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(O,{variant:`secondary`,onClick:o,disabled:L,children:`Cancel`}),(0,G.jsx)(O,{variant:`primary`,onClick:se,loading:L,disabled:oe,children:`Preview changes`})]}),children:M?(0,G.jsxs)(`div`,{className:`space-y-5 pb-1`,children:[(0,G.jsx)(Ce,{changes:M.changes,reasons:M.loosenReasons,live:i}),M.yaml&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`mb-2 text-[13px] font-semibold text-soft`,children:`As it will be written in the settings file`}),(0,G.jsx)(ee,{label:`The rule as written`,children:M.yaml})]})]}):(0,G.jsxs)(`div`,{className:`space-y-5 pb-1`,children:[P&&(0,G.jsx)(c,{tone:`danger`,children:P}),l?(0,G.jsx)(a,{label:`Rule name`,help:`Shown in the activity log next to every call this rule decides.`,error:u?ie:null,children:(0,G.jsx)(d,{value:u,onChange:U(f),mono:!0,placeholder:`ask-before-writes`})}):(0,G.jsxs)(`p`,{className:`text-[13.5px] text-soft`,children:[`Rule name`,` `,(0,G.jsx)(`code`,{className:`mono ml-1 rounded-md bg-sunken px-1.5 py-0.5 text-[12.5px] text-ink`,children:e.id}),(0,G.jsx)(`span`,{className:`block text-[12.5px]`,children:`The name cannot be changed, because the activity log refers to it.`})]}),(0,G.jsx)(a,{label:`Which tools`,technical:`match`,help:(0,G.jsxs)(G.Fragment,{children:[`A tool name, or a pattern where * stands for any text, such as fs.* or *__delete_*.`,` `,p.trim()&&(z.length?`Matches ${n(z.length,`tool`)}: ${z.slice(0,5).join(`, `)}${z.length>5?`…`:``}`:`Matches no tool served right now.`)]}),error:p?B:null,children:(0,G.jsx)(d,{value:p,onChange:U(h),mono:!0,placeholder:`notes__create_*`})}),(0,G.jsx)(a,{label:`What should happen`,technical:`decision`,children:(0,G.jsx)(m,{label:`What should happen`,value:y,onChange:U(b),options:[`allow`,`approve`,`deny`].map(e=>({value:e,label:re[e].label}))})}),(0,G.jsx)(a,{label:`What these tools do`,technical:`effect`,help:`Labels the matching tools. The label decides how the default stance and your safety check treat them.`,optional:!0,children:(0,G.jsx)(k,{value:g,onChange:U(v),options:[{value:``,label:`Leave as the tool describes itself`},{value:`read`,label:`${F.read.label}: ${F.read.explain}`},{value:`write`,label:`${F.write.label}: ${F.write.explain}`},{value:`destructive`,label:`${F.destructive.label}: ${F.destructive.explain}`}]})}),(0,G.jsxs)(`fieldset`,{className:`rounded-2xl border border-line p-4`,children:[(0,G.jsxs)(`legend`,{className:`px-1 text-[13px] font-semibold`,children:[`Input limits `,(0,G.jsx)(S,{term:`limits`})]}),(0,G.jsx)(`p`,{className:`mb-3 text-[12.5px] text-soft`,children:`Allowed values for the tool's inputs. Text patterns can't be added from here; ones already in the settings file are kept as they are.`}),(0,G.jsx)(`div`,{className:`space-y-3`,children:x.map((e,t)=>(0,G.jsx)(ze,{a:e,error:V[t]??null,onChange:t=>le(e.key,t),onRemove:()=>U(C)(x.filter(t=>t.key!==e.key))},e.key))}),(0,G.jsx)(O,{size:`sm`,variant:`ghost`,icon:`plus`,className:`mt-2`,onClick:()=>U(C)([...x,{key:Pe++,path:``,max:null,min:null,maxLength:null,maxItems:null,values:[],typed:[],optional:!1,extra:{}}]),children:`Add a limit`}),x.length>0&&(0,G.jsxs)(`div`,{className:`mt-4 grid gap-4 border-t border-faint pt-4 sm:grid-cols-2`,children:[(0,G.jsx)(a,{label:`A call outside the limits`,technical:`on_violation`,children:(0,G.jsx)(m,{label:`A call outside the limits`,size:`sm`,value:w,onChange:U(T),options:[{value:`deny`,label:`Block it`},{value:`approve`,label:`Ask me`}]})}),(0,G.jsx)(a,{label:`Inputs no limit mentions`,technical:`unknown_args`,children:(0,G.jsx)(m,{label:`Inputs no limit mentions`,size:`sm`,value:E,onChange:U(te),options:[{value:`allow`,label:`Allow`},{value:`approve`,label:`Ask me`},{value:`deny`,label:`Block`}]})})]})]}),(0,G.jsx)(a,{label:`Why this rule exists`,technical:`reason`,optional:!0,help:`A note for whoever reads the settings later.`,children:(0,G.jsx)(d,{value:D,onChange:U(ne)})}),l&&(0,G.jsx)(a,{label:`Where in the list`,help:`Rules higher up are checked first.`,children:(0,G.jsx)(k,{value:String(A),onChange:e=>U(j)(Number(e)),options:[...t.length?[{value:`0`,label:`At the top, checked first`}]:[],...t.slice(0,-1).map((e,t)=>({value:String(t+1),label:`After ${e.id}`})),{value:String(t.length),label:t.length?`At the end, after ${t[t.length-1].id}`:`First rule`}]})})]})})}function ze({a:n,error:r,onChange:o,onRemove:s}){let c=Object.keys(n.extra);return(0,G.jsxs)(`div`,{className:`rounded-xl bg-sunken p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,G.jsx)(a,{label:`Input name`,className:`min-w-0 flex-1`,error:r,children:(0,G.jsx)(d,{value:n.path,onChange:e=>o({path:e}),mono:!0,placeholder:`body`})}),(0,G.jsx)(D,{icon:`x`,label:`Remove the limit on ${n.path||`this input`}`,size:36,onClick:s})]}),(0,G.jsxs)(`div`,{className:`mt-3 grid grid-cols-2 gap-3 md:grid-cols-4`,children:[(0,G.jsx)(a,{label:`Largest number`,children:(0,G.jsx)(i,{value:n.max,onChange:e=>o({max:e})})}),(0,G.jsx)(a,{label:`Smallest number`,children:(0,G.jsx)(i,{value:n.min,onChange:e=>o({min:e})})}),(0,G.jsx)(a,{label:`Longest text`,children:(0,G.jsx)(i,{value:n.maxLength,onChange:e=>o({maxLength:e}),min:1,unit:`chars`})}),(0,G.jsx)(a,{label:`Most items`,children:(0,G.jsx)(i,{value:n.maxItems,onChange:e=>o({maxItems:e}),min:0})})]}),(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(a,{label:`Only these values`,optional:!0,children:(0,G.jsx)(t,{value:n.values,onChange:e=>o({values:e}),placeholder:`Type a value and press Enter`})})}),(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(z,{checked:n.optional,onChange:e=>o({optional:e}),label:`The AI may leave this input out`,description:`Otherwise a call without it is outside the limits.`})}),c.length>0&&(0,G.jsxs)(`p`,{className:`mt-3 flex items-center gap-1.5 text-[12.5px] text-soft`,children:[(0,G.jsx)(e,{tone:`neutral`,icon:`lock`,children:`Kept as written`}),c.map(e=>Le[e]??e).join(`, `)]})]})}function Be({p:e,nav:t}){let n=Z(`enforcement`,e.enforcement);return(0,G.jsx)(J,{id:`mode`,title:`Mode`,intro:`Whether the toolbox applies your settings, or only watches and notes what it would have done.`,children:(0,G.jsxs)(Y,{label:`Protection mode`,explain:(0,G.jsxs)(G.Fragment,{children:[`Watch-only is for learning what your AI does before you set rules.`,` `,(0,G.jsx)(S,{term:`watchOnly`})]}),yamlKey:`enforcement`,saving:n.saving,wide:!0,children:[(0,G.jsx)(X,{label:`Protection mode`,value:n.value,onChange:e=>void n.choose(e),disabled:n.disabled,options:[{value:`enforce`,title:`Protecting`,icon:`shield-check`,body:(0,G.jsxs)(`ul`,{className:`space-y-1`,children:[(0,G.jsx)(`li`,{children:`Blocked calls stop before they reach the tool.`}),(0,G.jsx)(`li`,{children:`Calls that need you wait for your approval.`}),(0,G.jsx)(`li`,{children:`Everything is written to the activity log.`})]})},{value:`observe`,title:`Watch-only`,icon:`eye`,body:(0,G.jsxs)(`ul`,{className:`space-y-1`,children:[(0,G.jsx)(`li`,{children:`Every call runs, even ones your rules would block.`}),(0,G.jsx)(`li`,{children:`Nothing waits for you.`}),(0,G.jsx)(`li`,{children:`The log notes what would have happened. Tools you turned off stay off.`})]})}]}),n.value===`observe`&&(0,G.jsx)(`div`,{className:`mt-4`,children:(0,G.jsx)(c,{tone:`warn`,title:`Your AI is not being protected right now`,actions:(0,G.jsx)(C,{href:r(t,`/suggestions`),variant:`secondary`,size:`sm`,icon:`lightbulb`,children:`See suggested rules`}),children:`Suggestions turns what watch-only saw into rules, so you can switch protection on without blocking work you rely on.`})})]})})}var Ve={"read-only":[`allow`,`deny`,`deny`],"approve-writes":[`allow`,`approve`,`approve`],locked:[`deny`,`deny`,`deny`]},He={allow:`run`,approve:`ask you first`,deny:`are blocked`};function Ue({stance:e}){let[t,n,r]=Ve[e],i=(e,t)=>(0,G.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(v,{decision:t}),(0,G.jsxs)(`span`,{children:[e,` `,He[t]]})]});return(0,G.jsxs)(`span`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`block`,children:L[e].explain}),(0,G.jsxs)(`ul`,{className:`mt-3 space-y-1.5`,children:[i(`Tools that look`,t),i(`Tools that make changes`,n),i(`Tools that delete`,r)]})]})}function We({p:e}){let t=Z(`defaults.mode`,e.defaults.mode??`read-only`),r=Z(`defaults.on_unclassified`,e.defaults.onUnclassified),i=Z(`on_tool_change`,e.onToolChange);return(0,G.jsxs)(J,{id:`stance`,title:`Default stance`,intro:`What happens to a call that none of your rules mention. Rules always come first.`,children:[(0,G.jsx)(Y,{label:`For tools no rule mentions`,explain:(0,G.jsxs)(G.Fragment,{children:[`Choose how careful to be by default. `,(0,G.jsx)(S,{term:`defaultStance`})]}),yamlKey:`defaults.mode`,saving:t.saving,wide:!0,children:(0,G.jsx)(X,{label:`Default stance`,columns:3,value:t.value,onChange:e=>void t.choose(e),disabled:t.disabled,options:[{value:`read-only`,title:`Only let it look`,icon:`eye`,body:(0,G.jsx)(Ue,{stance:`read-only`})},{value:`approve-writes`,title:`Ask before changes`,icon:`clock`,body:(0,G.jsx)(Ue,{stance:`approve-writes`})},{value:`locked`,title:`Lock everything`,icon:`lock`,body:(0,G.jsx)(Ue,{stance:`locked`})}]})}),(0,G.jsx)(Y,{label:`Tools nobody has labelled`,explain:(0,G.jsxs)(G.Fragment,{children:[`A tool that nobody has marked as looking, changing or deleting.`,` `,e.surface.unclassifiedCount>0&&(0,G.jsxs)(`strong`,{className:`font-semibold text-ink`,children:[n(e.surface.unclassifiedCount,`tool`),` like this right now.`,` `]}),(0,G.jsx)(S,{term:`unknownTools`})]}),yamlKey:`defaults.on_unclassified`,saving:r.saving,children:(0,G.jsx)(X,{label:`Tools nobody has labelled`,size:`sm`,value:r.value,onChange:e=>void r.choose(e),disabled:r.disabled,options:[{value:`deny`,title:`Block them`,body:`Nothing unlabelled runs. The safest choice.`},{value:`approve`,title:`Ask me`,body:`Each call waits for you to approve or block it.`}]})}),(0,G.jsx)(Y,{label:`When a tool changes after you reviewed it`,explain:(0,G.jsxs)(G.Fragment,{children:[`A tool's description or inputs can change when its server is updated, or when someone changes what it does without telling you.`,` `,(0,G.jsx)(S,{term:`changedTools`})]}),yamlKey:`on_tool_change`,saving:i.saving,children:(0,G.jsx)(X,{label:`When a tool changes after you reviewed it`,size:`sm`,value:i.value,onChange:e=>void i.choose(e),disabled:i.disabled,options:[{value:`warn`,title:`Warn me`,body:`The tool keeps working, and the change is listed for you to review.`},{value:`deny`,title:`Block it until I review`,body:`The tool is held back until you accept the change.`}]})})]})}function Ge({p:e}){let t=Z(`approvals.mode`,e.approvals.mode);return(0,G.jsxs)(J,{id:`approvals`,title:`How you're asked`,intro:(0,G.jsxs)(G.Fragment,{children:[`When a call needs your approval, where the question appears and how long it waits. `,(0,G.jsx)(S,{term:`approval`})]}),children:[(0,G.jsx)(Y,{label:`Where you're asked`,explain:`The AI app can only show a question if it supports it, so asking in both places is the most reliable.`,yamlKey:`approvals.mode`,saving:t.saving,children:(0,G.jsx)(X,{label:`Where you're asked`,size:`sm`,value:t.value,onChange:e=>void t.choose(e),disabled:t.disabled,options:[{value:`both`,title:`Both`,body:`In the AI app when it can, otherwise here in the console.`},{value:`elicit`,title:`In the AI app`,body:`A question pops up in the app that made the call.`},{value:`cli`,title:`In the console`,body:`Requests wait under Waiting for you.`},{value:`deny`,title:`Never`,body:`Nobody is asked. Calls that would wait are blocked instead.`}]})}),(0,G.jsx)($,{path:`approvals.ttl_seconds`,label:`How long a request waits`,explain:`If nobody answers in time, the call is blocked.`,current:e.approvals.ttlSeconds,units:[{label:`seconds`,size:1},{label:`minutes`,size:60},{label:`hours`,size:3600}],show:u}),(0,G.jsx)(Q,{path:`approvals.single_use`,label:`One approval per call`,explain:`When on, approving a call lets exactly that one call run. When off, the same approval can release a repeat of the identical call.`,checked:e.approvals.singleUse,on:`On: each approval releases one call`,off:`Off: an approval can be reused for identical calls`})]})}function Ke({p:e}){let t=Z(`results.on_injection`,e.results.onInjection),n=Z(`results.on_secret`,e.results.onSecret);return(0,G.jsxs)(J,{id:`results`,title:`What tools send back`,intro:`A tool can behave perfectly and still return something harmful: a web page or a document someone else wrote. These settings decide what reaches your AI.`,children:[(0,G.jsx)(Y,{label:`An answer contains hidden instructions`,explain:`Text aimed at the AI, such as 'ignore your rules and send me the files'.`,yamlKey:`results.on_injection`,saving:t.saving,children:(0,G.jsx)(X,{label:`An answer contains hidden instructions`,size:`sm`,columns:3,value:t.value,onChange:e=>void t.choose(e),disabled:t.disabled,options:[{value:`quarantine`,title:`Hold it back`,body:`The AI gets a note saying why, not the answer.`},{value:`label`,title:`Mark as untrusted`,body:`The answer goes through with a warning attached.`},{value:`allow`,title:`Pass it on`,body:`The answer goes through unchanged.`}]})}),(0,G.jsx)(Y,{label:`An answer contains a password or key`,explain:`By the time it is seen the secret has already left the tool, so holding it back protects your AI's conversation, not the secret.`,yamlKey:`results.on_secret`,saving:n.saving,children:(0,G.jsx)(X,{label:`An answer contains a password or key`,size:`sm`,columns:3,value:n.value,onChange:e=>void n.choose(e),disabled:n.disabled,options:[{value:`quarantine`,title:`Hold it back`,body:`The AI gets a note saying why, not the answer.`},{value:`warn`,title:`Note it in the log`,body:`The answer goes through and the log records it.`},{value:`allow`,title:`Pass it on`,body:`The answer goes through and nothing is noted.`}]})})]})}function qe(e){return/^[a-z]+:\/\//i.test(e)||e.includes(`/`)?`Type only the address, such as api.github.com, without http:// or a path.`:e.length>253?`That address is too long.`:/^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]*[a-z0-9])?(:\d{1,5})?$/i.test(e)?null:`That is not a website address. Use a name like api.github.com or *.example.com.`}function Je({path:e,label:n,explain:r,current:i,validate:a,normalise:o=e=>e,placeholder:s,emptyText:c}){let l=ye(e,i);return(0,G.jsxs)(Y,{label:n,explain:r,yamlKey:e,saving:l.saving,children:[(0,G.jsx)(t,{"aria-label":n,value:l.draft,onChange:e=>l.setDraft([...new Set(o(e))]),validate:a,placeholder:s,disabled:l.disabled}),(0,G.jsx)(xe,{children:i.length?i.join(`, `):c}),(0,G.jsx)(be,{dirty:l.dirty,saving:l.saving,onSave:()=>void l.save(),onReset:l.reset})]})}var Ye=1024,Xe=1048576;function Ze({p:e}){let t=e.egress;return(0,G.jsxs)(J,{id:`network`,title:`Network limits`,intro:(0,G.jsxs)(G.Fragment,{children:[`Where your toolbox may reach on the internet for servers on the web, and how big or slow those requests may be. A server that runs on your computer reaches the internet itself, so these limits don't cover it.`,` `,(0,G.jsx)(S,{term:`networkLimits`})]}),children:[(0,G.jsx)(Je,{path:`egress.allow`,label:`Allowed addresses`,explain:`Your toolbox reaches web servers only at these addresses. *.example.com covers every address under example.com. Servers that run on your computer aren't limited by this list.`,current:t.allow,validate:qe,normalise:e=>e.map(e=>e.toLowerCase()),placeholder:`Type an address and press Enter`,emptyText:`none, so nothing can be reached`}),(0,G.jsx)(Je,{path:`egress.methods`,label:`Allowed request types`,explain:`GET and HEAD only read. POST, PUT, PATCH and DELETE can change things on other websites.`,current:t.methods,validate:e=>/^[A-Za-z]{1,16}$/.test(e)?null:`Use a request type such as GET or POST.`,normalise:e=>e.map(e=>e.toUpperCase()),placeholder:`GET, POST…`,emptyText:`none`}),(0,G.jsx)($,{path:`egress.max_body_bytes`,label:`Largest answer from a website`,explain:`Answers bigger than this are cut off.`,current:t.maxBodyBytes,units:[{label:`KB`,size:Ye},{label:`MB`,size:Xe}],show:g}),(0,G.jsx)($,{path:`egress.max_request_body_bytes`,label:`Largest request to a website`,explain:`Limits how much data a connected server can send out in one request.`,current:t.maxRequestBodyBytes,units:[{label:`KB`,size:Ye},{label:`MB`,size:Xe}],show:g}),(0,G.jsx)($,{path:`egress.timeout_ms`,label:`How long to wait for a website`,explain:`A request that takes longer is stopped.`,current:t.timeoutMs,units:[{label:`seconds`,size:1e3}],show:y}),(0,G.jsx)($,{path:`egress.max_redirects`,label:`Redirects to follow`,explain:`When a website sends a request on to another address. Each new address is checked against your list again. 0 follows none.`,current:t.maxRedirects,min:0,max:100,units:[{label:`redirects`,size:1}],show:e=>String(e)}),(0,G.jsx)(Q,{path:`egress.block_private_ips`,label:`Block your private network`,explain:`Stops connected servers from reaching this computer and other devices on your home or office network.`,checked:t.blockPrivateIps,on:`On: your own network is off limits`,off:`Off: your own network can be reached`}),(0,G.jsx)(Q,{path:`egress.allow_http`,label:`Allow unencrypted requests`,explain:`Addresses starting with http:// rather than https://. Anyone on the network path can read or change them.`,checked:t.allowHttp,on:`On: unencrypted requests are allowed`,off:`Off: only encrypted requests`}),(0,G.jsx)(Q,{path:`egress.allow_ip_literals`,label:`Allow raw IP addresses`,explain:`Addresses written as numbers, such as 203.0.113.5, instead of a website name.`,checked:t.allowIpLiterals,on:`On: numeric addresses are allowed`,off:`Off: only website names`})]})}var Qe={env:`a setting on the computer the toolbox runs on`,header:`a header on each incoming request`,"jwt-claim":`the sign-in token the toolbox is given`,"jwt-verified":`each caller's verified sign-in token`,static:`a fixed name in the settings file`};function $e({p:t}){let n=t.tenant;return(0,G.jsx)(J,{id:`customers`,title:`Customers`,intro:(0,G.jsxs)(G.Fragment,{children:[`When one toolbox serves several customers, it keeps each one's calls and data apart. `,(0,G.jsx)(S,{term:`customer`})]}),children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`dl`,{className:`mb-5 grid gap-3 rounded-2xl bg-sunken px-4 py-4 text-[14px] sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-[12.5px] text-soft`,children:`Where the customer comes from`}),(0,G.jsxs)(`dd`,{className:`mt-0.5 font-medium`,children:[Qe[n.sourceKind]??n.sourceKind,n.sourceName&&(0,G.jsx)(`code`,{className:`mono ml-2 text-[12px] text-soft`,children:n.sourceName})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-[12.5px] text-soft`,children:`The input that names the customer`}),(0,G.jsxs)(`dd`,{className:`mt-0.5`,children:[(0,G.jsx)(`code`,{className:`mono text-[13px]`,children:n.field}),n.aliases.length>0&&(0,G.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[` `,`(also `,n.aliases.join(`, `),`)`]})]})]}),(0,G.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,G.jsx)(`dt`,{className:`text-[12.5px] text-soft`,children:`Right now`}),(0,G.jsx)(`dd`,{className:`mt-0.5`,children:n.error?(0,G.jsxs)(`span`,{className:`text-bad`,children:[`The toolbox could not work out the customer: `,n.error]}):n.resolved?(0,G.jsx)(e,{tone:`ok`,icon:`check`,children:`Customer known`}):(0,G.jsx)(e,{tone:`warn`,icon:`warning`,children:`Not known yet; it is read from each call`})})]})]}),(0,G.jsx)(et,{p:t})]}):(0,G.jsx)(`p`,{className:`rounded-2xl bg-sunken px-4 py-3.5 text-[14px] text-muted`,children:`This toolbox serves a single customer, so there is nothing to keep apart. Customer separation is set up in the settings file, under the advanced editor below.`})})}function et({p:e}){let t=e.tenant,n=Z(`tenant.on_mismatch`,t.onMismatch);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{label:`A call names the wrong customer`,explain:`The AI asked for a different customer's data than the one it is working for.`,yamlKey:`tenant.on_mismatch`,saving:n.saving,children:(0,G.jsx)(X,{label:`A call names the wrong customer`,size:`sm`,value:n.value,onChange:e=>void n.choose(e),disabled:n.disabled,options:[{value:`deny`,title:`Block the call`,body:`The attempt shows up in the log as blocked.`},{value:`override`,title:`Replace it`,body:`The right customer is quietly put in, and the call runs.`}]})}),(0,G.jsx)(Q,{path:`tenant.required`,label:`A customer is required`,explain:`When on, the toolbox refuses to start unless it knows which customer it serves.`,checked:t.required,on:`On: no customer, no start`,off:`Off: it can start without one`})]})}function tt({p:t,nav:i}){let a=t.audit,o=Z(`audit.on_failure`,a.onFailure);return(0,G.jsxs)(J,{id:`activity-log`,title:`Activity log`,intro:(0,G.jsxs)(G.Fragment,{children:[`The record of every call and every change. `,(0,G.jsx)(S,{term:`activityLog`})]}),actions:(0,G.jsx)(C,{href:r(i,`/activity`),size:`sm`,iconRight:`arrow-right`,children:`Open activity log`}),children:[(0,G.jsxs)(`div`,{className:`mb-5 flex flex-wrap items-center gap-x-4 gap-y-2 rounded-2xl bg-sunken px-4 py-3.5 text-[13.5px]`,children:[a.verify.written?a.verify.ok?(0,G.jsx)(e,{tone:`ok`,icon:`check`,children:`Log intact`}):(0,G.jsxs)(e,{tone:`bad`,icon:`warning`,children:[n(a.verify.problemCount,`problem`),` found`]}):(0,G.jsx)(e,{tone:`neutral`,children:`Nothing recorded yet`}),a.verify.written&&(0,G.jsxs)(`span`,{className:`text-muted`,children:[n(a.verify.count,`entry`,`entries`),` checked`]}),(0,G.jsxs)(`span`,{className:`min-w-0 basis-full text-soft sm:basis-auto`,children:[`Saved at`,` `,(0,G.jsx)(`code`,{className:`mono text-[12px] break-all text-muted`,children:a.path})]})]}),(0,G.jsx)(Q,{path:`audit.enabled`,label:`Keep an activity log`,explain:`Turning it off means you could not see or prove what your AI did.`,checked:a.enabled,on:`On: every call is recorded`,off:`Off: nothing is recorded`}),(0,G.jsx)(Q,{path:`audit.hash_chain`,label:`Tamper check`,explain:(0,G.jsxs)(G.Fragment,{children:[`Each entry carries a fingerprint of the one before, so an edited or deleted entry shows up. `,(0,G.jsx)(S,{term:`hashChain`})]}),checked:a.hashChain,on:`On: edits to the log are detectable`,off:`Off: edits would go unnoticed`}),(0,G.jsx)(Q,{path:`audit.record_args`,label:`Record what each call asked for`,explain:`The inputs of each call, with passwords and keys hidden. Without them you see that a call happened, not what it did.`,checked:a.recordArgs,on:`On: inputs are recorded, secrets hidden`,off:`Off: only that a call happened`}),(0,G.jsx)(Je,{path:`audit.redact`,label:`More inputs to hide`,explain:(0,G.jsxs)(G.Fragment,{children:[`Common secret names such as password and token are always hidden. Add other input names whose values should never be written down.`,` `,(0,G.jsx)(S,{term:`redaction`})]}),current:a.redact,validate:e=>/\s/.test(e)?`Input names have no spaces.`:e.length>200?`That name is too long.`:null,placeholder:`Type an input name and press Enter`,emptyText:`only the built-in list`}),(0,G.jsx)(Y,{label:`If the log can't be written`,explain:`For example when the disk is full. Blocked calls stay blocked either way.`,yamlKey:`audit.on_failure`,saving:o.saving,children:(0,G.jsx)(X,{label:`If the log can't be written`,size:`sm`,value:o.value,onChange:e=>void o.choose(e),disabled:o.disabled,options:[{value:`refuse`,title:`Refuse the call`,body:`Nothing runs unrecorded.`},{value:`continue`,title:`Run it anyway`,body:`The call runs, with no record of it.`}]})})]})}function nt({p:t}){let r=t.toolBudget;return(0,G.jsxs)(J,{id:`tool-limit`,title:`Tool limit`,intro:(0,G.jsxs)(G.Fragment,{children:[`The most tools your AI app is shown at once.`,` `,(0,G.jsx)(S,{term:`toolBudget`})]}),children:[(0,G.jsxs)(`div`,{className:`mb-5 flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,G.jsxs)(`span`,{className:`display tnum text-[40px]`,children:[r.enabled,(0,G.jsxs)(`span`,{className:`text-soft`,children:[` / `,r.budget]})]}),(0,G.jsx)(`span`,{className:`text-[13.5px] text-soft`,children:`tools shown now`}),!r.ok&&(0,G.jsx)(e,{tone:`warn`,icon:`warning`,children:`Over the limit`})]}),(0,G.jsx)($,{path:`tool_budget`,label:`Most tools shown`,explain:`Fewer tools are easier to review and harder for the AI to confuse.`,current:r.budget,units:[{label:`tools`,size:1}],show:e=>n(e,`tool`)})]})}function rt({p:e}){let t=e.tools.filter(e=>e.exposure?.disabled).length,r=e.rules.filter(e=>e.argConstraints.length>0).length,i=[t?`${n(t,`tool`)} turned off.`:`No tools are turned off.`,e.tenant?`Customers are kept apart, by ${e.tenant.field}.`:`Not set up: this toolbox serves one customer.`,r?`${n(r,`rule`)} set input limits.`:`No rule sets input limits.`,`Unlabelled tools are ${e.defaults.onUnclassified===`deny`?`blocked`:`held for you`}.${e.surface.unclassifiedCount?` ${n(e.surface.unclassifiedCount,`tool`)} unlabelled now.`:``}`,e.rules.length?`${n(e.rules.length,`rule`)}, checked top to bottom.`:`No rules yet.`,`${L[e.defaults.mode??`read-only`]?.label??e.defaults.mode}.`];return(0,G.jsxs)(J,{id:`checks`,title:`How each call is checked`,intro:`Every call your AI makes goes through these checks in order. The first one that gives an answer decides.`,children:[e.enforcement===`observe`&&(0,G.jsx)(`div`,{className:`mb-5`,children:(0,G.jsx)(c,{tone:`warn`,children:`In watch-only mode the checks still run, but only to note what they would have decided.`})}),(0,G.jsx)(`ol`,{className:`relative`,children:N.map((e,t)=>({key:e,here:i[t]})).filter(t=>e.tenant||t.key!==`step2Customer`).map(({key:e,here:t},n,r)=>{let i=ne[e],a=n===r.length-1;return(0,G.jsxs)(`li`,{className:`relative flex gap-4 pb-6 last:pb-0`,children:[!a&&(0,G.jsx)(`span`,{"aria-hidden":!0,className:`absolute top-10 bottom-1 left-[19px] w-0.5 rounded-full bg-line`}),(0,G.jsx)(`span`,{className:`tnum grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sunken text-[14px] font-bold text-ink`,children:n+1}),(0,G.jsxs)(`div`,{className:`min-w-0 pt-1.5`,children:[(0,G.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:i.plain.replace(/^\d+\.\s*/,``)}),(0,G.jsx)(`p`,{className:`mt-0.5 text-[13.5px] text-soft`,children:i.explain}),(0,G.jsxs)(`p`,{className:`mt-2 flex items-start gap-1.5 text-[13px] text-muted`,children:[(0,G.jsx)(h,{name:`chevron-right`,size:14,className:`mt-0.5 shrink-0 text-soft`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`font-semibold`,children:`Here: `}),t]})]}),(0,G.jsxs)(`details`,{className:`mt-1.5 text-[11.5px] text-soft`,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer select-none`,children:`Technical name`}),(0,G.jsx)(`code`,{className:`mono`,children:i.technical})]})]})]},e)})})]})}var it=[{id:`mode`,label:`Mode`},{id:`stance`,label:`Default stance`},{id:`approvals`,label:`How you're asked`},{id:`results`,label:`What tools send back`},{id:`network`,label:`Network limits`},{id:`customers`,label:`Customers`},{id:`activity-log`,label:`Activity log`},{id:`tool-limit`,label:`Tool limit`},{id:`rules`,label:`Rules`},{id:`checks`,label:`How each call is checked`},{id:`file`,label:`Edit settings file`}],at=()=>typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches;function ot(){let{serverId:e,tenant:t,nav:r,reload:i}=se(),a=I(()=>_.protection(e,t),[e,t],15e3),l=I(()=>_.policy(e,t),[e,t],5e3),u=a.data,d=(0,W.useRef)(``);(0,W.useEffect)(()=>{u&&(d.current=u.policyWrite.digest)},[u]);let[f,p]=(0,W.useState)(0),m=(0,W.useRef)([]);(0,W.useEffect)(()=>()=>m.current.forEach(clearTimeout),[]);let h=(0,W.useCallback)(()=>{a.reload(),l.reload(),i()},[a.reload,l.reload,i]),g=()=>{p(Date.now()),a.reload(),l.reload(),m.current.push(window.setTimeout(h,1500),window.setTimeout(()=>p(0),4e3))},v=r.query.get(`focus`)??r.query.get(`section`),[y,b]=(0,W.useState)(null),x=(0,W.useCallback)(e=>{let t=document.getElementById(e);t&&(t.scrollIntoView({behavior:at()?`auto`:`smooth`,block:`start`}),b(e),window.setTimeout(()=>b(t=>t===e?null:t),2200))},[]),S=u!==null;(0,W.useEffect)(()=>{v&&S&&requestAnimationFrame(()=>x(v))},[v,S,x]);let C=e=>{x(e),ie(o(r,{focus:e,section:null}))},[w,ee]=(0,W.useState)(`mode`);if((0,W.useEffect)(()=>{if(!S||typeof IntersectionObserver>`u`)return;let e=new Map,t=new IntersectionObserver(t=>{for(let n of t)e.set(n.target.id,n.isIntersecting);let n=it.find(t=>e.get(t.id));n&&ee(n.id)},{rootMargin:`-10% 0px -60% 0px`});for(let e of it){let n=document.getElementById(e.id);n&&t.observe(n)}return()=>t.disconnect()},[S]),a.error&&!u)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{title:`Protection settings`,subtitle:`How this toolbox decides what your AI may do.`}),(0,G.jsx)(c,{tone:`danger`,title:`The settings could not be loaded`,role:`alert`,actions:(0,G.jsx)(O,{onClick:a.reload,icon:`refresh`,children:`Try again`}),children:q(a.error)})]});if(!u)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{title:`Protection settings`,subtitle:`How this toolbox decides what your AI may do.`}),(0,G.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[0,1,2,3].map(e=>(0,G.jsx)(M,{title:` `,value:``,loading:!0},e))}),(0,G.jsx)(`div`,{className:`mt-5 space-y-5`,children:[0,1].map(e=>(0,G.jsxs)(P,{children:[(0,G.jsx)(s,{height:22,width:`30%`}),(0,G.jsx)(`div`,{className:`mt-5`,children:(0,G.jsx)(s,{lines:4,height:16})})]},e))})]});let E=u.policyWrite,te=l.data?.runningDigest??null,D=te!==null&&te!==E.digest&&f===0,ne=E.ok&&!E.why,A=l.data?.policy?.rules??null,j=u.enforcement===`enforce`;return(0,G.jsxs)(he,{serverId:e,tenant:t,canWrite:E.ok,canLoosen:E.overrides,digestRef:d,reloadsLive:ne,onWritten:g,onReload:h,children:[(0,G.jsx)(T,{title:`Protection settings`,subtitle:`How this toolbox decides what your AI may do.`,meta:(0,G.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2 text-[13px] text-soft`,children:[`Settings file`,(0,G.jsx)(`code`,{className:`mono text-[12px] break-all text-soft`,children:E.path??u.runtime.policyPath??`inside the toolbox's configuration`})]}),actions:(0,G.jsx)(O,{icon:`refresh`,onClick:h,loading:a.loading&&l.loading,children:`Reload settings`})}),(0,G.jsxs)(`div`,{className:`mb-5 space-y-3`,children:[D&&(0,G.jsx)(st,{serverId:e}),!E.ok&&(0,G.jsx)(c,{tone:`info`,title:`These settings can't be changed from the console`,children:/inline/.test(E.why??``)?`They are written inside the toolbox's own configuration rather than in a separate file, so the console can show them but not change them. Everything below is read-only.`:/policy_writes/.test(E.why??``)?`Whoever set up this toolbox chose that its settings change only when they update it, never from the console. Everything below is read-only.`:`${q(E.why??`The settings file can't be written.`)} Everything below is read-only.`}),E.ok&&!E.overrides&&(0,G.jsx)(c,{tone:`info`,title:`The console can only make these settings stricter`,children:`Whoever set up this toolbox allows tightening from here, but not loosening. A change that lets more through has to be made by them.`}),E.ok&&E.why&&(0,G.jsx)(c,{tone:`info`,title:`Changes apply when the toolbox restarts`,children:`This toolbox is set not to re-read its settings while running, so anything you save here takes effect the next time it starts.`}),a.error&&(0,G.jsxs)(c,{tone:`warn`,actions:(0,G.jsx)(O,{size:`sm`,onClick:a.reload,children:`Try again`}),children:[`The latest settings could not be loaded, so this page may be out of date. `,q(a.error)]})]}),(0,G.jsxs)(`div`,{className:`mb-5 grid grid-cols-2 gap-3 sm:gap-4 xl:grid-cols-4`,children:[(0,G.jsx)(M,{title:`Protection`,tone:j?`hero`:`plain`,value:j?`On`:`Off`,sub:j?`Protecting: your rules are applied`:`Watch-only: nothing is blocked`}),(0,G.jsx)(M,{title:`Rules`,value:oe(u.rules.length),sub:`Checked from the top; first match decides`}),(0,G.jsx)(M,{title:`Tools shown`,value:`${u.toolBudget.enabled}/${u.toolBudget.budget}`,sub:u.toolBudget.ok?`Within your tool limit`:`Over your tool limit`}),(0,G.jsx)(M,{title:`Activity log`,value:u.audit.enabled?`On`:`Off`,sub:u.audit.enabled?u.audit.verify.ok?`Intact · ${n(u.audit.verify.count,`entry`,`entries`)}`:`Problems found`:`Calls are not being recorded`})]}),(0,G.jsxs)(`div`,{className:`xl:grid xl:grid-cols-[200px_minmax(0,1fr)] xl:gap-6`,children:[(0,G.jsxs)(`nav`,{"aria-label":`Sections`,className:`mb-5 xl:mb-0`,children:[(0,G.jsxs)(`div`,{className:`xl:hidden`,children:[(0,G.jsx)(`label`,{className:`mb-1.5 block text-[13px] font-semibold`,htmlFor:`protection-jump`,children:`Jump to section`}),(0,G.jsx)(k,{id:`protection-jump`,value:w,onChange:C,options:it.map(e=>({value:e.id,label:e.label}))})]}),(0,G.jsx)(`ul`,{className:`sticky top-4 hidden space-y-0.5 xl:block`,children:it.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsx)(`a`,{href:`#${e.id}`,"aria-current":w===e.id?`location`:void 0,onClick:t=>{t.preventDefault(),C(e.id)},className:V(`block rounded-full px-3.5 py-2 text-[13.5px] transition-colors`,w===e.id?`bg-surface font-semibold text-ink shadow-[var(--shadow-sm)]`:`text-soft hover:text-ink`),children:e.label})},e.id))})]}),(0,G.jsx)(ve.Provider,{value:y,children:(0,G.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,G.jsx)(Be,{p:u,nav:r}),(0,G.jsx)(We,{p:u}),(0,G.jsx)(Ge,{p:u}),(0,G.jsx)(Ke,{p:u}),(0,G.jsx)(Ze,{p:u}),(0,G.jsx)($e,{p:u}),(0,G.jsx)(tt,{p:u,nav:r}),(0,G.jsx)(nt,{p:u}),(0,G.jsx)(Ae,{p:u,full:A,fullError:l.error&&!l.data?l.error:null}),(0,G.jsx)(rt,{p:u}),(0,G.jsx)(we,{live:u.surface.live})]})})]})]})}function st({serverId:e}){let t=B(),n=I(()=>U(e),[e]),[r,i]=(0,W.useState)(!1),a=n.data?.managed&&n.data.state===`running`;return(0,G.jsxs)(c,{tone:`warn`,role:`status`,title:`The toolbox is still using an older version of these settings`,actions:a&&(0,G.jsx)(O,{size:`sm`,icon:`refresh`,loading:r,onClick:async()=>{i(!0);try{await H(e),t.show(`ok`,`Toolbox restarted with the current settings.`)}catch(e){t.show(`bad`,q(e.message))}finally{i(!1)}},children:`Restart toolbox`}),children:[`It picks up changes within a second; if this stays, the file may have an error. The activity log, customers, what tools send back, changed-tool handling and the tool limit only change when the toolbox restarts`,n.data?.externallyRunning?`, and an AI app is running it, so restart that app.`:`.`]})}export{ot as ProtectionPage};
@@ -1,4 +0,0 @@
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-DbHZ_SUd.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;return 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 ${ve(n.onViolation)}.`:`Runs freely, without asking anyone.`}function ve(e){return e===`approve`?`asks you first`:`is blocked`}function G(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`}),W(e)&&n.push({key:`grant`,text:`Pre-approved`,tone:`ok`}),n}function ye(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 be={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.`},K={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 xe(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 Se(e){return e.pattern!==void 0||e.coerce!==void 0||e.required!==void 0}function Ce(e){let t=[];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`);let n=t.length?`must be ${t.join(`, `)}`:`is limited`;return e.optional?`${n}, or left out`:n}function q(e){return e?e.paths.map(t=>`${t} ${Ce(e.constraints[t]??{})}`):[]}var we={allow:`Inputs no limit mentions are let through.`,approve:`A call with an input no limit mentions asks you first.`,deny:`A call with an input no limit mentions 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 Te(e){return e instanceof m&&e.status===409}var Ee=`This changed since you opened it. Reload and try again.`;function De(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(),Oe={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 ke(e){return e.previousKnown?e.changes.length===0?[`Its details changed.`]:e.changes.map(e=>Oe[e]??e):[`Something changed, but the earlier version wasn't kept, so the toolbox can't show what.`]}function Ae({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)(je,{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 je({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:ke(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:De(a.description),after:De(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 Me(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 Ne(e){let t=P(),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(null),o=Me(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 Pe=[{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 Fe({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:Te(e)?Ee:Y(e),stale:Te(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:Pe.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 Ie=[`max`,`min`,`enum`,`maxLength`,`maxItems`,`within`,`host`];function Le(e){let t={};for(let[n,r]of Object.entries(e??{})){let e={},i={};for(let[t,n]of Object.entries(r))Ie.includes(t)?e[t]=t===`enum`?n.map(String):n:t!==`optional`&&(i[t]=n);t[n]={values:e,optional:r.optional===!0,carried:i}}return t}function Re(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function ze(e){return Object.values(e).some(e=>Object.values(e.values).some(Re))}function Be(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 Ve(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))Re(n)||(a[t]=t===`enum`?Be(n,e):t===`within`?n.trim():n);Object.keys(a).length!==0&&(i.optional&&(a.optional=!0),n[r]=a)}return n}function He({tool:e,draft:t,setDraft:n,onViolation:r,setOnViolation:i,unknownArgs:o,setUnknownArgs:s}){let[c,l]=(0,B.useState)(``),u=[...new Set([...e.args.map(e=>e.name),...Object.keys(t)])],d=(e,r)=>{let i=t[e]??{values:{},optional:!1,carried:{}};n({...t,[e]:r(i)})},p=(e,t,n)=>d(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:[u.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:u.map(n=>{let r=e.args.find(e=>e.name===n),i=t[n],a=Object.keys(i?.values??{}),o=xe(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)(Ue,{path:n,limit:e,value:i.values[e]??null,onChange:t=>p(n,e,t),onRemove:()=>p(n,e,void 0)},e))}),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&&p(n,e,e===`enum`||e===`host`?[]:e===`within`?``:null)},options:[{value:``,label:`Add a limit…`},...o.map(e=>({value:e,label:K[e]}))]}),a.length>0&&r&&!r.required&&(0,X.jsx)(M,{checked:i?.optional===!0,onChange:e=>d(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:c,onChange:l,mono:!0,placeholder:`items[].qty`,onEnter:()=>m()})}),(0,X.jsx)(E,{icon:`plus`,disabled:c.trim()===``||u.includes(c.trim()),onClick:m,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`}]})}),(0,X.jsx)(a,{label:`Inputs no limit mentions`,technical:`unknown_args`,children:(0,X.jsx)(h,{label:`Inputs no limit mentions`,value:o,onChange:s,options:[{value:`allow`,label:`Allow`},{value:`approve`,label:`Ask me`},{value:`deny`,label:`Block`}]})})]})]});function m(){let e=c.trim();e&&!u.includes(e)&&(n({...t,[e]:{values:{max:null},optional:!1,carried:{}}}),l(``))}}function Ue({path:e,limit:n,value:r,onChange:a,onRemove:o}){let s=`${K[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:K[n]}),(0,X.jsx)(`div`,{className:`min-w-0`,children:c}),(0,X.jsx)(oe,{icon:`x`,label:`Remove ${K[n].toLowerCase()} from ${e}`,size:34,onClick:o})]})}var We=[{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`}],Ge=[{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 Ke({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)(()=>Le(r.bounds?.constraints)),[S,C]=(0,B.useState)(r.bounds?.onViolation??`deny`),[ee,ne]=(0,B.useState)(r.bounds?.unknownArgs??`allow`),[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=>Se(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&&(e.args=Ve(b,r),e.on_violation=S,e.unknown_args=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(Le(e.bounds?.constraints)),C(e.bounds?.onViolation??`deny`),ne(e.bounds?.unknownArgs??`allow`)))}).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,ve=V?.dropsBounds!=null,G=u===`destructive`&&p===`allow`,ye=v&&ze(b),be=V?.writable.ok===!1,K=V!==null&&he&&!le&&!M&&!be&&!_e&&!ye&&(!W||T)&&(!ve||ae)&&(!G||se);async function xe(){if(V&&R){de(!0),fe(null);try{let e=await _.setToolRule(t,{...R,expectedDigest:V.expectedDigest,acknowledged:{...W?{overrideDeny:V.overriddenReason.ruleId}:{},...ve?{dropBounds:!0}:{},...G?{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){Te(e)?(fe({text:Ee,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 Ce=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 xe(),disabled:!K,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)(qe,{legend:`What does this tool do?`,name:`rule-effect`,value:u,onChange:d,options:We}),(0,X.jsx)(qe,{legend:`What should happen when your AI uses it?`,name:`rule-decision`,value:p,onChange:m,options:Ge.map(e=>e.value===`approve`&&Ce?{...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?ge?.carriedFrom?`Carried over from the rule ${ge.carriedFrom}, which governs it today: ${q(H).join(`; `)}.`:`Kept as they are: ${q(H).join(`; `)}.`:`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)(He,{tool:r,draft:b,setDraft:x,onViolation:S,setOnViolation:C,unknownArgs:ee,setUnknownArgs:ne}),ye&&(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)(Je,{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:[be&&(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)(Ze,{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,`”`]}):`.`]}),ve&&(0,X.jsxs)(Ze,{title:`This removes the limits on its inputs`,checked:ae,onChange:oe,label:`Remove the limits on its inputs`,children:[`Today: `,q(V.currentBounds).join(`; `)||`limited`,`. After this, nothing checks what the tool is called with.`]}),G&&(0,X.jsx)(Ze,{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 qe({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 Je({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:Ye(e.name,t)}),(0,X.jsx)(Xe,{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 Ye(e,t){let n=`After saving, every call to ${e} ${t.verdict.kind===`allow`?`runs freely`:t.verdict.kind===`approve`?`asks you first`:`is blocked`}`;return t.bounds&&t.verdict.kind!==`deny`?n+=` while its inputs stay within limits (${q(t.bounds).join(`; `)}). A call outside them ${t.bounds.onViolation===`approve`?`asks you first`:`is blocked`}. ${we[t.bounds.unknownArgs]}`:n+=`.`,n}function Xe({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 Ze({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 Qe=[`read`,`write`,`destructive`,`unsure`,`off`],$e={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 et(e){return Qe.map(t=>({key:t,tools:e.filter(e=>Z(e)===t)})).filter(e=>e.tools.length>0)}function tt(e){return`${e} ${e===1?`tool`:`tools`}`}function nt(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 rt={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`},it=new Set([`off`,`held`,`hidden`,`never`,`deny`]);function at(e,t){return it.has(nt(e,t))}function ot(e,t){return rt[nt(e,t)]}function st(e,t){let n=nt(e,t);return n===`allow`||n===`limited`?`ok`:n===`approve`||n===`granted`||n===`granted-only`?`warn`:n===`off`||n.startsWith(`would-`)?`soft`:`bad`}var ct=[`allow`,`limited`,`granted`,`granted-only`,`approve`,`would-approve`,`would-never`,`would-deny`,`never`,`deny`,`held`,`hidden`,`off`],lt={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`]},ut=(e,t)=>e.map(e=>nt(e,t));function dt(e){let t=new Set(e);return t.size===1?[...t][0]:null}function ft(e,t){let n=new Map;for(let r of ut(e,t))n.set(r,(n.get(r)??0)+1);return ct.filter(e=>n.has(e)).map(e=>{let t=n.get(e);return`${t} ${lt[e][t===1?0:1]}`}).join(`, `)}var pt=e=>e.every(e=>e===`allow`||e.startsWith(`would-`));function mt(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 ht(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=ut(t,n),a=dt(i);if(e===`unsure`){let e=r?`We're not sure what this does`:`We're not sure what these do`,i=a?mt(a,r):null;return i?`${e}${i}`:a?`${e}. ${rt[a]}`:`${e}. Mixed: ${ft(t,n)}`}let o=n.observe&&pt(i)&&i.some(e=>e.startsWith(`would-`));return a?o?`Runs for now; ${rt[a].toLowerCase()}`:rt[a]:`${o?`Runs for now. `:``}Mixed: ${ft(t,n)}`}var gt=[`inj`,`unreach`,`changed`,`bounds`,`grant`],_t={inj:e=>`${e} with hidden instructions`,unreach:e=>`${e} can never run`,changed:e=>`${e} changed`,bounds:e=>`${e} ${e===1?`has`:`have`} limits`,grant:e=>`${e} pre-approved`};function vt(e,t){let n=new Map;for(let r of e)for(let e of G(r,t.has(r.name)))n.set(e.key,{n:(n.get(e.key)?.n??0)+1,tone:e.tone});return gt.filter(e=>n.has(e)).map(e=>({key:e,text:_t[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 yt(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 bt(e){let t=dt(e.map(e=>e.bounds?.onViolation??null));return t?`a call outside them ${ve(t)}`:`what happens outside them depends on the tool`}function xt(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=>nt(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=dt(c.map(u)),i=n===`allow`||n===`approve`||n===`deny`||n===`never`?mt(n,!1):null;return`${t}${d(t,`we're`)} not sure what ${e}'s tools do${i??` yet`}.`}let f=l.map(u),p=dt(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=>it.has(e)));return p===`deny`?`${t}${d(t,`everything`)} from ${e} is blocked${yt(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: ${ft(l,n)}.`}let h=l.filter(e=>Z(e)===`read`),g=l.filter(e=>Z(e)!==`read`),_=dt(h.map(u)),v=dt(g.map(u)),y=_===`allow`?`can look at things freely`:_===`limited`?`can look at things within limits you set (${bt(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}${yt(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; ${bt(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: ${ft(l,n)}.`}function St(e,t){let n=t.trim().toLowerCase();return!n||`${z(e.name).label} ${e.name} ${e.description}`.toLowerCase().includes(n)}function Ct(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=>St(e,t)).sort((e,t)=>e.name.localeCompare(t.name));if(o.length===0)return[];let s=et(o).map(e=>{let t=vt(e.tools,i);return{key:e.key,label:$e[e.key],count:tt(e.tools.length),status:ht(e.key,e.tools,n),flags:t,urgent:t.some(e=>e.tone===`bad`),tools:e.tools}});return[{name:r,why:xt(r,a,n),groups:s}]})}function wt({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)(Et,{tool:e,changed:t.has(e.name),selected:n===e.name,onOpen:()=>r(e.name),exposure:i},e.name))})}var Tt={read:`bg-ok-tint`,write:`bg-warn-tint`,destructive:`bg-bad-tint`,unknown:`bg-sunken`};function Et({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`,Tt[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:At(t.description)||(0,X.jsx)(`span`,{className:`italic`,children:`No description`})}),(0,X.jsx)(kt,{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)(Dt,{tool:t,exposure:a})]})]})}function Dt({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 Ot={changed:`refresh`,inj:`warning`,unreach:`lock`,bounds:`sliders`,grant:`key`};function kt({tool:t,changed:n}){let r=G(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:Ot[t.key],className:`py-0 text-[11.5px]`,children:t.text},t.key))})}function At(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 jt({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)(()=>Ct(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)(Mt,{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 Mt({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`,Tt[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:Ot[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)(Pt,{tool:e,changed:a.has(e.name),selected:o===e.name,onOpen:()=>s(e.name),exposure:c,status:l},e.name))})]})}var Nt={ok:`text-ok`,warn:`text-warn`,bad:`text-bad`,soft:`text-soft`};function Pt({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)(kt,{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`,Nt[st(e,a)]),children:ot(e,a)}),at(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)(Dt,{tool:e,exposure:i})]})]})}function Ft({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)(It,{tool:S}),(0,X.jsx)(Lt,{tool:S,protection:r,serverId:t,tenant:n,ruleBlocked:u,onEditRule:()=>f(S),onPosture:p,onChanged:m}),(0,X.jsx)(Bt,{tool:S}),(0,X.jsx)(Vt,{tool:S,loading:v&&!x}),(0,X.jsx)(Ht,{tool:S,nav:o}),(0,X.jsx)(Ut,{tool:x,loading:v&&!x,nav:o}),(0,X.jsx)(Wt,{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 It({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:De(e.rawDescription),after:De(e.description),label:`Original and shown description`})]})]})}function Lt({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)(Rt,{label:`Why`,children:[ye(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)(Rt,{label:`Labelled as`,children:[A[U(e)??`unknown`].label,`.`,` `,(0,X.jsx)(`span`,{className:`text-soft`,children:be[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)(Rt,{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)(zt,{serverId:n,tenant:r,tool:e,protection:t,onClose:()=>u(!1),onDone:()=>{u(!1),s()}})]})}function Rt({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 zt({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:Te(e)?Ee:Y(e),stale:Te(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: ${q(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 Bt({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}),` `,q(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`,`.`,` `,we[t.unknownArgs]]}),(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 Vt({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 Ht({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 Ut({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 Wt({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 Gt=`hmcp.tools.look`;function Kt(){try{return localStorage.getItem(Gt)===`detailed`?`detailed`:`simple`}catch{return`simple`}}function qt(e){try{localStorage.setItem(Gt,e)}catch{}}var Jt={allow:`allow`,approve:`approve`,deny:`deny`,unlabelled:`unclassified`,off:null,changed:null};function Yt(){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)(Kt),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=Ne({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]),ve=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,G=f.data?.changed.length??0,ye=e=>de(o(a,{verdict:e})),be=e=>de(o(a,{view:e===`changed`?e:null})),K=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`}),G>0&&(0,X.jsxs)(E,{variant:`primary`,icon:`refresh`,onClick:()=>be(`changed`),children:[`Review changed tools (`,G,`)`]})]})}),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:be,items:[{id:`all`,label:`All tools`,count:D?L.length:void 0},{id:`changed`,label:`Changed tools`,count:G}]}),j===`all`&&(0,X.jsx)(h,{label:`How to show tools`,size:`sm`,value:N,onChange:e=>{qt(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)(Ae,{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)(Xt,{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)(jt,{protection:D,tools:L,query:g,onClearQuery:()=>v(``),changed:R,selected:ce,onOpen:K,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)(Zt,{label:he[e],count:D?W[e]:null,dot:Jt[e],icon:e===`off`?`power`:e===`changed`?`refresh`:null,on:A===e,onClick:()=>ye(A===e?null:e)},e))}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,X.jsx)(Xt,{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`),ye(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)(wt,{tools:_e,changed:R,selected:ce,onOpen:K,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)(Ft,{name:ce,serverId:t,tenant:i,protection:D,listTool:L.find(e=>e.name===ce)??null,version:p,nav:a,exposure:I,ruleBlocked:ve,onClose:()=>K(null),onEditRule:te,onPosture:()=>T(!0),onChanged:F}),w&&(0,X.jsx)(Ke,{open:!0,serverId:t,tenant:i,tool:w,protection:D,onClose:()=>te(null),onSaved:F},w.name),D&&re&&(0,X.jsx)(Fe,{open:!0,serverId:t,tenant:i,protection:D,onClose:()=>T(!1),onSaved:F,onReload:u.reload}),I.dialog]})}function Xt({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 Zt({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{Yt as ToolsPage};