hmcp-web 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,6 +163,23 @@ export interface ToolProtection {
163
163
  * `true` closed, `false` explicitly open, `null` the upstream did not say.
164
164
  */
165
165
  readonly schemaClosed: boolean | null;
166
+ /**
167
+ * The top-level inputs the governing rule's limits leave unlimited.
168
+ *
169
+ * Only for a rule that has limits and lets every other input through
170
+ * (`unknown_args: allow`): such a rule reads as protecting the whole tool,
171
+ * while an extra input like `force: true` is never checked. A bound on any
172
+ * path under an input (`meta.tag`, `items[].qty`) covers it. Names only,
173
+ * never values. Empty when the rule has no limits, or blocks or asks about
174
+ * the inputs they don't mention, since then nothing is let through unseen.
175
+ */
176
+ readonly unboundedInputs: readonly string[];
177
+ /**
178
+ * The tool accepts inputs its schema doesn't name, somewhere the limits
179
+ * don't fully reach, so `unboundedInputs` is not the whole list. Without
180
+ * this the console would read as complete when it is not.
181
+ */
182
+ readonly unboundedOpen: boolean;
166
183
  readonly standingGrants: readonly {
167
184
  readonly grantId: string;
168
185
  readonly reason: string;
@@ -90,6 +90,61 @@ function boundsArg(rule, name) {
90
90
  }
91
91
  return false;
92
92
  }
93
+ const sameStep = (a, b) => a.kind === b.kind && (a.kind === "items" || a.name === b.name);
94
+ /** True when `inner` is `outer` or sits beneath it, compared as patterns. */
95
+ const atOrUnder = (inner, outer) => outer.length <= inner.length && outer.every((step, i) => sameStep(step, inner[i]));
96
+ const pathText = (at) => at.map((s, i) => (s.kind === "items" ? "[]" : i === 0 ? s.name : `.${s.name}`)).join("");
97
+ const asNode = (raw) => (typeof raw === "object" && raw !== null && !Array.isArray(raw) ? raw : {});
98
+ /**
99
+ * What the matched rule's limits leave unlimited, walked through the input
100
+ * schema the way `findUnknownArgs` walks a call.
101
+ *
102
+ * A bound claims its own path and everything under it, and nothing beside it:
103
+ * `meta.tag` leaves `meta.other` unclaimed, and `items[].qty` leaves
104
+ * `items[].sku`. So an input no bound touches is listed whole, one a bound
105
+ * reaches into is walked, and one a bound claims is skipped. Where the schema
106
+ * leaves room for inputs it doesn't name, the list cannot be complete, and
107
+ * `unboundedOpen` says so. Only for a rule with limits that lets everything
108
+ * else through, and not for one that blocks the tool anyway.
109
+ */
110
+ function unboundedOf(rule, inputSchema) {
111
+ const none = { unboundedInputs: [], unboundedOpen: false };
112
+ if (!rule || rule.decision === "deny" || rule.unknown_args !== "allow")
113
+ return none;
114
+ const specs = [];
115
+ for (const spec of Object.keys(rule.args ?? {})) {
116
+ const parsed = parseArgPath(spec);
117
+ if (parsed.ok)
118
+ specs.push(parsed.segments);
119
+ }
120
+ if (specs.length === 0)
121
+ return none;
122
+ const inputs = [];
123
+ let open = false;
124
+ const place = (at, node) => {
125
+ if (specs.some((spec) => atOrUnder(at, spec)))
126
+ return;
127
+ if (specs.some((spec) => spec.length > at.length && atOrUnder(spec, at)))
128
+ visit(at, node);
129
+ else
130
+ inputs.push(pathText(at));
131
+ };
132
+ // `at` is reached into by some bound but claimed by none.
133
+ const visit = (at, raw) => {
134
+ const node = asNode(raw);
135
+ if (node["type"] === "array" || node["items"] !== undefined) {
136
+ place([...at, { kind: "items" }], node["items"]);
137
+ return;
138
+ }
139
+ const props = node["properties"];
140
+ if (typeof props !== "object" || props === null || node["additionalProperties"] !== false)
141
+ open = true;
142
+ for (const [name, child] of Object.entries(asNode(props)))
143
+ place([...at, { kind: "key", name }], child);
144
+ };
145
+ visit([], inputSchema);
146
+ return { unboundedInputs: inputs, unboundedOpen: open };
147
+ }
93
148
  export function toolProtection(server, tool, grants) {
94
149
  const policy = server.policy;
95
150
  const effect = tool.effect ?? undefined;
@@ -147,6 +202,7 @@ export function toolProtection(server, tool, grants) {
147
202
  defaultIsUrl: isHttpUrl(node.defaultValue)
148
203
  })),
149
204
  schemaClosed: schema.additionalProperties === false ? true : schema.additionalProperties === true ? false : null,
