hmcp-web 0.1.0 → 0.2.0

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.
Files changed (44) hide show
  1. package/README.md +3 -2
  2. package/dist/api.d.ts +11 -0
  3. package/dist/api.js +64 -10
  4. package/dist/model/app-servers.d.ts +85 -0
  5. package/dist/model/app-servers.js +109 -0
  6. package/dist/model/import-record.d.ts +80 -0
  7. package/dist/model/import-record.js +179 -0
  8. package/dist/model/metrics.js +16 -1
  9. package/dist/routes/connect-import.d.ts +9 -0
  10. package/dist/routes/connect-import.js +594 -0
  11. package/dist/routes/connect.d.ts +36 -0
  12. package/dist/routes/connect.js +71 -13
  13. package/dist/routes/github.d.ts +97 -0
  14. package/dist/routes/github.js +587 -0
  15. package/dist/routes/guard.d.ts +3 -0
  16. package/dist/routes/guard.js +166 -0
  17. package/dist/routes/runtime.d.ts +6 -0
  18. package/dist/routes/runtime.js +1 -1
  19. package/dist/routes/servers-add.d.ts +8 -0
  20. package/dist/routes/servers-add.js +2 -2
  21. package/dist-ui/assets/{Activity-BqKGpXMN.js → Activity-CZ78RyRO.js} +1 -1
  22. package/dist-ui/assets/Approvals-DPIlNZsv.js +1 -0
  23. package/dist-ui/assets/AttachApp-DjSeWCbS.js +5 -0
  24. package/dist-ui/assets/Connections-qcA96lXh.js +2 -0
  25. package/dist-ui/assets/{Gallery-B39L2Yma.js → Gallery-DB_OO7Vw.js} +1 -1
  26. package/dist-ui/assets/{PreApprovals-BsIhjMqb.js → PreApprovals-C4cKajcK.js} +1 -1
  27. package/dist-ui/assets/{Protection-DlB09ABa.js → Protection-B8h-5YAb.js} +1 -1
  28. package/dist-ui/assets/{Safety-CN-oHO2h.js → Safety-BQqHyYdo.js} +1 -1
  29. package/dist-ui/assets/{Settings-BLD7G1Ag.js → Settings-Cx50zZSt.js} +1 -1
  30. package/dist-ui/assets/StartPage-CdX-v7ej.js +1 -0
  31. package/dist-ui/assets/{Suggestions-Dp7pofcs.js → Suggestions-CRo5UOTT.js} +1 -1
  32. package/dist-ui/assets/Tools-xo39lPKB.js +4 -0
  33. package/dist-ui/assets/index-DttDjRpu.js +16 -0
  34. package/dist-ui/assets/index-QeJyD5z2.css +2 -0
  35. package/dist-ui/assets/{kit-DQ7Oxf5n.js → kit-DRVm92_t.js} +1 -1
  36. package/dist-ui/index.html +3 -3
  37. package/package.json +4 -4
  38. package/dist-ui/assets/Approvals-Qo7bCcli.js +0 -1
  39. package/dist-ui/assets/AttachApp-0zRSPgSY.js +0 -5
  40. package/dist-ui/assets/Connections-CE0JGe8c.js +0 -2
  41. package/dist-ui/assets/StartPage-HuZSnmSr.js +0 -1
  42. package/dist-ui/assets/Tools-Bfot3bx5.js +0 -4
  43. package/dist-ui/assets/index-Khp0l1zp.js +0 -16
  44. package/dist-ui/assets/index-Ylyt4DEr.css +0 -2
@@ -1 +1 @@
1
- import{$ as e,B as t,Ct as n,Et as r,G as i,H as a,It as o,Nt as s,O as c,Ot as l,Pt as u,U as d,W as f,Z as p,_ as m,_t as h,b as g,c as _,d as v,et as y,ht as b,kt as x,mt as S,pt as C,s as w,w as T,wt as E,x as D,y as O,z as k}from"./kit-DQ7Oxf5n.js";import{Zt as A,dt as j,ft as M,ht as N,lt as P,mt as F,pt as I,ut as L}from"./index-Khp0l1zp.js";var R=o(),z=`Suggested from what watch-only mode recorded`;async function B(e,t,n){if(!j(n.match)&&n.effect){let r={tool:n.match,effect:n.effect,decision:n.decision,...n.args?{args:n.args}:{},...n.on_violation?{on_violation:n.on_violation}:{},...n.unknown_args?{unknown_args:n.unknown_args}:{},reason:n.reason??z};return{kind:`tool`,body:r,preview:await u.toolRulePreview(e,r,t)}}let r={...n,reason:n.reason??z};return{kind:`rules`,rule:r,preview:await u.previewRules(e,{op:`add`,rule:r,index:0},t)}}function V(e){if(e.kind===`tool`){let t=e.preview,n=t.overriddenReason;return{override:n,drop:t.dropsBounds,destructive:e.body.effect===`destructive`&&e.body.decision===`allow`,loosens:t.loosens,refused:t.writable.ok?n&&!t.overridesAllowed?`This toolbox does not let the console reverse rule ${n.ruleId}. Change it in the protection settings file instead.`:null:t.writable.why??`The protection settings file cannot be changed from here.`}}let t=e.preview;return{override:null,drop:null,destructive:!1,loosens:t.loosens,refused:t.writable.ok?t.loosens&&!t.overridesAllowed?`This toolbox lets the console tighten its rules but not loosen them.`:null:t.writable.why??`The protection settings file cannot be changed from here.`}}async function H(e,t,n,r){if(n.kind===`tool`){let i=n.preview,a={...r.override&&i.overriddenReason?{overrideDeny:i.overriddenReason.ruleId}:{},...r.drop&&i.dropsBounds?{dropBounds:!0}:{},...r.destructive?{destructiveAllow:!0}:{}};return{warning:(await u.setToolRule(e,{...n.body,expectedDigest:i.expectedDigest,...Object.keys(a).length>0?{acknowledged:a}:{}},t)).warning}}return{warning:(await u.addRule(e,n.rule,n.preview.expectedDigest,0,r.loosens?{loosens:!0}:void 0,t)).warning}}var U=e=>e instanceof s&&e.needsLoosenAck,W=x();function G({serverId:e,tenant:t,rule:n,onClose:r,onApplied:o}){let s=O(),[c,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,_]=(0,R.useState)({override:!1,drop:!1,destructive:!1}),[x,S]=(0,R.useState)(!1),[C,w]=(0,R.useState)(!1),E=(0,R.useCallback)(()=>{u(null),f(null),m(null),_({override:!1,drop:!1,destructive:!1}),B(e,t,n).then(u).catch(e=>f(I(e.message)))},[e,t,n]);(0,R.useEffect)(E,[E]);let k=c?V(c):null,A=c!==null&&k!==null&&!k.refused&&(!k.override||h.override)&&(!k.drop||h.drop)&&(!k.destructive||h.destructive);async function j(i){if(c){w(!0),m(null);try{let{warning:a}=await H(e,t,c,{...h,loosens:i});s.show(`ok`,`Rule applied for ${n.match}.`),a&&s.show(`warn`,I(a)),o(),r()}catch(e){!i&&U(e)?S(!0):(S(!1),m(M(e)?{text:P,stale:!0}:{text:I(e.message),stale:!1}))}finally{w(!1)}}}let N=F(n);if(x&&c){let e=c.kind===`rules`?c.preview.loosenReasons.map(I):[];return(0,W.jsx)(g,{open:!0,title:`Let these calls run without asking?`,confirmLabel:`Apply rule`,busy:C,error:p?.text,onCancel:()=>S(!1),onConfirm:()=>void j(!0),consequences:e.length>0?e:[`Calls to ${n.match} that today ask you first will run on their own while their inputs look like the ones seen.`],children:`This rule lets more through than your settings do now. Calls outside what was seen still ask you or are blocked.`})}return(0,W.jsx)(D,{open:!0,onClose:r,dismissable:!C,width:600,title:`Apply suggested rule`,description:(0,W.jsxs)(W.Fragment,{children:[N.lead,` `,(0,W.jsx)(`span`,{className:`font-mono text-[13px] text-ink`,children:N.subject}),N.rest]}),footer:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(b,{variant:`secondary`,onClick:r,disabled:C,children:`Cancel`}),(0,W.jsx)(b,{variant:`primary`,disabled:!A,loading:C,onClick:()=>k?.loosens?S(!0):void j(!1),children:`Apply rule`})]}),children:(0,W.jsx)(`div`,{className:`space-y-4 pb-1 text-[14px]`,children:d?(0,W.jsx)(a,{tone:`danger`,title:`The rule could not be checked`,actions:(0,W.jsx)(b,{size:`sm`,onClick:E,children:`Try again`}),children:d}):!c||!k?(0,W.jsx)(i,{lines:4}):(0,W.jsxs)(W.Fragment,{children:[c.kind===`tool`?(0,W.jsxs)(`div`,{className:`rounded-2xl bg-sunken px-4 py-3`,children:[(0,W.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`What changes for this tool`}),(0,W.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[13px] text-muted`,children:`Now`}),(0,W.jsx)(y,{decision:c.preview.current.kind}),(0,W.jsx)(l,{name:`arrow-right`,size:16,className:`text-soft`}),(0,W.jsx)(`span`,{className:`text-[13px] text-muted`,children:`After`}),(0,W.jsx)(y,{decision:c.preview.verdict.kind})]}),c.preview.bounds&&c.preview.verdict.kind!==`deny`&&(0,W.jsxs)(`p`,{className:`mt-2 text-[13px] text-muted`,children:[`That holds while its inputs stay within the limits below. A call outside them`,` `,c.preview.bounds.onViolation===`approve`?`asks you first`:`is blocked`,`.`]})]}):(0,W.jsxs)(`div`,{className:`rounded-2xl bg-sunken px-4 py-3`,children:[(0,W.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`What changes`}),c.preview.changes.length===0?(0,W.jsx)(`p`,{className:`mt-1 text-[13px] text-muted`,children:`No tool this toolbox serves changes how it is handled.`}):(0,W.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:c.preview.changes.map(e=>(0,W.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`font-mono text-[12.5px]`,children:e.tool}),(0,W.jsx)(y,{decision:e.before}),(0,W.jsx)(l,{name:`arrow-right`,size:14,className:`text-soft`}),(0,W.jsx)(y,{decision:e.after})]},e.tool))})]}),k.refused&&(0,W.jsx)(a,{tone:`info`,title:`This cannot be applied from here`,children:I(k.refused)}),c.kind===`tool`&&c.preview.overridden&&(0,W.jsx)(a,{tone:`warn`,children:I(c.preview.overridden)}),c.kind===`tool`&&c.preview.nameContradiction&&(0,W.jsx)(a,{tone:`warn`,children:I(c.preview.nameContradiction)}),c.kind===`tool`&&!c.preview.reloads&&(0,W.jsx)(`p`,{className:`text-[13px] text-muted`,children:`This toolbox reads its settings only when it starts, so the rule applies after a restart.`}),!k.refused&&(k.override||k.drop||k.destructive)&&(0,W.jsxs)(`div`,{className:`space-y-3 rounded-2xl border border-bad/40 px-4 py-3`,children:[k.override&&(0,W.jsx)(T,{checked:h.override,onChange:e=>_(t=>({...t,override:e})),label:`Reverse rule ${k.override.ruleId}`,description:`Someone set this tool to "${k.override.decision}" with the note "${k.override.reason}". This rule overrides that.`}),k.drop&&(0,W.jsx)(T,{checked:h.drop,onChange:e=>_(t=>({...t,drop:e})),label:`Drop the input limits this tool has today`,description:`Rule ${k.drop} limits this tool's inputs now. Those limits would no longer apply.`}),k.destructive&&(0,W.jsx)(T,{checked:h.destructive,onChange:e=>_(t=>({...t,destructive:e})),label:`Let a tool that deletes run without asking`,description:`Your AI app could remove things with nobody asked first.`})]}),p&&(0,W.jsx)(a,{tone:`danger`,role:`alert`,actions:p.stale?(0,W.jsx)(b,{size:`sm`,onClick:E,children:`Reload preview`}):void 0,children:p.text}),(0,W.jsxs)(`details`,{className:`group`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-medium text-muted select-none`,children:`Show the rule as written in the settings file`}),(0,W.jsx)(`div`,{className:`mt-2`,children:(0,W.jsx)(v,{label:`Rule as written`,maxHeight:240,children:(c.kind,c.preview.yaml??``)})})]})]})})})}var K=[{value:`24h`,label:`Last 24 hours`,ms:864e5,phrase:`in the last 24 hours`},{value:`7d`,label:`Last 7 days`,ms:6048e5,phrase:`in the last 7 days`},{value:`all`,label:`Everything`,ms:null,phrase:`so far`}];function q(){let{serverId:t,tenant:o,nav:s}=A(),l=s.query.get(`since`),f=l===`24h`||l===`7d`?l:`all`,p=K.find(e=>e.value===f),g=(0,R.useMemo)(()=>p.ms?new Date(Date.now()-p.ms).toISOString():void 0,[p]),v=w(()=>u.suggestions(t,g),[t,g]),y=w(()=>u.protection(t,o),[t,o]),[x,T]=(0,R.useState)(null),[D,O]=(0,R.useState)(new Set),[j,M]=(0,R.useState)(!1),N=v.data,P=y.data,F=e=>D.has(e.id)||Y(e,P),L=N?N.rules.filter(e=>!F(e)):[],z=(e,t={})=>n(s,e,t);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_,{title:`Suggestions`,subtitle:`Rules drawn from what your AI app did while the toolbox was in watch-only mode.`,actions:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(c,{size:`sm`,label:`Calls since`,value:f,onChange:e=>E(r(s,{since:e===`all`?null:e})),options:K.map(e=>({value:e.value,label:e.label}))}),N&&N.rules.length>0&&(0,W.jsx)(b,{variant:`primary`,icon:`check`,disabled:L.length===0,onClick:()=>M(!0),children:`Apply all safe suggestions`})]})}),P?.enforcement===`enforce`&&N&&N.calls>0&&(0,W.jsx)(`div`,{className:`mb-4`,children:(0,W.jsx)(a,{tone:`info`,title:`This toolbox is protecting`,children:`Suggestions come from calls recorded in watch-only mode. Those already recorded are shown below; new calls add nothing here until the toolbox is in watch-only mode again.`})}),v.error&&!N?(0,W.jsx)(a,{tone:`danger`,title:`The suggestions could not be loaded`,actions:(0,W.jsx)(b,{size:`sm`,onClick:v.reload,children:`Try again`}),children:I(v.error)}):N?N.calls===0?(0,W.jsx)(C,{children:(0,W.jsx)(d,{level:2,icon:`lightbulb`,title:`No calls recorded in watch-only mode ${p.phrase}`,actions:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(h,{href:z(`/protection`,{focus:`mode`}),variant:`primary`,children:`Open protection mode`}),f!==`all`&&(0,W.jsx)(b,{variant:`secondary`,onClick:()=>E(r(s,{since:null})),children:`Show everything`})]}),children:P?.enforcement===`enforce`?`This toolbox is protecting, so calls are not recorded for suggestions. Switch it to watch-only for a while, use your AI app as you normally would, and suggestions appear here.`:`Suggestions appear after your AI app has been used for a while with the toolbox in watch-only mode. Use it as you normally would, then come back.`})}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,W.jsx)(S,{title:`Calls seen`,value:k(N.calls),sub:J(N)}),(0,W.jsx)(S,{title:`Would run`,value:k(N.wouldRun),sub:`without asking you`}),(0,W.jsx)(S,{title:`Would ask you`,value:k(N.wouldAsk),sub:`before running`,href:z(`/approvals`),hrefLabel:`Open waiting calls`}),(0,W.jsx)(S,{title:`Would be blocked`,value:k(N.wouldRefuse),sub:`had protection been on`})]}),(0,W.jsxs)(`p`,{className:`mt-3 flex items-center gap-1.5 text-[13px] text-soft`,children:[`Every one of these calls ran. The numbers say what would have happened had your rules been applied.`,(0,W.jsx)(m,{term:`watchOnly`})]}),(0,W.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,W.jsx)(X,{title:`Tools nobody has labelled yet`,empty:`Every tool that was called has a label.`,intro:N.onUnclassified===`deny`?`Nobody has said what these do, so with protection on every call to them is blocked. Label each one once.`:`Nobody has said what these do, so with protection on every call to them asks you. Label each one once.`,items:N.unclassified,nav:s,trailing:e=>(0,W.jsx)(h,{size:`sm`,variant:`secondary`,href:n(s,`/tools`,{tool:e.tool}),children:`Label tool`})}),(0,W.jsx)(X,{title:`Calls that would be blocked`,empty:`No call would have been blocked.`,intro:`A rule or setting would stop these. Change it if they should run.`,items:N.refused,nav:s,detail:e=>(0,W.jsxs)(W.Fragment,{children:[I(e.reason),` `,(0,W.jsx)(`span`,{className:`font-mono text-[11.5px]`,children:e.ruleId})]})})]}),(0,W.jsx)(`div`,{className:`mt-4`,children:(0,W.jsx)(X,{title:`Calls that would ask you`,empty:`No call would have waited for you.`,intro:`These would wait for your approval each time. Where the calls looked alike, a rule below lets the usual ones run.`,items:N.asked,nav:s,detail:e=>I(e.why),trailing:t=>t.suggested?(0,W.jsx)(e,{tone:`ok`,icon:`lightbulb`,children:`Rule suggested`}):null})}),(0,W.jsxs)(`section`,{className:`mt-8`,"aria-labelledby":`suggested-rules`,children:[(0,W.jsxs)(`header`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{id:`suggested-rules`,className:`text-[22px] font-medium tracking-[-0.02em]`,children:`Suggested rules`}),(0,W.jsx)(m,{term:`rule`}),y.error&&!P&&(0,W.jsx)(e,{tone:`warn`,children:`Could not check which are already applied`})]}),N.rules.length===0?(0,W.jsx)(C,{children:(0,W.jsx)(d,{icon:`lightbulb`,title:`No rules to suggest`,compact:!0,children:`A rule is suggested when a tool asked you at least three times with inputs that look alike. Tools that delete things are always left to you.`})}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 gap-4 xl:grid-cols-2`,children:N.rules.map(e=>(0,W.jsx)(Z,{rule:e,note:N.notes[e.id],done:F(e),canWrite:P?.policyWrite.ok??!0,onApply:()=>T(e)},e.id))})]})]}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[0,1,2,3].map(e=>(0,W.jsx)(C,{children:(0,W.jsx)(i,{lines:3,height:18})},e))}),x&&(0,W.jsx)(G,{serverId:t,tenant:o,rule:x,onClose:()=>T(null),onApplied:()=>{O(e=>new Set(e).add(x.id)),y.reload()}}),j&&N&&(0,W.jsx)(Q,{serverId:t,tenant:o,rules:L,onClose:()=>M(!1),onApplied:e=>O(t=>new Set(t).add(e)),onDone:()=>{v.reload(),y.reload()}})]})}function J(e){return!e.from||!e.to?`recorded in watch-only mode`:`${new Date(e.from).toLocaleDateString(void 0,{day:`numeric`,month:`short`})} to ${new Date(e.to).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`}function Y(e,t){if(!t)return!1;let n=t.tools.find(t=>t.name===e.match);return!!n&&n.consoleRule!==null&&n.verdict.kind===e.decision}function X({title:r,intro:i,empty:a,items:o,nav:s,detail:c,trailing:l}){return(0,W.jsx)(C,{title:r,actions:(0,W.jsx)(e,{tone:`neutral`,children:t(o.length,`tool`)}),children:o.length===0?(0,W.jsx)(d,{icon:`check`,title:a,compact:!0}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`-mt-2 mb-2 text-[13px] text-soft`,children:i}),(0,W.jsx)(`div`,{className:`-my-1`,children:o.map(e=>(0,W.jsx)(f,{leading:(0,W.jsx)(`span`,{className:`grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,W.jsx)(p,{effect:e.effect})}),title:(0,W.jsx)(`span`,{className:`font-mono text-[13px]`,children:e.tool}),sub:(0,W.jsxs)(W.Fragment,{children:[`Called `,t(e.calls,`time`),c&&(0,W.jsxs)(W.Fragment,{children:[` · `,c(e)]})]}),trailing:l?.(e)??(0,W.jsx)(h,{size:`sm`,variant:`ghost`,href:n(s,`/tools`,{tool:e.tool}),children:`Open tool`})},e.tool))})]})})}function Z({rule:t,note:n,done:r,canWrite:i,onApply:a}){let o=F(t),s=Object.entries(t.args??{});return(0,W.jsxs)(C,{as:`article`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`p`,{className:`text-[17px] leading-snug font-medium tracking-[-0.01em]`,children:[o.lead,` `,(0,W.jsx)(`span`,{className:`font-mono text-[15px] break-all`,children:o.subject}),o.rest]}),(0,W.jsx)(`p`,{className:`mt-1 font-mono text-[11.5px] text-soft`,children:t.id})]}),r?(0,W.jsx)(e,{tone:`ok`,icon:`check`,children:`Applied`}):(0,W.jsx)(b,{variant:`primary`,size:`sm`,onClick:a,disabled:!i,title:i?void 0:`The protection settings file cannot be changed from here`,children:`Apply rule`})]}),n&&(0,W.jsxs)(`p`,{className:`mt-3 text-[13px] text-muted`,children:[`Based on `,n.charAt(0).toLowerCase()+n.slice(1)]}),s.length>0&&(0,W.jsx)(`ul`,{className:`mt-3 space-y-1 rounded-2xl bg-sunken px-4 py-3 text-[13px]`,children:s.map(([e,t])=>(0,W.jsxs)(`li`,{className:`flex flex-wrap gap-x-2`,children:[(0,W.jsx)(`span`,{className:`font-mono text-[12px] text-ink`,children:e}),(0,W.jsx)(`span`,{className:`text-muted`,children:L(t)})]},e))}),(0,W.jsxs)(`details`,{className:`mt-3`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-medium text-muted select-none`,children:`Show the rule as written`}),(0,W.jsx)(`div`,{className:`mt-2`,children:(0,W.jsx)(v,{label:`Rule ${t.id}`,maxHeight:260,copy:!0,children:N(t)})})]})]})}function Q({serverId:e,tenant:n,rules:r,onClose:i,onApplied:a,onDone:o}){let s=O(),[c,l]=(0,R.useState)(()=>r.map(e=>({rule:e,state:`waiting`}))),[u,d]=(0,R.useState)(`ready`);async function f(){d(`running`);let i=(e,t)=>l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),c=0;for(let[t,o]of r.entries()){i(t,{state:`checking`});try{let r=await B(e,n,o),s=V(r),l=s.refused?I(s.refused):s.loosens?`Lets calls run without asking. Apply it on its own to confirm.`:s.override||s.drop||s.destructive?`Needs your confirmation. Apply it on its own.`:null;if(l){i(t,{state:`skipped`,why:l});continue}let{warning:u}=await H(e,n,r,{});c++,a(o.id),i(t,{state:`applied`,...u?{why:I(u)}:{}})}catch(e){i(t,{state:`failed`,why:M(e)?P:I(e.message)})}}d(`done`),c>0&&s.show(`ok`,`${t(c,`rule`)} applied.`),o()}let p=c.filter(e=>e.state===`applied`).length,m=c.filter(e=>e.state===`skipped`).length,h=c.filter(e=>e.state===`failed`).length,g=c.findIndex(e=>e.state===`checking`);return(0,W.jsx)(D,{open:!0,onClose:i,dismissable:u!==`running`,width:600,title:`Apply all safe suggestions`,description:u===`ready`?`Only rules that let nothing more through than today are applied. Any that would let calls run without asking you are skipped, so you can look at each on its own.`:u===`running`?`Checking ${g+1} of ${c.length}`:`${t(p,`rule`)} applied, ${m} skipped${h?`, ${h} failed`:``}.`,footer:u===`ready`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(b,{variant:`secondary`,onClick:i,children:`Cancel`}),(0,W.jsx)(b,{variant:`primary`,onClick:()=>void f(),children:`Check and apply ${t(c.length,`rule`)}`})]}):(0,W.jsx)(b,{variant:`primary`,onClick:i,disabled:u===`running`,loading:u===`running`,children:`Close summary`}),children:(0,W.jsx)(`ul`,{className:`space-y-2 pb-1`,"aria-live":`polite`,children:c.map(e=>(0,W.jsxs)(`li`,{className:`flex items-start gap-3 rounded-2xl bg-sunken px-3 py-2.5`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate font-mono text-[13px]`,children:e.rule.match}),e.why&&(0,W.jsx)(`span`,{className:`mt-0.5 block text-[12.5px] text-soft`,children:e.why})]}),(0,W.jsx)($,{state:e.state})]},e.rule.id))})})}function $({state:t}){return t===`applied`?(0,W.jsx)(e,{tone:`ok`,icon:`check`,children:`Applied`}):t===`skipped`?(0,W.jsx)(e,{tone:`warn`,children:`Skipped`}):t===`failed`?(0,W.jsx)(e,{tone:`bad`,icon:`x`,children:`Not applied`}):t===`checking`?(0,W.jsx)(e,{tone:`neutral`,children:`Checking`}):(0,W.jsx)(e,{tone:`neutral`,children:`Waiting`})}export{q as SuggestionsPage};
1
+ import{$ as e,B as t,Ct as n,Et as r,G as i,H as a,It as o,Nt as s,O as c,Ot as l,Pt as u,U as d,W as f,Z as p,_ as m,_t as h,b as g,c as _,d as v,et as y,ht as b,kt as x,mt as S,pt as C,s as w,w as T,wt as E,x as D,y as O,z as k}from"./kit-DRVm92_t.js";import{dt as A,ft as j,ht as M,lt as N,mt as P,pt as F,un as I,ut as L}from"./index-DttDjRpu.js";var R=o(),z=`Suggested from what watch-only mode recorded`;async function B(e,t,n){if(!A(n.match)&&n.effect){let r={tool:n.match,effect:n.effect,decision:n.decision,...n.args?{args:n.args}:{},...n.on_violation?{on_violation:n.on_violation}:{},...n.unknown_args?{unknown_args:n.unknown_args}:{},reason:n.reason??z};return{kind:`tool`,body:r,preview:await u.toolRulePreview(e,r,t)}}let r={...n,reason:n.reason??z};return{kind:`rules`,rule:r,preview:await u.previewRules(e,{op:`add`,rule:r,index:0},t)}}function V(e){if(e.kind===`tool`){let t=e.preview,n=t.overriddenReason;return{override:n,drop:t.dropsBounds,destructive:e.body.effect===`destructive`&&e.body.decision===`allow`,loosens:t.loosens,refused:t.writable.ok?n&&!t.overridesAllowed?`This toolbox does not let the console reverse rule ${n.ruleId}. Change it in the protection settings file instead.`:null:t.writable.why??`The protection settings file cannot be changed from here.`}}let t=e.preview;return{override:null,drop:null,destructive:!1,loosens:t.loosens,refused:t.writable.ok?t.loosens&&!t.overridesAllowed?`This toolbox lets the console tighten its rules but not loosen them.`:null:t.writable.why??`The protection settings file cannot be changed from here.`}}async function H(e,t,n,r){if(n.kind===`tool`){let i=n.preview,a={...r.override&&i.overriddenReason?{overrideDeny:i.overriddenReason.ruleId}:{},...r.drop&&i.dropsBounds?{dropBounds:!0}:{},...r.destructive?{destructiveAllow:!0}:{}};return{warning:(await u.setToolRule(e,{...n.body,expectedDigest:i.expectedDigest,...Object.keys(a).length>0?{acknowledged:a}:{}},t)).warning}}return{warning:(await u.addRule(e,n.rule,n.preview.expectedDigest,0,r.loosens?{loosens:!0}:void 0,t)).warning}}var U=e=>e instanceof s&&e.needsLoosenAck,W=x();function G({serverId:e,tenant:t,rule:n,onClose:r,onApplied:o}){let s=O(),[c,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,_]=(0,R.useState)({override:!1,drop:!1,destructive:!1}),[x,S]=(0,R.useState)(!1),[C,w]=(0,R.useState)(!1),E=(0,R.useCallback)(()=>{u(null),f(null),m(null),_({override:!1,drop:!1,destructive:!1}),B(e,t,n).then(u).catch(e=>f(F(e.message)))},[e,t,n]);(0,R.useEffect)(E,[E]);let k=c?V(c):null,A=c!==null&&k!==null&&!k.refused&&(!k.override||h.override)&&(!k.drop||h.drop)&&(!k.destructive||h.destructive);async function M(i){if(c){w(!0),m(null);try{let{warning:a}=await H(e,t,c,{...h,loosens:i});s.show(`ok`,`Rule applied for ${n.match}.`),a&&s.show(`warn`,F(a)),o(),r()}catch(e){!i&&U(e)?S(!0):(S(!1),m(j(e)?{text:N,stale:!0}:{text:F(e.message),stale:!1}))}finally{w(!1)}}}let I=P(n);if(x&&c){let e=c.kind===`rules`?c.preview.loosenReasons.map(F):[];return(0,W.jsx)(g,{open:!0,title:`Let these calls run without asking?`,confirmLabel:`Apply rule`,busy:C,error:p?.text,onCancel:()=>S(!1),onConfirm:()=>void M(!0),consequences:e.length>0?e:[`Calls to ${n.match} that today ask you first will run on their own while their inputs look like the ones seen.`],children:`This rule lets more through than your settings do now. Calls outside what was seen still ask you or are blocked.`})}return(0,W.jsx)(D,{open:!0,onClose:r,dismissable:!C,width:600,title:`Apply suggested rule`,description:(0,W.jsxs)(W.Fragment,{children:[I.lead,` `,(0,W.jsx)(`span`,{className:`font-mono text-[13px] text-ink`,children:I.subject}),I.rest]}),footer:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(b,{variant:`secondary`,onClick:r,disabled:C,children:`Cancel`}),(0,W.jsx)(b,{variant:`primary`,disabled:!A,loading:C,onClick:()=>k?.loosens?S(!0):void M(!1),children:`Apply rule`})]}),children:(0,W.jsx)(`div`,{className:`space-y-4 pb-1 text-[14px]`,children:d?(0,W.jsx)(a,{tone:`danger`,title:`The rule could not be checked`,actions:(0,W.jsx)(b,{size:`sm`,onClick:E,children:`Try again`}),children:d}):!c||!k?(0,W.jsx)(i,{lines:4}):(0,W.jsxs)(W.Fragment,{children:[c.kind===`tool`?(0,W.jsxs)(`div`,{className:`rounded-2xl bg-sunken px-4 py-3`,children:[(0,W.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`What changes for this tool`}),(0,W.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[13px] text-muted`,children:`Now`}),(0,W.jsx)(y,{decision:c.preview.current.kind}),(0,W.jsx)(l,{name:`arrow-right`,size:16,className:`text-soft`}),(0,W.jsx)(`span`,{className:`text-[13px] text-muted`,children:`After`}),(0,W.jsx)(y,{decision:c.preview.verdict.kind})]}),c.preview.bounds&&c.preview.verdict.kind!==`deny`&&(0,W.jsxs)(`p`,{className:`mt-2 text-[13px] text-muted`,children:[`That holds while its inputs stay within the limits below. A call outside them`,` `,c.preview.bounds.onViolation===`approve`?`asks you first`:`is blocked`,`.`]})]}):(0,W.jsxs)(`div`,{className:`rounded-2xl bg-sunken px-4 py-3`,children:[(0,W.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`What changes`}),c.preview.changes.length===0?(0,W.jsx)(`p`,{className:`mt-1 text-[13px] text-muted`,children:`No tool this toolbox serves changes how it is handled.`}):(0,W.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:c.preview.changes.map(e=>(0,W.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`font-mono text-[12.5px]`,children:e.tool}),(0,W.jsx)(y,{decision:e.before}),(0,W.jsx)(l,{name:`arrow-right`,size:14,className:`text-soft`}),(0,W.jsx)(y,{decision:e.after})]},e.tool))})]}),k.refused&&(0,W.jsx)(a,{tone:`info`,title:`This cannot be applied from here`,children:F(k.refused)}),c.kind===`tool`&&c.preview.overridden&&(0,W.jsx)(a,{tone:`warn`,children:F(c.preview.overridden)}),c.kind===`tool`&&c.preview.nameContradiction&&(0,W.jsx)(a,{tone:`warn`,children:F(c.preview.nameContradiction)}),c.kind===`tool`&&!c.preview.reloads&&(0,W.jsx)(`p`,{className:`text-[13px] text-muted`,children:`This toolbox reads its settings only when it starts, so the rule applies after a restart.`}),!k.refused&&(k.override||k.drop||k.destructive)&&(0,W.jsxs)(`div`,{className:`space-y-3 rounded-2xl border border-bad/40 px-4 py-3`,children:[k.override&&(0,W.jsx)(T,{checked:h.override,onChange:e=>_(t=>({...t,override:e})),label:`Reverse rule ${k.override.ruleId}`,description:`Someone set this tool to "${k.override.decision}" with the note "${k.override.reason}". This rule overrides that.`}),k.drop&&(0,W.jsx)(T,{checked:h.drop,onChange:e=>_(t=>({...t,drop:e})),label:`Drop the input limits this tool has today`,description:`Rule ${k.drop} limits this tool's inputs now. Those limits would no longer apply.`}),k.destructive&&(0,W.jsx)(T,{checked:h.destructive,onChange:e=>_(t=>({...t,destructive:e})),label:`Let a tool that deletes run without asking`,description:`Your AI app could remove things with nobody asked first.`})]}),p&&(0,W.jsx)(a,{tone:`danger`,role:`alert`,actions:p.stale?(0,W.jsx)(b,{size:`sm`,onClick:E,children:`Reload preview`}):void 0,children:p.text}),(0,W.jsxs)(`details`,{className:`group`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-medium text-muted select-none`,children:`Show the rule as written in the settings file`}),(0,W.jsx)(`div`,{className:`mt-2`,children:(0,W.jsx)(v,{label:`Rule as written`,maxHeight:240,children:(c.kind,c.preview.yaml??``)})})]})]})})})}var K=[{value:`24h`,label:`Last 24 hours`,ms:864e5,phrase:`in the last 24 hours`},{value:`7d`,label:`Last 7 days`,ms:6048e5,phrase:`in the last 7 days`},{value:`all`,label:`Everything`,ms:null,phrase:`so far`}];function q(){let{serverId:t,tenant:o,nav:s}=I(),l=s.query.get(`since`),f=l===`24h`||l===`7d`?l:`all`,p=K.find(e=>e.value===f),g=(0,R.useMemo)(()=>p.ms?new Date(Date.now()-p.ms).toISOString():void 0,[p]),v=w(()=>u.suggestions(t,g),[t,g]),y=w(()=>u.protection(t,o),[t,o]),[x,T]=(0,R.useState)(null),[D,O]=(0,R.useState)(new Set),[A,j]=(0,R.useState)(!1),M=v.data,N=y.data,P=e=>D.has(e.id)||Y(e,N),L=M?M.rules.filter(e=>!P(e)):[],z=(e,t={})=>n(s,e,t);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_,{title:`Suggestions`,subtitle:`Rules drawn from what your AI app did while the toolbox was in watch-only mode.`,actions:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(c,{size:`sm`,label:`Calls since`,value:f,onChange:e=>E(r(s,{since:e===`all`?null:e})),options:K.map(e=>({value:e.value,label:e.label}))}),M&&M.rules.length>0&&(0,W.jsx)(b,{variant:`primary`,icon:`check`,disabled:L.length===0,onClick:()=>j(!0),children:`Apply all safe suggestions`})]})}),N?.enforcement===`enforce`&&M&&M.calls>0&&(0,W.jsx)(`div`,{className:`mb-4`,children:(0,W.jsx)(a,{tone:`info`,title:`This toolbox is protecting`,children:`Suggestions come from calls recorded in watch-only mode. Those already recorded are shown below; new calls add nothing here until the toolbox is in watch-only mode again.`})}),v.error&&!M?(0,W.jsx)(a,{tone:`danger`,title:`The suggestions could not be loaded`,actions:(0,W.jsx)(b,{size:`sm`,onClick:v.reload,children:`Try again`}),children:F(v.error)}):M?M.calls===0?(0,W.jsx)(C,{children:(0,W.jsx)(d,{level:2,icon:`lightbulb`,title:`No calls recorded in watch-only mode ${p.phrase}`,actions:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(h,{href:z(`/protection`,{focus:`mode`}),variant:`primary`,children:`Open protection mode`}),f!==`all`&&(0,W.jsx)(b,{variant:`secondary`,onClick:()=>E(r(s,{since:null})),children:`Show everything`})]}),children:N?.enforcement===`enforce`?`This toolbox is protecting, so calls are not recorded for suggestions. Switch it to watch-only for a while, use your AI app as you normally would, and suggestions appear here.`:`Suggestions appear after your AI app has been used for a while with the toolbox in watch-only mode. Use it as you normally would, then come back.`})}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,W.jsx)(S,{title:`Calls seen`,value:k(M.calls),sub:J(M)}),(0,W.jsx)(S,{title:`Would run`,value:k(M.wouldRun),sub:`without asking you`}),(0,W.jsx)(S,{title:`Would ask you`,value:k(M.wouldAsk),sub:`before running`,href:z(`/approvals`),hrefLabel:`Open waiting calls`}),(0,W.jsx)(S,{title:`Would be blocked`,value:k(M.wouldRefuse),sub:`had protection been on`})]}),(0,W.jsxs)(`p`,{className:`mt-3 flex items-center gap-1.5 text-[13px] text-soft`,children:[`Every one of these calls ran. The numbers say what would have happened had your rules been applied.`,(0,W.jsx)(m,{term:`watchOnly`})]}),(0,W.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,W.jsx)(X,{title:`Tools nobody has labelled yet`,empty:`Every tool that was called has a label.`,intro:M.onUnclassified===`deny`?`Nobody has said what these do, so with protection on every call to them is blocked. Label each one once.`:`Nobody has said what these do, so with protection on every call to them asks you. Label each one once.`,items:M.unclassified,nav:s,trailing:e=>(0,W.jsx)(h,{size:`sm`,variant:`secondary`,href:n(s,`/tools`,{tool:e.tool}),children:`Label tool`})}),(0,W.jsx)(X,{title:`Calls that would be blocked`,empty:`No call would have been blocked.`,intro:`A rule or setting would stop these. Change it if they should run.`,items:M.refused,nav:s,detail:e=>(0,W.jsxs)(W.Fragment,{children:[F(e.reason),` `,(0,W.jsx)(`span`,{className:`font-mono text-[11.5px]`,children:e.ruleId})]})})]}),(0,W.jsx)(`div`,{className:`mt-4`,children:(0,W.jsx)(X,{title:`Calls that would ask you`,empty:`No call would have waited for you.`,intro:`These would wait for your approval each time. Where the calls looked alike, a rule below lets the usual ones run.`,items:M.asked,nav:s,detail:e=>F(e.why),trailing:t=>t.suggested?(0,W.jsx)(e,{tone:`ok`,icon:`lightbulb`,children:`Rule suggested`}):null})}),(0,W.jsxs)(`section`,{className:`mt-8`,"aria-labelledby":`suggested-rules`,children:[(0,W.jsxs)(`header`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{id:`suggested-rules`,className:`text-[22px] font-medium tracking-[-0.02em]`,children:`Suggested rules`}),(0,W.jsx)(m,{term:`rule`}),y.error&&!N&&(0,W.jsx)(e,{tone:`warn`,children:`Could not check which are already applied`})]}),M.rules.length===0?(0,W.jsx)(C,{children:(0,W.jsx)(d,{icon:`lightbulb`,title:`No rules to suggest`,compact:!0,children:`A rule is suggested when a tool asked you at least three times with inputs that look alike. Tools that delete things are always left to you.`})}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 gap-4 xl:grid-cols-2`,children:M.rules.map(e=>(0,W.jsx)(Z,{rule:e,note:M.notes[e.id],done:P(e),canWrite:N?.policyWrite.ok??!0,onApply:()=>T(e)},e.id))})]})]}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[0,1,2,3].map(e=>(0,W.jsx)(C,{children:(0,W.jsx)(i,{lines:3,height:18})},e))}),x&&(0,W.jsx)(G,{serverId:t,tenant:o,rule:x,onClose:()=>T(null),onApplied:()=>{O(e=>new Set(e).add(x.id)),y.reload()}}),A&&M&&(0,W.jsx)(Q,{serverId:t,tenant:o,rules:L,onClose:()=>j(!1),onApplied:e=>O(t=>new Set(t).add(e)),onDone:()=>{v.reload(),y.reload()}})]})}function J(e){return!e.from||!e.to?`recorded in watch-only mode`:`${new Date(e.from).toLocaleDateString(void 0,{day:`numeric`,month:`short`})} to ${new Date(e.to).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`}function Y(e,t){if(!t)return!1;let n=t.tools.find(t=>t.name===e.match);return!!n&&n.consoleRule!==null&&n.verdict.kind===e.decision}function X({title:r,intro:i,empty:a,items:o,nav:s,detail:c,trailing:l}){return(0,W.jsx)(C,{title:r,actions:(0,W.jsx)(e,{tone:`neutral`,children:t(o.length,`tool`)}),children:o.length===0?(0,W.jsx)(d,{icon:`check`,title:a,compact:!0}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`-mt-2 mb-2 text-[13px] text-soft`,children:i}),(0,W.jsx)(`div`,{className:`-my-1`,children:o.map(e=>(0,W.jsx)(f,{leading:(0,W.jsx)(`span`,{className:`grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,W.jsx)(p,{effect:e.effect})}),title:(0,W.jsx)(`span`,{className:`font-mono text-[13px]`,children:e.tool}),sub:(0,W.jsxs)(W.Fragment,{children:[`Called `,t(e.calls,`time`),c&&(0,W.jsxs)(W.Fragment,{children:[` · `,c(e)]})]}),trailing:l?.(e)??(0,W.jsx)(h,{size:`sm`,variant:`ghost`,href:n(s,`/tools`,{tool:e.tool}),children:`Open tool`})},e.tool))})]})})}function Z({rule:t,note:n,done:r,canWrite:i,onApply:a}){let o=P(t),s=Object.entries(t.args??{});return(0,W.jsxs)(C,{as:`article`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`p`,{className:`text-[17px] leading-snug font-medium tracking-[-0.01em]`,children:[o.lead,` `,(0,W.jsx)(`span`,{className:`font-mono text-[15px] break-all`,children:o.subject}),o.rest]}),(0,W.jsx)(`p`,{className:`mt-1 font-mono text-[11.5px] text-soft`,children:t.id})]}),r?(0,W.jsx)(e,{tone:`ok`,icon:`check`,children:`Applied`}):(0,W.jsx)(b,{variant:`primary`,size:`sm`,onClick:a,disabled:!i,title:i?void 0:`The protection settings file cannot be changed from here`,children:`Apply rule`})]}),n&&(0,W.jsxs)(`p`,{className:`mt-3 text-[13px] text-muted`,children:[`Based on `,n.charAt(0).toLowerCase()+n.slice(1)]}),s.length>0&&(0,W.jsx)(`ul`,{className:`mt-3 space-y-1 rounded-2xl bg-sunken px-4 py-3 text-[13px]`,children:s.map(([e,t])=>(0,W.jsxs)(`li`,{className:`flex flex-wrap gap-x-2`,children:[(0,W.jsx)(`span`,{className:`font-mono text-[12px] text-ink`,children:e}),(0,W.jsx)(`span`,{className:`text-muted`,children:L(t)})]},e))}),(0,W.jsxs)(`details`,{className:`mt-3`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-medium text-muted select-none`,children:`Show the rule as written`}),(0,W.jsx)(`div`,{className:`mt-2`,children:(0,W.jsx)(v,{label:`Rule ${t.id}`,maxHeight:260,copy:!0,children:M(t)})})]})]})}function Q({serverId:e,tenant:n,rules:r,onClose:i,onApplied:a,onDone:o}){let s=O(),[c,l]=(0,R.useState)(()=>r.map(e=>({rule:e,state:`waiting`}))),[u,d]=(0,R.useState)(`ready`);async function f(){d(`running`);let i=(e,t)=>l(n=>n.map((n,r)=>r===e?{...n,...t}:n)),c=0;for(let[t,o]of r.entries()){i(t,{state:`checking`});try{let r=await B(e,n,o),s=V(r),l=s.refused?F(s.refused):s.loosens?`Lets calls run without asking. Apply it on its own to confirm.`:s.override||s.drop||s.destructive?`Needs your confirmation. Apply it on its own.`:null;if(l){i(t,{state:`skipped`,why:l});continue}let{warning:u}=await H(e,n,r,{});c++,a(o.id),i(t,{state:`applied`,...u?{why:F(u)}:{}})}catch(e){i(t,{state:`failed`,why:j(e)?N:F(e.message)})}}d(`done`),c>0&&s.show(`ok`,`${t(c,`rule`)} applied.`),o()}let p=c.filter(e=>e.state===`applied`).length,m=c.filter(e=>e.state===`skipped`).length,h=c.filter(e=>e.state===`failed`).length,g=c.findIndex(e=>e.state===`checking`);return(0,W.jsx)(D,{open:!0,onClose:i,dismissable:u!==`running`,width:600,title:`Apply all safe suggestions`,description:u===`ready`?`Only rules that let nothing more through than today are applied. Any that would let calls run without asking you are skipped, so you can look at each on its own.`:u===`running`?`Checking ${g+1} of ${c.length}`:`${t(p,`rule`)} applied, ${m} skipped${h?`, ${h} failed`:``}.`,footer:u===`ready`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(b,{variant:`secondary`,onClick:i,children:`Cancel`}),(0,W.jsx)(b,{variant:`primary`,onClick:()=>void f(),children:`Check and apply ${t(c.length,`rule`)}`})]}):(0,W.jsx)(b,{variant:`primary`,onClick:i,disabled:u===`running`,loading:u===`running`,children:`Close summary`}),children:(0,W.jsx)(`ul`,{className:`space-y-2 pb-1`,"aria-live":`polite`,children:c.map(e=>(0,W.jsxs)(`li`,{className:`flex items-start gap-3 rounded-2xl bg-sunken px-3 py-2.5`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate font-mono text-[13px]`,children:e.rule.match}),e.why&&(0,W.jsx)(`span`,{className:`mt-0.5 block text-[12.5px] text-soft`,children:e.why})]}),(0,W.jsx)($,{state:e.state})]},e.rule.id))})})}function $({state:t}){return t===`applied`?(0,W.jsx)(e,{tone:`ok`,icon:`check`,children:`Applied`}):t===`skipped`?(0,W.jsx)(e,{tone:`warn`,children:`Skipped`}):t===`failed`?(0,W.jsx)(e,{tone:`bad`,icon:`x`,children:`Not applied`}):t===`checking`?(0,W.jsx)(e,{tone:`neutral`,children:`Checking`}):(0,W.jsx)(e,{tone:`neutral`,children:`Waiting`})}export{q as SuggestionsPage};
@@ -0,0 +1,4 @@
1
+ import{$ as e,A as t,B as n,Ct as r,D as i,E as a,Et as o,G as s,H as c,I as l,It as u,J as d,M as f,N as p,Nt as m,O as h,Ot as g,Pt as _,Q as v,S as y,U as b,V as x,Y as S,Z as C,_ as w,_t as T,bt as ee,c as te,d as E,et as D,f as O,ft as ne,gt as k,ht as A,k as re,kt as j,lt as M,ot as N,pt as P,q as ie,rt as F,s as ae,st as I,w as L,wt as oe,x as R,y as z,yt as B}from"./kit-DRVm92_t.js";import{_n as se,bn as V,fn as ce,gn as le,pn as H,un as ue}from"./index-DttDjRpu.js";var U=u(),de=[`allow`,`approve`,`deny`,`unlabelled`,`off`,`changed`],W={allow:`Runs freely`,approve:`Asks you first`,deny:`Blocked`,unlabelled:`Not labelled`,off:`Turned off`,changed:`Changed`};function fe(e){return e!==null&&de.includes(e)}function G(e){return e.exposure.disabled?`off`:e.effect===null&&!e.reclassifiedTo?`unlabelled`:e.verdict.kind}function K(e){let t=e.reclassifiedTo??e.effect;return t===`read`||t===`write`||t===`destructive`?t:null}function q(e){return e.standingGrants.some(e=>e.covers)}function pe(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 ${n.onViolation===`approve`?`asks you first`:`is blocked`}.`:`Runs freely, without asking anyone.`}function me(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: ${X(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. ${I[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 he={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.`},J={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 ge(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 _e(e){return e.pattern!==void 0||e.coerce!==void 0||e.required!==void 0}function ve(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 Y(e){return e?e.paths.map(t=>`${t} ${ve(e.constraints[t]??{})}`):[]}var ye={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 X(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 Z(e){return X(e instanceof Error?e.message:String(e))}function be(e){return e instanceof m&&e.status===409}var xe=`This changed since you opened it. Reload and try again.`;function Se(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 Q=j(),Ce={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 we(e){return e.previousKnown?e.changes.length===0?[`Its details changed.`]:e.changes.map(e=>Ce[e]??e):[`Something changed, but the earlier version wasn't kept, so the toolbox can't show what.`]}function Te({serverId:e,data:t,error:r,loading:i,reload:a,onAccepted:o}){let l=z(),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(!1);async function v(t){p(!0);try{let n=t?await H(e,t):await ce(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`),le(e).then(h,()=>h(null))),a(),o()}catch(e){l.show(`bad`,`Not accepted. ${Z(e)}`)}finally{p(!1)}}async function y(){_(!0);try{let t=await V(e);l.show(`ok`,`The toolbox restarted. Accepted tools are available again.`),t.warning&&l.show(`warn`,X(t.warning)),h(null),a(),o()}catch(e){l.show(`bad`,`The toolbox didn't restart. ${Z(e)}`)}finally{_(!1)}}if(r&&!t)return(0,Q.jsx)(c,{tone:`danger`,title:`Changed tools couldn't be loaded`,actions:(0,Q.jsx)(A,{size:`sm`,icon:`refresh`,onClick:a,children:`Try again`}),children:Z(r)});if(!t)return(0,Q.jsx)(P,{children:(0,Q.jsx)(s,{lines:5})});let S=t.changed;return(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[m&&(0,Q.jsx)(c,{tone:`warn`,title:`Restart the toolbox to bring accepted tools back`,actions:m!==`checking`&&m.managed&&(0,Q.jsx)(A,{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. ${X(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,Q.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,Q.jsxs)(P,{title:(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[`Changed tools `,(0,Q.jsx)(w,{term:`changedTools`})]}),actions:S.length>1&&(0,Q.jsx)(A,{size:`sm`,variant:`primary`,icon:`check`,disabled:!t.live,onClick:()=>d({tool:null}),children:`Accept all`}),children:[(0,Q.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,Q.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,Q.jsx)(`ul`,{className:`space-y-3`,children:S.map(e=>(0,Q.jsx)(Ee,{change:e,live:t.live,loading:i,onAccept:()=>d({tool:e.tool})},e.tool))})]}),t.pins.length>0&&(0,Q.jsx)(P,{padded:!1,children:(0,Q.jsxs)(`details`,{className:`group p-6`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer items-center justify-between gap-3 text-[17px] font-medium tracking-[-0.015em]`,children:[`Reviewed tools`,(0,Q.jsx)(`span`,{className:`text-[13px] font-normal text-soft`,children:n(t.pins.length,`tool`)})]}),(0,Q.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,Q.jsx)(`ul`,{className:`mt-3 divide-y divide-faint`,children:t.pins.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-0.5 py-2.5`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-[13.5px] break-all`,children:e.tool}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[`Accepted `,x(e.pinnedAt),` by `,e.pinnedBy,(0,Q.jsx)(`span`,{className:`ml-2 font-mono text-[11px]`,children:e.digest.slice(0,12)})]})]},e.tool))})]})}),(0,Q.jsx)(R,{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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(A,{variant:`secondary`,onClick:()=>d(null),disabled:f,children:`Cancel`}),(0,Q.jsx)(A,{variant:`primary`,icon:`check`,loading:f,onClick:()=>void v(u?.tool??null),children:u?.tool?`Accept change`:`Accept all`})]}),children:(0,Q.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 Ee({change:t,live:n,loading:r,onAccept:i}){let a=t.was;return(0,Q.jsxs)(`li`,{className:`rounded-[20px] border border-line p-4 sm:p-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-[14.5px] font-medium break-all`,children:t.tool}),t.withheld?(0,Q.jsx)(e,{tone:`bad`,icon:`lock`,children:`Held back until reviewed`}):(0,Q.jsx)(e,{tone:`warn`,icon:`refresh`,children:`Changed`})]}),(0,Q.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Noticed `,x(t.detectedAt),` · last accepted `,x(t.pinnedAt),` by `,t.pinnedBy]})]}),(0,Q.jsx)(A,{size:`sm`,variant:`primary`,icon:`check`,onClick:i,disabled:!n||r,children:`Accept change`})]}),(0,Q.jsx)(`ul`,{className:`mt-3 space-y-1`,children:we(t).map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-2 text-[13.5px]`,children:[(0,Q.jsx)(`span`,{className:`mt-[8px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),e]},e))}),a&&(0,Q.jsxs)(`details`,{className:`mt-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`See what changed`}),(0,Q.jsxs)(`div`,{className:`mt-3 space-y-4`,children:[a.effect!==t.now.effect&&(0,Q.jsxs)(`p`,{className:`text-[13.5px]`,children:[`What it does: `,(0,Q.jsx)(`strong`,{children:F[a.effect??`unknown`].label}),` →`,` `,(0,Q.jsx)(`strong`,{children:F[t.now.effect??`unknown`].label})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Description`}),(0,Q.jsx)(O,{before:Se(a.description),after:Se(t.now.description),label:`Description of ${t.tool}, before and after`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Inputs`}),(0,Q.jsx)(O,{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,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1.5 text-[12.5px] font-semibold text-soft`,children:`Hints from its server`}),(0,Q.jsx)(O,{before:JSON.stringify(a.annotations??{},null,2),after:JSON.stringify(t.now.annotations??{},null,2),label:`Hints for ${t.tool}, before and after`})]})]})]})]})}function De(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 Oe(e){let t=z(),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),o=De(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`,Z(r.warning)),e.onChanged(),!0}catch(e){return t.show(`bad`,`${n.name} was not changed. ${Z(e)}`),!1}finally{r(null)}}function c(e,t,n=``){let r=K(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,Q.jsx)(R,{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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(A,{variant:`secondary`,onClick:()=>a(null),children:`Keep it off`}),(0,Q.jsx)(A,{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,Q.jsxs)(`div`,{className:`space-y-3 text-[14px] text-muted`,children:[(0,Q.jsxs)(`p`,{children:[`This tool `,K(l.tool)===`destructive`?`deletes things`:`makes changes`,`. Under your rules today it would `,(0,Q.jsx)(`strong`,{className:`text-ink`,children:u}),` (`,M(l.tool.verdict.kind),`).`]}),(0,Q.jsx)(`p`,{children:`The change is written to the activity log and takes effect on the next call.`})]})})}}var ke=[{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 Ae({open:e,serverId:t,tenant:n,protection:r,onClose:i,onSaved:a,onReload:o}){let s=z(),l=r.onUnclassified===`approve`?`approve`:`deny`,[u,d]=(0,U.useState)(l),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.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`,X(e.warning)),a(),i()}catch(e){h({text:be(e)?xe:Z(e),stale:be(e)})}finally{p(!1)}}return(0,Q.jsx)(R,{open:e,onClose:i,title:`What happens to unlabelled tools`,description:(0,Q.jsxs)(Q.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,Q.jsxs)(Q.Fragment,{children:[m?.stale&&(0,Q.jsx)(A,{variant:`ghost`,icon:`refresh`,className:`mr-auto`,onClick:()=>{h(null),o()},children:`Reload`}),(0,Q.jsx)(A,{variant:`secondary`,onClick:i,disabled:f,children:`Cancel`}),(0,Q.jsx)(A,{variant:`primary`,onClick:()=>void b(),disabled:!v.ok||u===l,loading:f,children:`Save setting`})]}),children:(0,Q.jsxs)(`div`,{className:`space-y-4 text-[14px]`,children:[(0,Q.jsx)(`div`,{role:`radiogroup`,"aria-label":`What happens to unlabelled tools`,className:`space-y-2`,children:ke.map(e=>{let t=u===e.value;return(0,Q.jsxs)(`label`,{className:B(`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,Q.jsx)(`input`,{type:`radio`,name:`unlabelled`,checked:t,onChange:()=>d(e.value),className:`sr-only`}),(0,Q.jsx)(g,{name:e.icon,size:20,strokeWidth:2,className:B(`mt-0.5 shrink-0`,t?`text-ok`:`text-soft`)}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold`,children:[e.label,e.value===l&&(0,Q.jsx)(`span`,{className:`text-[12px] font-medium text-soft`,children:`current setting`})]}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[13px] text-soft`,children:e.hint})]})]},e.value)})}),(0,Q.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,Q.jsx)(`code`,{className:`font-mono text-[11.5px]`,children:`defaults.on_unclassified`})]}),!v.ok&&(0,Q.jsx)(c,{tone:`warn`,title:`This toolbox's settings can't be changed from here`,children:X(v.why??`The settings file is not writable.`)}),m&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-[13.5px] font-medium text-bad`,children:m.text})]})})}var je=[`max`,`min`,`enum`,`maxLength`,`maxItems`,`within`,`host`];function Me(e){let t={};for(let[n,r]of Object.entries(e??{})){let e={},i={};for(let[t,n]of Object.entries(r))je.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 Ne(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function Pe(e){return Object.values(e).some(e=>Object.values(e.values).some(Ne))}function Fe(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 Ie(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))Ne(n)||(a[t]=t===`enum`?Fe(n,e):t===`within`?n.trim():n);Object.keys(a).length!==0&&(i.optional&&(a.optional=!0),n[r]=a)}return n}function Le({tool:e,draft:t,setDraft:n,onViolation:r,setOnViolation:i,unknownArgs:o,setUnknownArgs:s}){let[c,l]=(0,U.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,Q.jsxs)(`div`,{className:`space-y-4`,children:[u.length===0&&(0,Q.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,Q.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=ge(r?.type).filter(e=>!a.includes(e));return(0,Q.jsxs)(`li`,{className:`rounded-2xl border border-line p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-[13.5px] font-medium break-all`,children:n}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[r?.type??`any type`,` · `,r?r.required?`required`:`optional`:`nested input`]})]}),r?.description&&(0,Q.jsx)(`p`,{className:`mt-0.5 line-clamp-2 text-[12.5px] text-soft`,children:r.description}),a.length>0&&(0,Q.jsx)(`div`,{className:`mt-3 space-y-2.5`,children:a.map(e=>(0,Q.jsx)(Re,{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,Q.jsxs)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:[`Also kept as written in the settings file:`,` `,(0,Q.jsx)(`code`,{className:`font-mono`,children:Object.keys(i.carried).join(`, `)})]}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[o.length>0&&(0,Q.jsx)(re,{"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:J[e]}))]}),a.length>0&&r&&!r.required&&(0,Q.jsx)(L,{checked:i?.optional===!0,onChange:e=>d(n,t=>({...t,optional:e})),label:`It's fine to leave this input out`})]})]},n)})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,Q.jsx)(a,{label:`Limit a nested input`,className:`min-w-0 flex-1 basis-56`,children:(0,Q.jsx)(f,{value:c,onChange:l,mono:!0,placeholder:`items[].qty`,onEnter:()=>m()})}),(0,Q.jsx)(A,{icon:`plus`,disabled:c.trim()===``||u.includes(c.trim()),onClick:m,children:`Add input`})]}),(0,Q.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,Q.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Q.jsx)(a,{label:`If a call breaks a limit`,technical:`on_violation`,children:(0,Q.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,Q.jsx)(a,{label:`Inputs no limit mentions`,technical:`unknown_args`,children:(0,Q.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 Re({path:e,limit:n,value:r,onChange:a,onRemove:o}){let s=`${J[n]} (${e})`,c;return c=n===`enum`||n===`host`?(0,Q.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,Q.jsx)(f,{"aria-label":s,value:r??``,onChange:a,mono:!0,placeholder:`/Users/you/project`}):(0,Q.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,Q.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,Q.jsx)(`span`,{className:`col-span-2 text-[13px] font-semibold sm:col-span-1`,children:J[n]}),(0,Q.jsx)(`div`,{className:`min-w-0`,children:c}),(0,Q.jsx)(k,{icon:`x`,label:`Remove ${J[n].toLowerCase()} from ${e}`,size:34,onClick:o})]})}var ze=[{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`}],Be=[{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 Ve({open:e,serverId:t,tenant:n,tool:r,protection:i,onClose:o,onSaved:s}){let l=z(),[u,d]=(0,U.useState)(K(r)),[p,m]=(0,U.useState)(K(r)===null?null:r.verdict.kind),[h,g]=(0,U.useState)(``),[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(()=>Me(r.bounds?.constraints)),[S,C]=(0,U.useState)(r.bounds?.onViolation??`deny`),[T,te]=(0,U.useState)(r.bounds?.unknownArgs??`allow`),[D,O]=(0,U.useState)(!1),[ne,k]=(0,U.useState)(!1),[re,j]=(0,U.useState)(!1),[N,P]=(0,U.useState)(null),[ie,F]=(0,U.useState)(null),[ae,I]=(0,U.useState)(0),[L,oe]=(0,U.useState)(!1),[B,se]=(0,U.useState)(null),[V,ce]=(0,U.useState)(null),le=Object.values((N?.preview.bounds??r.bounds)?.constraints??{}).some(e=>_e(e)),H=(0,U.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=Ie(b,r),e.on_violation=S,e.unknown_args=T),e},[r,u,p,h,v,b,S,T]),ue=ee(H?JSON.stringify(H):``,350);(0,U.useEffect)(()=>{if(!e||!ue){P(null);return}let r=!0;return F(null),_.toolRulePreview(t,JSON.parse(ue),n).then(e=>{r&&(P({key:ue,preview:e}),v||(x(Me(e.bounds?.constraints)),C(e.bounds?.onViolation??`deny`),te(e.bounds?.unknownArgs??`allow`)))}).catch(e=>r&&F(Z(e))),()=>{r=!1}},[e,ue,t,n,ae]);let de=H?JSON.stringify(H):``,W=N&&N.key===de?N.preview:null,fe=W!==null,G=N?.preview??null,q=G?G.bounds:r.bounds,pe=W?.overriddenReason!=null,me=pe&&W?.overridesAllowed===!1,he=W?.dropsBounds!=null,J=u===`destructive`&&p===`allow`,ge=v&&Pe(b),ve=W?.writable.ok===!1,ye=W!==null&&fe&&!ie&&!L&&!ve&&!me&&!ge&&(!pe||D)&&(!he||ne)&&(!J||re);async function Se(){if(W&&H){oe(!0),se(null);try{let e=await _.setToolRule(t,{...H,expectedDigest:W.expectedDigest,acknowledged:{...pe?{overrideDeny:W.overriddenReason.ruleId}:{},...he?{dropBounds:!0}:{},...J?{destructiveAllow:!0}:{}}},n);ce({yaml:e.yaml,reloads:W.reloads}),l.show(`ok`,`Saved what ${r.name} may do.`),e.warning&&l.show(`warn`,X(e.warning)),s()}catch(e){be(e)?(se({text:xe,stale:!0}),P(null),I(e=>e+1)):se({text:Z(e),stale:!1})}finally{oe(!1)}}}if(V)return(0,Q.jsx)(R,{open:e,onClose:o,title:`Saved`,width:600,footer:(0,Q.jsx)(A,{variant:`primary`,onClick:o,children:`Close`}),children:(0,Q.jsxs)(`div`,{className:`space-y-4 text-[14px]`,children:[(0,Q.jsxs)(`p`,{className:`text-muted`,children:[`The rule for `,(0,Q.jsx)(`code`,{className:`font-mono text-ink`,children:r.name}),` is in your protection settings.`,` `,V.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,Q.jsxs)(`details`,{className:`group`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show what was written`}),(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(E,{label:`The rule that was written`,children:V.yaml})})]})]})});let Ce=W?.approvalsReachable===!1;return(0,Q.jsx)(R,{open:e,onClose:o,title:(0,Q.jsxs)(Q.Fragment,{children:[`Change what `,(0,Q.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,Q.jsxs)(Q.Fragment,{children:[B?.stale&&(0,Q.jsx)(A,{variant:`ghost`,icon:`refresh`,onClick:()=>I(e=>e+1),className:`mr-auto`,children:`Reload preview`}),(0,Q.jsx)(A,{variant:`secondary`,onClick:o,disabled:L,children:`Cancel`}),(0,Q.jsx)(A,{variant:`primary`,onClick:()=>void Se(),disabled:!ye,loading:L,children:`Save rule`})]}),children:(0,Q.jsxs)(`div`,{className:`space-y-6 pb-1 text-[14px]`,children:[i?.tenant&&(0,Q.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,Q.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,Q.jsx)(He,{legend:`What does this tool do?`,name:`rule-effect`,value:u,onChange:d,options:ze}),(0,Q.jsx)(He,{legend:`What should happen when your AI uses it?`,name:`rule-decision`,value:p,onChange:m,options:Be.map(e=>e.value===`approve`&&Ce?{...e,disabled:!0,hint:`Approvals are switched off on this toolbox, so nobody could answer.`}:e)}),(0,Q.jsxs)(`section`,{className:`rounded-[20px] bg-sunken/60 p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`h3`,{className:`flex items-center gap-2 text-[15px] font-semibold`,children:[`Limits on its inputs `,(0,Q.jsx)(w,{term:`limits`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-soft`,children:le?`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.`:q?G?.carriedFrom?`Carried over from the rule ${G.carriedFrom}, which governs it today: ${Y(q).join(`; `)}.`:`Kept as they are: ${Y(q).join(`; `)}.`:`None. Every input is passed on as your AI sends it.`})]}),!v&&!le&&(0,Q.jsx)(A,{size:`sm`,icon:q?`edit`:`plus`,onClick:()=>y(!0),children:q?`Edit limits`:`Add limits on its inputs`})]}),v&&(0,Q.jsxs)(`div`,{className:`mt-4`,children:[(0,Q.jsx)(Le,{tool:r,draft:b,setDraft:x,onViolation:S,setOnViolation:C,unknownArgs:T,setUnknownArgs:te}),ge&&(0,Q.jsx)(`p`,{className:`mt-3 text-[13px] font-medium text-warn`,children:`Fill in every limit you added, or remove it.`})]})]}),(0,Q.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,Q.jsx)(f,{value:h,onChange:g,placeholder:`For example: finance signs these off by hand`})}),(0,Q.jsx)(Ue,{tool:r,preview:W,loading:H!==null&&W===null&&!ie,error:ie,incomplete:H===null}),W&&fe&&(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[ve&&(0,Q.jsx)(c,{tone:`warn`,title:`This toolbox's settings can't be changed from here`,children:X(W.writable.why??`The settings file is not writable.`)}),me?(0,Q.jsxs)(c,{tone:`info`,title:`This toolbox doesn't allow reversing a rule from here`,children:[`The rule `,(0,Q.jsx)(`code`,{className:`font-mono`,children:W.overriddenReason.ruleId}),` stays as it is. It can only be changed in the settings file itself.`]}):pe&&(0,Q.jsxs)(Ke,{title:`This reverses a rule somebody wrote`,checked:D,onChange:O,label:`Reverse the rule ${W.overriddenReason.ruleId} anyway`,children:[`The rule `,(0,Q.jsx)(`code`,{className:`font-mono`,children:W.overriddenReason.ruleId}),` says`,` `,(0,Q.jsx)(`strong`,{children:M(W.overriddenReason.decision).toLowerCase()}),` for this tool`,W.overriddenReason.reason?(0,Q.jsxs)(Q.Fragment,{children:[`, because: “`,W.overriddenReason.reason,`”`]}):`.`]}),he&&(0,Q.jsxs)(Ke,{title:`This removes the limits on its inputs`,checked:ne,onChange:k,label:`Remove the limits on its inputs`,children:[`Today: `,Y(W.currentBounds).join(`; `)||`limited`,`. After this, nothing checks what the tool is called with.`]}),J&&(0,Q.jsx)(Ke,{title:`Your AI could delete things without asking`,checked:re,onChange:j,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.`})]}),B&&(0,Q.jsx)(c,{tone:`danger`,role:`alert`,title:B.stale?`Not saved`:`The toolbox refused this change`,children:B.text})]})})}function He({legend:e,name:t,value:n,onChange:r,options:i}){return(0,Q.jsxs)(`fieldset`,{children:[(0,Q.jsx)(`legend`,{className:`mb-2.5 text-[15px] font-semibold`,children:e}),(0,Q.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:i.map(e=>{let i=n===e.value;return(0,Q.jsxs)(`label`,{className:B(`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,Q.jsx)(`input`,{type:`radio`,name:t,value:e.value,checked:i,disabled:e.disabled,onChange:()=>r(e.value),className:`sr-only`}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold`,children:[(0,Q.jsx)(g,{name:e.icon,size:17,strokeWidth:2,className:i?`text-ok`:`text-soft`}),e.label,i&&(0,Q.jsx)(g,{name:`check`,size:16,strokeWidth:2.4,className:`ml-auto text-ok`})]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] leading-snug text-soft`,children:e.hint})]},e.value)})})]})}function Ue({tool:e,preview:t,loading:n,error:r,incomplete:i}){return(0,Q.jsxs)(`section`,{"aria-live":`polite`,className:`rounded-[20px] border-[1.5px] border-line p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:`What changes`}),i?(0,Q.jsx)(`p`,{className:`mt-2 text-[13.5px] text-soft`,children:`Answer both questions above to see what changes.`}):r?(0,Q.jsx)(`p`,{role:`alert`,className:`mt-2 text-[13.5px] font-medium text-bad`,children:r}):n||!t?(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(s,{lines:3})}):(0,Q.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] text-soft`,children:`Now`}),(0,Q.jsx)(D,{decision:t.current.kind}),(0,Q.jsx)(g,{name:`arrow-right`,size:18,className:`text-soft`,label:`becomes`}),(0,Q.jsx)(`span`,{className:`text-[13px] text-soft`,children:`After`}),(0,Q.jsx)(D,{decision:t.verdict.kind})]}),(0,Q.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:We(e.name,t)}),(0,Q.jsx)(Ge,{preview:t}),(0,Q.jsxs)(`details`,{children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the rule that will be written`}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,Q.jsx)(E,{label:`The rule that will be written`,children:t.yaml}),t.policyPath&&(0,Q.jsx)(`p`,{className:`font-mono text-[11.5px] break-all text-soft`,children:t.policyPath})]})]})]})]})}function We(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 (${Y(t.bounds).join(`; `)}). A call outside them ${t.bounds.onViolation===`approve`?`asks you first`:`is blocked`}. ${ye[t.bounds.unknownArgs]}`:n+=`.`,n}function Ge({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:X(e.overridden)}),e.nameContradiction&&t.push({key:`name`,tone:`warn`,text:X(e.nameContradiction)}),e.strandedRule&&t.push({key:`stranded`,tone:`info`,text:(0,Q.jsxs)(Q.Fragment,{children:[`The rule `,(0,Q.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,Q.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:B(`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,Q.jsx)(g,{name:e.tone===`warn`?`warning`:`info`,size:16,strokeWidth:2,className:B(`mt-0.5 shrink-0`,e.tone===`warn`?`text-warn`:`text-soft`)}),(0,Q.jsx)(`span`,{className:`text-ink`,children:e.text})]},e.key))})}function Ke({title:e,children:t,checked:n,onChange:r,label:i}){return(0,Q.jsxs)(`div`,{className:`rounded-[18px] border-[1.5px] border-bad/45 bg-bad-tint/50 p-4`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 font-semibold text-bad`,children:[(0,Q.jsx)(g,{name:`warning`,size:17,strokeWidth:2}),e]}),(0,Q.jsx)(`div`,{className:`mt-1 text-[13.5px] text-muted`,children:t}),(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(L,{checked:n,onChange:r,label:i})})]})}function qe({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}=ae(()=>e?_.tool(t,e,n):Promise.resolve(null),[t,e,n,a]),x=h&&h.name===e?h:null,S=x??i;return(0,Q.jsx)(y,{open:e!==null,onClose:d,width:620,title:(0,Q.jsx)(`span`,{className:`font-mono text-[18px] break-all`,children:e}),subtitle:S?(0,Q.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,Q.jsx)(C,{effect:K(S),withLabel:!0}),(0,Q.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,Q.jsxs)(`span`,{children:[`on `,(0,Q.jsx)(`span`,{className:`font-medium text-muted`,children:S.upstream})]}),(0,Q.jsx)(w,{term:`connectedServer`})]}):void 0,children:g&&!S?(0,Q.jsx)(c,{tone:`danger`,title:`This tool couldn't be loaded`,actions:(0,Q.jsx)(A,{size:`sm`,icon:`refresh`,onClick:b,children:`Try again`}),children:Z(g)}):S?(0,Q.jsxs)(`div`,{className:`space-y-8`,children:[(0,Q.jsx)(Je,{tool:S}),(0,Q.jsx)(Ye,{tool:S,protection:r,serverId:t,tenant:n,ruleBlocked:u,onEditRule:()=>f(S),onPosture:p,onChanged:m}),(0,Q.jsx)(Qe,{tool:S}),(0,Q.jsx)($e,{tool:S,loading:v&&!x}),(0,Q.jsx)(et,{tool:S,nav:o}),(0,Q.jsx)(tt,{tool:x,loading:v&&!x,nav:o}),(0,Q.jsx)(nt,{tool:S,exposure:l,perCustomer:!!r?.tenant},S.name)]}):(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(s,{height:20,lines:3}),(0,Q.jsx)(s,{height:40}),(0,Q.jsx)(s,{lines:4})]})})}function $({title:e,aside:t,children:n}){return(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`header`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`flex items-center gap-2 text-[16px] font-semibold tracking-[-0.01em]`,children:e}),t]}),n]})}function Je({tool:e}){let t=e.rawDescription!==e.description,n=e.injection??[],r=n.length>0&&!e.hiddenByPolicy&&!t;return(0,Q.jsxs)($,{title:`What it does`,children:[(0,Q.jsx)(`p`,{className:`text-[14.5px] whitespace-pre-wrap text-ink`,children:e.description||(0,Q.jsx)(`span`,{className:`text-soft italic`,children:`The connected server gave no description.`})}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[12.5px] text-soft`,children:`This is the description your AI sees.`}),n.length>0&&(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.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,Q.jsx)(`span`,{className:`mt-1.5 block font-mono text-[11.5px] text-soft`,children:n.map(e=>ne(e)===e?e:`${e} (${ne(e)})`).join(`, `)})]})}),t&&(0,Q.jsxs)(`details`,{className:`mt-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show original`}),(0,Q.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,Q.jsx)(O,{before:Se(e.rawDescription),after:Se(e.description),label:`Original and shown description`})]})]})}function Ye({tool:e,protection:t,serverId:n,tenant:r,ruleBlocked:i,onEditRule:a,onPosture:o,onChanged:s}){let[l,u]=(0,U.useState)(!1),d=e.effect===null&&!e.reclassifiedTo,f=e.exposure.disabled?`deny`:e.verdict.kind;return(0,Q.jsxs)($,{title:`What it's allowed to do`,children:[(0,Q.jsxs)(`div`,{className:`rounded-[20px] bg-sunken/70 p-5`,children:[(0,Q.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,Q.jsx)(D,{decision:f,label:e.exposure.disabled?`Turned off`:void 0})}),(0,Q.jsx)(`p`,{className:`display mt-3 text-[22px] leading-snug`,children:pe(e)}),t?.enforcement===`observe`&&e.verdict.kind!==`allow`&&!e.exposure.disabled&&(0,Q.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,Q.jsxs)(`dl`,{className:`mt-4 space-y-2 text-[13.5px]`,children:[(0,Q.jsxs)(Xe,{label:`Why`,children:[me(e.verdict,t?.defaults.mode??null),(0,Q.jsx)(`code`,{className:`mt-0.5 block font-mono text-[11.5px] break-all text-soft`,children:e.verdict.ruleId})]}),(0,Q.jsxs)(Xe,{label:`Labelled as`,children:[F[K(e)??`unknown`].label,`.`,` `,(0,Q.jsx)(`span`,{className:`text-soft`,children:he[e.effectSource]??e.effectSource}),e.reclassifiedTo&&e.effect&&(0,Q.jsxs)(`span`,{className:`block text-[12.5px] text-soft`,children:[`The connected server calls it “`,F[e.effect]?.label??e.effect,`”; a rule changed that.`]})]}),e.consoleRule&&(0,Q.jsx)(Xe,{label:`Set by`,children:`You, from this console. Use “Undo my change” to remove it.`})]}),(0,Q.jsxs)(`div`,{className:`mt-5 flex flex-wrap gap-2`,children:[(0,Q.jsx)(A,{variant:`primary`,icon:`sliders`,onClick:a,disabled:i!==null,children:`Change what it may do`}),e.consoleRule&&(0,Q.jsx)(A,{icon:`refresh`,onClick:()=>u(!0),disabled:i!==null,children:`Undo my change`}),d&&(0,Q.jsx)(A,{variant:`ghost`,onClick:o,children:`Change the setting for unlabelled tools`})]}),i&&(0,Q.jsx)(`p`,{className:`mt-2 text-[12.5px] text-soft`,children:i})]}),(0,Q.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[t?.runtime.policyApplied===!1&&(0,Q.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,Q.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,Q.jsx)(`code`,{className:`font-mono text-[12px]`,children:e.boundsDrift.ruleId}),`. That rule has changed since:`,(0,Q.jsx)(`ul`,{className:`mt-1.5 list-disc space-y-0.5 pl-5`,children:e.boundsDrift.differences.map(e=>(0,Q.jsx)(`li`,{children:X(e)},e))}),(0,Q.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,Q.jsx)(Ze,{serverId:n,tenant:r,tool:e,protection:t,onClose:()=>u(!1),onDone:()=>{u(!1),s()}})]})}function Xe({label:e,children:t}){return(0,Q.jsxs)(`div`,{className:`grid gap-x-4 gap-y-0.5 sm:grid-cols-[110px_1fr]`,children:[(0,Q.jsx)(`dt`,{className:`font-semibold text-soft`,children:e}),(0,Q.jsx)(`dd`,{className:`min-w-0 text-ink`,children:t})]})}function Ze({serverId:e,tenant:t,tool:n,protection:r,onClose:i,onDone:a}){let o=z(),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(!1),[h,g]=(0,U.useState)(0);(0,U.useEffect)(()=>{let r=!0;return u(null),_.clearPreview(e,n.name,t).then(e=>r&&u(e),e=>r&&f({text:Z(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`,X(r.warning)),a()}catch(e){f({text:be(e)?xe:Z(e),stale:be(e)})}finally{m(!1)}}}let y=l?.verdict.kind===`allow`?`run freely`:l?.verdict.kind===`approve`?`ask you first`:`be blocked`;return(0,Q.jsx)(R,{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,Q.jsxs)(Q.Fragment,{children:[d?.stale&&(0,Q.jsx)(A,{variant:`ghost`,icon:`refresh`,className:`mr-auto`,onClick:()=>{f(null),g(e=>e+1)},children:`Reload`}),(0,Q.jsx)(A,{variant:`secondary`,onClick:i,disabled:p,children:`Keep my change`}),(0,Q.jsx)(A,{variant:`primary`,onClick:()=>void v(),disabled:!l,loading:p,children:`Undo change`})]}),children:(0,Q.jsxs)(`div`,{className:`space-y-3 text-[14px]`,children:[!l&&!d&&(0,Q.jsx)(s,{lines:3}),l&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] text-soft`,children:`Afterwards it will`}),(0,Q.jsx)(D,{decision:l.verdict.kind})]}),(0,Q.jsxs)(`p`,{className:`text-muted`,children:[`Every call to `,(0,Q.jsx)(`code`,{className:`font-mono text-ink`,children:n.name}),` will `,y,l.verdict.ruleId.startsWith(`defaults.`)?`, by your default settings`:``,`.`,l.bounds?` Limits: ${Y(l.bounds).join(`; `)}.`:``]}),l.becomesUnclassified&&(0,Q.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,Q.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`This affects every customer of this toolbox.`}),(0,Q.jsxs)(`details`,{children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the rule being removed`}),(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(E,{label:`The rule being removed`,children:l.yaml})})]})]}),d&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-[13.5px] font-medium text-bad`,children:d.text})]})})}function Qe({tool:e}){let t=e.bounds;return(0,Q.jsx)($,{title:(0,Q.jsxs)(Q.Fragment,{children:[`Limits on its inputs `,(0,Q.jsx)(w,{term:`limits`})]}),children:t?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(`ul`,{className:`space-y-1.5`,children:t.paths.map((e,n)=>(0,Q.jsxs)(`li`,{className:`flex gap-2.5 text-[14px]`,children:[(0,Q.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--soft)]`,"aria-hidden":!0}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`code`,{className:`font-mono text-[13px] font-medium`,children:e}),` `,Y(t)[n].slice(e.length+1)]})]},e))}),(0,Q.jsxs)(`p`,{className:`text-[13px] text-soft`,children:[`A call that breaks a limit `,t.onViolation===`approve`?`asks you first`:`is blocked`,`.`,` `,ye[t.unknownArgs]]}),(0,Q.jsx)(`p`,{className:`font-mono text-[11.5px] text-soft`,children:t.ruleId})]}):(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`No limits. Every input is passed on as your AI sends it.`})})}function $e({tool:t,loading:n}){return(0,Q.jsxs)($,{title:`Inputs`,children:[t.args.length===0?(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`This tool takes no inputs.`}):(0,Q.jsx)(`ul`,{className:`divide-y divide-faint rounded-[18px] border border-line`,children:t.args.map(t=>(0,Q.jsxs)(`li`,{className:`px-4 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-[13.5px] font-medium break-all`,children:t.name}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[t.type??`any type`,t.format?`, ${t.format}`:``,` · `,t.required?`required`:`optional`]}),t.constrainedByRule&&(0,Q.jsx)(e,{tone:`neutral`,icon:`sliders`,className:`py-0 text-[11.5px]`,children:`Limited`})]}),t.description&&(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-muted`,children:t.description}),t.enumValues&&(0,Q.jsxs)(`p`,{className:`mt-1 text-[12.5px] text-soft`,children:[`Accepts: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t.enumValues.join(`, `)})]}),t.defaultValue!==null&&(0,Q.jsxs)(`p`,{className:t.defaultIsUrl?`mt-1 text-[12.5px] text-warn`:`mt-1 text-[12.5px] text-soft`,children:[`If left out: `,(0,Q.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,Q.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,Q.jsxs)(`details`,{className:`mt-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-[13px] font-semibold text-soft`,children:`Show the full input definition`}),(0,Q.jsx)(`div`,{className:`mt-2`,children:n?(0,Q.jsx)(s,{lines:4}):(0,Q.jsx)(E,{copy:!0,label:`Input definition`,children:JSON.stringify(t.inputSchema??{},null,2)})})]})]})}function et({tool:t,nav:n}){return(0,Q.jsx)($,{title:(0,Q.jsxs)(Q.Fragment,{children:[`Pre-approvals that cover it `,(0,Q.jsx)(w,{term:`preApproval`})]}),aside:(0,Q.jsx)(T,{href:r(n,`/pre-approvals`),size:`sm`,variant:`ghost`,iconRight:`arrow-right`,children:`Open pre-approvals`}),children:t.standingGrants.length===0?(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`None. When this tool asks first, you decide each call.`}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:t.standingGrants.map(t=>(0,Q.jsxs)(`li`,{className:`rounded-[18px] border border-line px-4 py-3 text-[13.5px]`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(e,{tone:t.covers?`ok`:`neutral`,icon:t.covers?`check`:`x`,children:t.covers?`Covers this tool`:`Doesn't apply`}),(0,Q.jsxs)(`span`,{className:`text-soft`,children:[t.uses,` of `,t.maxUses??`unlimited`,` uses · ends `,x(t.expiresAt)]})]}),t.reason&&(0,Q.jsx)(`p`,{className:`mt-1.5 text-ink`,children:t.reason}),!t.covers&&(0,Q.jsx)(`p`,{className:`mt-1 text-soft`,children:X(t.why)}),t.covers&&t.heldBounds.length>0&&(0,Q.jsxs)(`p`,{className:`mt-1 text-soft`,children:[`A call that breaks the limit on `,(0,Q.jsx)(`span`,{className:`font-mono`,children:t.heldBounds.join(`, `)}),` still asks you, because this pre-approval doesn't limit that input.`]}),(0,Q.jsx)(`p`,{className:`mt-1 font-mono text-[11.5px] text-soft`,children:t.grantId})]},t.grantId))})})}function tt({tool:t,loading:n,nav:i}){let a=t?.activity??[];return(0,Q.jsx)($,{title:`Recent activity`,aside:t&&(0,Q.jsx)(T,{href:r(i,`/activity`,{tool:t.name}),size:`sm`,variant:`ghost`,iconRight:`arrow-right`,children:`Open activity`}),children:n?(0,Q.jsx)(s,{lines:3}):a.length===0?(0,Q.jsx)(`p`,{className:`text-[14px] text-soft`,children:`Your AI hasn't used this tool yet.`}):(0,Q.jsx)(`ul`,{className:`divide-y divide-faint`,children:a.map(t=>{let n=N[t.outcome];return(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-start gap-x-3 gap-y-1 py-2.5`,children:[(0,Q.jsx)(`span`,{className:`w-24 shrink-0 text-[12.5px] text-soft`,title:l(t.ts),children:x(t.ts)}),(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Q.jsx)(D,{decision:t.decision}),n&&(0,Q.jsx)(e,{tone:n.tone,className:`py-0 text-[11.5px]`,children:n.label}),t.observe&&(0,Q.jsx)(e,{tone:`neutral`,className:`py-0 text-[11.5px]`,children:`Watch-only`})]}),t.reason&&(0,Q.jsx)(`span`,{className:`w-full text-[12.5px] text-soft sm:pl-[108px]`,children:X(t.reason)})]},t.id)})})})}function nt({tool:e,exposure:t,perCustomer:n}){let[r,i]=(0,U.useState)(``),o=e.exposure.disabled;return(0,Q.jsx)($,{title:(0,Q.jsxs)(Q.Fragment,{children:[`Turn off this tool `,(0,Q.jsx)(w,{term:`killSwitch`})]}),children:(0,Q.jsxs)(`div`,{className:`space-y-4 rounded-[20px] border border-line p-5`,children:[(0,Q.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,Q.jsxs)(`p`,{className:`text-[13.5px] text-muted`,children:[`Reason given: `,(0,Q.jsx)(`span`,{className:`text-ink`,children:e.exposure.reason})]}),!o&&(0,Q.jsx)(a,{label:`Reason`,optional:!0,help:`Saved in the activity log with the change.`,children:(0,Q.jsx)(f,{value:r,onChange:i,placeholder:`For example: misbehaving since the last update`,disabled:t.blocked!==null})}),(0,Q.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,Q.jsx)(c,{tone:`warn`,title:`Not available right now`,children:t.blocked})]})})}function rt({tools:e,changed:t,selected:n,onOpen:r,exposure:i}){return(0,Q.jsx)(`ul`,{className:`divide-y divide-faint`,children:e.map(e=>(0,Q.jsx)(at,{tool:e,changed:t.has(e.name),selected:n===e.name,onOpen:()=>r(e.name),exposure:i},e.name))})}var it={read:`bg-ok-tint`,write:`bg-warn-tint`,destructive:`bg-bad-tint`,unknown:`bg-sunken`};function at({tool:t,changed:n,selected:r,onOpen:i,exposure:a}){let o=G(t),s=K(t),c=t.exposure.disabled,l=a.busy(t.name);return(0,Q.jsxs)(`li`,{onClick:i,className:B(`-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,Q.jsx)(`span`,{className:B(`grid h-11 w-11 shrink-0 place-items-center rounded-full`,it[s??`unknown`],c&&`opacity-50`),title:F[s??`unknown`].label,children:(0,Q.jsx)(C,{effect:s})}),(0,Q.jsxs)(`div`,{className:B(`min-w-0 flex-1 basis-[calc(100%-64px)] sm:basis-auto`,c&&`opacity-70`),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[(0,Q.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,Q.jsxs)(`span`,{className:`truncate text-[12.5px] text-soft`,children:[`on `,t.upstream]})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 line-clamp-1 text-[13px] text-soft`,children:st(t.description)||(0,Q.jsx)(`span`,{className:`italic`,children:`No description`})}),(0,Q.jsx)(ot,{tool:t,changed:n})]}),(0,Q.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,Q.jsx)(e,{tone:`neutral`,icon:`power`,children:`Turned off`}):o===`unlabelled`?(0,Q.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,Q.jsx)(D,{decision:t.verdict.kind}),(0,Q.jsx)(A,{size:`sm`,variant:`ghost`,icon:`power`,loading:l,disabled:a.blocked!==null,title:a.blocked??void 0,onClick:e=>{e.stopPropagation(),a.set(t,!c)},"aria-label":`${c?`Turn on`:`Turn off`} ${t.name}`,className:`justify-center sm:w-[104px]`,children:c?`Turn on`:`Turn off`})]})]})}function ot({tool:t,changed:n}){let r=[];return n&&r.push({key:`changed`,text:`Changed`,tone:`warn`,icon:`refresh`}),t.injection&&t.injection.length>0&&r.push({key:`inj`,text:`Hidden instructions found`,tone:`bad`,icon:`warning`}),t.unreachable&&r.push({key:`unreach`,text:`Can never run`,tone:`bad`,icon:`lock`}),t.bounds&&r.push({key:`bounds`,text:`Has limits`,tone:`neutral`,icon:`sliders`}),q(t)&&r.push({key:`grant`,text:`Pre-approved`,tone:`ok`,icon:`key`}),r.length===0?null:(0,Q.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:r.map(t=>(0,Q.jsx)(e,{tone:t.tone,icon:t.icon,className:`py-0 text-[11.5px]`,children:t.text},t.key))})}function st(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}var ct={allow:`allow`,approve:`approve`,deny:`deny`,unlabelled:`unclassified`,off:null,changed:null};function lt(){let{serverId:e,tenant:t,nav:r,reload:i}=ue(),a=ae(()=>_.protection(e,t),[e,t],3e4),l=ae(()=>se(e),[e],3e4),[u,p]=(0,U.useState)(0),[m,h]=(0,U.useState)(``),[v,y]=(0,U.useState)(`any`),[C,w]=(0,U.useState)(null),[T,ee]=(0,U.useState)(!1),E=(0,U.useRef)(void 0);(0,U.useEffect)(()=>()=>clearTimeout(E.current),[]);let D=a.data,O=r.query.get(`tool`),ne=r.query.get(`verdict`),k=fe(ne)?ne:null,j=r.query.get(`view`)===`changed`?`changed`:`all`,M=()=>{a.reload(),l.reload(),p(e=>e+1),i()},N=()=>{M(),clearTimeout(E.current),E.current=setTimeout(M,1500)},F=Oe({serverId:e,tenant:t,protection:D,onChanged:M}),I=(0,U.useMemo)(()=>D?.tools??[],[D]),L=(0,U.useMemo)(()=>new Set((l.data?.changed??[]).map(e=>e.tool)),[l.data]),R=(0,U.useMemo)(()=>{let e={allow:0,approve:0,deny:0,unlabelled:0,off:0,changed:0};for(let t of I)e[G(t)]++,L.has(t.name)&&e.changed++;return e},[I,L]),z=(0,U.useMemo)(()=>{let e=m.trim().toLowerCase();return I.filter(t=>!((k===`changed`?!L.has(t.name):k!==null&&G(t)!==k)||v!==`any`&&K(t)!==v||e&&!`${t.name} ${t.description} ${t.upstream}`.toLowerCase().includes(e))).sort((e,t)=>e.upstream.localeCompare(t.upstream)||e.name.localeCompare(t.name))},[I,k,v,m,L]),B=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:X(D.policyWrite.why??`This toolbox's settings can't be changed from here.`):null,V=l.data?.changed.length??0,ce=e=>oe(o(r,{verdict:e})),le=e=>oe(o(r,{view:e===`changed`?e:null})),H=e=>oe(o(r,{tool:e}));return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(te,{title:`Tools`,subtitle:`Everything your AI can use through your toolbox, and what each one is allowed to do.`,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(A,{icon:`help`,onClick:()=>ee(!0),disabled:!D,children:`What happens to unlabelled tools`}),V>0&&(0,Q.jsxs)(A,{variant:`primary`,icon:`refresh`,onClick:()=>le(`changed`),children:[`Review changed tools (`,V,`)`]})]})}),D?.enforcement===`observe`&&(0,Q.jsx)(`div`,{className:`mb-5`,children:(0,Q.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,Q.jsx)(`div`,{className:`mb-5`,children:(0,Q.jsx)(ie,{label:`Tool views`,value:j,onChange:le,items:[{id:`all`,label:`All tools`,count:D?I.length:void 0},{id:`changed`,label:`Changed tools`,count:V}]})}),(0,Q.jsx)(`div`,{role:`tabpanel`,id:S(j),"aria-labelledby":d(j),className:`space-y-5`,children:j===`changed`?(0,Q.jsx)(Te,{serverId:e,data:l.data,error:l.error,loading:l.loading,reload:l.reload,onAccepted:M}):a.error&&!D?(0,Q.jsx)(c,{tone:`danger`,title:`The tool list couldn't be loaded`,actions:(0,Q.jsx)(A,{size:`sm`,icon:`refresh`,onClick:a.reload,children:`Try again`}),children:Z(a.error)}):(0,Q.jsxs)(Q.Fragment,{children:[D&&F.blocked&&(0,Q.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.`}),(0,Q.jsxs)(P,{padded:!1,children:[(0,Q.jsxs)(`div`,{className:`space-y-4 border-b border-faint p-5 sm:p-6`,children:[(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Show tools that`,className:`flex flex-wrap gap-2`,children:de.map(e=>(0,Q.jsx)(ut,{label:W[e],count:D?R[e]:null,dot:ct[e],icon:e===`off`?`power`:e===`changed`?`refresh`:null,on:k===e,onClick:()=>ce(k===e?null:e)},e))}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-60`,children:[(0,Q.jsx)(g,{name:`search`,size:18,className:`pointer-events-none absolute top-1/2 left-3.5 -translate-y-1/2 text-soft`}),(0,Q.jsx)(f,{type:`search`,value:m,onChange:h,placeholder:`Search by name or description`,"aria-label":`Search tools by name or description`,className:`pl-10`})]}),(0,Q.jsx)(re,{"aria-label":`Show tools by what they do`,value:v,onChange:y,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,Q.jsx)(`div`,{className:`px-5 pt-1 pb-3 sm:px-6`,children:D?I.length===0?(0,Q.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.`}):z.length===0?(0,Q.jsx)(b,{icon:`search`,title:`No tools match`,compact:!0,actions:(0,Q.jsx)(A,{onClick:()=>{h(``),y(`any`),ce(null)},children:`Clear filters`}),children:`Nothing on this toolbox matches what you picked.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`sr-only`,"aria-live":`polite`,children:[n(z.length,`tool`),` shown`]}),(0,Q.jsx)(rt,{tools:z,changed:L,selected:O,onOpen:H,exposure:F})]}):(0,Q.jsx)(`div`,{className:`space-y-5 py-4`,"aria-busy":!0,children:[0,1,2,3].map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(`span`,{className:`skeleton h-11 w-11 shrink-0 rounded-full`}),(0,Q.jsx)(`div`,{className:`flex-1`,children:(0,Q.jsx)(s,{lines:2})})]},e))})})]})]})}),(0,Q.jsx)(qe,{name:O,serverId:e,tenant:t,protection:D,listTool:I.find(e=>e.name===O)??null,version:u,nav:r,exposure:F,ruleBlocked:B,onClose:()=>H(null),onEditRule:w,onPosture:()=>ee(!0),onChanged:N}),C&&(0,Q.jsx)(Ve,{open:!0,serverId:e,tenant:t,tool:C,protection:D,onClose:()=>w(null),onSaved:N},C.name),D&&T&&(0,Q.jsx)(Ae,{open:!0,serverId:e,tenant:t,protection:D,onClose:()=>ee(!1),onSaved:N,onReload:a.reload}),F.dialog]})}function ut({label:e,count:t,dot:n,icon:r,on:i,onClick:a}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":i,onClick:a,className:B(`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,Q.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-full bg-white`,"aria-hidden":!0}):(0,Q.jsx)(v,{decision:n})),r&&(0,Q.jsx)(g,{name:r,size:15,strokeWidth:2}),e,(0,Q.jsx)(`span`,{className:B(`tnum rounded-full px-1.5 text-[12px]`,i?`bg-white/20`:`bg-faint`),children:t??`–`})]})}export{lt as ToolsPage};