205
+ ...unboundedOf(matchedRule, tool.inputSchema),
150
206
  standingGrants: grants.map((grant) => {
151
207
  const match = grantCoversTool(grant, tool.name, decision.effect);
152
208
  return {
@@ -1 +1 @@
1
- import{$ as e,B as t,Ct as n,E as r,Et as i,G as a,H as o,I as s,It as c,M as l,O as u,Ot as d,P as f,Pt as p,R as m,S as h,St as g,U as _,V as v,Z as y,_ as b,bt as x,c as ee,d as S,dt as C,et as w,gt as T,ht as E,k as D,kt as O,lt as k,ot as A,pt as j,s as M,tt as te,ut as N,w as ne,wt as re,x as P,y as F,yt as I,z as L}from"./kit-DRVm92_t.js";import{Ct as ie,Dt as R,Et as z,Ot as B,St as ae,Tt as V,_t as oe,bt as H,gt as se,kt as U,s as W,un as ce,vt as G,wt as le,xt as K,yt as q}from"./index-DbHZ_SUd.js";var J=c(),Y=O();function ue({open:e,onClose:n,serverId:i}){let s=F(),[c,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),[ee,S]=(0,J.useState)(!1),C=()=>{h(!0),f(null),p.verify(i).then(u).catch(e=>f(e.message)).finally(()=>h(!1))};(0,J.useEffect)(()=>{e&&(u(null),y(null),x(null),C())},[e,i]);let w=g.trim().toLowerCase(),D=/^[0-9a-f]{16,128}$/.test(w),O=()=>{D&&(S(!0),x(null),p.verify(i,w).then(e=>y({head:w,result:e})).catch(e=>x(e.message)).finally(()=>S(!1)))},k=async e=>{let t=await q(e);s.show(t?`ok`:`bad`,t?`Fingerprint copied`:`The browser did not allow copying`)};return(0,Y.jsx)(P,{open:e,onClose:n,title:`Check log integrity`,description:`Reads every entry in the activity log and checks that each still matches its fingerprint.`,width:600,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,icon:`refresh`,onClick:C,loading:m,children:`Check again`}),(0,Y.jsx)(E,{variant:`primary`,onClick:n,children:`Close`})]}),children:(0,Y.jsxs)(`div`,{className:`space-y-5 pb-1 text-[14px]`,children:[d&&(0,Y.jsx)(o,{tone:`danger`,title:`The check could not run`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:C,children:`Try again`}),children:d}),!c&&!d&&(0,Y.jsx)(a,{lines:3,height:18}),c&&(0,Y.jsxs)(Y.Fragment,{children:[c.ok?(0,Y.jsx)(o,{tone:`ok`,role:`status`,title:`All ${L(c.count)} entries are intact`,children:`No entry has been edited, removed or put out of order.`}):(0,Y.jsxs)(o,{tone:`danger`,role:`alert`,title:`${t(c.problems.length,`problem`)} found in ${t(c.count,`entry`,`entries`)}`,children:[(0,Y.jsx)(`ul`,{className:`mt-1 space-y-1`,children:c.problems.slice(0,8).map(e=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsxs)(`span`,{className:`font-semibold`,children:[`Entry `,e.line,`:`]}),` `,de(e.message),` `,(0,Y.jsxs)(`span`,{className:`mono text-[11.5px] opacity-80`,children:[`(`,e.message,`)`]})]},`${e.line}-${e.message}`))}),c.problems.length>8&&(0,Y.jsxs)(`p`,{className:`mt-1`,children:[`And `,c.problems.length-8,` more.`]})]}),c.head?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`mb-1.5 text-[13px] font-semibold`,children:`Fingerprint of the latest entry`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl bg-sunken py-2 pr-2 pl-4`,children:[(0,Y.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[12px] break-all`,children:c.head}),(0,Y.jsx)(T,{icon:`copy`,label:`Copy fingerprint`,variant:`soft`,size:36,onClick:()=>k(c.head)})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`Save this somewhere the toolbox cannot reach, such as a note or a ticket. The check above catches an entry that was edited or removed, but not the newest entries being cut off the end, because what is left still checks out. A fingerprint you saved earlier can prove nothing was cut.`})]}):(0,Y.jsx)(`p`,{className:`text-soft`,children:`The log has no entries yet, so there is no fingerprint to save.`}),(0,Y.jsxs)(`div`,{className:`border-t border-faint pt-5`,children:[(0,Y.jsx)(r,{label:`Compare with a fingerprint you saved earlier`,help:`Paste the fingerprint exactly as you saved it.`,error:g.trim()&&!D?`That does not look like a fingerprint. It is a long run of letters a–f and digits.`:null,children:(0,Y.jsx)(l,{value:g,onChange:_,mono:!0,onEnter:O,placeholder:`e.g. 3f9a…`})}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(E,{onClick:O,disabled:!D,loading:ee,icon:`search`,children:`Compare fingerprint`})}),b&&(0,Y.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] font-medium text-bad`,children:b}),v&&(0,Y.jsx)(`div`,{className:`mt-4`,children:v.result.headPosition===void 0?(0,Y.jsx)(o,{tone:`danger`,role:`alert`,title:`Not found in this log`,children:`The log may have been cut short or replaced, or the fingerprint came from a different toolbox's log. Treat this as something to look into.`}):(0,Y.jsxs)(o,{tone:`ok`,role:`status`,title:`Found at entry ${L(v.result.headPosition+1)} of ${L(v.result.count)}`,children:[`Everything up to that entry is still in the log, so nothing written before you saved the fingerprint was lost.`,` `,v.result.count-v.result.headPosition-1>0?`${t(v.result.count-v.result.headPosition-1,`entry has`,`entries have`)} been added since.`:`No entries have been added since.`]})})]})]})]})})}function de(e){return/^record altered/.test(e)?`This entry was changed after it was written.`:/^sequence gap/.test(e)?`An entry before this one was removed, or entries were put out of order.`:/^chain break/.test(e)?`This entry doesn't follow on from the one before it: something was removed or put in between.`:/^unparseable JSON/.test(e)?`This entry can't be read; the file was edited or cut short.`:e}function fe({record:t,onClose:r,nav:a,redaction:o}){let c=F();if(!t)return null;let l=t,u=K(l),p=l.rule_id===`gateway.unknown-tool`,g=p?null:U(l),_=A[l.outcome]?.tone??`neutral`;return(0,Y.jsx)(h,{open:!0,onClose:r,title:u?u.title:(0,Y.jsxs)(Y.Fragment,{children:[G(l),` `,(0,Y.jsx)(`span`,{className:`mono text-[17px]`,children:l.tool})]}),subtitle:`Entry ${L(l.seq)} · ${s(l.ts)}`,width:620,footer:(0,Y.jsx)(E,{icon:`copy`,onClick:async()=>{let e=await q(`${location.origin}${i(a,{seq:String(l.seq)})}`);c.show(e?`ok`:`bad`,e?`Link to this entry copied`:`The browser did not allow copying`)},children:`Copy link to entry`}),children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[p?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool: your AI app asked for a tool this toolbox doesn't have`}):(0,Y.jsx)(w,{decision:l.decision}),!p&&C(l.outcome)!==k(l.decision)&&(0,Y.jsx)(e,{tone:_,children:V(l)?`You said no`:C(l.outcome)}),l.grant_id&&(0,Y.jsx)(e,{icon:`key`,children:`Released by a pre-approval`})]}),g&&(0,Y.jsxs)(`p`,{className:`flex gap-2 rounded-2xl bg-warn-tint px-4 py-3 text-[14px] text-ink`,children:[(0,Y.jsx)(d,{name:`eye`,size:18,className:`mt-0.5 shrink-0 text-warn`}),(0,Y.jsxs)(`span`,{children:[g,`. `,(0,Y.jsx)(b,{term:`watchOnly`})]})]}),(0,Y.jsxs)(X,{title:`What happened`,children:[(0,Y.jsx)(Z,{label:`Tool`,children:(0,Y.jsx)(`span`,{className:`mono text-[13px] break-all`,children:l.tool})}),(0,Y.jsx)(Z,{label:`What the tool does`,children:l.effect?(0,Y.jsx)(y,{effect:l.effect,withLabel:!0}):(0,Y.jsx)($,{children:N(null)})}),(0,Y.jsxs)(Z,{label:`Decided by`,children:[H(l),` `,(0,Y.jsx)(Q,{children:l.rule_id})]}),(0,Y.jsx)(Z,{label:`Reason`,children:l.reason||(0,Y.jsx)($,{children:`None recorded`})}),(0,Y.jsx)(Z,{label:`Took`,children:l.duration_ms===null?(0,Y.jsx)($,{children:`Not timed`}):m(l.duration_ms)}),l.error&&(0,Y.jsx)(Z,{label:`Error`,children:(0,Y.jsx)(`span`,{className:`text-bad`,children:l.error})})]}),(0,Y.jsxs)(X,{title:`Who asked`,children:[(0,Y.jsx)(Z,{label:`Asked by`,children:(0,Y.jsx)(`span`,{className:`break-all`,children:l.actor})}),(0,Y.jsx)(Z,{label:`Session`,children:(0,Y.jsx)(Q,{children:l.session})}),(0,Y.jsx)(Z,{label:`Written by`,children:(0,Y.jsx)(Q,{children:l.component})}),l.tenant!==null&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Customer `,(0,Y.jsx)(b,{term:`customer`})]}),children:l.tenant===``?(0,Y.jsx)($,{children:`None`}):l.tenant})]}),l.upstream&&(0,Y.jsxs)(X,{title:`Request to the connected server`,children:[(0,Y.jsx)(Z,{label:`Request`,children:(0,Y.jsxs)(`span`,{className:`mono text-[12.5px] break-all`,children:[l.upstream.method??`?`,` `,l.upstream.host??``,l.upstream.path??``]})}),(0,Y.jsx)(Z,{label:`Answer`,children:l.upstream.status===null?(0,Y.jsx)($,{children:`No status`}):(0,Y.jsx)(`span`,{className:`tnum`,children:l.upstream.status})}),l.upstream.bytes!==null&&(0,Y.jsx)(Z,{label:`Size`,children:f(l.upstream.bytes)})]}),(l.approval_id||l.grant_id)&&(0,Y.jsxs)(X,{title:`Linked`,children:[l.approval_id&&(0,Y.jsx)(Z,{label:`Approval request`,children:(0,Y.jsx)(me,{href:n(a,`/approvals`,{id:l.approval_id}),children:l.approval_id})}),l.grant_id&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Pre-approval `,(0,Y.jsx)(b,{term:`preApproval`})]}),children:(0,Y.jsx)(me,{href:n(a,`/pre-approvals`,{id:l.grant_id}),children:l.grant_id})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Inputs, as recorded `,(0,Y.jsx)(b,{term:`redaction`})]}),l.args_redacted===null?(0,Y.jsx)(`p`,{className:`text-[14px] text-soft`,children:`This toolbox does not record call inputs.`}):(0,Y.jsx)(S,{label:`Inputs as recorded`,maxHeight:260,children:JSON.stringify(l.args_redacted,null,2)}),o&&l.args_redacted!==null&&(0,Y.jsxs)(`details`,{className:`mt-3 rounded-2xl border border-faint px-4 py-3 text-[13px]`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`What the hidden-value markers mean`}),(0,Y.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:o.markers.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-3`,children:[(0,Y.jsx)(Q,{children:e.marker}),(0,Y.jsxs)(`span`,{className:`text-muted`,children:[pe(e.meaning),`.`]})]},e.marker))}),(0,Y.jsx)(`p`,{className:`mt-2 text-soft`,children:`Inputs are hidden by their name as well as their content, so a harmless value can still be hidden. The original values were never written down, so they cannot be recovered from the log.`})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Tamper check `,(0,Y.jsx)(b,{term:`hashChain`})]}),(0,Y.jsxs)(`ol`,{className:`space-y-2 text-[13px]`,children:[(0,Y.jsx)(he,{label:`Fingerprint of the entry before`,value:l.prev_hash}),(0,Y.jsx)(`li`,{"aria-hidden":!0,className:`pl-4 text-soft`,children:(0,Y.jsx)(d,{name:`chevron`,size:16})}),(0,Y.jsx)(he,{label:`Fingerprint of this entry`,value:l.hash,strong:!0})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`This entry's fingerprint covers its contents and the one before it, so editing or removing any earlier entry breaks every fingerprint after it.`}),(0,Y.jsxs)(`p`,{className:`mt-3 text-[12.5px] text-soft`,children:[`Fingerprint of the inputs: `,(0,Y.jsx)(Q,{children:l.args_hash})]})]})]})})}var pe=e=>e.charAt(0).toUpperCase()+e.slice(1);function X({title:e,children:t}){return(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[15px] font-semibold`,children:e}),(0,Y.jsx)(`dl`,{className:`divide-y divide-faint rounded-2xl border border-faint px-4`,children:t})]})}function Z({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`grid gap-1 py-2.5 sm:grid-cols-[160px_1fr] sm:gap-4`,children:[(0,Y.jsx)(`dt`,{className:`flex items-center gap-1.5 text-[13px] text-soft`,children:e}),(0,Y.jsx)(`dd`,{className:`min-w-0 text-[14px]`,children:t})]})}var Q=({children:e})=>(0,Y.jsx)(`code`,{className:`mono text-[12px] break-all text-soft`,children:e}),$=({children:e})=>(0,Y.jsx)(`span`,{className:`text-soft`,children:e});function me({href:e,children:t}){return(0,Y.jsx)(`a`,{href:e,onClick:g,className:`mono text-[12.5px] break-all text-ok underline underline-offset-2`,children:t})}function he({label:e,value:t,strong:n}){return(0,Y.jsxs)(`li`,{className:n?`rounded-2xl bg-sunken px-4 py-3`:`rounded-2xl border border-faint px-4 py-3`,children:[(0,Y.jsx)(`span`,{className:`block text-[12.5px] text-soft`,children:e}),(0,Y.jsx)(`code`,{className:`mono mt-1 block text-[12px] break-all text-ink`,children:t})]})}function ge(){let{serverId:e,server:n,tenant:a,tenantInfo:s,nav:c}=ce(),[d,f]=(0,J.useState)(()=>le(c)),[m,h]=(0,J.useState)(()=>Date.now()),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)(),[b,S]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),[O,N]=(0,J.useState)(!1),[P=``,F=``,I=``]=x([d.tool,d.actor,d.component].join(`\0`),300).split(`\0`),R={...d,tool:P,actor:F,component:I};(0,J.useEffect)(()=>{re(i(c,{...ae(R),seq:b?String(b.seq):null}))},[JSON.stringify(R),b?.seq]);let z=oe(R,a,m),B=JSON.stringify(z),V=M(()=>p.audit(e,v===void 0?z:{...z,cursor:String(v)}),[e,B,v],v===void 0?5e3:void 0),H=M(()=>p.redaction(),[]),U=v===void 0?V.data?.records??[]:[...g,...V.data?.records??[]],W=V.loading&&!V.data;function G(e){f(t=>({...t,...e})),y(void 0),_([]),e.range!==void 0&&h(Date.now())}let K=()=>{y(void 0),_([]),h(Date.now()),V.reload()},[q,de]=(0,J.useState)(()=>c.query.get(`seq`));(0,J.useEffect)(()=>{if(!q)return;let t=Number(q);if(de(null),!Number.isInteger(t)||t<0)return;let n={limit:`1`,cursor:String(t+1)};!d.allTenants&&a!==null&&(n.tenant=a),p.audit(e,n).then(e=>{let n=e.records.find(e=>e.seq===t);n&&S(n)}).catch(()=>void 0)},[q]);let pe=(0,J.useMemo)(()=>[{value:``,label:`Any decision`},...(H.data?.decisions??Object.keys(te).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:k(e.value)}))],[H.data]),X=(0,J.useMemo)(()=>[{value:``,label:`Any result`},...(H.data?.outcomes??Object.keys(A).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:C(e.value)}))],[H.data]),Z=s?.configured?s.tenants.filter(e=>e!==``):[];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ee,{title:`Activity`,subtitle:`Every call your AI made through this toolbox, and what happened. Each entry is chained to the one before it, so edits can be detected.`,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`primary`,icon:`shield-check`,onClick:()=>T(!0),children:`Check log integrity`}),(0,Y.jsx)(E,{icon:`download`,onClick:()=>N(!0),disabled:U.length===0,children:`Download log`})]})}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(j,{title:`Filters`,actions:ie(d)&&(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`x`,onClick:()=>G(se),children:`Clear filters`}),children:[(0,Y.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,Y.jsx)(r,{label:`Result`,children:(0,Y.jsx)(D,{value:d.outcome,onChange:e=>G({outcome:e}),options:X})}),(0,Y.jsx)(r,{label:`Decision`,children:(0,Y.jsx)(D,{value:d.decision,onChange:e=>G({decision:e}),options:pe})}),(0,Y.jsx)(r,{label:`Tool`,help:`Use * to match any text, like files.*`,children:(0,Y.jsx)(l,{value:d.tool,onChange:e=>G({tool:e}),mono:!0,placeholder:`Any tool`})}),(0,Y.jsx)(r,{label:`Who asked`,children:(0,Y.jsx)(l,{value:d.actor,onChange:e=>G({actor:e}),placeholder:`Anyone`})}),Z.length>0&&(0,Y.jsx)(r,{label:`Customer`,children:(0,Y.jsx)(D,{value:d.allTenants?`*`:a??``,onChange:e=>{e===`*`?G({allTenants:!0}):e===a?G({allTenants:!1}):re(i(c,{tenant:e,allTenants:null}))},options:[...a===null?[{value:``,label:`Choose a customer`}]:[],...Z.map(e=>({value:e,label:e})),{value:`*`,label:`All customers`}]})}),d.component&&(0,Y.jsx)(r,{label:`Written by`,technical:`component`,children:(0,Y.jsx)(l,{value:d.component,onChange:e=>G({component:e}),mono:!0})})]}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-end justify-between gap-4 border-t border-faint pt-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-[13px] font-semibold text-soft`,"aria-hidden":!0,children:`When`}),(0,Y.jsx)(u,{label:`Time range`,value:d.range,onChange:e=>G({range:e}),options:[{value:``,label:`Any time`},{value:`1h`,label:`Last hour`},{value:`24h`,label:`Last 24 hours`},{value:`7d`,label:`Last 7 days`},{value:`custom`,label:`Custom`}]})]}),(0,Y.jsx)(ne,{checked:d.noteworthy,onChange:e=>G({noteworthy:e}),label:`Only problems`,description:`Blocked, failed or still waiting.`})]}),d.range===`custom`&&(0,Y.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2`,children:[(0,Y.jsx)(xe,{label:`From`,value:d.since,onChange:e=>G({since:e})}),(0,Y.jsx)(xe,{label:`Until`,value:d.until,onChange:e=>G({until:e}),help:`Leave empty for up to now.`})]})]}),V.data&&V.data.malformed>0&&(0,Y.jsxs)(o,{tone:`warn`,title:`${t(V.data.malformed,`line`)} could not be read`,children:[`Of the `,L(V.data.scanned),` lines read for this list, `,L(V.data.malformed),` were damaged and skipped. Run the integrity check to see where.`]}),(0,Y.jsxs)(j,{title:W?`Entries`:`${t(U.length,`entry`,`entries`)}${V.data?.nextCursor==null?``:` so far`}`,actions:(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:K,loading:V.loading&&!!V.data,children:`Refresh list`}),children:[(0,Y.jsx)(_e,{loading:W,error:V.error,onRetry:V.reload,records:U,filtered:ie(d),onClear:()=>G(se),onOpen:S,mixedCustomers:d.allTenants}),V.data?.nextCursor!=null&&(0,Y.jsx)(`div`,{className:`mt-5 flex flex-wrap items-center gap-3`,children:(0,Y.jsx)(E,{icon:`chevron`,loading:V.loading,onClick:()=>{_(U),y(V.data.nextCursor)},children:`Load older entries`})})]})]}),(0,Y.jsx)(fe,{record:b,onClose:()=>S(null),nav:c,redaction:H.data}),(0,Y.jsx)(ue,{open:w,onClose:()=>T(!1),serverId:e}),(0,Y.jsx)(Se,{open:O,onClose:()=>N(!1),records:U,stem:`activity-${n.id}-${new Date().toISOString().slice(0,10)}`})]})}function _e({loading:e,error:t,onRetry:n,records:r,filtered:i,onClear:s,onOpen:c,mixedCustomers:l}){return t?(0,Y.jsx)(o,{tone:`danger`,title:`The activity log could not be read`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:n,children:`Try again`}),children:t}):e?(0,Y.jsx)(`div`,{className:`space-y-5`,"aria-busy":!0,children:[0,1,2,3,4].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`skeleton h-10 w-10 shrink-0 rounded-full`}),(0,Y.jsx)(a,{lines:2})]},e))}):r.length===0?i?(0,Y.jsx)(_,{icon:`filter`,title:`No entries match these filters`,actions:(0,Y.jsx)(E,{onClick:s,children:`Clear filters`}),children:`The whole log was searched. Try a wider time range or fewer filters.`}):(0,Y.jsx)(_,{icon:`activity`,title:`No activity yet`,children:`Calls appear here as soon as an AI app connected to this toolbox uses a tool.`}):(0,Y.jsx)(`ul`,{className:`-mx-2`,children:r.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(be,{record:e,onOpen:()=>c(e),showCustomer:l})},`${e.seq}-${e.id}`))})}var ve={ok:`bg-ok-tint text-ok`,warn:`bg-warn-tint text-warn`,bad:`bg-bad-tint text-bad`,neutral:`bg-sunken text-muted`};function ye(e,t){if(!t&&(e.actor===`agent`||!e.actor))return`Your AI app`;if(e.actor===`gateway`)return`The toolbox`;let n=e.args_redacted?.origin;return t&&(n===`console`||e.component===`hmcp-web`||e.rule_id===`approval.decide`||e.tool?.startsWith(`(`))?e.actor&&e.actor!==`console`?`You (${e.actor})`:`You`:e.actor}function be({record:t,onOpen:n,showCustomer:r}){let i=K(t),a=t.rule_id===`gateway.unknown-tool`,o=a?null:U(t),c=A[t.outcome]?.tone??`neutral`,l=i?`neutral`:a?`warn`:t.outcome===`error`?`bad`:te[t.decision]?.tone??`neutral`,u=i?.icon??(t.decision===`deny`?`x`:t.decision===`approve`?`clock`:`check`);return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`flex w-full flex-wrap items-center gap-x-3 gap-y-2 rounded-2xl px-2 py-3 text-left transition-colors hover:bg-faint focus-visible:bg-faint`,children:[(0,Y.jsx)(`span`,{className:I(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,ve[l]),children:(0,Y.jsx)(d,{name:u,size:18,strokeWidth:2})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1 basis-56`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-[14.5px] font-medium`,children:i?(0,Y.jsxs)(Y.Fragment,{children:[i.title,t.tool&&!t.tool.startsWith(`(`)&&(0,Y.jsx)(`span`,{className:`ml-1.5 text-soft`,title:t.tool,children:W(t.tool).label})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-soft`,children:G(t)}),` `,(0,Y.jsx)(`span`,{title:t.tool,children:W(t.tool).label})]})}),(0,Y.jsxs)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:[(0,Y.jsx)(`time`,{dateTime:t.ts,title:s(t.ts),children:v(t.ts)}),` · `,ye(t,i!==null),r&&t.tenant?` · ${t.tenant}`:``,!i&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,H(t)]})]}),o&&(0,Y.jsxs)(`span`,{className:`mt-1 flex items-center gap-1.5 text-[12.5px] font-medium text-warn`,children:[(0,Y.jsx)(d,{name:`eye`,size:14,strokeWidth:2}),o]})]}),(0,Y.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 max-sm:pl-[52px] sm:shrink-0`,children:[a?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool`}):!i&&(0,Y.jsx)(w,{decision:t.decision}),!a&&(i||C(t.outcome)!==k(t.decision))&&(0,Y.jsx)(e,{tone:c,children:V(t)?`You said no`:C(t.outcome)}),(0,Y.jsx)(d,{name:`chevron-right`,size:18,className:`text-soft max-sm:hidden`})]})]})}function xe({label:e,value:t,onChange:n,help:i}){return(0,Y.jsx)(r,{label:e,help:i,children:(0,Y.jsx)(`input`,{type:`datetime-local`,value:t,onChange:e=>n(e.target.value),className:`field`})})}function Se({open:e,onClose:n,records:r,stem:i}){let[a,o]=(0,J.useState)(`jsonl`);return(0,Y.jsx)(P,{open:e,onClose:n,title:`Download log`,description:`Saves the ${t(r.length,`entry`,`entries`)} listed now, with the filters you set. Load older entries first to include more.`,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,Y.jsx)(E,{variant:`primary`,icon:`download`,onClick:()=>{a===`jsonl`?z(`${i}.jsonl`,`application/x-ndjson`,B(r)):z(`${i}.csv`,`text/csv`,R(r)),n()},children:`Download file`})]}),children:(0,Y.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,Y.jsx)(`legend`,{className:`sr-only`,children:`File format`}),(0,Y.jsx)(Ce,{checked:a===`jsonl`,onSelect:()=>o(`jsonl`),title:`Exact log entries (JSONL)`,children:`One entry per line, exactly as written, fingerprints included. Use this to keep a copy or to check it later.`}),(0,Y.jsx)(Ce,{checked:a===`csv`,onSelect:()=>o(`csv`),title:`Spreadsheet (CSV)`,children:`The main columns, for sorting and counting in a spreadsheet. Fingerprints are left out.`})]})})}function Ce({checked:e,onSelect:t,title:n,children:r}){return(0,Y.jsxs)(`label`,{className:I(`flex cursor-pointer gap-3 rounded-2xl border-[1.5px] px-4 py-3 transition-colors`,e?`border-[var(--primary)] bg-ok-tint/40`:`border-line hover:bg-faint`),children:[(0,Y.jsx)(`input`,{type:`radio`,name:`log-format`,checked:e,onChange:t,className:`mt-1 accent-[var(--primary)]`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-[14px] font-semibold`,children:n}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[13px] text-soft`,children:r})]})]})}export{ge as ActivityPage};
1
+ import{$ as e,B as t,Ct as n,E as r,Et as i,G as a,H as o,I as s,It as c,M as l,O as u,Ot as d,P as f,Pt as p,R as m,S as h,St as g,U as _,V as v,Z as y,_ as b,bt as x,c as ee,d as S,dt as C,et as w,gt as T,ht as E,k as D,kt as O,lt as k,ot as A,pt as j,s as M,tt as te,ut as N,w as ne,wt as re,x as P,y as F,yt as I,z as L}from"./kit-DRVm92_t.js";import{Ct as ie,Dt as R,Et as z,Ot as B,St as ae,Tt as V,_t as oe,bt as H,gt as se,kt as U,s as W,un as ce,vt as G,wt as le,xt as K,yt as q}from"./index-CTvq_isK.js";var J=c(),Y=O();function ue({open:e,onClose:n,serverId:i}){let s=F(),[c,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),[ee,S]=(0,J.useState)(!1),C=()=>{h(!0),f(null),p.verify(i).then(u).catch(e=>f(e.message)).finally(()=>h(!1))};(0,J.useEffect)(()=>{e&&(u(null),y(null),x(null),C())},[e,i]);let w=g.trim().toLowerCase(),D=/^[0-9a-f]{16,128}$/.test(w),O=()=>{D&&(S(!0),x(null),p.verify(i,w).then(e=>y({head:w,result:e})).catch(e=>x(e.message)).finally(()=>S(!1)))},k=async e=>{let t=await q(e);s.show(t?`ok`:`bad`,t?`Fingerprint copied`:`The browser did not allow copying`)};return(0,Y.jsx)(P,{open:e,onClose:n,title:`Check log integrity`,description:`Reads every entry in the activity log and checks that each still matches its fingerprint.`,width:600,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,icon:`refresh`,onClick:C,loading:m,children:`Check again`}),(0,Y.jsx)(E,{variant:`primary`,onClick:n,children:`Close`})]}),children:(0,Y.jsxs)(`div`,{className:`space-y-5 pb-1 text-[14px]`,children:[d&&(0,Y.jsx)(o,{tone:`danger`,title:`The check could not run`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:C,children:`Try again`}),children:d}),!c&&!d&&(0,Y.jsx)(a,{lines:3,height:18}),c&&(0,Y.jsxs)(Y.Fragment,{children:[c.ok?(0,Y.jsx)(o,{tone:`ok`,role:`status`,title:`All ${L(c.count)} entries are intact`,children:`No entry has been edited, removed or put out of order.`}):(0,Y.jsxs)(o,{tone:`danger`,role:`alert`,title:`${t(c.problems.length,`problem`)} found in ${t(c.count,`entry`,`entries`)}`,children:[(0,Y.jsx)(`ul`,{className:`mt-1 space-y-1`,children:c.problems.slice(0,8).map(e=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsxs)(`span`,{className:`font-semibold`,children:[`Entry `,e.line,`:`]}),` `,de(e.message),` `,(0,Y.jsxs)(`span`,{className:`mono text-[11.5px] opacity-80`,children:[`(`,e.message,`)`]})]},`${e.line}-${e.message}`))}),c.problems.length>8&&(0,Y.jsxs)(`p`,{className:`mt-1`,children:[`And `,c.problems.length-8,` more.`]})]}),c.head?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`mb-1.5 text-[13px] font-semibold`,children:`Fingerprint of the latest entry`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl bg-sunken py-2 pr-2 pl-4`,children:[(0,Y.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[12px] break-all`,children:c.head}),(0,Y.jsx)(T,{icon:`copy`,label:`Copy fingerprint`,variant:`soft`,size:36,onClick:()=>k(c.head)})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`Save this somewhere the toolbox cannot reach, such as a note or a ticket. The check above catches an entry that was edited or removed, but not the newest entries being cut off the end, because what is left still checks out. A fingerprint you saved earlier can prove nothing was cut.`})]}):(0,Y.jsx)(`p`,{className:`text-soft`,children:`The log has no entries yet, so there is no fingerprint to save.`}),(0,Y.jsxs)(`div`,{className:`border-t border-faint pt-5`,children:[(0,Y.jsx)(r,{label:`Compare with a fingerprint you saved earlier`,help:`Paste the fingerprint exactly as you saved it.`,error:g.trim()&&!D?`That does not look like a fingerprint. It is a long run of letters a–f and digits.`:null,children:(0,Y.jsx)(l,{value:g,onChange:_,mono:!0,onEnter:O,placeholder:`e.g. 3f9a…`})}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(E,{onClick:O,disabled:!D,loading:ee,icon:`search`,children:`Compare fingerprint`})}),b&&(0,Y.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] font-medium text-bad`,children:b}),v&&(0,Y.jsx)(`div`,{className:`mt-4`,children:v.result.headPosition===void 0?(0,Y.jsx)(o,{tone:`danger`,role:`alert`,title:`Not found in this log`,children:`The log may have been cut short or replaced, or the fingerprint came from a different toolbox's log. Treat this as something to look into.`}):(0,Y.jsxs)(o,{tone:`ok`,role:`status`,title:`Found at entry ${L(v.result.headPosition+1)} of ${L(v.result.count)}`,children:[`Everything up to that entry is still in the log, so nothing written before you saved the fingerprint was lost.`,` `,v.result.count-v.result.headPosition-1>0?`${t(v.result.count-v.result.headPosition-1,`entry has`,`entries have`)} been added since.`:`No entries have been added since.`]})})]})]})]})})}function de(e){return/^record altered/.test(e)?`This entry was changed after it was written.`:/^sequence gap/.test(e)?`An entry before this one was removed, or entries were put out of order.`:/^chain break/.test(e)?`This entry doesn't follow on from the one before it: something was removed or put in between.`:/^unparseable JSON/.test(e)?`This entry can't be read; the file was edited or cut short.`:e}function fe({record:t,onClose:r,nav:a,redaction:o}){let c=F();if(!t)return null;let l=t,u=K(l),p=l.rule_id===`gateway.unknown-tool`,g=p?null:U(l),_=A[l.outcome]?.tone??`neutral`;return(0,Y.jsx)(h,{open:!0,onClose:r,title:u?u.title:(0,Y.jsxs)(Y.Fragment,{children:[G(l),` `,(0,Y.jsx)(`span`,{className:`mono text-[17px]`,children:l.tool})]}),subtitle:`Entry ${L(l.seq)} · ${s(l.ts)}`,width:620,footer:(0,Y.jsx)(E,{icon:`copy`,onClick:async()=>{let e=await q(`${location.origin}${i(a,{seq:String(l.seq)})}`);c.show(e?`ok`:`bad`,e?`Link to this entry copied`:`The browser did not allow copying`)},children:`Copy link to entry`}),children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[p?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool: your AI app asked for a tool this toolbox doesn't have`}):(0,Y.jsx)(w,{decision:l.decision}),!p&&C(l.outcome)!==k(l.decision)&&(0,Y.jsx)(e,{tone:_,children:V(l)?`You said no`:C(l.outcome)}),l.grant_id&&(0,Y.jsx)(e,{icon:`key`,children:`Released by a pre-approval`})]}),g&&(0,Y.jsxs)(`p`,{className:`flex gap-2 rounded-2xl bg-warn-tint px-4 py-3 text-[14px] text-ink`,children:[(0,Y.jsx)(d,{name:`eye`,size:18,className:`mt-0.5 shrink-0 text-warn`}),(0,Y.jsxs)(`span`,{children:[g,`. `,(0,Y.jsx)(b,{term:`watchOnly`})]})]}),(0,Y.jsxs)(X,{title:`What happened`,children:[(0,Y.jsx)(Z,{label:`Tool`,children:(0,Y.jsx)(`span`,{className:`mono text-[13px] break-all`,children:l.tool})}),(0,Y.jsx)(Z,{label:`What the tool does`,children:l.effect?(0,Y.jsx)(y,{effect:l.effect,withLabel:!0}):(0,Y.jsx)($,{children:N(null)})}),(0,Y.jsxs)(Z,{label:`Decided by`,children:[H(l),` `,(0,Y.jsx)(Q,{children:l.rule_id})]}),(0,Y.jsx)(Z,{label:`Reason`,children:l.reason||(0,Y.jsx)($,{children:`None recorded`})}),(0,Y.jsx)(Z,{label:`Took`,children:l.duration_ms===null?(0,Y.jsx)($,{children:`Not timed`}):m(l.duration_ms)}),l.error&&(0,Y.jsx)(Z,{label:`Error`,children:(0,Y.jsx)(`span`,{className:`text-bad`,children:l.error})})]}),(0,Y.jsxs)(X,{title:`Who asked`,children:[(0,Y.jsx)(Z,{label:`Asked by`,children:(0,Y.jsx)(`span`,{className:`break-all`,children:l.actor})}),(0,Y.jsx)(Z,{label:`Session`,children:(0,Y.jsx)(Q,{children:l.session})}),(0,Y.jsx)(Z,{label:`Written by`,children:(0,Y.jsx)(Q,{children:l.component})}),l.tenant!==null&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Customer `,(0,Y.jsx)(b,{term:`customer`})]}),children:l.tenant===``?(0,Y.jsx)($,{children:`None`}):l.tenant})]}),l.upstream&&(0,Y.jsxs)(X,{title:`Request to the connected server`,children:[(0,Y.jsx)(Z,{label:`Request`,children:(0,Y.jsxs)(`span`,{className:`mono text-[12.5px] break-all`,children:[l.upstream.method??`?`,` `,l.upstream.host??``,l.upstream.path??``]})}),(0,Y.jsx)(Z,{label:`Answer`,children:l.upstream.status===null?(0,Y.jsx)($,{children:`No status`}):(0,Y.jsx)(`span`,{className:`tnum`,children:l.upstream.status})}),l.upstream.bytes!==null&&(0,Y.jsx)(Z,{label:`Size`,children:f(l.upstream.bytes)})]}),(l.approval_id||l.grant_id)&&(0,Y.jsxs)(X,{title:`Linked`,children:[l.approval_id&&(0,Y.jsx)(Z,{label:`Approval request`,children:(0,Y.jsx)(me,{href:n(a,`/approvals`,{id:l.approval_id}),children:l.approval_id})}),l.grant_id&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Pre-approval `,(0,Y.jsx)(b,{term:`preApproval`})]}),children:(0,Y.jsx)(me,{href:n(a,`/pre-approvals`,{id:l.grant_id}),children:l.grant_id})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Inputs, as recorded `,(0,Y.jsx)(b,{term:`redaction`})]}),l.args_redacted===null?(0,Y.jsx)(`p`,{className:`text-[14px] text-soft`,children:`This toolbox does not record call inputs.`}):(0,Y.jsx)(S,{label:`Inputs as recorded`,maxHeight:260,children:JSON.stringify(l.args_redacted,null,2)}),o&&l.args_redacted!==null&&(0,Y.jsxs)(`details`,{className:`mt-3 rounded-2xl border border-faint px-4 py-3 text-[13px]`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`What the hidden-value markers mean`}),(0,Y.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:o.markers.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-3`,children:[(0,Y.jsx)(Q,{children:e.marker}),(0,Y.jsxs)(`span`,{className:`text-muted`,children:[pe(e.meaning),`.`]})]},e.marker))}),(0,Y.jsx)(`p`,{className:`mt-2 text-soft`,children:`Inputs are hidden by their name as well as their content, so a harmless value can still be hidden. The original values were never written down, so they cannot be recovered from the log.`})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Tamper check `,(0,Y.jsx)(b,{term:`hashChain`})]}),(0,Y.jsxs)(`ol`,{className:`space-y-2 text-[13px]`,children:[(0,Y.jsx)(he,{label:`Fingerprint of the entry before`,value:l.prev_hash}),(0,Y.jsx)(`li`,{"aria-hidden":!0,className:`pl-4 text-soft`,children:(0,Y.jsx)(d,{name:`chevron`,size:16})}),(0,Y.jsx)(he,{label:`Fingerprint of this entry`,value:l.hash,strong:!0})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`This entry's fingerprint covers its contents and the one before it, so editing or removing any earlier entry breaks every fingerprint after it.`}),(0,Y.jsxs)(`p`,{className:`mt-3 text-[12.5px] text-soft`,children:[`Fingerprint of the inputs: `,(0,Y.jsx)(Q,{children:l.args_hash})]})]})]})})}var pe=e=>e.charAt(0).toUpperCase()+e.slice(1);function X({title:e,children:t}){return(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[15px] font-semibold`,children:e}),(0,Y.jsx)(`dl`,{className:`divide-y divide-faint rounded-2xl border border-faint px-4`,children:t})]})}function Z({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`grid gap-1 py-2.5 sm:grid-cols-[160px_1fr] sm:gap-4`,children:[(0,Y.jsx)(`dt`,{className:`flex items-center gap-1.5 text-[13px] text-soft`,children:e}),(0,Y.jsx)(`dd`,{className:`min-w-0 text-[14px]`,children:t})]})}var Q=({children:e})=>(0,Y.jsx)(`code`,{className:`mono text-[12px] break-all text-soft`,children:e}),$=({children:e})=>(0,Y.jsx)(`span`,{className:`text-soft`,children:e});function me({href:e,children:t}){return(0,Y.jsx)(`a`,{href:e,onClick:g,className:`mono text-[12.5px] break-all text-ok underline underline-offset-2`,children:t})}function he({label:e,value:t,strong:n}){return(0,Y.jsxs)(`li`,{className:n?`rounded-2xl bg-sunken px-4 py-3`:`rounded-2xl border border-faint px-4 py-3`,children:[(0,Y.jsx)(`span`,{className:`block text-[12.5px] text-soft`,children:e}),(0,Y.jsx)(`code`,{className:`mono mt-1 block text-[12px] break-all text-ink`,children:t})]})}function ge(){let{serverId:e,server:n,tenant:a,tenantInfo:s,nav:c}=ce(),[d,f]=(0,J.useState)(()=>le(c)),[m,h]=(0,J.useState)(()=>Date.now()),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)(),[b,S]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),[O,N]=(0,J.useState)(!1),[P=``,F=``,I=``]=x([d.tool,d.actor,d.component].join(`\0`),300).split(`\0`),R={...d,tool:P,actor:F,component:I};(0,J.useEffect)(()=>{re(i(c,{...ae(R),seq:b?String(b.seq):null}))},[JSON.stringify(R),b?.seq]);let z=oe(R,a,m),B=JSON.stringify(z),V=M(()=>p.audit(e,v===void 0?z:{...z,cursor:String(v)}),[e,B,v],v===void 0?5e3:void 0),H=M(()=>p.redaction(),[]),U=v===void 0?V.data?.records??[]:[...g,...V.data?.records??[]],W=V.loading&&!V.data;function G(e){f(t=>({...t,...e})),y(void 0),_([]),e.range!==void 0&&h(Date.now())}let K=()=>{y(void 0),_([]),h(Date.now()),V.reload()},[q,de]=(0,J.useState)(()=>c.query.get(`seq`));(0,J.useEffect)(()=>{if(!q)return;let t=Number(q);if(de(null),!Number.isInteger(t)||t<0)return;let n={limit:`1`,cursor:String(t+1)};!d.allTenants&&a!==null&&(n.tenant=a),p.audit(e,n).then(e=>{let n=e.records.find(e=>e.seq===t);n&&S(n)}).catch(()=>void 0)},[q]);let pe=(0,J.useMemo)(()=>[{value:``,label:`Any decision`},...(H.data?.decisions??Object.keys(te).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:k(e.value)}))],[H.data]),X=(0,J.useMemo)(()=>[{value:``,label:`Any result`},...(H.data?.outcomes??Object.keys(A).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:C(e.value)}))],[H.data]),Z=s?.configured?s.tenants.filter(e=>e!==``):[];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ee,{title:`Activity`,subtitle:`Every call your AI made through this toolbox, and what happened. Each entry is chained to the one before it, so edits can be detected.`,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`primary`,icon:`shield-check`,onClick:()=>T(!0),children:`Check log integrity`}),(0,Y.jsx)(E,{icon:`download`,onClick:()=>N(!0),disabled:U.length===0,children:`Download log`})]})}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(j,{title:`Filters`,actions:ie(d)&&(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`x`,onClick:()=>G(se),children:`Clear filters`}),children:[(0,Y.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,Y.jsx)(r,{label:`Result`,children:(0,Y.jsx)(D,{value:d.outcome,onChange:e=>G({outcome:e}),options:X})}),(0,Y.jsx)(r,{label:`Decision`,children:(0,Y.jsx)(D,{value:d.decision,onChange:e=>G({decision:e}),options:pe})}),(0,Y.jsx)(r,{label:`Tool`,help:`Use * to match any text, like files.*`,children:(0,Y.jsx)(l,{value:d.tool,onChange:e=>G({tool:e}),mono:!0,placeholder:`Any tool`})}),(0,Y.jsx)(r,{label:`Who asked`,children:(0,Y.jsx)(l,{value:d.actor,onChange:e=>G({actor:e}),placeholder:`Anyone`})}),Z.length>0&&(0,Y.jsx)(r,{label:`Customer`,children:(0,Y.jsx)(D,{value:d.allTenants?`*`:a??``,onChange:e=>{e===`*`?G({allTenants:!0}):e===a?G({allTenants:!1}):re(i(c,{tenant:e,allTenants:null}))},options:[...a===null?[{value:``,label:`Choose a customer`}]:[],...Z.map(e=>({value:e,label:e})),{value:`*`,label:`All customers`}]})}),d.component&&(0,Y.jsx)(r,{label:`Written by`,technical:`component`,children:(0,Y.jsx)(l,{value:d.component,onChange:e=>G({component:e}),mono:!0})})]}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-end justify-between gap-4 border-t border-faint pt-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-[13px] font-semibold text-soft`,"aria-hidden":!0,children:`When`}),(0,Y.jsx)(u,{label:`Time range`,value:d.range,onChange:e=>G({range:e}),options:[{value:``,label:`Any time`},{value:`1h`,label:`Last hour`},{value:`24h`,label:`Last 24 hours`},{value:`7d`,label:`Last 7 days`},{value:`custom`,label:`Custom`}]})]}),(0,Y.jsx)(ne,{checked:d.noteworthy,onChange:e=>G({noteworthy:e}),label:`Only problems`,description:`Blocked, failed or still waiting.`})]}),d.range===`custom`&&(0,Y.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2`,children:[(0,Y.jsx)(xe,{label:`From`,value:d.since,onChange:e=>G({since:e})}),(0,Y.jsx)(xe,{label:`Until`,value:d.until,onChange:e=>G({until:e}),help:`Leave empty for up to now.`})]})]}),V.data&&V.data.malformed>0&&(0,Y.jsxs)(o,{tone:`warn`,title:`${t(V.data.malformed,`line`)} could not be read`,children:[`Of the `,L(V.data.scanned),` lines read for this list, `,L(V.data.malformed),` were damaged and skipped. Run the integrity check to see where.`]}),(0,Y.jsxs)(j,{title:W?`Entries`:`${t(U.length,`entry`,`entries`)}${V.data?.nextCursor==null?``:` so far`}`,actions:(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:K,loading:V.loading&&!!V.data,children:`Refresh list`}),children:[(0,Y.jsx)(_e,{loading:W,error:V.error,onRetry:V.reload,records:U,filtered:ie(d),onClear:()=>G(se),onOpen:S,mixedCustomers:d.allTenants}),V.data?.nextCursor!=null&&(0,Y.jsx)(`div`,{className:`mt-5 flex flex-wrap items-center gap-3`,children:(0,Y.jsx)(E,{icon:`chevron`,loading:V.loading,onClick:()=>{_(U),y(V.data.nextCursor)},children:`Load older entries`})})]})]}),(0,Y.jsx)(fe,{record:b,onClose:()=>S(null),nav:c,redaction:H.data}),(0,Y.jsx)(ue,{open:w,onClose:()=>T(!1),serverId:e}),(0,Y.jsx)(Se,{open:O,onClose:()=>N(!1),records:U,stem:`activity-${n.id}-${new Date().toISOString().slice(0,10)}`})]})}function _e({loading:e,error:t,onRetry:n,records:r,filtered:i,onClear:s,onOpen:c,mixedCustomers:l}){return t?(0,Y.jsx)(o,{tone:`danger`,title:`The activity log could not be read`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:n,children:`Try again`}),children:t}):e?(0,Y.jsx)(`div`,{className:`space-y-5`,"aria-busy":!0,children:[0,1,2,3,4].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`skeleton h-10 w-10 shrink-0 rounded-full`}),(0,Y.jsx)(a,{lines:2})]},e))}):r.length===0?i?(0,Y.jsx)(_,{icon:`filter`,title:`No entries match these filters`,actions:(0,Y.jsx)(E,{onClick:s,children:`Clear filters`}),children:`The whole log was searched. Try a wider time range or fewer filters.`}):(0,Y.jsx)(_,{icon:`activity`,title:`No activity yet`,children:`Calls appear here as soon as an AI app connected to this toolbox uses a tool.`}):(0,Y.jsx)(`ul`,{className:`-mx-2`,children:r.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(be,{record:e,onOpen:()=>c(e),showCustomer:l})},`${e.seq}-${e.id}`))})}var ve={ok:`bg-ok-tint text-ok`,warn:`bg-warn-tint text-warn`,bad:`bg-bad-tint text-bad`,neutral:`bg-sunken text-muted`};function ye(e,t){if(!t&&(e.actor===`agent`||!e.actor))return`Your AI app`;if(e.actor===`gateway`)return`The toolbox`;let n=e.args_redacted?.origin;return t&&(n===`console`||e.component===`hmcp-web`||e.rule_id===`approval.decide`||e.tool?.startsWith(`(`))?e.actor&&e.actor!==`console`?`You (${e.actor})`:`You`:e.actor}function be({record:t,onOpen:n,showCustomer:r}){let i=K(t),a=t.rule_id===`gateway.unknown-tool`,o=a?null:U(t),c=A[t.outcome]?.tone??`neutral`,l=i?`neutral`:a?`warn`:t.outcome===`error`?`bad`:te[t.decision]?.tone??`neutral`,u=i?.icon??(t.decision===`deny`?`x`:t.decision===`approve`?`clock`:`check`);return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`flex w-full flex-wrap items-center gap-x-3 gap-y-2 rounded-2xl px-2 py-3 text-left transition-colors hover:bg-faint focus-visible:bg-faint`,children:[(0,Y.jsx)(`span`,{className:I(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,ve[l]),children:(0,Y.jsx)(d,{name:u,size:18,strokeWidth:2})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1 basis-56`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-[14.5px] font-medium`,children:i?(0,Y.jsxs)(Y.Fragment,{children:[i.title,t.tool&&!t.tool.startsWith(`(`)&&(0,Y.jsx)(`span`,{className:`ml-1.5 text-soft`,title:t.tool,children:W(t.tool).label})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-soft`,children:G(t)}),` `,(0,Y.jsx)(`span`,{title:t.tool,children:W(t.tool).label})]})}),(0,Y.jsxs)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:[(0,Y.jsx)(`time`,{dateTime:t.ts,title:s(t.ts),children:v(t.ts)}),` · `,ye(t,i!==null),r&&t.tenant?` · ${t.tenant}`:``,!i&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,H(t)]})]}),o&&(0,Y.jsxs)(`span`,{className:`mt-1 flex items-center gap-1.5 text-[12.5px] font-medium text-warn`,children:[(0,Y.jsx)(d,{name:`eye`,size:14,strokeWidth:2}),o]})]}),(0,Y.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 max-sm:pl-[52px] sm:shrink-0`,children:[a?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool`}):!i&&(0,Y.jsx)(w,{decision:t.decision}),!a&&(i||C(t.outcome)!==k(t.decision))&&(0,Y.jsx)(e,{tone:c,children:V(t)?`You said no`:C(t.outcome)}),(0,Y.jsx)(d,{name:`chevron-right`,size:18,className:`text-soft max-sm:hidden`})]})]})}function xe({label:e,value:t,onChange:n,help:i}){return(0,Y.jsx)(r,{label:e,help:i,children:(0,Y.jsx)(`input`,{type:`datetime-local`,value:t,onChange:e=>n(e.target.value),className:`field`})})}function Se({open:e,onClose:n,records:r,stem:i}){let[a,o]=(0,J.useState)(`jsonl`);return(0,Y.jsx)(P,{open:e,onClose:n,title:`Download log`,description:`Saves the ${t(r.length,`entry`,`entries`)} listed now, with the filters you set. Load older entries first to include more.`,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,Y.jsx)(E,{variant:`primary`,icon:`download`,onClick:()=>{a===`jsonl`?z(`${i}.jsonl`,`application/x-ndjson`,B(r)):z(`${i}.csv`,`text/csv`,R(r)),n()},children:`Download file`})]}),children:(0,Y.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,Y.jsx)(`legend`,{className:`sr-only`,children:`File format`}),(0,Y.jsx)(Ce,{checked:a===`jsonl`,onSelect:()=>o(`jsonl`),title:`Exact log entries (JSONL)`,children:`One entry per line, exactly as written, fingerprints included. Use this to keep a copy or to check it later.`}),(0,Y.jsx)(Ce,{checked:a===`csv`,onSelect:()=>o(`csv`),title:`Spreadsheet (CSV)`,children:`The main columns, for sorting and counting in a spreadsheet. Fingerprints are left out.`})]})})}function Ce({checked:e,onSelect:t,title:n,children:r}){return(0,Y.jsxs)(`label`,{className:I(`flex cursor-pointer gap-3 rounded-2xl border-[1.5px] px-4 py-3 transition-colors`,e?`border-[var(--primary)] bg-ok-tint/40`:`border-line hover:bg-faint`),children:[(0,Y.jsx)(`input`,{type:`radio`,name:`log-format`,checked:e,onChange:t,className:`mt-1 accent-[var(--primary)]`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-[14px] font-semibold`,children:n}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[13px] text-soft`,children:r})]})]})}export{ge as ActivityPage};
@@ -1 +1 @@
1
- import{$ as e,B as t,Ct as n,D as r,E as i,Et as a,F as o,G as s,H as c,I as l,It as u,J as d,K as f,M as p,Nt as m,Ot as h,Pt as g,T as _,U as v,V as ee,Y as te,Z as y,_ as b,_t as x,c as S,gt as ne,ht as C,j as w,kt as T,mt as E,pt as D,q as O,rt as k,s as A,w as j,wt as M,x as re,y as ie,yt as N}from"./kit-DRVm92_t.js";import{a as P,c as ae,l as F,n as oe,o as I,r as L,s as R,t as se,u as z,un as ce}from"./index-DbHZ_SUd.js";var B=u(),V=T(),H=/^\[redacted:([^\]]+)\]$/,U=/…\[truncated (\d+) chars\]$/,W=/^\[truncated (\d+) items\]$/;function G(e){if(typeof e!=`string`)return null;let t=H.exec(e);return t?t[1]===`key`||t[1]===`circular`||t[1]===`max-depth`?t[1]:`pattern`:U.test(e)?`chars`:W.test(e)?`items`:null}function K(e,t,n=0){if(n>20)return;let r=G(e);r&&t.add(r),Array.isArray(e)?e.forEach(e=>K(e,t,n+1)):e&&typeof e==`object`&&Object.values(e).forEach(e=>K(e,t,n+1))}var q={key:`[redacted:key]`,pattern:`[redacted:<pattern>]`,circular:`[redacted:circular]`,"max-depth":`[redacted:max-depth]`,chars:`…[truncated N chars]`,items:`[truncated N items]`},J={key:`Hidden`,pattern:`Hidden`,circular:`Hidden`,"max-depth":`Hidden`,chars:`Cut short`,items:`Cut short`};function Y({args:e,error:t,meta:n}){let r=new Set;K(e,r);let i=e=>n?.markers.find(t=>t.marker===q[e])?.meaning,a=e&&typeof e==`object`&&!Array.isArray(e)?Object.entries(e):null;return(0,V.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,V.jsx)(c,{tone:`warn`,title:`Some inputs could not be read back`,children:t}),a===null?e==null?!t&&(0,V.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`The inputs were not recorded.`}):(0,V.jsx)(X,{value:e,meaning:i}):a.length===0?(0,V.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`This call sent no inputs.`}):(0,V.jsx)(`dl`,{className:`divide-y divide-faint overflow-hidden rounded-2xl bg-sunken/60`,children:a.map(([e,t])=>(0,V.jsxs)(`div`,{className:`grid gap-1 px-4 py-2.5 sm:grid-cols-[minmax(6rem,10rem)_minmax(0,1fr)] sm:gap-4`,children:[(0,V.jsx)(`dt`,{className:`mono pt-px text-[12.5px] break-all text-soft`,children:e}),(0,V.jsx)(`dd`,{className:`min-w-0`,children:(0,V.jsx)(X,{value:t,meaning:i})})]},e))}),r.size>0&&(0,V.jsxs)(`div`,{className:`flex gap-2 text-[12.5px] text-soft`,children:[(0,V.jsx)(h,{name:`eye-off`,size:15,className:`mt-0.5 shrink-0`}),(0,V.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-muted`,children:[`Some values are hidden or cut short in the record `,(0,V.jsx)(b,{term:`redaction`})]}),[...r].map(e=>(0,V.jsxs)(`p`,{children:[(0,V.jsx)(`code`,{className:`mono text-[11.5px]`,children:q[e]}),`: `,i(e)??`not shown in full`]},e))]})]})]})}function X({value:t,meaning:n}){let r=G(t);if(r&&r!==`chars`)return(0,V.jsx)(e,{tone:`neutral`,icon:`eye-off`,title:n(r),children:J[r]});if(typeof t==`string`){let r=U.exec(t),i=r?t.slice(0,r.index):t;return(0,V.jsxs)(`p`,{className:`scrollbar-thin max-h-40 overflow-y-auto text-[13.5px] break-words whitespace-pre-wrap`,children:[i===``?(0,V.jsx)(`span`,{className:`text-soft`,children:`(empty)`}):i,r&&(0,V.jsxs)(e,{tone:`neutral`,className:`ml-1.5 align-middle`,title:n(`chars`),children:[r[1],` more characters not recorded`]})]})}return typeof t==`number`||typeof t==`boolean`||t===null?(0,V.jsx)(`span`,{className:`mono text-[13px]`,children:String(t)}):(0,V.jsx)(`pre`,{className:`scrollbar-thin mono max-h-48 overflow-auto rounded-xl bg-surface px-3 py-2 text-[12px] leading-relaxed whitespace-pre-wrap break-words`,children:JSON.stringify(t,null,2)})}var Z=e=>e instanceof m&&(e.status===409||e.status===404);function le({approval:e,meta:t,now:n,serverId:a,tenant:s,selecting:u,selected:d,onSelect:f,locked:h,onDecided:v,onRemembered:te}){let x=ie(),[S,ne]=(0,B.useState)(``),[w,T]=(0,B.useState)(null),[E,D]=(0,B.useState)(!1),[O,A]=(0,B.useState)(t?.rememberDefaults.ttlSeconds??3600),[M,re]=(0,B.useState)(t?.rememberDefaults.maxUses??20),[F,oe]=(0,B.useState)(!1),[ce,H]=(0,B.useState)(null),U=R(e.tool),W=e.expiresAt-n,G=L(e),K=t?.grantTtlMaxSeconds,q=h||w!==null;async function J(t,n={}){T(n.remember?`remember`:n.classify?`classify-${n.classify}`:t),H(null);let r;try{r=await g.decide(a,e.id,t,S.trim(),s,n.classify,n.remember)}catch(e){T(null),Z(e)?(x.show(`warn`,`This call was already answered, or it ran out of time.`),v()):n.remember&&e instanceof m&&e.status===422?H(I(e.message)):x.show(`bad`,I(e.message));return}T(null),t===`denied`?x.show(`ok`,`You said no. ${U.label} will not run, and the AI is told you said no.`):r.remembered?(x.show(`ok`,`Approved. Similar calls won't ask until ${ae(r.remembered.expiresAt)}.`),te(r.remembered,e.tool)):r.classifyWarning?x.show(`warn`,I(r.classifyWarning)):r.classified&&n.classify?x.show(`ok`,`Approved, and ${U.label} is now labelled "${k[n.classify].label}". Its calls still ask you.`):x.show(`ok`,`Approved. The call can go ahead.`),v()}let X=O!==null&&(K===void 0||O<=K)&&(F||M!==null&&M>=1);return(0,V.jsxs)(`article`,{"aria-labelledby":`apr-${e.id}`,className:N(`card flex min-w-0 flex-col gap-5 p-5 sm:p-6`,d&&`outline-2 outline-offset-2 outline-[var(--primary)]`),children:[(0,V.jsxs)(`header`,{className:`flex items-start gap-3`,children:[u&&(0,V.jsx)(`span`,{className:`pt-2.5`,children:(0,V.jsx)(j,{checked:d,onChange:f,disabled:q,label:(0,V.jsxs)(`span`,{className:`sr-only`,children:[`Select `,U.label]})})}),(0,V.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,V.jsx)(y,{effect:e.effect})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`h3`,{id:`apr-${e.id}`,tabIndex:-1,className:`text-[18px] outline-none focus-visible:outline-2 focus-visible:outline-[var(--focus)] leading-snug font-medium tracking-[-0.015em] break-words`,children:U.label}),(0,V.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-[12.5px] text-soft`,children:[U.server&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{children:U.server}),(0,V.jsx)(`span`,{"aria-hidden":!0,children:`·`})]}),(0,V.jsx)(y,{effect:e.effect,withLabel:!0})]})]})]}),(0,V.jsxs)(`section`,{"aria-label":`What it wants to do`,className:`space-y-2.5`,children:[(0,V.jsx)(`p`,{className:`text-[15px] leading-relaxed [overflow-wrap:anywhere]`,children:se(e)}),(0,V.jsx)(`p`,{className:`text-[14px] text-muted`,children:z(e)}),e.violations.length>0&&(0,V.jsx)(`ul`,{className:`space-y-1.5 rounded-2xl bg-warn-tint px-4 py-3 text-[13.5px]`,children:e.violations.map(t=>(0,V.jsxs)(`li`,{className:`flex gap-2`,children:[(0,V.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),(0,V.jsx)(`span`,{className:`min-w-0 break-words`,children:P(t,e.args)})]},t))}),(0,V.jsx)(`p`,{className:`text-[13px] text-soft`,children:W>0?`If you don't answer by ${o(e.expiresAt)}, it doesn't run. The AI can ask again.`:`This request ran out of time, so it doesn't run. The AI can ask again.`})]}),(0,V.jsxs)(`section`,{"aria-label":`The details it would send`,className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`eyebrow`,children:`The details it would send`}),(0,V.jsx)(Y,{args:e.args,error:e.argsError,meta:t})]}),(0,V.jsxs)(`details`,{className:`group text-[12.5px] text-soft`,children:[(0,V.jsx)(`summary`,{className:`cursor-pointer select-none font-medium text-muted`,children:`Details`}),(0,V.jsxs)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1`,children:[(0,V.jsx)(`dt`,{children:`Tool`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.tool})}),(0,V.jsx)(`dt`,{children:`Asked by`}),(0,V.jsxs)(`dd`,{children:[e.actor,` `,(0,V.jsx)(`span`,{title:l(e.createdAt),children:ee(e.createdAt,n)})]}),(0,V.jsx)(`dt`,{children:`Session`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.session})}),e.ruleId&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`dt`,{children:`Rule`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.ruleId})})]}),(0,V.jsx)(`dt`,{children:`Request`}),(0,V.jsxs)(`dd`,{children:[(0,V.jsx)(`code`,{className:`mono break-all`,children:e.id}),`, expires `,l(e.expiresAt)]})]})]}),(0,V.jsxs)(`div`,{className:`mt-auto space-y-3 border-t border-faint pt-4`,children:[(0,V.jsx)(i,{label:`Note for the activity log`,optional:!0,children:(0,V.jsx)(p,{value:S,onChange:ne,placeholder:`Why you said yes or no`,disabled:q})}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(C,{variant:`primary`,icon:`check`,onClick:()=>J(`granted`),loading:w===`granted`,disabled:q,children:`Approve`}),(0,V.jsx)(C,{variant:`secondary`,icon:`x`,onClick:()=>J(`denied`),loading:w===`denied`,disabled:q,children:`Say no`}),e.rememberAllowed&&!G&&(0,V.jsx)(C,{variant:`ghost`,icon:E?`chevron`:`chevron-right`,"aria-expanded":E,"aria-controls":`remember-${e.id}`,onClick:()=>D(e=>!e),disabled:q,children:`Approve and don't ask again`})]}),G&&(0,V.jsxs)(`div`,{className:`space-y-2.5 rounded-2xl bg-sunken/70 p-4`,children:[(0,V.jsx)(`p`,{className:`text-[13.5px] font-semibold`,children:`Approve and remember this tool as:`}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":`Approve and say what this tool does`,children:[`read`,`write`,`destructive`].map(e=>(0,V.jsx)(C,{size:`sm`,variant:`secondary`,onClick:()=>J(`granted`,{classify:e}),loading:w===`classify-${e}`,disabled:q,title:k[e].explain,children:k[e].label},e))}),(0,V.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`This approves the call and saves what the tool does in your protection settings. Its calls still ask you; once it is labelled you can set a rule for it on the Tools page.`})]}),E&&e.rememberAllowed&&(0,V.jsxs)(`div`,{id:`remember-${e.id}`,className:`space-y-4 rounded-2xl bg-sunken/70 p-4`,children:[(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[14px] font-semibold`,children:[`Approve and don't ask again `,(0,V.jsx)(b,{term:`preApproval`})]}),(0,V.jsx)(i,{label:`For how long`,children:(0,V.jsx)(_,{value:O,onChange:A,label:`For how long`,max:K})}),(0,V.jsx)(i,{label:`Up to how many calls`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,V.jsx)(r,{value:F?null:M,onChange:re,min:1,step:1,unit:`calls`,disabled:F||q,className:`w-40`}),(0,V.jsx)(j,{checked:F,onChange:oe,label:`No limit`,disabled:q})]})}),(0,V.jsx)(`p`,{className:`text-[13px] text-muted`,children:`For the time you choose, your AI can make this same request again without asking. Anything different still asks you, including a list with items changed, repeated or left out. You can take it back any time on the Pre-approvals page.`}),ce&&(0,V.jsx)(c,{tone:`danger`,title:`Nothing was approved`,role:`alert`,children:ce}),(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,V.jsx)(C,{variant:`primary`,icon:`check`,disabled:!X||q,loading:w===`remember`,onClick:()=>J(`granted`,{remember:{ttlSeconds:O,maxUses:F?null:M}}),children:`Approve and remember`}),(0,V.jsx)(C,{variant:`ghost`,onClick:()=>D(!1),disabled:w!==null,children:`Cancel`})]})]})]})]})}var ue={elicit:`On this toolbox your AI app asks you in its own window, so calls usually do not wait here.`,cli:`On this toolbox every call that needs your OK waits here until you answer it.`,both:`Your AI app asks you in its own window when it can. When it cannot, the call waits here.`,deny:`On this toolbox calls that would need your OK are blocked instead, so nothing waits here.`};function Q(){let{serverId:e,tenant:r,nav:i,reload:o}=ce(),l=ie(),u=F(1e3),f=A(()=>g.pending(e,r),[e,r],2e3),p=A(()=>g.approvals(e,r,{limit:200}),[e,r],15e3),h=A(()=>g.redaction(),[]),_=A(()=>g.protection(e,r),[e,r],3e4),y=i.query.get(`id`),b=y!==null&&(f.data??[]).some(e=>e.id===y),T=i.query.get(`tab`)===`history`||y!==null&&f.data!==null&&!b?`history`:`waiting`,k=e=>M(a(i,{tab:e===`waiting`?null:e})),j=(0,B.useMemo)(()=>[...f.data??[]].filter(e=>e.expiresAt>u).sort((e,t)=>e.createdAt-t.createdAt),[f.data,u]),N=(0,B.useMemo)(()=>(p.data??[]).filter(e=>e.state!==`pending`).sort((e,t)=>(t.decidedAt??t.expiresAt)-(e.decidedAt??e.expiresAt)),[p.data]),[P,L]=(0,B.useState)(!1),[se,z]=(0,B.useState)([]),H=new Set(j.map(e=>e.id)),U=se.filter(e=>H.has(e)),[W,G]=(0,B.useState)(null),[K,q]=(0,B.useState)(``),[J,Y]=(0,B.useState)(!1),[X,Z]=(0,B.useState)(null),Q=(0,B.useRef)(!1),de=(0,B.useRef)(null),fe=(0,B.useRef)(null);(0,B.useEffect)(()=>{Q.current&&f.data!==null&&(Q.current=!1,(de.current?.querySelector(`article h3[tabindex]`)??fe.current)?.focus())},[f.data]);let me=()=>{f.reload(),p.reload(),_.reload(),o()};async function he(n){Y(!0);let i=0,a=0,o=[];for(let t of U)try{await g.decide(e,t,n,K.trim(),r),i++}catch(e){e instanceof m&&(e.status===409||e.status===404)?a++:o.push(I(e.message))}Y(!1),G(null),q(``),z([]),L(!1),me();let s=[`${n===`granted`?`Approved`:`Denied`} ${t(i,`call`)}.`];a&&s.push(`${t(a,`call`)} had already been answered or ran out of time.`),o.length&&s.push(`${o.length} failed: ${o[0]}`),l.show(o.length?`bad`:a?`warn`:`ok`,s.join(` `))}let $=_.data?.approvals,ge=$?ue[$.mode]:void 0,_e=j.reduce((e,t)=>e===null||t.expiresAt<e?t.expiresAt:e,null),ve=j[0];return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(S,{title:`Waiting for you`,subtitle:`Your AI wanted to do these things. Nothing happens until you decide.`,actions:(0,V.jsx)(C,{variant:P?`primary`:`secondary`,icon:P?`x`:`list`,"aria-pressed":P,disabled:!P&&j.length<2,onClick:()=>{L(e=>!e),z([])},children:P?`Stop selecting`:`Select several`})}),(0,V.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,V.jsx)(E,{tone:`hero`,title:`Waiting now`,loading:f.data===null&&!f.error,value:j.length,sub:ve?`Oldest asked ${ee(ve.createdAt,u)}`:`Nothing needs you`}),(0,V.jsxs)(`div`,{className:`contents max-sm:hidden`,children:[(0,V.jsx)(E,{title:`Expires next`,loading:f.data===null&&!f.error,value:_e===null?`None`:oe(_e-u),sub:_e===null?`Nothing is waiting`:`A request nobody answers doesn't run`}),(0,V.jsx)(E,{title:`Pre-approvals in use`,loading:_.data===null&&!_.error,value:$?.activeGrantCount??`–`,sub:`Calls they cover skip this page`,href:n(i,`/pre-approvals`),hrefLabel:`Open pre-approvals`})]})]}),(0,V.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[$&&$.pendingElsewhere>0&&(0,V.jsxs)(c,{tone:`info`,title:`${t($.pendingElsewhere,`call`)} ${$.pendingElsewhere===1?`is`:`are`} waiting for a different customer`,children:[`Choose that customer at the top of the page to answer `,$.pendingElsewhere===1?`it`:`them`,`.`]}),X&&(0,V.jsxs)(c,{tone:`ok`,title:`Pre-approval created`,role:`status`,actions:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(x,{size:`sm`,variant:`secondary`,href:n(i,`/pre-approvals`,{grant:X.grant.id}),children:`Open pre-approval`}),(0,V.jsx)(ne,{icon:`x`,label:`Dismiss message`,size:32,onClick:()=>Z(null)})]}),children:[`Calls like this one to `,R(X.tool).label,` won't ask until `,ae(X.grant.expiresAt),X.grant.maxUses===null?``:`, for up to ${t(X.grant.maxUses,`call`)}`,`.`]})]}),(0,V.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center justify-between gap-3`,children:[(0,V.jsx)(O,{label:`Calls`,value:T,onChange:k,items:[{id:`waiting`,label:`Waiting`,count:j.length},{id:`history`,label:`Decided earlier`,count:N.length}]}),T===`waiting`&&j.length>0&&(0,V.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Oldest first: the call at the top runs out soonest.`})]}),(0,V.jsx)(`div`,{role:`tabpanel`,id:te(T),"aria-labelledby":d(T),className:`mt-5`,children:T===`waiting`?(0,V.jsxs)(V.Fragment,{children:[P&&j.length>0&&(0,V.jsx)(D,{className:`mb-5`,padded:!1,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-5 py-4`,children:[(0,V.jsxs)(`p`,{className:`min-w-0 flex-1 text-[14px]`,children:[(0,V.jsx)(`span`,{className:`tnum font-semibold`,children:U.length}),` of `,t(j.length,`call`),` selected`]}),(0,V.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>z(U.length===j.length?[]:j.map(e=>e.id)),children:U.length===j.length?`Clear selection`:`Select all`}),(0,V.jsx)(C,{size:`sm`,variant:`primary`,icon:`check`,disabled:U.length===0,onClick:()=>G(`granted`),children:`Approve all`}),(0,V.jsx)(C,{size:`sm`,variant:`secondary`,icon:`x`,disabled:U.length===0,onClick:()=>G(`denied`),children:`Deny all`})]})}),f.error&&(0,V.jsx)(`div`,{className:`mb-5`,children:(0,V.jsx)(c,{tone:`danger`,title:`Could not load the calls waiting for you`,role:`alert`,actions:(0,V.jsx)(C,{size:`sm`,icon:`refresh`,onClick:f.reload,children:`Try again`}),children:I(f.error)})}),f.data===null?!f.error&&(0,V.jsx)(`div`,{className:`grid gap-5 xl:grid-cols-2`,children:[0,1].map(e=>(0,V.jsxs)(D,{children:[(0,V.jsx)(s,{height:22,width:`45%`}),(0,V.jsx)(`div`,{className:`mt-5`,children:(0,V.jsx)(s,{lines:4})})]},e))}):j.length===0?(0,V.jsx)(D,{children:(0,V.jsx)(`div`,{ref:fe,tabIndex:-1,className:`outline-none`,children:(0,V.jsxs)(v,{icon:`inbox`,title:`Nothing is waiting for you.`,actions:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(C,{variant:`secondary`,onClick:()=>k(`history`),children:`Show decided calls`}),(0,V.jsx)(x,{variant:`secondary`,href:n(i,`/pre-approvals`),children:`Manage pre-approvals`})]}),children:[`When your AI tries something that needs your OK, it appears here and this page updates by itself.`,` `,ge]})})}):(0,V.jsx)(`div`,{ref:de,className:`grid items-start gap-5 xl:grid-cols-2`,children:j.map(t=>(0,V.jsx)(`div`,{className:t.id===y?`rounded-[22px] ring-2 ring-[var(--focus)] ring-offset-2 ring-offset-[var(--bg)]`:void 0,children:(0,V.jsx)(le,{approval:t,meta:h.data,now:u,serverId:e,tenant:r,selecting:P,selected:P&&U.includes(t.id),onSelect:e=>z(n=>e?[...new Set([...n,t.id])]:n.filter(e=>e!==t.id)),locked:J,onDecided:()=>{Q.current=!0,me()},onRemembered:(e,t)=>Z({grant:e,tool:t})})},t.id))})]}):(0,V.jsx)(pe,{rows:N,error:p.error,loading:p.data===null,retry:p.reload,now:u,focusId:y})}),(0,V.jsxs)(re,{open:W!==null,onClose:()=>!J&&G(null),dismissable:!J,title:W===`granted`?`Approve ${t(U.length,`call`)}?`:`Deny ${t(U.length,`call`)}?`,description:W===`granted`?`Each call runs with exactly the inputs shown on its card. Nothing else is approved.`:`None of these calls will run. Your AI is told they were denied.`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(C,{variant:`secondary`,onClick:()=>G(null),disabled:J,children:`Go back`}),(0,V.jsx)(C,{variant:W===`granted`?`primary`:`danger`,loading:J,onClick:()=>W&&he(W),children:W===`granted`?`Approve all`:`Deny all`})]}),children:[(0,V.jsx)(`ul`,{className:`mb-4 max-h-48 space-y-1 overflow-y-auto text-[14px]`,children:j.filter(e=>U.includes(e.id)).map(e=>(0,V.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:R(e.tool).label}),(0,V.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.tool})]},e.id))}),(0,V.jsx)(w,{value:K,onChange:q,rows:2,"aria-label":`Note for the activity log, for every selected call`,placeholder:`Note for the activity log (optional)`})]})]})}function de(t){return t.decidedBy?.startsWith(`standing-grant:`)?(0,V.jsx)(e,{tone:`ok`,icon:`key`,children:`Let through by a pre-approval`}):t.state===`granted`||t.state===`used`?(0,V.jsx)(e,{tone:`ok`,icon:`check`,children:`Approved`}):t.state===`denied`?(0,V.jsx)(e,{tone:`bad`,icon:`x`,children:`Denied`}):t.state===`expired`?(0,V.jsx)(e,{tone:`neutral`,icon:`clock`,children:`Expired`}):(0,V.jsx)(e,{children:t.state})}function fe(e){return e.decidedBy?e.decidedBy.startsWith(`standing-grant:`)?(0,V.jsxs)(`span`,{children:[`Pre-approval `,(0,V.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.decidedBy.slice(15)})]}):e.decidedBy:(0,V.jsx)(`span`,{className:`text-soft`,children:e.state===`expired`?`Nobody answered`:`Not recorded`})}function pe({rows:e,error:t,loading:n,retry:r,now:i,focusId:a}){let o=[{key:`call`,header:`Call`,cell:e=>(0,V.jsxs)(`span`,{className:`block min-w-0`,children:[(0,V.jsx)(`span`,{className:`block font-medium`,children:R(e.tool).label}),(0,V.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.tool})]})},{key:`result`,header:`Result`,cell:de},{key:`who`,header:`Decided by`,cell:fe},{key:`when`,header:`When`,cell:e=>{let t=e.decidedAt??e.expiresAt;return(0,V.jsx)(`span`,{title:l(t),children:ee(t,i)})}},{key:`note`,header:`Note`,cell:e=>e.decisionNote?(0,V.jsx)(`span`,{className:`break-words`,children:e.decisionNote}):(0,V.jsx)(`span`,{className:`text-soft`,children:`None`}),hideOnMobile:!1}];return(0,V.jsxs)(D,{children:[t&&(0,V.jsx)(`div`,{className:`mb-4`,children:(0,V.jsx)(c,{tone:`danger`,title:`Could not load decided calls`,actions:(0,V.jsx)(C,{size:`sm`,icon:`refresh`,onClick:r,children:`Try again`}),children:I(t)})}),n?!t&&(0,V.jsx)(s,{lines:5,height:18}):(0,V.jsx)(f,{caption:`Calls decided earlier`,columns:o,rows:e,rowKey:e=>e.id,selectedKey:a,empty:(0,V.jsx)(v,{icon:`clock`,title:`No calls decided yet`,compact:!0,children:`Calls you approve or deny, and calls that run out of time, are listed here.`})})]})}export{Q as ApprovalsPage};
1
+ import{$ as e,B as t,Ct as n,D as r,E as i,Et as a,F as o,G as s,H as c,I as l,It as u,J as d,K as f,M as p,Nt as m,Ot as h,Pt as g,T as _,U as v,V as ee,Y as te,Z as y,_ as b,_t as x,c as S,gt as ne,ht as C,j as w,kt as T,mt as E,pt as D,q as O,rt as k,s as A,w as j,wt as M,x as re,y as ie,yt as N}from"./kit-DRVm92_t.js";import{a as P,c as ae,l as F,n as oe,o as I,r as L,s as R,t as se,u as z,un as ce}from"./index-CTvq_isK.js";var B=u(),V=T(),H=/^\[redacted:([^\]]+)\]$/,U=/…\[truncated (\d+) chars\]$/,W=/^\[truncated (\d+) items\]$/;function G(e){if(typeof e!=`string`)return null;let t=H.exec(e);return t?t[1]===`key`||t[1]===`circular`||t[1]===`max-depth`?t[1]:`pattern`:U.test(e)?`chars`:W.test(e)?`items`:null}function K(e,t,n=0){if(n>20)return;let r=G(e);r&&t.add(r),Array.isArray(e)?e.forEach(e=>K(e,t,n+1)):e&&typeof e==`object`&&Object.values(e).forEach(e=>K(e,t,n+1))}var q={key:`[redacted:key]`,pattern:`[redacted:<pattern>]`,circular:`[redacted:circular]`,"max-depth":`[redacted:max-depth]`,chars:`…[truncated N chars]`,items:`[truncated N items]`},J={key:`Hidden`,pattern:`Hidden`,circular:`Hidden`,"max-depth":`Hidden`,chars:`Cut short`,items:`Cut short`};function Y({args:e,error:t,meta:n}){let r=new Set;K(e,r);let i=e=>n?.markers.find(t=>t.marker===q[e])?.meaning,a=e&&typeof e==`object`&&!Array.isArray(e)?Object.entries(e):null;return(0,V.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,V.jsx)(c,{tone:`warn`,title:`Some inputs could not be read back`,children:t}),a===null?e==null?!t&&(0,V.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`The inputs were not recorded.`}):(0,V.jsx)(X,{value:e,meaning:i}):a.length===0?(0,V.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`This call sent no inputs.`}):(0,V.jsx)(`dl`,{className:`divide-y divide-faint overflow-hidden rounded-2xl bg-sunken/60`,children:a.map(([e,t])=>(0,V.jsxs)(`div`,{className:`grid gap-1 px-4 py-2.5 sm:grid-cols-[minmax(6rem,10rem)_minmax(0,1fr)] sm:gap-4`,children:[(0,V.jsx)(`dt`,{className:`mono pt-px text-[12.5px] break-all text-soft`,children:e}),(0,V.jsx)(`dd`,{className:`min-w-0`,children:(0,V.jsx)(X,{value:t,meaning:i})})]},e))}),r.size>0&&(0,V.jsxs)(`div`,{className:`flex gap-2 text-[12.5px] text-soft`,children:[(0,V.jsx)(h,{name:`eye-off`,size:15,className:`mt-0.5 shrink-0`}),(0,V.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-muted`,children:[`Some values are hidden or cut short in the record `,(0,V.jsx)(b,{term:`redaction`})]}),[...r].map(e=>(0,V.jsxs)(`p`,{children:[(0,V.jsx)(`code`,{className:`mono text-[11.5px]`,children:q[e]}),`: `,i(e)??`not shown in full`]},e))]})]})]})}function X({value:t,meaning:n}){let r=G(t);if(r&&r!==`chars`)return(0,V.jsx)(e,{tone:`neutral`,icon:`eye-off`,title:n(r),children:J[r]});if(typeof t==`string`){let r=U.exec(t),i=r?t.slice(0,r.index):t;return(0,V.jsxs)(`p`,{className:`scrollbar-thin max-h-40 overflow-y-auto text-[13.5px] break-words whitespace-pre-wrap`,children:[i===``?(0,V.jsx)(`span`,{className:`text-soft`,children:`(empty)`}):i,r&&(0,V.jsxs)(e,{tone:`neutral`,className:`ml-1.5 align-middle`,title:n(`chars`),children:[r[1],` more characters not recorded`]})]})}return typeof t==`number`||typeof t==`boolean`||t===null?(0,V.jsx)(`span`,{className:`mono text-[13px]`,children:String(t)}):(0,V.jsx)(`pre`,{className:`scrollbar-thin mono max-h-48 overflow-auto rounded-xl bg-surface px-3 py-2 text-[12px] leading-relaxed whitespace-pre-wrap break-words`,children:JSON.stringify(t,null,2)})}var Z=e=>e instanceof m&&(e.status===409||e.status===404);function le({approval:e,meta:t,now:n,serverId:a,tenant:s,selecting:u,selected:d,onSelect:f,locked:h,onDecided:v,onRemembered:te}){let x=ie(),[S,ne]=(0,B.useState)(``),[w,T]=(0,B.useState)(null),[E,D]=(0,B.useState)(!1),[O,A]=(0,B.useState)(t?.rememberDefaults.ttlSeconds??3600),[M,re]=(0,B.useState)(t?.rememberDefaults.maxUses??20),[F,oe]=(0,B.useState)(!1),[ce,H]=(0,B.useState)(null),U=R(e.tool),W=e.expiresAt-n,G=L(e),K=t?.grantTtlMaxSeconds,q=h||w!==null;async function J(t,n={}){T(n.remember?`remember`:n.classify?`classify-${n.classify}`:t),H(null);let r;try{r=await g.decide(a,e.id,t,S.trim(),s,n.classify,n.remember)}catch(e){T(null),Z(e)?(x.show(`warn`,`This call was already answered, or it ran out of time.`),v()):n.remember&&e instanceof m&&e.status===422?H(I(e.message)):x.show(`bad`,I(e.message));return}T(null),t===`denied`?x.show(`ok`,`You said no. ${U.label} will not run, and the AI is told you said no.`):r.remembered?(x.show(`ok`,`Approved. Similar calls won't ask until ${ae(r.remembered.expiresAt)}.`),te(r.remembered,e.tool)):r.classifyWarning?x.show(`warn`,I(r.classifyWarning)):r.classified&&n.classify?x.show(`ok`,`Approved, and ${U.label} is now labelled "${k[n.classify].label}". Its calls still ask you.`):x.show(`ok`,`Approved. The call can go ahead.`),v()}let X=O!==null&&(K===void 0||O<=K)&&(F||M!==null&&M>=1);return(0,V.jsxs)(`article`,{"aria-labelledby":`apr-${e.id}`,className:N(`card flex min-w-0 flex-col gap-5 p-5 sm:p-6`,d&&`outline-2 outline-offset-2 outline-[var(--primary)]`),children:[(0,V.jsxs)(`header`,{className:`flex items-start gap-3`,children:[u&&(0,V.jsx)(`span`,{className:`pt-2.5`,children:(0,V.jsx)(j,{checked:d,onChange:f,disabled:q,label:(0,V.jsxs)(`span`,{className:`sr-only`,children:[`Select `,U.label]})})}),(0,V.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,V.jsx)(y,{effect:e.effect})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`h3`,{id:`apr-${e.id}`,tabIndex:-1,className:`text-[18px] outline-none focus-visible:outline-2 focus-visible:outline-[var(--focus)] leading-snug font-medium tracking-[-0.015em] break-words`,children:U.label}),(0,V.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-[12.5px] text-soft`,children:[U.server&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{children:U.server}),(0,V.jsx)(`span`,{"aria-hidden":!0,children:`·`})]}),(0,V.jsx)(y,{effect:e.effect,withLabel:!0})]})]})]}),(0,V.jsxs)(`section`,{"aria-label":`What it wants to do`,className:`space-y-2.5`,children:[(0,V.jsx)(`p`,{className:`text-[15px] leading-relaxed [overflow-wrap:anywhere]`,children:se(e)}),(0,V.jsx)(`p`,{className:`text-[14px] text-muted`,children:z(e)}),e.violations.length>0&&(0,V.jsx)(`ul`,{className:`space-y-1.5 rounded-2xl bg-warn-tint px-4 py-3 text-[13.5px]`,children:e.violations.map(t=>(0,V.jsxs)(`li`,{className:`flex gap-2`,children:[(0,V.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),(0,V.jsx)(`span`,{className:`min-w-0 break-words`,children:P(t,e.args)})]},t))}),(0,V.jsx)(`p`,{className:`text-[13px] text-soft`,children:W>0?`If you don't answer by ${o(e.expiresAt)}, it doesn't run. The AI can ask again.`:`This request ran out of time, so it doesn't run. The AI can ask again.`})]}),(0,V.jsxs)(`section`,{"aria-label":`The details it would send`,className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`eyebrow`,children:`The details it would send`}),(0,V.jsx)(Y,{args:e.args,error:e.argsError,meta:t})]}),(0,V.jsxs)(`details`,{className:`group text-[12.5px] text-soft`,children:[(0,V.jsx)(`summary`,{className:`cursor-pointer select-none font-medium text-muted`,children:`Details`}),(0,V.jsxs)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1`,children:[(0,V.jsx)(`dt`,{children:`Tool`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.tool})}),(0,V.jsx)(`dt`,{children:`Asked by`}),(0,V.jsxs)(`dd`,{children:[e.actor,` `,(0,V.jsx)(`span`,{title:l(e.createdAt),children:ee(e.createdAt,n)})]}),(0,V.jsx)(`dt`,{children:`Session`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.session})}),e.ruleId&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`dt`,{children:`Rule`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{className:`mono break-all`,children:e.ruleId})})]}),(0,V.jsx)(`dt`,{children:`Request`}),(0,V.jsxs)(`dd`,{children:[(0,V.jsx)(`code`,{className:`mono break-all`,children:e.id}),`, expires `,l(e.expiresAt)]})]})]}),(0,V.jsxs)(`div`,{className:`mt-auto space-y-3 border-t border-faint pt-4`,children:[(0,V.jsx)(i,{label:`Note for the activity log`,optional:!0,children:(0,V.jsx)(p,{value:S,onChange:ne,placeholder:`Why you said yes or no`,disabled:q})}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(C,{variant:`primary`,icon:`check`,onClick:()=>J(`granted`),loading:w===`granted`,disabled:q,children:`Approve`}),(0,V.jsx)(C,{variant:`secondary`,icon:`x`,onClick:()=>J(`denied`),loading:w===`denied`,disabled:q,children:`Say no`}),e.rememberAllowed&&!G&&(0,V.jsx)(C,{variant:`ghost`,icon:E?`chevron`:`chevron-right`,"aria-expanded":E,"aria-controls":`remember-${e.id}`,onClick:()=>D(e=>!e),disabled:q,children:`Approve and don't ask again`})]}),G&&(0,V.jsxs)(`div`,{className:`space-y-2.5 rounded-2xl bg-sunken/70 p-4`,children:[(0,V.jsx)(`p`,{className:`text-[13.5px] font-semibold`,children:`Approve and remember this tool as:`}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":`Approve and say what this tool does`,children:[`read`,`write`,`destructive`].map(e=>(0,V.jsx)(C,{size:`sm`,variant:`secondary`,onClick:()=>J(`granted`,{classify:e}),loading:w===`classify-${e}`,disabled:q,title:k[e].explain,children:k[e].label},e))}),(0,V.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`This approves the call and saves what the tool does in your protection settings. Its calls still ask you; once it is labelled you can set a rule for it on the Tools page.`})]}),E&&e.rememberAllowed&&(0,V.jsxs)(`div`,{id:`remember-${e.id}`,className:`space-y-4 rounded-2xl bg-sunken/70 p-4`,children:[(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[14px] font-semibold`,children:[`Approve and don't ask again `,(0,V.jsx)(b,{term:`preApproval`})]}),(0,V.jsx)(i,{label:`For how long`,children:(0,V.jsx)(_,{value:O,onChange:A,label:`For how long`,max:K})}),(0,V.jsx)(i,{label:`Up to how many calls`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,V.jsx)(r,{value:F?null:M,onChange:re,min:1,step:1,unit:`calls`,disabled:F||q,className:`w-40`}),(0,V.jsx)(j,{checked:F,onChange:oe,label:`No limit`,disabled:q})]})}),(0,V.jsx)(`p`,{className:`text-[13px] text-muted`,children:`For the time you choose, your AI can make this same request again without asking. Anything different still asks you, including a list with items changed, repeated or left out. You can take it back any time on the Pre-approvals page.`}),ce&&(0,V.jsx)(c,{tone:`danger`,title:`Nothing was approved`,role:`alert`,children:ce}),(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,V.jsx)(C,{variant:`primary`,icon:`check`,disabled:!X||q,loading:w===`remember`,onClick:()=>J(`granted`,{remember:{ttlSeconds:O,maxUses:F?null:M}}),children:`Approve and remember`}),(0,V.jsx)(C,{variant:`ghost`,onClick:()=>D(!1),disabled:w!==null,children:`Cancel`})]})]})]})]})}var ue={elicit:`On this toolbox your AI app asks you in its own window, so calls usually do not wait here.`,cli:`On this toolbox every call that needs your OK waits here until you answer it.`,both:`Your AI app asks you in its own window when it can. When it cannot, the call waits here.`,deny:`On this toolbox calls that would need your OK are blocked instead, so nothing waits here.`};function Q(){let{serverId:e,tenant:r,nav:i,reload:o}=ce(),l=ie(),u=F(1e3),f=A(()=>g.pending(e,r),[e,r],2e3),p=A(()=>g.approvals(e,r,{limit:200}),[e,r],15e3),h=A(()=>g.redaction(),[]),_=A(()=>g.protection(e,r),[e,r],3e4),y=i.query.get(`id`),b=y!==null&&(f.data??[]).some(e=>e.id===y),T=i.query.get(`tab`)===`history`||y!==null&&f.data!==null&&!b?`history`:`waiting`,k=e=>M(a(i,{tab:e===`waiting`?null:e})),j=(0,B.useMemo)(()=>[...f.data??[]].filter(e=>e.expiresAt>u).sort((e,t)=>e.createdAt-t.createdAt),[f.data,u]),N=(0,B.useMemo)(()=>(p.data??[]).filter(e=>e.state!==`pending`).sort((e,t)=>(t.decidedAt??t.expiresAt)-(e.decidedAt??e.expiresAt)),[p.data]),[P,L]=(0,B.useState)(!1),[se,z]=(0,B.useState)([]),H=new Set(j.map(e=>e.id)),U=se.filter(e=>H.has(e)),[W,G]=(0,B.useState)(null),[K,q]=(0,B.useState)(``),[J,Y]=(0,B.useState)(!1),[X,Z]=(0,B.useState)(null),Q=(0,B.useRef)(!1),de=(0,B.useRef)(null),fe=(0,B.useRef)(null);(0,B.useEffect)(()=>{Q.current&&f.data!==null&&(Q.current=!1,(de.current?.querySelector(`article h3[tabindex]`)??fe.current)?.focus())},[f.data]);let me=()=>{f.reload(),p.reload(),_.reload(),o()};async function he(n){Y(!0);let i=0,a=0,o=[];for(let t of U)try{await g.decide(e,t,n,K.trim(),r),i++}catch(e){e instanceof m&&(e.status===409||e.status===404)?a++:o.push(I(e.message))}Y(!1),G(null),q(``),z([]),L(!1),me();let s=[`${n===`granted`?`Approved`:`Denied`} ${t(i,`call`)}.`];a&&s.push(`${t(a,`call`)} had already been answered or ran out of time.`),o.length&&s.push(`${o.length} failed: ${o[0]}`),l.show(o.length?`bad`:a?`warn`:`ok`,s.join(` `))}let $=_.data?.approvals,ge=$?ue[$.mode]:void 0,_e=j.reduce((e,t)=>e===null||t.expiresAt<e?t.expiresAt:e,null),ve=j[0];return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(S,{title:`Waiting for you`,subtitle:`Your AI wanted to do these things. Nothing happens until you decide.`,actions:(0,V.jsx)(C,{variant:P?`primary`:`secondary`,icon:P?`x`:`list`,"aria-pressed":P,disabled:!P&&j.length<2,onClick:()=>{L(e=>!e),z([])},children:P?`Stop selecting`:`Select several`})}),(0,V.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,V.jsx)(E,{tone:`hero`,title:`Waiting now`,loading:f.data===null&&!f.error,value:j.length,sub:ve?`Oldest asked ${ee(ve.createdAt,u)}`:`Nothing needs you`}),(0,V.jsxs)(`div`,{className:`contents max-sm:hidden`,children:[(0,V.jsx)(E,{title:`Expires next`,loading:f.data===null&&!f.error,value:_e===null?`None`:oe(_e-u),sub:_e===null?`Nothing is waiting`:`A request nobody answers doesn't run`}),(0,V.jsx)(E,{title:`Pre-approvals in use`,loading:_.data===null&&!_.error,value:$?.activeGrantCount??`–`,sub:`Calls they cover skip this page`,href:n(i,`/pre-approvals`),hrefLabel:`Open pre-approvals`})]})]}),(0,V.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[$&&$.pendingElsewhere>0&&(0,V.jsxs)(c,{tone:`info`,title:`${t($.pendingElsewhere,`call`)} ${$.pendingElsewhere===1?`is`:`are`} waiting for a different customer`,children:[`Choose that customer at the top of the page to answer `,$.pendingElsewhere===1?`it`:`them`,`.`]}),X&&(0,V.jsxs)(c,{tone:`ok`,title:`Pre-approval created`,role:`status`,actions:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(x,{size:`sm`,variant:`secondary`,href:n(i,`/pre-approvals`,{grant:X.grant.id}),children:`Open pre-approval`}),(0,V.jsx)(ne,{icon:`x`,label:`Dismiss message`,size:32,onClick:()=>Z(null)})]}),children:[`Calls like this one to `,R(X.tool).label,` won't ask until `,ae(X.grant.expiresAt),X.grant.maxUses===null?``:`, for up to ${t(X.grant.maxUses,`call`)}`,`.`]})]}),(0,V.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center justify-between gap-3`,children:[(0,V.jsx)(O,{label:`Calls`,value:T,onChange:k,items:[{id:`waiting`,label:`Waiting`,count:j.length},{id:`history`,label:`Decided earlier`,count:N.length}]}),T===`waiting`&&j.length>0&&(0,V.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Oldest first: the call at the top runs out soonest.`})]}),(0,V.jsx)(`div`,{role:`tabpanel`,id:te(T),"aria-labelledby":d(T),className:`mt-5`,children:T===`waiting`?(0,V.jsxs)(V.Fragment,{children:[P&&j.length>0&&(0,V.jsx)(D,{className:`mb-5`,padded:!1,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-5 py-4`,children:[(0,V.jsxs)(`p`,{className:`min-w-0 flex-1 text-[14px]`,children:[(0,V.jsx)(`span`,{className:`tnum font-semibold`,children:U.length}),` of `,t(j.length,`call`),` selected`]}),(0,V.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>z(U.length===j.length?[]:j.map(e=>e.id)),children:U.length===j.length?`Clear selection`:`Select all`}),(0,V.jsx)(C,{size:`sm`,variant:`primary`,icon:`check`,disabled:U.length===0,onClick:()=>G(`granted`),children:`Approve all`}),(0,V.jsx)(C,{size:`sm`,variant:`secondary`,icon:`x`,disabled:U.length===0,onClick:()=>G(`denied`),children:`Deny all`})]})}),f.error&&(0,V.jsx)(`div`,{className:`mb-5`,children:(0,V.jsx)(c,{tone:`danger`,title:`Could not load the calls waiting for you`,role:`alert`,actions:(0,V.jsx)(C,{size:`sm`,icon:`refresh`,onClick:f.reload,children:`Try again`}),children:I(f.error)})}),f.data===null?!f.error&&(0,V.jsx)(`div`,{className:`grid gap-5 xl:grid-cols-2`,children:[0,1].map(e=>(0,V.jsxs)(D,{children:[(0,V.jsx)(s,{height:22,width:`45%`}),(0,V.jsx)(`div`,{className:`mt-5`,children:(0,V.jsx)(s,{lines:4})})]},e))}):j.length===0?(0,V.jsx)(D,{children:(0,V.jsx)(`div`,{ref:fe,tabIndex:-1,className:`outline-none`,children:(0,V.jsxs)(v,{icon:`inbox`,title:`Nothing is waiting for you.`,actions:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(C,{variant:`secondary`,onClick:()=>k(`history`),children:`Show decided calls`}),(0,V.jsx)(x,{variant:`secondary`,href:n(i,`/pre-approvals`),children:`Manage pre-approvals`})]}),children:[`When your AI tries something that needs your OK, it appears here and this page updates by itself.`,` `,ge]})})}):(0,V.jsx)(`div`,{ref:de,className:`grid items-start gap-5 xl:grid-cols-2`,children:j.map(t=>(0,V.jsx)(`div`,{className:t.id===y?`rounded-[22px] ring-2 ring-[var(--focus)] ring-offset-2 ring-offset-[var(--bg)]`:void 0,children:(0,V.jsx)(le,{approval:t,meta:h.data,now:u,serverId:e,tenant:r,selecting:P,selected:P&&U.includes(t.id),onSelect:e=>z(n=>e?[...new Set([...n,t.id])]:n.filter(e=>e!==t.id)),locked:J,onDecided:()=>{Q.current=!0,me()},onRemembered:(e,t)=>Z({grant:e,tool:t})})},t.id))})]}):(0,V.jsx)(pe,{rows:N,error:p.error,loading:p.data===null,retry:p.reload,now:u,focusId:y})}),(0,V.jsxs)(re,{open:W!==null,onClose:()=>!J&&G(null),dismissable:!J,title:W===`granted`?`Approve ${t(U.length,`call`)}?`:`Deny ${t(U.length,`call`)}?`,description:W===`granted`?`Each call runs with exactly the inputs shown on its card. Nothing else is approved.`:`None of these calls will run. Your AI is told they were denied.`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(C,{variant:`secondary`,onClick:()=>G(null),disabled:J,children:`Go back`}),(0,V.jsx)(C,{variant:W===`granted`?`primary`:`danger`,loading:J,onClick:()=>W&&he(W),children:W===`granted`?`Approve all`:`Deny all`})]}),children:[(0,V.jsx)(`ul`,{className:`mb-4 max-h-48 space-y-1 overflow-y-auto text-[14px]`,children:j.filter(e=>U.includes(e.id)).map(e=>(0,V.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:R(e.tool).label}),(0,V.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.tool})]},e.id))}),(0,V.jsx)(w,{value:K,onChange:q,rows:2,"aria-label":`Note for the activity log, for every selected call`,placeholder:`Note for the activity log (optional)`})]})]})}function de(t){return t.decidedBy?.startsWith(`standing-grant:`)?(0,V.jsx)(e,{tone:`ok`,icon:`key`,children:`Let through by a pre-approval`}):t.state===`granted`||t.state===`used`?(0,V.jsx)(e,{tone:`ok`,icon:`check`,children:`Approved`}):t.state===`denied`?(0,V.jsx)(e,{tone:`bad`,icon:`x`,children:`Denied`}):t.state===`expired`?(0,V.jsx)(e,{tone:`neutral`,icon:`clock`,children:`Expired`}):(0,V.jsx)(e,{children:t.state})}function fe(e){return e.decidedBy?e.decidedBy.startsWith(`standing-grant:`)?(0,V.jsxs)(`span`,{children:[`Pre-approval `,(0,V.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.decidedBy.slice(15)})]}):e.decidedBy:(0,V.jsx)(`span`,{className:`text-soft`,children:e.state===`expired`?`Nobody answered`:`Not recorded`})}function pe({rows:e,error:t,loading:n,retry:r,now:i,focusId:a}){let o=[{key:`call`,header:`Call`,cell:e=>(0,V.jsxs)(`span`,{className:`block min-w-0`,children:[(0,V.jsx)(`span`,{className:`block font-medium`,children:R(e.tool).label}),(0,V.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.tool})]})},{key:`result`,header:`Result`,cell:de},{key:`who`,header:`Decided by`,cell:fe},{key:`when`,header:`When`,cell:e=>{let t=e.decidedAt??e.expiresAt;return(0,V.jsx)(`span`,{title:l(t),children:ee(t,i)})}},{key:`note`,header:`Note`,cell:e=>e.decisionNote?(0,V.jsx)(`span`,{className:`break-words`,children:e.decisionNote}):(0,V.jsx)(`span`,{className:`text-soft`,children:`None`}),hideOnMobile:!1}];return(0,V.jsxs)(D,{children:[t&&(0,V.jsx)(`div`,{className:`mb-4`,children:(0,V.jsx)(c,{tone:`danger`,title:`Could not load decided calls`,actions:(0,V.jsx)(C,{size:`sm`,icon:`refresh`,onClick:r,children:`Try again`}),children:I(t)})}),n?!t&&(0,V.jsx)(s,{lines:5,height:18}):(0,V.jsx)(f,{caption:`Calls decided earlier`,columns:o,rows:e,rowKey:e=>e.id,selectedKey:a,empty:(0,V.jsx)(v,{icon:`clock`,title:`No calls decided yet`,compact:!0,children:`Calls you approve or deny, and calls that run out of time, are listed here.`})})]})}export{Q as ApprovalsPage};
@@ -1,4 +1,4 @@
1
- import{$ as e,A as t,At as n,B as r,Ct as i,E as a,G as o,H as s,It as c,J as l,M as u,N as d,Nt as f,O as p,Ot as m,Pt as h,Tt as g,U as _,V as v,Y as y,Z as b,_t as x,a as S,b as C,bt as w,et as T,ht as E,i as D,jt as O,k,kt as A,n as ee,o as te,q as j,r as M,rt as N,s as ne,t as P,tt as re,vt as ie,w as ae,x as oe,xt as se,y as ce,yt as F}from"./kit-DRVm92_t.js";import{$ as I,$t as le,A as ue,At as de,B as fe,Bt as L,C as R,D as pe,Dn as me,E as he,F as ge,Ft as _e,G as ve,Gt as ye,H as be,I as xe,It as z,J as Se,Jt as B,K as Ce,Kt as we,L as Te,Lt as Ee,M as De,Mt as V,N as Oe,O as ke,P as Ae,Pt as H,Q as U,Qt as je,R as Me,Rt as W,S as Ne,T as G,U as Pe,Ut as K,V as Fe,Vt as Ie,W as Le,X as Re,Y as ze,Yt as Be,Zt as Ve,an as q,b as He,cn as J,ct as Ue,en as Y,et as X,hn as We,in as Ge,j as Ke,k as qe,ln as Je,m as Ye,nt as Xe,on as Ze,q as Qe,rn as $e,rt as et,s as tt,tt as nt,x as rt,z as it}from"./index-DbHZ_SUd.js";var Z=c(),Q=A(),at=()=>({name:``,transport:`stdio`,command:``,args:[],env:[],passEnv:[],cwd:``,url:``,headers:[],passthrough:!1,passthroughHeader:`authorization`,passthroughRequired:!1,onInjection:``});function ot(e){let t=at();return t.name=e.name,t.transport=e.transport,t.onInjection=e.on_injection??``,e.transport===`stdio`?(t.command=e.command,t.args=e.args??[],t.env=et(e.env),t.passEnv=e.pass_env??[],t.cwd=e.cwd??``):(t.url=e.url,t.headers=et(e.headers),t.passthrough=!!e.credential_passthrough?.enabled,t.passthroughHeader=e.credential_passthrough?.header??`authorization`,t.passthroughRequired=!!e.credential_passthrough?.required),t}function st(e){let t=e.onInjection?{on_injection:e.onInjection}:{};return e.transport===`stdio`?{name:e.name.trim(),transport:`stdio`,...t,command:e.command.trim(),...e.args.length?{args:e.args}:{},...e.env.length?{env:Xe(e.env)}:{},...e.passEnv.length?{pass_env:e.passEnv}:{},...e.cwd.trim()?{cwd:e.cwd.trim()}:{}}:{name:e.name.trim(),transport:`http`,...t,url:e.url.trim(),...e.headers.length?{headers:Xe(e.headers)}:{},...e.passthrough?{credential_passthrough:{enabled:!0,header:e.passthroughHeader.trim()||`authorization`,required:e.passthroughRequired}}:{}}}function ct(e,t=[]){if(!/^[a-z0-9_]+$/.test(e.name.trim()))return`Give the server a name of lower-case letters, digits and underscores.`;if(t.includes(e.name.trim()))return`Another connected server is already called “${e.name.trim()}”.`;if(e.transport===`stdio`&&!e.command.trim())return`Say which program starts the server.`;if(e.transport===`http`)try{new URL(e.url.trim())}catch{return`Enter the server's full web address, starting with https://.`}return null}function lt({value:e,onChange:n,nameLocked:r,secret:i,literalWarning:o}){let c=(t,r)=>n({...e,[t]:r}),l=([e,t])=>!!t&&t!==i&&!le(t)&&!B(e),f=e.transport===`stdio`?e.env.some(l):e.headers.some(l);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(a,{label:`Name`,technical:`name`,help:r?`A server's name can't be changed. Remove it and add it again under a new name.`:`Lower-case letters, digits and underscores. Its tools are shown to your AI app as name__tool.`,children:(0,Q.jsx)(u,{value:e.name,onChange:e=>c(`name`,e),mono:!0,disabled:r,placeholder:`files`})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Where it runs`}),(0,Q.jsx)(p,{label:`Where it runs`,value:e.transport,onChange:e=>c(`transport`,e),options:[{value:`stdio`,label:`Runs on this computer`},{value:`http`,label:`Remote server`}]})]}),e.transport===`stdio`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Program to start`,technical:`command`,help:`The program the toolbox runs to start this server, such as npx or a full path.`,children:(0,Q.jsx)(u,{value:e.command,onChange:e=>c(`command`,e),mono:!0,placeholder:`npx`})}),(0,Q.jsx)(a,{label:`What to pass the program`,technical:`args`,optional:!0,help:`One item at a time. Press Enter after each.`,children:(0,Q.jsx)(t,{value:e.args,onChange:e=>c(`args`,e),placeholder:`-y, @modelcontextprotocol/server-filesystem`})}),(0,Q.jsx)(a,{label:`Values it is given`,technical:`env`,optional:!0,help:`Settings the server reads when it starts, such as an access key.`,children:(0,Q.jsx)(I,{value:e.env,onChange:e=>c(`env`,e),keyLabel:`Name of value`,valueLabel:`Value`,addLabel:`Add a value`,secret:i,valueType:`password`,keyPlaceholder:`API_KEY`})}),(0,Q.jsx)(a,{label:`Values passed on from the toolbox`,technical:`pass_env`,optional:!0,help:`Names of values the toolbox already has, given to this server as they are. Nothing else is passed on.`,children:(0,Q.jsx)(t,{value:e.passEnv,onChange:e=>c(`passEnv`,e),placeholder:`GITHUB_TOKEN`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Web address`,technical:`url`,children:(0,Q.jsx)(u,{value:e.url,onChange:e=>c(`url`,e),type:`url`,mono:!0,placeholder:`https://mcp.example.com/mcp`})}),(0,Q.jsx)(a,{label:`Headers sent with every request`,technical:`headers`,optional:!0,help:`Such as an access key the server expects.`,children:(0,Q.jsx)(I,{value:e.headers,onChange:e=>c(`headers`,e),keyLabel:`Header name`,valueLabel:`Header value`,addLabel:`Add a header`,secret:i,valueType:`password`,keyPlaceholder:`authorization`})})]}),o&&f&&(0,Q.jsx)(s,{tone:`warn`,title:`These values are saved in the toolbox's settings file as typed`,children:`A value whose name says it is a key (a TOKEN, KEY, SECRET or PASSWORD) goes into your locked keys instead. If another one is a password or key, give it a name like that, or anyone who can read the file can read it.`}),(0,Q.jsxs)(U,{title:`More options`,children:[(0,Q.jsx)(a,{label:`Hidden instructions in its tool descriptions`,technical:`on_injection`,help:e.onInjection?V[e.onInjection].explain:`Uses the toolbox-wide setting.`,children:(0,Q.jsx)(k,{value:e.onInjection,onChange:e=>c(`onInjection`,e),options:[{value:``,label:`Same as the toolbox`},{value:`strip`,label:V.strip.label},{value:`deny`,label:V.deny.label},{value:`annotate`,label:V.annotate.label}]})}),e.transport===`stdio`?(0,Q.jsx)(a,{label:`Folder it starts in`,technical:`cwd`,optional:!0,children:(0,Q.jsx)(u,{value:e.cwd,onChange:e=>c(`cwd`,e),mono:!0,placeholder:`/Users/me/project`})}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(d,{checked:e.passthrough,onChange:e=>c(`passthrough`,e),label:`Send each caller's own sign-in`,description:`Instead of one shared key, the toolbox passes on the key each AI app connects with. This sends that key to this server.`}),e.passthrough&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Header it goes in`,technical:`credential_passthrough.header`,children:(0,Q.jsx)(u,{value:e.passthroughHeader,onChange:e=>c(`passthroughHeader`,e),mono:!0})}),(0,Q.jsx)(d,{checked:e.passthroughRequired,onChange:e=>c(`passthroughRequired`,e),label:`Refuse calls without a sign-in`,description:`Otherwise a caller with no key of its own falls back to the headers above.`})]})]})]})]})}function ut({compact:e,tab:t,onTab:r,onCatalog:i,onDraft:a}){let[o,s]=(0,Z.useState)(null),[c,u]=(0,Z.useState)(!1),d=e&&!c;if((0,Z.useEffect)(()=>{if(d)return;let e=!0;return n.settings().then(t=>e&&s(t.registry.enabled)).catch(()=>e&&s(!0)),()=>{e=!1}},[d]),d){let e=e=>{u(!0),r(e)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(dt,{compact:!0,onPick:i}),(0,Q.jsxs)(`p`,{className:`text-[13px] text-soft`,children:[`Other ways:`,` `,(0,Q.jsx)(`button`,{type:`button`,className:`font-medium text-muted underline hover:text-ink`,onClick:()=>e(`registry`),children:`search the public list`}),` · `,(0,Q.jsx)(`button`,{type:`button`,className:`font-medium text-muted underline hover:text-ink`,onClick:()=>e(`paste`),children:`paste instructions from a README`})]})]})}let f=[{id:`popular`,label:`Popular`},...o===!1?[]:[{id:`registry`,label:`Search the public list`}],{id:`paste`,label:`Paste instructions`},{id:`advanced`,label:`Advanced`}],p=t===`registry`&&o===!1?`popular`:t;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(j,{items:f,value:p,onChange:r,label:`Where to find the server`}),(0,Q.jsx)(`div`,{role:`tabpanel`,id:y(p),"aria-labelledby":l(p),children:p===`popular`?(0,Q.jsx)(dt,{onPick:i}):p===`registry`?(0,Q.jsx)(mt,{onCatalogId:(e,t)=>t&&i(t),onDraft:a}):p===`paste`?(0,Q.jsx)(ht,{onDraft:a,onAdvanced:()=>r(`advanced`)}):(0,Q.jsx)(gt,{onDraft:a})})]})}function dt({onPick:e,compact:t}){let i=ne(()=>n.catalog(),[]),[a,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(`all`),[d,f]=(0,Z.useState)(!1),p=i.data?.entries??[],h=a?it(p,a,l):[...it(p,a,l)].sort((e,t)=>Number(t.id===ft)-Number(e.id===ft)),g=[...new Set(p.map(e=>e.category))],v=t&&!d&&!a?6:1/0,y=h.slice(0,v);return i.error&&!i.data?(0,Q.jsx)(s,{tone:`danger`,title:`The list of servers could not be loaded`,actions:(0,Q.jsx)(E,{size:`sm`,icon:`refresh`,onClick:i.reload,children:`Try again`}),children:K(i.error)}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`span`,{className:`relative flex items-center`,children:[(0,Q.jsx)(m,{name:`search`,size:17,className:`pointer-events-none absolute left-3.5 text-soft`}),(0,Q.jsx)(`input`,{type:`search`,value:a,onChange:e=>c(e.target.value),placeholder:`Search: files, GitHub, notes…`,"aria-label":`Search servers`,className:`field pl-10`})]}),!t&&g.length>1&&(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Kind of server`,className:`flex flex-wrap gap-1.5`,children:[`all`,...g].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":l===e,onClick:()=>u(e),className:F(`h-8 rounded-full border-[1.5px] px-3.5 text-[13px] font-semibold transition-colors`,l===e?`border-primary bg-primary text-white`:`border-line text-muted hover:border-[var(--soft)] hover:text-ink`),children:e===`all`?`All`:R[e]},e))})]}),i.data?h.length===0?(0,Q.jsxs)(_,{icon:`search`,title:`Nothing matches`,compact:!0,children:[`Try another word. You can also search the public list, or paste the server's setup instructions, using the `,t?`links below`:`tabs above`,`.`]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`sr-only`,role:`status`,children:[r(h.length,`server`),` found`]}),(0,Q.jsx)(`ul`,{className:`grid gap-3 sm:grid-cols-2`,children:y.map(t=>(0,Q.jsx)(`li`,{children:(0,Q.jsx)(pt,{entry:t,onPick:()=>e(t)})},t.id))}),y.length<h.length&&(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(E,{size:`sm`,variant:`ghost`,onClick:()=>f(!0),children:[`Show all `,h.length]})})]}):(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[0,1,2,3].map(e=>(0,Q.jsx)(`div`,{className:`rounded-[18px] border border-line p-4`,children:(0,Q.jsx)(o,{lines:3})},e))})]})}var ft=`filesystem`;function pt({entry:t,onPick:n}){let r=Me(t.requires);return(0,Q.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-full w-full min-w-0 flex-col items-start gap-2 rounded-[18px] border-[1.5px] border-line p-4 text-left transition-colors hover:border-[var(--soft)] hover:bg-faint/50`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-[15.5px] font-semibold`,children:t.name}),(0,Q.jsxs)(`span`,{className:`block text-[12.5px] text-muted`,children:[`by `,t.publisher.name]})]}),t.id===ft?(0,Q.jsx)(e,{tone:`ok`,icon:`check`,children:`Good first choice`}):t.publisher.official&&(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Official`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:t.summary}),(r.setup.length>0||r.needs.length>0)&&(0,Q.jsxs)(`span`,{className:`mt-auto flex flex-wrap gap-1.5 pt-1`,children:[r.setup.length>0&&(0,Q.jsx)(`span`,{title:`Needs ${r.setup.map(e=>G[e]??e).join(` and `)}. The next screen walks you through it.`,children:(0,Q.jsx)(e,{icon:`wrench`,children:`Needs a little setup`})}),r.needs.map(t=>(0,Q.jsx)(e,{children:t},t))]})]})}function mt({onCatalogId:t,onDraft:i}){let[a,c]=(0,Z.useState)(``),l=w(a.trim(),300),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(0),[C,T]=(0,Z.useState)(null),D=ne(()=>n.catalog(),[]),O=l?it(D.data?.entries??[],l).slice(0,3):[];(0,Z.useEffect)(()=>{if(!l){d(null),h([]),_(null),b(!1);return}let e=!0;return b(!0),n.registrySearch(l).then(t=>{e&&(d(t),h(t.hits),_(null))}).catch(t=>{e&&(t instanceof f&&(t.status===404||t.code===`registry-off`)?_(`Searching the public list is switched off in Settings & help.`):_(K(t)))}).finally(()=>e&&b(!1)),()=>{e=!1}},[l,x]),(0,Z.useEffect)(()=>{if(!u?.loading)return;let e=setTimeout(()=>S(e=>e+1),2e3);return()=>clearTimeout(e)},[u]);let k=()=>{u?.nextCursor&&(b(!0),n.registrySearch(l,u.nextCursor).then(e=>{d(e),h(t=>[...t,...e.hits])}).catch(e=>_(K(e))).finally(()=>b(!1)))},A=e=>{e.catalogId?(T(e.name),n.catalog().then(n=>t(e.catalogId,n.entries.find(t=>t.id===e.catalogId)??null)).catch(e=>_(K(e))).finally(()=>T(null))):e.draft&&i(e.draft,{})};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:`A public directory of servers that anyone can publish to. Only the words you type are sent to it to find matches. Nobody has checked these servers, so look at who made one before you add it.`}),(0,Q.jsxs)(`span`,{className:`relative flex items-center`,children:[(0,Q.jsx)(m,{name:`search`,size:17,className:`pointer-events-none absolute left-3.5 text-soft`}),(0,Q.jsx)(`input`,{type:`search`,value:a,onChange:e=>c(e.target.value),placeholder:`Search the public list`,"aria-label":`Search the public list`,className:`field pl-10`}),y&&(0,Q.jsx)(`span`,{className:`absolute right-3.5 text-soft`,children:(0,Q.jsx)(ie,{})})]}),(0,Q.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-[13px] text-soft`,children:u?.loading?(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ie,{size:14}),` Getting the list…`]}):u&&l?`${r(u.total+O.length,`server`)}${u.updatedAt?` · list updated ${v(u.updatedAt)}`:``}`:null}),u?.problem&&(0,Q.jsx)(s,{tone:`warn`,children:u.problem}),g&&(0,Q.jsx)(s,{tone:`danger`,role:`alert`,actions:(0,Q.jsx)(E,{size:`sm`,icon:`refresh`,onClick:()=>S(e=>e+1),children:`Try again`}),children:g}),l?!u&&!g?(0,Q.jsx)(o,{lines:4,height:18}):(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[O.map(n=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id,n),className:`flex w-full min-w-0 flex-col items-start gap-1 rounded-[18px] border-[1.5px] border-line p-4 text-left transition-colors hover:border-[var(--soft)] hover:bg-faint/50`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[15px] font-semibold`,children:n.name}),(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Checked by us`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:n.summary}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[`by `,n.publisher.name]})]})},`catalog-${n.id}`)),p.filter(e=>!e.catalogId||!O.some(t=>t.id===e.catalogId)).map(t=>{let n=!!t.catalogId||!!t.draft;return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>A(t),"aria-describedby":n?void 0:`why-${t.name}`,className:F(`flex w-full min-w-0 flex-col items-start gap-1 rounded-[18px] border-[1.5px] p-4 text-left transition-colors`,n?`border-line hover:border-[var(--soft)] hover:bg-faint/50`:`cursor-not-allowed border-line bg-sunken/40 opacity-70`),children:[(0,Q.jsxs)(`span`,{className:`flex w-full flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[15px] font-semibold`,children:t.title??t.name}),C===t.name&&(0,Q.jsx)(ie,{}),t.catalogId?(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Checked by us`}):n?(0,Q.jsx)(e,{tone:`warn`,children:`From the public list — not checked by us`}):(0,Q.jsx)(e,{children:`Can't be added`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:t.description}),t.caution&&(0,Q.jsxs)(`span`,{className:`flex items-start gap-1.5 text-[12.5px] font-medium text-warn`,children:[(0,Q.jsx)(m,{name:`warning`,size:14,className:`mt-0.5 shrink-0`}),t.caution]}),(0,Q.jsxs)(`code`,{className:`mono text-[11.5px] text-soft`,children:[t.name,` · `,t.version]}),!n&&(0,Q.jsx)(`span`,{id:`why-${t.name}`,className:`text-[12.5px] text-soft`,children:t.unsupported??`It can't be started from the public list's description.`})]})},t.name)})]}):(0,Q.jsx)(`p`,{className:`rounded-2xl bg-sunken/60 px-4 py-3 text-[13.5px] text-muted`,children:`Type the name of a server or a service, such as “weather” or “slack”, to search the public list.`}),u?.nextCursor&&(0,Q.jsx)(`div`,{children:(0,Q.jsx)(E,{size:`sm`,variant:`ghost`,onClick:k,loading:y,children:`Show more`})})]})}function ht({onDraft:e,onAdvanced:t}){let[i,a]=(0,Z.useState)(``),[o,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`add-paste`,className:`text-[13px] font-semibold`,children:`Paste the setup instructions`}),(0,Q.jsx)(`textarea`,{id:`add-paste`,rows:8,value:i,onChange:e=>{a(e.target.value),u(null)},"aria-describedby":`add-paste-help`,placeholder:`{
1
+ import{$ as e,A as t,At as n,B as r,Ct as i,E as a,G as o,H as s,It as c,J as l,M as u,N as d,Nt as f,O as p,Ot as m,Pt as h,Tt as g,U as _,V as v,Y as y,Z as b,_t as x,a as S,b as C,bt as w,et as T,ht as E,i as D,jt as O,k,kt as A,n as ee,o as te,q as j,r as M,rt as N,s as ne,t as P,tt as re,vt as ie,w as ae,x as oe,xt as se,y as ce,yt as F}from"./kit-DRVm92_t.js";import{$ as I,$t as le,A as ue,At as de,B as fe,Bt as L,C as R,D as pe,Dn as me,E as he,F as ge,Ft as _e,G as ve,Gt as ye,H as be,I as xe,It as z,J as Se,Jt as B,K as Ce,Kt as we,L as Te,Lt as Ee,M as De,Mt as V,N as Oe,O as ke,P as Ae,Pt as H,Q as U,Qt as je,R as Me,Rt as W,S as Ne,T as G,U as Pe,Ut as K,V as Fe,Vt as Ie,W as Le,X as Re,Y as ze,Yt as Be,Zt as Ve,an as q,b as He,cn as J,ct as Ue,en as Y,et as X,hn as We,in as Ge,j as Ke,k as qe,ln as Je,m as Ye,nt as Xe,on as Ze,q as Qe,rn as $e,rt as et,s as tt,tt as nt,x as rt,z as it}from"./index-CTvq_isK.js";var Z=c(),Q=A(),at=()=>({name:``,transport:`stdio`,command:``,args:[],env:[],passEnv:[],cwd:``,url:``,headers:[],passthrough:!1,passthroughHeader:`authorization`,passthroughRequired:!1,onInjection:``});function ot(e){let t=at();return t.name=e.name,t.transport=e.transport,t.onInjection=e.on_injection??``,e.transport===`stdio`?(t.command=e.command,t.args=e.args??[],t.env=et(e.env),t.passEnv=e.pass_env??[],t.cwd=e.cwd??``):(t.url=e.url,t.headers=et(e.headers),t.passthrough=!!e.credential_passthrough?.enabled,t.passthroughHeader=e.credential_passthrough?.header??`authorization`,t.passthroughRequired=!!e.credential_passthrough?.required),t}function st(e){let t=e.onInjection?{on_injection:e.onInjection}:{};return e.transport===`stdio`?{name:e.name.trim(),transport:`stdio`,...t,command:e.command.trim(),...e.args.length?{args:e.args}:{},...e.env.length?{env:Xe(e.env)}:{},...e.passEnv.length?{pass_env:e.passEnv}:{},...e.cwd.trim()?{cwd:e.cwd.trim()}:{}}:{name:e.name.trim(),transport:`http`,...t,url:e.url.trim(),...e.headers.length?{headers:Xe(e.headers)}:{},...e.passthrough?{credential_passthrough:{enabled:!0,header:e.passthroughHeader.trim()||`authorization`,required:e.passthroughRequired}}:{}}}function ct(e,t=[]){if(!/^[a-z0-9_]+$/.test(e.name.trim()))return`Give the server a name of lower-case letters, digits and underscores.`;if(t.includes(e.name.trim()))return`Another connected server is already called “${e.name.trim()}”.`;if(e.transport===`stdio`&&!e.command.trim())return`Say which program starts the server.`;if(e.transport===`http`)try{new URL(e.url.trim())}catch{return`Enter the server's full web address, starting with https://.`}return null}function lt({value:e,onChange:n,nameLocked:r,secret:i,literalWarning:o}){let c=(t,r)=>n({...e,[t]:r}),l=([e,t])=>!!t&&t!==i&&!le(t)&&!B(e),f=e.transport===`stdio`?e.env.some(l):e.headers.some(l);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(a,{label:`Name`,technical:`name`,help:r?`A server's name can't be changed. Remove it and add it again under a new name.`:`Lower-case letters, digits and underscores. Its tools are shown to your AI app as name__tool.`,children:(0,Q.jsx)(u,{value:e.name,onChange:e=>c(`name`,e),mono:!0,disabled:r,placeholder:`files`})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Where it runs`}),(0,Q.jsx)(p,{label:`Where it runs`,value:e.transport,onChange:e=>c(`transport`,e),options:[{value:`stdio`,label:`Runs on this computer`},{value:`http`,label:`Remote server`}]})]}),e.transport===`stdio`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Program to start`,technical:`command`,help:`The program the toolbox runs to start this server, such as npx or a full path.`,children:(0,Q.jsx)(u,{value:e.command,onChange:e=>c(`command`,e),mono:!0,placeholder:`npx`})}),(0,Q.jsx)(a,{label:`What to pass the program`,technical:`args`,optional:!0,help:`One item at a time. Press Enter after each.`,children:(0,Q.jsx)(t,{value:e.args,onChange:e=>c(`args`,e),placeholder:`-y, @modelcontextprotocol/server-filesystem`})}),(0,Q.jsx)(a,{label:`Values it is given`,technical:`env`,optional:!0,help:`Settings the server reads when it starts, such as an access key.`,children:(0,Q.jsx)(I,{value:e.env,onChange:e=>c(`env`,e),keyLabel:`Name of value`,valueLabel:`Value`,addLabel:`Add a value`,secret:i,valueType:`password`,keyPlaceholder:`API_KEY`})}),(0,Q.jsx)(a,{label:`Values passed on from the toolbox`,technical:`pass_env`,optional:!0,help:`Names of values the toolbox already has, given to this server as they are. Nothing else is passed on.`,children:(0,Q.jsx)(t,{value:e.passEnv,onChange:e=>c(`passEnv`,e),placeholder:`GITHUB_TOKEN`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Web address`,technical:`url`,children:(0,Q.jsx)(u,{value:e.url,onChange:e=>c(`url`,e),type:`url`,mono:!0,placeholder:`https://mcp.example.com/mcp`})}),(0,Q.jsx)(a,{label:`Headers sent with every request`,technical:`headers`,optional:!0,help:`Such as an access key the server expects.`,children:(0,Q.jsx)(I,{value:e.headers,onChange:e=>c(`headers`,e),keyLabel:`Header name`,valueLabel:`Header value`,addLabel:`Add a header`,secret:i,valueType:`password`,keyPlaceholder:`authorization`})})]}),o&&f&&(0,Q.jsx)(s,{tone:`warn`,title:`These values are saved in the toolbox's settings file as typed`,children:`A value whose name says it is a key (a TOKEN, KEY, SECRET or PASSWORD) goes into your locked keys instead. If another one is a password or key, give it a name like that, or anyone who can read the file can read it.`}),(0,Q.jsxs)(U,{title:`More options`,children:[(0,Q.jsx)(a,{label:`Hidden instructions in its tool descriptions`,technical:`on_injection`,help:e.onInjection?V[e.onInjection].explain:`Uses the toolbox-wide setting.`,children:(0,Q.jsx)(k,{value:e.onInjection,onChange:e=>c(`onInjection`,e),options:[{value:``,label:`Same as the toolbox`},{value:`strip`,label:V.strip.label},{value:`deny`,label:V.deny.label},{value:`annotate`,label:V.annotate.label}]})}),e.transport===`stdio`?(0,Q.jsx)(a,{label:`Folder it starts in`,technical:`cwd`,optional:!0,children:(0,Q.jsx)(u,{value:e.cwd,onChange:e=>c(`cwd`,e),mono:!0,placeholder:`/Users/me/project`})}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(d,{checked:e.passthrough,onChange:e=>c(`passthrough`,e),label:`Send each caller's own sign-in`,description:`Instead of one shared key, the toolbox passes on the key each AI app connects with. This sends that key to this server.`}),e.passthrough&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{label:`Header it goes in`,technical:`credential_passthrough.header`,children:(0,Q.jsx)(u,{value:e.passthroughHeader,onChange:e=>c(`passthroughHeader`,e),mono:!0})}),(0,Q.jsx)(d,{checked:e.passthroughRequired,onChange:e=>c(`passthroughRequired`,e),label:`Refuse calls without a sign-in`,description:`Otherwise a caller with no key of its own falls back to the headers above.`})]})]})]})]})}function ut({compact:e,tab:t,onTab:r,onCatalog:i,onDraft:a}){let[o,s]=(0,Z.useState)(null),[c,u]=(0,Z.useState)(!1),d=e&&!c;if((0,Z.useEffect)(()=>{if(d)return;let e=!0;return n.settings().then(t=>e&&s(t.registry.enabled)).catch(()=>e&&s(!0)),()=>{e=!1}},[d]),d){let e=e=>{u(!0),r(e)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(dt,{compact:!0,onPick:i}),(0,Q.jsxs)(`p`,{className:`text-[13px] text-soft`,children:[`Other ways:`,` `,(0,Q.jsx)(`button`,{type:`button`,className:`font-medium text-muted underline hover:text-ink`,onClick:()=>e(`registry`),children:`search the public list`}),` · `,(0,Q.jsx)(`button`,{type:`button`,className:`font-medium text-muted underline hover:text-ink`,onClick:()=>e(`paste`),children:`paste instructions from a README`})]})]})}let f=[{id:`popular`,label:`Popular`},...o===!1?[]:[{id:`registry`,label:`Search the public list`}],{id:`paste`,label:`Paste instructions`},{id:`advanced`,label:`Advanced`}],p=t===`registry`&&o===!1?`popular`:t;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(j,{items:f,value:p,onChange:r,label:`Where to find the server`}),(0,Q.jsx)(`div`,{role:`tabpanel`,id:y(p),"aria-labelledby":l(p),children:p===`popular`?(0,Q.jsx)(dt,{onPick:i}):p===`registry`?(0,Q.jsx)(mt,{onCatalogId:(e,t)=>t&&i(t),onDraft:a}):p===`paste`?(0,Q.jsx)(ht,{onDraft:a,onAdvanced:()=>r(`advanced`)}):(0,Q.jsx)(gt,{onDraft:a})})]})}function dt({onPick:e,compact:t}){let i=ne(()=>n.catalog(),[]),[a,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(`all`),[d,f]=(0,Z.useState)(!1),p=i.data?.entries??[],h=a?it(p,a,l):[...it(p,a,l)].sort((e,t)=>Number(t.id===ft)-Number(e.id===ft)),g=[...new Set(p.map(e=>e.category))],v=t&&!d&&!a?6:1/0,y=h.slice(0,v);return i.error&&!i.data?(0,Q.jsx)(s,{tone:`danger`,title:`The list of servers could not be loaded`,actions:(0,Q.jsx)(E,{size:`sm`,icon:`refresh`,onClick:i.reload,children:`Try again`}),children:K(i.error)}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`span`,{className:`relative flex items-center`,children:[(0,Q.jsx)(m,{name:`search`,size:17,className:`pointer-events-none absolute left-3.5 text-soft`}),(0,Q.jsx)(`input`,{type:`search`,value:a,onChange:e=>c(e.target.value),placeholder:`Search: files, GitHub, notes…`,"aria-label":`Search servers`,className:`field pl-10`})]}),!t&&g.length>1&&(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Kind of server`,className:`flex flex-wrap gap-1.5`,children:[`all`,...g].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":l===e,onClick:()=>u(e),className:F(`h-8 rounded-full border-[1.5px] px-3.5 text-[13px] font-semibold transition-colors`,l===e?`border-primary bg-primary text-white`:`border-line text-muted hover:border-[var(--soft)] hover:text-ink`),children:e===`all`?`All`:R[e]},e))})]}),i.data?h.length===0?(0,Q.jsxs)(_,{icon:`search`,title:`Nothing matches`,compact:!0,children:[`Try another word. You can also search the public list, or paste the server's setup instructions, using the `,t?`links below`:`tabs above`,`.`]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`sr-only`,role:`status`,children:[r(h.length,`server`),` found`]}),(0,Q.jsx)(`ul`,{className:`grid gap-3 sm:grid-cols-2`,children:y.map(t=>(0,Q.jsx)(`li`,{children:(0,Q.jsx)(pt,{entry:t,onPick:()=>e(t)})},t.id))}),y.length<h.length&&(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(E,{size:`sm`,variant:`ghost`,onClick:()=>f(!0),children:[`Show all `,h.length]})})]}):(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[0,1,2,3].map(e=>(0,Q.jsx)(`div`,{className:`rounded-[18px] border border-line p-4`,children:(0,Q.jsx)(o,{lines:3})},e))})]})}var ft=`filesystem`;function pt({entry:t,onPick:n}){let r=Me(t.requires);return(0,Q.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-full w-full min-w-0 flex-col items-start gap-2 rounded-[18px] border-[1.5px] border-line p-4 text-left transition-colors hover:border-[var(--soft)] hover:bg-faint/50`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-[15.5px] font-semibold`,children:t.name}),(0,Q.jsxs)(`span`,{className:`block text-[12.5px] text-muted`,children:[`by `,t.publisher.name]})]}),t.id===ft?(0,Q.jsx)(e,{tone:`ok`,icon:`check`,children:`Good first choice`}):t.publisher.official&&(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Official`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:t.summary}),(r.setup.length>0||r.needs.length>0)&&(0,Q.jsxs)(`span`,{className:`mt-auto flex flex-wrap gap-1.5 pt-1`,children:[r.setup.length>0&&(0,Q.jsx)(`span`,{title:`Needs ${r.setup.map(e=>G[e]??e).join(` and `)}. The next screen walks you through it.`,children:(0,Q.jsx)(e,{icon:`wrench`,children:`Needs a little setup`})}),r.needs.map(t=>(0,Q.jsx)(e,{children:t},t))]})]})}function mt({onCatalogId:t,onDraft:i}){let[a,c]=(0,Z.useState)(``),l=w(a.trim(),300),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(0),[C,T]=(0,Z.useState)(null),D=ne(()=>n.catalog(),[]),O=l?it(D.data?.entries??[],l).slice(0,3):[];(0,Z.useEffect)(()=>{if(!l){d(null),h([]),_(null),b(!1);return}let e=!0;return b(!0),n.registrySearch(l).then(t=>{e&&(d(t),h(t.hits),_(null))}).catch(t=>{e&&(t instanceof f&&(t.status===404||t.code===`registry-off`)?_(`Searching the public list is switched off in Settings & help.`):_(K(t)))}).finally(()=>e&&b(!1)),()=>{e=!1}},[l,x]),(0,Z.useEffect)(()=>{if(!u?.loading)return;let e=setTimeout(()=>S(e=>e+1),2e3);return()=>clearTimeout(e)},[u]);let k=()=>{u?.nextCursor&&(b(!0),n.registrySearch(l,u.nextCursor).then(e=>{d(e),h(t=>[...t,...e.hits])}).catch(e=>_(K(e))).finally(()=>b(!1)))},A=e=>{e.catalogId?(T(e.name),n.catalog().then(n=>t(e.catalogId,n.entries.find(t=>t.id===e.catalogId)??null)).catch(e=>_(K(e))).finally(()=>T(null))):e.draft&&i(e.draft,{})};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`p`,{className:`text-[13.5px] text-muted`,children:`A public directory of servers that anyone can publish to. Only the words you type are sent to it to find matches. Nobody has checked these servers, so look at who made one before you add it.`}),(0,Q.jsxs)(`span`,{className:`relative flex items-center`,children:[(0,Q.jsx)(m,{name:`search`,size:17,className:`pointer-events-none absolute left-3.5 text-soft`}),(0,Q.jsx)(`input`,{type:`search`,value:a,onChange:e=>c(e.target.value),placeholder:`Search the public list`,"aria-label":`Search the public list`,className:`field pl-10`}),y&&(0,Q.jsx)(`span`,{className:`absolute right-3.5 text-soft`,children:(0,Q.jsx)(ie,{})})]}),(0,Q.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-[13px] text-soft`,children:u?.loading?(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ie,{size:14}),` Getting the list…`]}):u&&l?`${r(u.total+O.length,`server`)}${u.updatedAt?` · list updated ${v(u.updatedAt)}`:``}`:null}),u?.problem&&(0,Q.jsx)(s,{tone:`warn`,children:u.problem}),g&&(0,Q.jsx)(s,{tone:`danger`,role:`alert`,actions:(0,Q.jsx)(E,{size:`sm`,icon:`refresh`,onClick:()=>S(e=>e+1),children:`Try again`}),children:g}),l?!u&&!g?(0,Q.jsx)(o,{lines:4,height:18}):(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[O.map(n=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id,n),className:`flex w-full min-w-0 flex-col items-start gap-1 rounded-[18px] border-[1.5px] border-line p-4 text-left transition-colors hover:border-[var(--soft)] hover:bg-faint/50`,children:[(0,Q.jsxs)(`span`,{className:`flex w-full flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[15px] font-semibold`,children:n.name}),(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Checked by us`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:n.summary}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-soft`,children:[`by `,n.publisher.name]})]})},`catalog-${n.id}`)),p.filter(e=>!e.catalogId||!O.some(t=>t.id===e.catalogId)).map(t=>{let n=!!t.catalogId||!!t.draft;return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>A(t),"aria-describedby":n?void 0:`why-${t.name}`,className:F(`flex w-full min-w-0 flex-col items-start gap-1 rounded-[18px] border-[1.5px] p-4 text-left transition-colors`,n?`border-line hover:border-[var(--soft)] hover:bg-faint/50`:`cursor-not-allowed border-line bg-sunken/40 opacity-70`),children:[(0,Q.jsxs)(`span`,{className:`flex w-full flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[15px] font-semibold`,children:t.title??t.name}),C===t.name&&(0,Q.jsx)(ie,{}),t.catalogId?(0,Q.jsx)(e,{tone:`ok`,icon:`shield-check`,children:`Checked by us`}):n?(0,Q.jsx)(e,{tone:`warn`,children:`From the public list — not checked by us`}):(0,Q.jsx)(e,{children:`Can't be added`})]}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-muted`,children:t.description}),t.caution&&(0,Q.jsxs)(`span`,{className:`flex items-start gap-1.5 text-[12.5px] font-medium text-warn`,children:[(0,Q.jsx)(m,{name:`warning`,size:14,className:`mt-0.5 shrink-0`}),t.caution]}),(0,Q.jsxs)(`code`,{className:`mono text-[11.5px] text-soft`,children:[t.name,` · `,t.version]}),!n&&(0,Q.jsx)(`span`,{id:`why-${t.name}`,className:`text-[12.5px] text-soft`,children:t.unsupported??`It can't be started from the public list's description.`})]})},t.name)})]}):(0,Q.jsx)(`p`,{className:`rounded-2xl bg-sunken/60 px-4 py-3 text-[13.5px] text-muted`,children:`Type the name of a server or a service, such as “weather” or “slack”, to search the public list.`}),u?.nextCursor&&(0,Q.jsx)(`div`,{children:(0,Q.jsx)(E,{size:`sm`,variant:`ghost`,onClick:k,loading:y,children:`Show more`})})]})}function ht({onDraft:e,onAdvanced:t}){let[i,a]=(0,Z.useState)(``),[o,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`add-paste`,className:`text-[13px] font-semibold`,children:`Paste the setup instructions`}),(0,Q.jsx)(`textarea`,{id:`add-paste`,rows:8,value:i,onChange:e=>{a(e.target.value),u(null)},"aria-describedby":`add-paste-help`,placeholder:`{
2
2
  "mcpServers": {
3
3
  "weather": { "command": "npx", "args": ["-y", "weather-mcp"] }
4
4
  }