hmcp-web 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts CHANGED
@@ -24,5 +24,14 @@ export interface ApiOptions {
24
24
  * hint. Advice only. Unset: `pgrep`; a test always sets it.
25
25
  */
26
26
  readonly appRunning?: (app: AppChoice) => Promise<boolean | null>;
27
+ /**
28
+ * What a connected app is told to start, before `serve -c <config>`. Unset:
29
+ * this build's own. A test runs from a checkout, which an app is never
30
+ * moved to, so it sets a published copy here.
31
+ */
32
+ readonly appLaunch?: {
33
+ readonly command: string;
34
+ readonly args: readonly string[];
35
+ };
27
36
  }
28
37
  export declare function buildRoutes(options: ApiOptions): Route[];
@@ -12,7 +12,7 @@ import { readImportRecord, readLiveImportRecord, upstreamDigest, writeImportReco
12
12
  import { recordedToolbox, targetFor } from "./app-servers.js";
13
13
  import { toolboxLabel } from "./toolbox-label.js";
14
14
  import { localLoosens, planNewToolbox, removeNewToolbox, writeNewToolbox } from "./new-toolbox.js";
15
- import { LABELS, gatewayAudit, pathDirsFromEnv, record } from "../routes/connect.js";
15
+ import { LABELS, gatewayAudit, launchOf, pathDirsFromEnv, record } from "../routes/connect.js";
16
16
  import { upstreamYaml } from "../routes/servers-add.js";
17
17
  /**
18
18
  * The toolbox this app was connected to from the console. An app that is
@@ -555,7 +555,8 @@ export async function bringIn(args) {
555
555
  home,
556
556
  gatewayConfigPath: made.configPath,
557
557
  pathDirs: [...(args.pathDirs ?? pathDirsFromEnv())],
558
- registryId: made.id
558
+ registryId: made.id,
559
+ ...launchOf(options)
559
560
  });
560
561
  // An entry that already ran this file was there before the toolbox was: not a connection this made.
561
562
  if (attached.alreadyConnected) {
@@ -5,7 +5,7 @@ import { homedir } from "node:os";
5
5
  import { join, resolve, sep } from "node:path";
6
6
  import { z } from "zod";
7
7
  import { SecretStore, expandPath, readRegistry } from "hmcp-core";
8
- import { GuardInstallError, adoptRevert, backupPath, connectClient, detectClients, guardStatus, importCandidates, installGuard, loadGatewayConfig, restartHintFor, uninstallGuard } from "hmcp-gateway";
8
+ import { GuardInstallError, adoptRevert, backupPath, connectClient, detectClients, guardStatus, importCandidates, installGuard, outdatedLaunch, loadGatewayConfig, restartHintFor, uninstallGuard } from "hmcp-gateway";
9
9
  import { HttpError, route, unprocessable } from "../http.js";
10
10
  import { APPS } from "../model/apps.js";
11
11
  import { appServersFor, connectionState, targetFor } from "../model/app-servers.js";
@@ -17,7 +17,7 @@ import { removeNewToolbox } from "../model/new-toolbox.js";
17
17
  import { removeProvisional, saveProvisional } from "../model/provisional-tools.js";
18
18
  import { loadServer } from "../model/server.js";
19
19
  import { toolboxLabel } from "../model/toolbox-label.js";
20
- import { LABELS, gatewayAudit, parse, pathDirsFromEnv, projectDirOf, record, withoutSameFile } from "./connect.js";
20
+ import { LABELS, gatewayAudit, launchOf, parse, pathDirsFromEnv, projectDirOf, record, recordRefresh, withoutSameFile } from "./connect.js";
21
21
  import { undoImport } from "./connect-import.js";
22
22
  import { DEFAULT_GATEWAY_ID, DEFAULT_GATEWAY_LABEL, secretUsage } from "./servers-add.js";
23
23
  const APP_IDS = APPS.map((a) => a.id);
@@ -387,6 +387,18 @@ export function connectAppRoutes(options, deps = {}) {
387
387
  // One-click Undo, offered on the card after a reload: a note from a click that still describes this connection.
388
388
  const note = readNote(options.registryPath, app.id);
389
389
  const undoable = info.connection === "console" && !!note && noteMatches(note, targetFor(app.scope, cwd, home));
390
+ // Connected, but its entry starts an older copy of the toolbox than this one: said before the click. Reads only.
391
+ const outdated = info.connection === "console" && attached && info.attachedTo
392
+ ? outdatedLaunch({
393
+ scope: app.scope,
394
+ cwd,
395
+ home,
396
+ gatewayConfigPath: resolve(expandPath(attached.config_path)),
397
+ entryName: info.attachedTo.entryName,
398
+ pathDirs: pathDirsFromEnv(),
399
+ ...launchOf(options)
400
+ })
401
+ : null;
390
402
  apps.push({
391
403
  id: app.id,
392
404
  label: app.name,
@@ -397,6 +409,7 @@ export function connectAppRoutes(options, deps = {}) {
397
409
  connected: info.connection === "console",
398
410
  connection: info.connection,
399
411
  undoable,
412
+ outdated,
400
413
  toolbox: chosen
401
414
  ? {
402
415
  id: chosen.id,
@@ -447,6 +460,7 @@ export function connectAppRoutes(options, deps = {}) {
447
460
  /* the toolbox: the one it's connected to, one the person confirmed, a one-click one, or a new one */
448
461
  let connected = null;
449
462
  let attachedHere = false;
463
+ let updated = null;
450
464
  if (alreadyConnected) {
451
465
  connected = connectedToolbox(options, scope, cwd);
452
466
  if (body.toolbox !== undefined && body.toolbox !== connected.entry.id) {
@@ -454,6 +468,22 @@ export function connectAppRoutes(options, deps = {}) {
454
468
  }
455
469
  // Its toolbox found by what it runs, under a new id: its records are pointed at that id first.
456
470
  adoptToolboxId(options.registryPath, connected);
471
+ // Its entry may start an older copy of the toolbox (an upgrade since): pointed at this one, nothing else changed.
472
+ const at = { scope, cwd, home, gatewayConfigPath: connected.configPath, entryName: connected.entryName, pathDirs, ...launchOf(options) };
473
+ // Why it was left alone is said only when the card offered the update, not on every click.
474
+ const offered = outdatedLaunch(at) !== null;
475
+ try {
476
+ const again = await connectClient({ ...at, registryId: connected.entry.id, refresh: true });
477
+ updated = again.refreshed;
478
+ if (again.leftAsIs && offered)
479
+ warnings.push(again.leftAsIs);
480
+ const w = recordRefresh(connected.configPath, ctx.actor, scope, again, connected.entry.id);
481
+ if (w)
482
+ warnings.push(w);
483
+ }
484
+ catch (err) {
485
+ warnings.push(`${app.name} still starts the copy of your toolbox it started before, because updating it failed: ${err.message}`);
486
+ }
457
487
  }
458
488
  else {
459
489
  const existing = defaultToolbox(options.registryPath);
@@ -473,7 +503,7 @@ export function connectAppRoutes(options, deps = {}) {
473
503
  const configPath = resolve(expandPath(existing.config_path));
474
504
  let attached;
475
505
  try {
476
- attached = await connectClient({ scope, cwd, home, gatewayConfigPath: configPath, pathDirs, registryId: existing.id });
506
+ attached = await connectClient({ scope, cwd, home, gatewayConfigPath: configPath, pathDirs, registryId: existing.id, ...launchOf(options) });
477
507
  }
478
508
  catch (err) {
479
509
  asHttp(err);
@@ -736,6 +766,7 @@ export function connectAppRoutes(options, deps = {}) {
736
766
  configPath: target.path,
737
767
  backupPath: backupPath(target),
738
768
  alreadyConnected,
769
+ refreshed: updated,
739
770
  imported,
740
771
  takenOut,
741
772
  left,
@@ -47,6 +47,25 @@ export declare function projectDirOf(raw: string | null | undefined): string;
47
47
  export declare function gatewayAudit(configPath: string, actor: string): AuditLog | null;
48
48
  /** Appends one record, and turns a failure into a warning: the change itself already happened. */
49
49
  export declare function record(log: AuditLog | null, entry: Parameters<AuditLog["appendStrict"]>[0]): string | null;
50
+ /** What a connected app starts, when the console was told (a test); otherwise connect's own choice. */
51
+ export declare function launchOf(options: Pick<ApiOptions, "appLaunch">): {
52
+ launch?: {
53
+ command: string;
54
+ args: string[];
55
+ };
56
+ };
57
+ /**
58
+ * An app already connected, whose entry now starts this copy of the toolbox
59
+ * instead of an older one: written down, with both copies in a few words.
60
+ */
61
+ export declare function recordRefresh(configPath: string, actor: string, scope: Scope, result: {
62
+ entryName: string;
63
+ configPath: string;
64
+ refreshed: {
65
+ from: string;
66
+ to: string;
67
+ } | null;
68
+ }, registryId: string): string | null;
50
69
  /**
51
70
  * Drops a project scope that is the very file of an all-projects scope: with
52
71
  * the project folder at the home folder, "Cursor — this project" and "Cursor —
@@ -330,6 +330,35 @@ export function record(log, entry) {
330
330
  return `the change was made but the activity log record failed: ${err.message}`;
331
331
  }
332
332
  }
333
+ /** What a connected app starts, when the console was told (a test); otherwise connect's own choice. */
334
+ export function launchOf(options) {
335
+ return options.appLaunch ? { launch: { command: options.appLaunch.command, args: [...options.appLaunch.args] } } : {};
336
+ }
337
+ /**
338
+ * An app already connected, whose entry now starts this copy of the toolbox
339
+ * instead of an older one: written down, with both copies in a few words.
340
+ */
341
+ export function recordRefresh(configPath, actor, scope, result, registryId) {
342
+ if (!result.refreshed)
343
+ return null;
344
+ return record(gatewayAudit(configPath, actor), {
345
+ tool: "(connect)",
346
+ effect: null,
347
+ decision: "allow",
348
+ rule_id: "connect.refresh",
349
+ reason: `${LABELS[scope]} updated via the console by ${actor} to start ${result.refreshed.to} instead of ${result.refreshed.from}, ` +
350
+ `as "${result.entryName}" in ${result.configPath}`,
351
+ outcome: "completed",
352
+ args_redacted: {
353
+ scope,
354
+ client_config: result.configPath,
355
+ entry: result.entryName,
356
+ registry_id: registryId,
357
+ from: result.refreshed.from,
358
+ to: result.refreshed.to
359
+ }
360
+ });
361
+ }
333
362
  /** A path with every existing folder on it resolved, so one file is always spelled one way. */
334
363
  function realPath(path) {
335
364
  try {
@@ -521,28 +550,35 @@ export function connectRoutes(options, deps = {}) {
521
550
  home: homedir(),
522
551
  gatewayConfigPath: configPath,
523
552
  pathDirs,
524
- registryId: entry.id
553
+ registryId: entry.id,
554
+ // Already connected to an older copy of this toolbox: moved to this one.
555
+ refresh: true,
556
+ ...launchOf(options)
525
557
  });
526
558
  }
527
559
  catch (err) {
528
560
  asHttp(err);
529
561
  }
530
- const warning = result.alreadyConnected
531
- ? null
532
- : record(gatewayAudit(configPath, ctx.actor), {
533
- tool: "(connect)",
534
- effect: null,
535
- decision: "allow",
536
- rule_id: "connect.attach",
537
- reason: `${LABELS[body.scope]} connected to this gateway via the console by ${ctx.actor}, as "${result.entryName}" in ${result.configPath}`,
538
- outcome: "completed",
539
- args_redacted: { scope: body.scope, client_config: result.configPath, entry: result.entryName, registry_id: entry.id }
540
- });
562
+ const warning = result.refreshed
563
+ ? recordRefresh(configPath, ctx.actor, body.scope, result, entry.id)
564
+ : result.alreadyConnected
565
+ ? null
566
+ : record(gatewayAudit(configPath, ctx.actor), {
567
+ tool: "(connect)",
568
+ effect: null,
569
+ decision: "allow",
570
+ rule_id: "connect.attach",
571
+ reason: `${LABELS[body.scope]} connected to this gateway via the console by ${ctx.actor}, as "${result.entryName}" in ${result.configPath}`,
572
+ outcome: "completed",
573
+ args_redacted: { scope: body.scope, client_config: result.configPath, entry: result.entryName, registry_id: entry.id }
574
+ });
541
575
  return {
542
576
  configPath: result.configPath,
543
577
  entryName: result.entryName,
544
578
  backupPath: result.backupPath,
545
579
  alreadyConnected: result.alreadyConnected,
580
+ refreshed: result.refreshed,
581
+ leftAsIs: result.leftAsIs,
546
582
  restartHint: result.restartHint,
547
583
  ...(warning ? { warning } : {})
548
584
  };
@@ -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 te,pt as ne,s as re,tt as ie,ut as A,w as ae,wt as oe,x as j,y as M,yt as N,z as P}from"./kit-BHB_ha4i.js";import{At as F,Ct as I,Dt as se,Et as ce,Mt as L,Ot as R,St as z,Tt as le,_t as ue,bt as B,gn as V,gt as de,hn as H,jt as fe,kt as U,pn as pe,s as W,vt as G,wt as K,xt as q,yt as me}from"./index-Cm4wG2zz.js";var J=c(),Y=O();function he({open:e,onClose:n,serverId:i}){let s=M(),[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)(j,{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 ${P(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,`:`]}),` `,ge(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 ${P(v.result.headPosition+1)} of ${P(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 ge(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 _e({record:t,onClose:r,nav:a,redaction:o}){let c=M(),l=H(),u=V();if(!t)return null;let p=t,g=K(p,l,u),_=p.rule_id===`gateway.unknown-tool`,v=_?null:L(p),x=te[p.outcome]?.tone??`neutral`;return(0,Y.jsx)(h,{open:!0,onClose:r,title:g?g.title:(0,Y.jsxs)(Y.Fragment,{children:[B(p),` `,(0,Y.jsx)(`span`,{className:`mono text-[17px]`,children:p.tool})]}),subtitle:`Entry ${P(p.seq)} · ${s(p.ts)}`,width:620,footer:(0,Y.jsx)(E,{icon:`copy`,onClick:async()=>{let e=await q(`${location.origin}${i(a,{seq:String(p.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:[_?(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:p.decision}),!_&&C(p.outcome)!==k(p.decision)&&(0,Y.jsx)(e,{tone:x,children:R(p)?`You said no`:C(p.outcome)}),p.grant_id&&(0,Y.jsx)(e,{icon:`key`,children:`Released by a pre-approval`})]}),v&&(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:[v,`. `,(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:p.tool})}),(0,Y.jsx)(Z,{label:`What the tool does`,children:p.effect?(0,Y.jsx)(y,{effect:p.effect,withLabel:!0}):(0,Y.jsx)($,{children:A(null)})}),(0,Y.jsxs)(Z,{label:`Decided by`,children:[I(p),` `,(0,Y.jsx)(Q,{children:p.rule_id})]}),(0,Y.jsx)(Z,{label:`Reason`,children:p.reason||(0,Y.jsx)($,{children:`None recorded`})}),(0,Y.jsx)(Z,{label:`Took`,children:p.duration_ms===null?(0,Y.jsx)($,{children:`Not timed`}):m(p.duration_ms)}),p.error&&(0,Y.jsx)(Z,{label:`Error`,children:(0,Y.jsx)(`span`,{className:`text-bad`,children:p.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:p.actor})}),G(p.client)&&(0,Y.jsxs)(Z,{label:`App (as it reports itself)`,children:[(0,Y.jsx)(`span`,{className:`block overflow-hidden break-all`,children:G(p.client)}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[12.5px] text-soft`,children:`The name the app gave when it connected. Any app can give any name, so it is not checked.`})]}),(0,Y.jsx)(Z,{label:`Session`,children:(0,Y.jsx)(Q,{children:p.session})}),(0,Y.jsx)(Z,{label:`Written by`,children:(0,Y.jsx)(Q,{children:p.component})}),p.tenant!==null&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Customer `,(0,Y.jsx)(b,{term:`customer`})]}),children:p.tenant===``?(0,Y.jsx)($,{children:`None`}):p.tenant})]}),p.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:[p.upstream.method??`?`,` `,p.upstream.host??``,p.upstream.path??``]})}),(0,Y.jsx)(Z,{label:`Answer`,children:p.upstream.status===null?(0,Y.jsx)($,{children:`No status`}):(0,Y.jsx)(`span`,{className:`tnum`,children:p.upstream.status})}),p.upstream.bytes!==null&&(0,Y.jsx)(Z,{label:`Size`,children:f(p.upstream.bytes)})]}),(p.approval_id||p.grant_id)&&(0,Y.jsxs)(X,{title:`Linked`,children:[p.approval_id&&(0,Y.jsx)(Z,{label:`Approval request`,children:(0,Y.jsx)(ye,{href:n(a,`/approvals`,{id:p.approval_id}),children:p.approval_id})}),p.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)(ye,{href:n(a,`/pre-approvals`,{id:p.grant_id}),children:p.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`})]}),p.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(p.args_redacted,null,2)}),o&&p.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:[ve(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)(be,{label:`Fingerprint of the entry before`,value:p.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)(be,{label:`Fingerprint of this entry`,value:p.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:p.args_hash})]})]})]})})}var ve=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 ye({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 be({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 xe(){let{serverId:e,server:n,tenant:a,tenantInfo:s,nav:c}=pe(),[d,f]=(0,J.useState)(()=>se(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,A]=(0,J.useState)(!1),[j=``,M=``,N=``]=x([d.tool,d.actor,d.component].join(`\0`),300).split(`\0`),F={...d,tool:j,actor:M,component:N};(0,J.useEffect)(()=>{oe(i(c,{...le(F),seq:b?String(b.seq):null}))},[JSON.stringify(F),b?.seq]);let I=ue(F,a,m),L=JSON.stringify(I),R=re(()=>p.audit(e,v===void 0?I:{...I,cursor:String(v)}),[e,L,v],v===void 0?5e3:void 0),z=re(()=>p.redaction(),[]),B=v===void 0?R.data?.records??[]:[...g,...R.data?.records??[]],V=R.loading&&!R.data;function H(e){f(t=>({...t,...e})),y(void 0),_([]),e.range!==void 0&&h(Date.now())}let fe=()=>{y(void 0),_([]),h(Date.now()),R.reload()},[U,W]=(0,J.useState)(()=>c.query.get(`seq`));(0,J.useEffect)(()=>{if(!U)return;let t=Number(U);if(W(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)},[U]);let G=(0,J.useMemo)(()=>[{value:``,label:`Any decision`},...(z.data?.decisions??Object.keys(ie).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:k(e.value)}))],[z.data]),K=(0,J.useMemo)(()=>[{value:``,label:`Any result`},...(z.data?.outcomes??Object.keys(te).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:C(e.value)}))],[z.data]),q=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:()=>A(!0),disabled:B.length===0,children:`Download log`})]})}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(ne,{title:`Filters`,actions:ce(d)&&(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`x`,onClick:()=>H(de),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=>H({outcome:e}),options:K})}),(0,Y.jsx)(r,{label:`Decision`,children:(0,Y.jsx)(D,{value:d.decision,onChange:e=>H({decision:e}),options:G})}),(0,Y.jsx)(r,{label:`Tool`,help:`Use * to match any text, like files.*`,children:(0,Y.jsx)(l,{value:d.tool,onChange:e=>H({tool:e}),mono:!0,placeholder:`Any tool`})}),(0,Y.jsx)(r,{label:`Who asked`,children:(0,Y.jsx)(l,{value:d.actor,onChange:e=>H({actor:e}),placeholder:`Anyone`})}),q.length>0&&(0,Y.jsx)(r,{label:`Customer`,children:(0,Y.jsx)(D,{value:d.allTenants?`*`:a??``,onChange:e=>{e===`*`?H({allTenants:!0}):e===a?H({allTenants:!1}):oe(i(c,{tenant:e,allTenants:null}))},options:[...a===null?[{value:``,label:`Choose a customer`}]:[],...q.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=>H({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=>H({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)(ae,{checked:d.noteworthy,onChange:e=>H({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)(Ee,{label:`From`,value:d.since,onChange:e=>H({since:e})}),(0,Y.jsx)(Ee,{label:`Until`,value:d.until,onChange:e=>H({until:e}),help:`Leave empty for up to now.`})]})]}),R.data&&R.data.malformed>0&&(0,Y.jsxs)(o,{tone:`warn`,title:`${t(R.data.malformed,`line`)} could not be read`,children:[`Of the `,P(R.data.scanned),` lines read for this list, `,P(R.data.malformed),` were damaged and skipped. Run the integrity check to see where.`]}),(0,Y.jsxs)(ne,{title:V?`Entries`:`${t(B.length,`entry`,`entries`)}${R.data?.nextCursor==null?``:` so far`}`,actions:(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:fe,loading:R.loading&&!!R.data,children:`Refresh list`}),children:[(0,Y.jsx)(Se,{loading:V,error:R.error,onRetry:R.reload,records:B,filtered:ce(d),onClear:()=>H(de),onOpen:S,mixedCustomers:d.allTenants}),R.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:R.loading,onClick:()=>{_(B),y(R.data.nextCursor)},children:`Load older entries`})})]})]}),(0,Y.jsx)(_e,{record:b,onClose:()=>S(null),nav:c,redaction:z.data}),(0,Y.jsx)(he,{open:w,onClose:()=>T(!1),serverId:e}),(0,Y.jsx)(De,{open:O,onClose:()=>A(!1),records:B,stem:`activity-${n.id}-${new Date().toISOString().slice(0,10)}`})]})}function Se({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)(Te,{record:e,onOpen:()=>c(e),showCustomer:l})},`${e.seq}-${e.id}`))})}var Ce={ok:`bg-ok-tint text-ok`,warn:`bg-warn-tint text-warn`,bad:`bg-bad-tint text-bad`,neutral:`bg-sunken text-muted`};function we(e,t){if(!t&&(e.actor===`agent`||!e.actor))return me(e.client);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 Te({record:t,onOpen:n,showCustomer:r}){let i=K(t,H(),V()),a=t.rule_id===`gateway.unknown-tool`,o=a?null:L(t),c=te[t.outcome]?.tone??`neutral`,l=i?`neutral`:a?`warn`:t.outcome===`error`?`bad`:ie[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:N(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,Ce[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:B(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)}),` · `,we(t,i!==null),r&&t.tenant?` · ${t.tenant}`:``,!i&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,z(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:R(t)?`You said no`:C(t.outcome)}),(0,Y.jsx)(d,{name:`chevron-right`,size:18,className:`text-soft max-sm:hidden`})]})]})}function Ee({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 De({open:e,onClose:n,records:r,stem:i}){let[a,o]=(0,J.useState)(`jsonl`);return(0,Y.jsx)(j,{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`?U(`${i}.jsonl`,`application/x-ndjson`,fe(r)):U(`${i}.csv`,`text/csv`,F(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)(Oe,{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)(Oe,{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 Oe({checked:e,onSelect:t,title:n,children:r}){return(0,Y.jsxs)(`label`,{className:N(`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{xe 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 te,pt as ne,s as re,tt as ie,ut as A,w as ae,wt as oe,x as j,y as M,yt as N,z as P}from"./kit-BHB_ha4i.js";import{At as F,Ct as I,Dt as se,Et as ce,Mt as L,Ot as R,St as z,Tt as le,_t as ue,bt as B,gn as V,gt as de,hn as H,jt as fe,kt as U,pn as pe,s as W,vt as G,wt as K,xt as q,yt as me}from"./index-DywhXnhV.js";var J=c(),Y=O();function he({open:e,onClose:n,serverId:i}){let s=M(),[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)(j,{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 ${P(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,`:`]}),` `,ge(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 ${P(v.result.headPosition+1)} of ${P(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 ge(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 _e({record:t,onClose:r,nav:a,redaction:o}){let c=M(),l=H(),u=V();if(!t)return null;let p=t,g=K(p,l,u),_=p.rule_id===`gateway.unknown-tool`,v=_?null:L(p),x=te[p.outcome]?.tone??`neutral`;return(0,Y.jsx)(h,{open:!0,onClose:r,title:g?g.title:(0,Y.jsxs)(Y.Fragment,{children:[B(p),` `,(0,Y.jsx)(`span`,{className:`mono text-[17px]`,children:p.tool})]}),subtitle:`Entry ${P(p.seq)} · ${s(p.ts)}`,width:620,footer:(0,Y.jsx)(E,{icon:`copy`,onClick:async()=>{let e=await q(`${location.origin}${i(a,{seq:String(p.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:[_?(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:p.decision}),!_&&C(p.outcome)!==k(p.decision)&&(0,Y.jsx)(e,{tone:x,children:R(p)?`You said no`:C(p.outcome)}),p.grant_id&&(0,Y.jsx)(e,{icon:`key`,children:`Released by a pre-approval`})]}),v&&(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:[v,`. `,(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:p.tool})}),(0,Y.jsx)(Z,{label:`What the tool does`,children:p.effect?(0,Y.jsx)(y,{effect:p.effect,withLabel:!0}):(0,Y.jsx)($,{children:A(null)})}),(0,Y.jsxs)(Z,{label:`Decided by`,children:[I(p),` `,(0,Y.jsx)(Q,{children:p.rule_id})]}),(0,Y.jsx)(Z,{label:`Reason`,children:p.reason||(0,Y.jsx)($,{children:`None recorded`})}),(0,Y.jsx)(Z,{label:`Took`,children:p.duration_ms===null?(0,Y.jsx)($,{children:`Not timed`}):m(p.duration_ms)}),p.error&&(0,Y.jsx)(Z,{label:`Error`,children:(0,Y.jsx)(`span`,{className:`text-bad`,children:p.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:p.actor})}),G(p.client)&&(0,Y.jsxs)(Z,{label:`App (as it reports itself)`,children:[(0,Y.jsx)(`span`,{className:`block overflow-hidden break-all`,children:G(p.client)}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[12.5px] text-soft`,children:`The name the app gave when it connected. Any app can give any name, so it is not checked.`})]}),(0,Y.jsx)(Z,{label:`Session`,children:(0,Y.jsx)(Q,{children:p.session})}),(0,Y.jsx)(Z,{label:`Written by`,children:(0,Y.jsx)(Q,{children:p.component})}),p.tenant!==null&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Customer `,(0,Y.jsx)(b,{term:`customer`})]}),children:p.tenant===``?(0,Y.jsx)($,{children:`None`}):p.tenant})]}),p.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:[p.upstream.method??`?`,` `,p.upstream.host??``,p.upstream.path??``]})}),(0,Y.jsx)(Z,{label:`Answer`,children:p.upstream.status===null?(0,Y.jsx)($,{children:`No status`}):(0,Y.jsx)(`span`,{className:`tnum`,children:p.upstream.status})}),p.upstream.bytes!==null&&(0,Y.jsx)(Z,{label:`Size`,children:f(p.upstream.bytes)})]}),(p.approval_id||p.grant_id)&&(0,Y.jsxs)(X,{title:`Linked`,children:[p.approval_id&&(0,Y.jsx)(Z,{label:`Approval request`,children:(0,Y.jsx)(ye,{href:n(a,`/approvals`,{id:p.approval_id}),children:p.approval_id})}),p.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)(ye,{href:n(a,`/pre-approvals`,{id:p.grant_id}),children:p.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`})]}),p.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(p.args_redacted,null,2)}),o&&p.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:[ve(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)(be,{label:`Fingerprint of the entry before`,value:p.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)(be,{label:`Fingerprint of this entry`,value:p.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:p.args_hash})]})]})]})})}var ve=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 ye({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 be({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 xe(){let{serverId:e,server:n,tenant:a,tenantInfo:s,nav:c}=pe(),[d,f]=(0,J.useState)(()=>se(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,A]=(0,J.useState)(!1),[j=``,M=``,N=``]=x([d.tool,d.actor,d.component].join(`\0`),300).split(`\0`),F={...d,tool:j,actor:M,component:N};(0,J.useEffect)(()=>{oe(i(c,{...le(F),seq:b?String(b.seq):null}))},[JSON.stringify(F),b?.seq]);let I=ue(F,a,m),L=JSON.stringify(I),R=re(()=>p.audit(e,v===void 0?I:{...I,cursor:String(v)}),[e,L,v],v===void 0?5e3:void 0),z=re(()=>p.redaction(),[]),B=v===void 0?R.data?.records??[]:[...g,...R.data?.records??[]],V=R.loading&&!R.data;function H(e){f(t=>({...t,...e})),y(void 0),_([]),e.range!==void 0&&h(Date.now())}let fe=()=>{y(void 0),_([]),h(Date.now()),R.reload()},[U,W]=(0,J.useState)(()=>c.query.get(`seq`));(0,J.useEffect)(()=>{if(!U)return;let t=Number(U);if(W(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)},[U]);let G=(0,J.useMemo)(()=>[{value:``,label:`Any decision`},...(z.data?.decisions??Object.keys(ie).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:k(e.value)}))],[z.data]),K=(0,J.useMemo)(()=>[{value:``,label:`Any result`},...(z.data?.outcomes??Object.keys(te).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:C(e.value)}))],[z.data]),q=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:()=>A(!0),disabled:B.length===0,children:`Download log`})]})}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(ne,{title:`Filters`,actions:ce(d)&&(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`x`,onClick:()=>H(de),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=>H({outcome:e}),options:K})}),(0,Y.jsx)(r,{label:`Decision`,children:(0,Y.jsx)(D,{value:d.decision,onChange:e=>H({decision:e}),options:G})}),(0,Y.jsx)(r,{label:`Tool`,help:`Use * to match any text, like files.*`,children:(0,Y.jsx)(l,{value:d.tool,onChange:e=>H({tool:e}),mono:!0,placeholder:`Any tool`})}),(0,Y.jsx)(r,{label:`Who asked`,children:(0,Y.jsx)(l,{value:d.actor,onChange:e=>H({actor:e}),placeholder:`Anyone`})}),q.length>0&&(0,Y.jsx)(r,{label:`Customer`,children:(0,Y.jsx)(D,{value:d.allTenants?`*`:a??``,onChange:e=>{e===`*`?H({allTenants:!0}):e===a?H({allTenants:!1}):oe(i(c,{tenant:e,allTenants:null}))},options:[...a===null?[{value:``,label:`Choose a customer`}]:[],...q.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=>H({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=>H({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)(ae,{checked:d.noteworthy,onChange:e=>H({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)(Ee,{label:`From`,value:d.since,onChange:e=>H({since:e})}),(0,Y.jsx)(Ee,{label:`Until`,value:d.until,onChange:e=>H({until:e}),help:`Leave empty for up to now.`})]})]}),R.data&&R.data.malformed>0&&(0,Y.jsxs)(o,{tone:`warn`,title:`${t(R.data.malformed,`line`)} could not be read`,children:[`Of the `,P(R.data.scanned),` lines read for this list, `,P(R.data.malformed),` were damaged and skipped. Run the integrity check to see where.`]}),(0,Y.jsxs)(ne,{title:V?`Entries`:`${t(B.length,`entry`,`entries`)}${R.data?.nextCursor==null?``:` so far`}`,actions:(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:fe,loading:R.loading&&!!R.data,children:`Refresh list`}),children:[(0,Y.jsx)(Se,{loading:V,error:R.error,onRetry:R.reload,records:B,filtered:ce(d),onClear:()=>H(de),onOpen:S,mixedCustomers:d.allTenants}),R.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:R.loading,onClick:()=>{_(B),y(R.data.nextCursor)},children:`Load older entries`})})]})]}),(0,Y.jsx)(_e,{record:b,onClose:()=>S(null),nav:c,redaction:z.data}),(0,Y.jsx)(he,{open:w,onClose:()=>T(!1),serverId:e}),(0,Y.jsx)(De,{open:O,onClose:()=>A(!1),records:B,stem:`activity-${n.id}-${new Date().toISOString().slice(0,10)}`})]})}function Se({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)(Te,{record:e,onOpen:()=>c(e),showCustomer:l})},`${e.seq}-${e.id}`))})}var Ce={ok:`bg-ok-tint text-ok`,warn:`bg-warn-tint text-warn`,bad:`bg-bad-tint text-bad`,neutral:`bg-sunken text-muted`};function we(e,t){if(!t&&(e.actor===`agent`||!e.actor))return me(e.client);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 Te({record:t,onOpen:n,showCustomer:r}){let i=K(t,H(),V()),a=t.rule_id===`gateway.unknown-tool`,o=a?null:L(t),c=te[t.outcome]?.tone??`neutral`,l=i?`neutral`:a?`warn`:t.outcome===`error`?`bad`:ie[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:N(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,Ce[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:B(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)}),` · `,we(t,i!==null),r&&t.tenant?` · ${t.tenant}`:``,!i&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,z(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:R(t)?`You said no`:C(t.outcome)}),(0,Y.jsx)(d,{name:`chevron-right`,size:18,className:`text-soft max-sm:hidden`})]})]})}function Ee({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 De({open:e,onClose:n,records:r,stem:i}){let[a,o]=(0,J.useState)(`jsonl`);return(0,Y.jsx)(j,{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`?U(`${i}.jsonl`,`application/x-ndjson`,fe(r)):U(`${i}.csv`,`text/csv`,F(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)(Oe,{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)(Oe,{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 Oe({checked:e,onSelect:t,title:n,children:r}){return(0,Y.jsxs)(`label`,{className:N(`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{xe 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 y,Y as ee,Z as b,_ as x,_t as S,c as te,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-BHB_ha4i.js";import{a as P,c as ae,hn as F,l as I,n as oe,o as L,pn as R,r as se,s as z,t as B,u as ce}from"./index-Cm4wG2zz.js";var V=u(),H=T(),U=/^\[redacted:([^\]]+)\]$/,W=/…\[truncated (\d+) chars\]$/,G=/^\[truncated (\d+) items\]$/;function K(e){if(typeof e!=`string`)return null;let t=U.exec(e);return t?t[1]===`key`||t[1]===`circular`||t[1]===`max-depth`?t[1]:`pattern`:W.test(e)?`chars`:G.test(e)?`items`:null}function q(e,t,n=0){if(n>20)return;let r=K(e);r&&t.add(r),Array.isArray(e)?e.forEach(e=>q(e,t,n+1)):e&&typeof e==`object`&&Object.values(e).forEach(e=>q(e,t,n+1))}var J={key:`[redacted:key]`,pattern:`[redacted:<pattern>]`,circular:`[redacted:circular]`,"max-depth":`[redacted:max-depth]`,chars:`…[truncated N chars]`,items:`[truncated N items]`},Y={key:`Hidden`,pattern:`Hidden`,circular:`Hidden`,"max-depth":`Hidden`,chars:`Cut short`,items:`Cut short`};function X({args:e,error:t,meta:n}){let r=new Set;q(e,r);let i=e=>n?.markers.find(t=>t.marker===J[e])?.meaning,a=e&&typeof e==`object`&&!Array.isArray(e)?Object.entries(e):null;return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,H.jsx)(c,{tone:`warn`,title:`Some inputs could not be read back`,children:t}),a===null?e==null?!t&&(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`The inputs were not recorded.`}):(0,H.jsx)(Z,{value:e,meaning:i}):a.length===0?(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`This call sent no inputs.`}):(0,H.jsx)(`dl`,{className:`divide-y divide-faint overflow-hidden rounded-2xl bg-sunken/60`,children:a.map(([e,t])=>(0,H.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,H.jsx)(`dt`,{className:`mono pt-px text-[12.5px] break-all text-soft`,children:e}),(0,H.jsx)(`dd`,{className:`min-w-0`,children:(0,H.jsx)(Z,{value:t,meaning:i})})]},e))}),r.size>0&&(0,H.jsxs)(`div`,{className:`flex gap-2 text-[12.5px] text-soft`,children:[(0,H.jsx)(h,{name:`eye-off`,size:15,className:`mt-0.5 shrink-0`}),(0,H.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,H.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,H.jsx)(x,{term:`redaction`})]}),[...r].map(e=>(0,H.jsxs)(`p`,{children:[(0,H.jsx)(`code`,{className:`mono text-[11.5px]`,children:J[e]}),`: `,i(e)??`not shown in full`]},e))]})]})]})}function Z({value:t,meaning:n}){let r=K(t);if(r&&r!==`chars`)return(0,H.jsx)(e,{tone:`neutral`,icon:`eye-off`,title:n(r),children:Y[r]});if(typeof t==`string`){let r=W.exec(t),i=r?t.slice(0,r.index):t;return(0,H.jsxs)(`p`,{className:`scrollbar-thin max-h-40 overflow-y-auto text-[13.5px] break-words whitespace-pre-wrap`,children:[i===``?(0,H.jsx)(`span`,{className:`text-soft`,children:`(empty)`}):i,r&&(0,H.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,H.jsx)(`span`,{className:`mono text-[13px]`,children:String(t)}):(0,H.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 Q=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:ee}){let S=ie(),[te,ne]=(0,V.useState)(``),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,A]=(0,V.useState)(t?.rememberDefaults.ttlSeconds??3600),[M,re]=(0,V.useState)(t?.rememberDefaults.maxUses??20),[I,oe]=(0,V.useState)(!1),[R,U]=(0,V.useState)(null),W=z(e.tool),G=F(),K=e.expiresAt-n,q=se(e),J=t?.grantTtlMaxSeconds,Y=h||w!==null;async function Z(t,n={}){T(n.remember?`remember`:n.classify?`classify-${n.classify}`:t),U(null);let r;try{r=await g.decide(a,e.id,t,te.trim(),s,n.classify,n.remember)}catch(e){T(null),Q(e)?(S.show(`warn`,`This call was already answered, or it ran out of time.`),v()):n.remember&&e instanceof m&&e.status===422?U(L(e.message)):S.show(`bad`,L(e.message));return}T(null),t===`denied`?S.show(`ok`,`You said no. ${W.label} will not run, and the AI is told you said no.`):r.remembered?(S.show(`ok`,`Approved. Similar calls won't ask until ${ae(r.remembered.expiresAt)}.`),ee(r.remembered,e.tool)):r.classifyWarning?S.show(`warn`,L(r.classifyWarning)):r.classified&&n.classify?S.show(`ok`,`Approved, and ${W.label} is now labelled "${k[n.classify].label}". Its calls still ask you.`):S.show(`ok`,`Approved. The call can go ahead.`),v()}let le=O!==null&&(J===void 0||O<=J)&&(I||M!==null&&M>=1);return(0,H.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,H.jsxs)(`header`,{className:`flex items-start gap-3`,children:[u&&(0,H.jsx)(`span`,{className:`pt-2.5`,children:(0,H.jsx)(j,{checked:d,onChange:f,disabled:Y,label:(0,H.jsxs)(`span`,{className:`sr-only`,children:[`Select `,W.label]})})}),(0,H.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,H.jsx)(b,{effect:e.effect})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.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:W.label}),(0,H.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-[12.5px] text-soft`,children:[W.server&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{title:W.server,children:G(W.server)}),(0,H.jsx)(`span`,{"aria-hidden":!0,children:`·`})]}),(0,H.jsx)(b,{effect:e.effect,withLabel:!0})]})]})]}),(0,H.jsxs)(`section`,{"aria-label":`What it wants to do`,className:`space-y-2.5`,children:[(0,H.jsx)(`p`,{className:`text-[15px] leading-relaxed [overflow-wrap:anywhere]`,children:B(e)}),(0,H.jsx)(`p`,{className:`text-[14px] text-muted`,children:ce(e)}),e.violations.length>0&&(0,H.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,H.jsxs)(`li`,{className:`flex gap-2`,children:[(0,H.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`min-w-0 break-words`,children:P(t,e.args)})]},t))}),(0,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:K>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,H.jsxs)(`section`,{"aria-label":`The details it would send`,className:`space-y-2`,children:[(0,H.jsx)(`h4`,{className:`eyebrow`,children:`The details it would send`}),(0,H.jsx)(X,{args:e.args,error:e.argsError,meta:t})]}),(0,H.jsxs)(`details`,{className:`group text-[12.5px] text-soft`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer select-none font-medium text-muted`,children:`Details`}),(0,H.jsxs)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1`,children:[(0,H.jsx)(`dt`,{children:`Tool`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.tool})}),(0,H.jsx)(`dt`,{children:`Asked by`}),(0,H.jsxs)(`dd`,{children:[e.actor,` `,(0,H.jsx)(`span`,{title:l(e.createdAt),children:y(e.createdAt,n)})]}),(0,H.jsx)(`dt`,{children:`Session`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.session})}),e.ruleId&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{children:`Rule`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.ruleId})})]}),(0,H.jsx)(`dt`,{children:`Request`}),(0,H.jsxs)(`dd`,{children:[(0,H.jsx)(`code`,{className:`mono break-all`,children:e.id}),`, expires `,l(e.expiresAt)]})]})]}),(0,H.jsxs)(`div`,{className:`mt-auto space-y-3 border-t border-faint pt-4`,children:[(0,H.jsx)(i,{label:`Note for the activity log`,optional:!0,children:(0,H.jsx)(p,{value:te,onChange:ne,placeholder:`Why you said yes or no`,disabled:Y})}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,onClick:()=>Z(`granted`),loading:w===`granted`,disabled:Y,children:`Approve`}),(0,H.jsx)(C,{variant:`secondary`,icon:`x`,onClick:()=>Z(`denied`),loading:w===`denied`,disabled:Y,children:`Say no`}),e.rememberAllowed&&!q&&(0,H.jsx)(C,{variant:`ghost`,icon:E?`chevron`:`chevron-right`,"aria-expanded":E,"aria-controls":`remember-${e.id}`,onClick:()=>D(e=>!e),disabled:Y,children:`Approve and don't ask again`})]}),q&&(0,H.jsxs)(`div`,{className:`space-y-2.5 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsx)(`p`,{className:`text-[13.5px] font-semibold`,children:`Approve and remember this tool as:`}),(0,H.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,H.jsx)(C,{size:`sm`,variant:`secondary`,onClick:()=>Z(`granted`,{classify:e}),loading:w===`classify-${e}`,disabled:Y,title:k[e].explain,children:k[e].label},e))}),(0,H.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,H.jsxs)(`div`,{id:`remember-${e.id}`,className:`space-y-4 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[14px] font-semibold`,children:[`Approve and don't ask again `,(0,H.jsx)(x,{term:`preApproval`})]}),(0,H.jsx)(i,{label:`For how long`,children:(0,H.jsx)(_,{value:O,onChange:A,label:`For how long`,max:J})}),(0,H.jsx)(i,{label:`Up to how many calls`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,H.jsx)(r,{value:I?null:M,onChange:re,min:1,step:1,unit:`calls`,disabled:I||Y,className:`w-40`}),(0,H.jsx)(j,{checked:I,onChange:oe,label:`No limit`,disabled:Y})]})}),(0,H.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.`}),R&&(0,H.jsx)(c,{tone:`danger`,title:`Nothing was approved`,role:`alert`,children:R}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,disabled:!le||Y,loading:w===`remember`,onClick:()=>Z(`granted`,{remember:{ttlSeconds:O,maxUses:I?null:M}}),children:`Approve and remember`}),(0,H.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 de(){let{serverId:e,tenant:r,nav:i,reload:o}=R(),l=ie(),u=I(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),b=i.query.get(`id`),x=b!==null&&(f.data??[]).some(e=>e.id===b),T=i.query.get(`tab`)===`history`||b!==null&&f.data!==null&&!x?`history`:`waiting`,k=e=>M(a(i,{tab:e===`waiting`?null:e})),j=(0,V.useMemo)(()=>[...f.data??[]].filter(e=>e.expiresAt>u).sort((e,t)=>e.createdAt-t.createdAt),[f.data,u]),N=(0,V.useMemo)(()=>(p.data??[]).filter(e=>e.state!==`pending`).sort((e,t)=>(t.decidedAt??t.expiresAt)-(e.decidedAt??e.expiresAt)),[p.data]),[P,F]=(0,V.useState)(!1),[se,B]=(0,V.useState)([]),ce=new Set(j.map(e=>e.id)),U=se.filter(e=>ce.has(e)),[W,G]=(0,V.useState)(null),[K,q]=(0,V.useState)(``),[J,Y]=(0,V.useState)(!1),[X,Z]=(0,V.useState)(null),Q=(0,V.useRef)(!1),de=(0,V.useRef)(null),fe=(0,V.useRef)(null);(0,V.useEffect)(()=>{Q.current&&f.data!==null&&(Q.current=!1,(de.current?.querySelector(`article h3[tabindex]`)??fe.current)?.focus())},[f.data]);let pe=()=>{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(L(e.message))}Y(!1),G(null),q(``),B([]),F(!1),pe();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,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(te,{title:`Waiting for you`,subtitle:`Your AI wanted to do these things. Nothing happens until you decide.`,actions:(0,H.jsx)(C,{variant:P?`primary`:`secondary`,icon:P?`x`:`list`,"aria-pressed":P,disabled:!P&&j.length<2,onClick:()=>{F(e=>!e),B([])},children:P?`Stop selecting`:`Select several`})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,H.jsx)(E,{tone:`hero`,title:`Waiting now`,loading:f.data===null&&!f.error,value:j.length,sub:ve?`Oldest asked ${y(ve.createdAt,u)}`:`Nothing needs you`}),(0,H.jsxs)(`div`,{className:`contents max-sm:hidden`,children:[(0,H.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,H.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,H.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[$&&$.pendingElsewhere>0&&(0,H.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,H.jsxs)(c,{tone:`ok`,title:`Pre-approval created`,role:`status`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{size:`sm`,variant:`secondary`,href:n(i,`/pre-approvals`,{grant:X.grant.id}),children:`Open pre-approval`}),(0,H.jsx)(ne,{icon:`x`,label:`Dismiss message`,size:32,onClick:()=>Z(null)})]}),children:[`Calls like this one to `,z(X.tool).label,` won't ask until `,ae(X.grant.expiresAt),X.grant.maxUses===null?``:`, for up to ${t(X.grant.maxUses,`call`)}`,`.`]})]}),(0,H.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center justify-between gap-3`,children:[(0,H.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,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Oldest first: the call at the top runs out soonest.`})]}),(0,H.jsx)(`div`,{role:`tabpanel`,id:ee(T),"aria-labelledby":d(T),className:`mt-5`,children:T===`waiting`?(0,H.jsxs)(H.Fragment,{children:[P&&j.length>0&&(0,H.jsx)(D,{className:`mb-5`,padded:!1,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-5 py-4`,children:[(0,H.jsxs)(`p`,{className:`min-w-0 flex-1 text-[14px]`,children:[(0,H.jsx)(`span`,{className:`tnum font-semibold`,children:U.length}),` of `,t(j.length,`call`),` selected`]}),(0,H.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>B(U.length===j.length?[]:j.map(e=>e.id)),children:U.length===j.length?`Clear selection`:`Select all`}),(0,H.jsx)(C,{size:`sm`,variant:`primary`,icon:`check`,disabled:U.length===0,onClick:()=>G(`granted`),children:`Approve all`}),(0,H.jsx)(C,{size:`sm`,variant:`secondary`,icon:`x`,disabled:U.length===0,onClick:()=>G(`denied`),children:`Deny all`})]})}),f.error&&(0,H.jsx)(`div`,{className:`mb-5`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load the calls waiting for you`,role:`alert`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:f.reload,children:`Try again`}),children:L(f.error)})}),f.data===null?!f.error&&(0,H.jsx)(`div`,{className:`grid gap-5 xl:grid-cols-2`,children:[0,1].map(e=>(0,H.jsxs)(D,{children:[(0,H.jsx)(s,{height:22,width:`45%`}),(0,H.jsx)(`div`,{className:`mt-5`,children:(0,H.jsx)(s,{lines:4})})]},e))}):j.length===0?(0,H.jsx)(D,{children:(0,H.jsx)(`div`,{ref:fe,tabIndex:-1,className:`outline-none`,children:(0,H.jsxs)(v,{icon:`inbox`,title:`Nothing is waiting for you.`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>k(`history`),children:`Show decided calls`}),(0,H.jsx)(S,{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,H.jsx)(`div`,{ref:de,className:`grid items-start gap-5 xl:grid-cols-2`,children:j.map(t=>(0,H.jsx)(`div`,{className:t.id===b?`rounded-[22px] ring-2 ring-[var(--focus)] ring-offset-2 ring-offset-[var(--bg)]`:void 0,children:(0,H.jsx)(le,{approval:t,meta:h.data,now:u,serverId:e,tenant:r,selecting:P,selected:P&&U.includes(t.id),onSelect:e=>B(n=>e?[...new Set([...n,t.id])]:n.filter(e=>e!==t.id)),locked:J,onDecided:()=>{Q.current=!0,pe()},onRemembered:(e,t)=>Z({grant:e,tool:t})})},t.id))})]}):(0,H.jsx)(me,{rows:N,error:p.error,loading:p.data===null,retry:p.reload,now:u,focusId:b})}),(0,H.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,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>G(null),disabled:J,children:`Go back`}),(0,H.jsx)(C,{variant:W===`granted`?`primary`:`danger`,loading:J,onClick:()=>W&&he(W),children:W===`granted`?`Approve all`:`Deny all`})]}),children:[(0,H.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,H.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.tool})]},e.id))}),(0,H.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 fe(t){return t.decidedBy?.startsWith(`standing-grant:`)?(0,H.jsx)(e,{tone:`ok`,icon:`key`,children:`Let through by a pre-approval`}):t.state===`granted`||t.state===`used`?(0,H.jsx)(e,{tone:`ok`,icon:`check`,children:`Approved`}):t.state===`denied`?(0,H.jsx)(e,{tone:`bad`,icon:`x`,children:`Denied`}):t.state===`expired`?(0,H.jsx)(e,{tone:`neutral`,icon:`clock`,children:`Expired`}):(0,H.jsx)(e,{children:t.state})}function pe(e){return e.decidedBy?e.decidedBy.startsWith(`standing-grant:`)?(0,H.jsxs)(`span`,{children:[`Pre-approval `,(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.decidedBy.slice(15)})]}):e.decidedBy:(0,H.jsx)(`span`,{className:`text-soft`,children:e.state===`expired`?`Nobody answered`:`Not recorded`})}function me({rows:e,error:t,loading:n,retry:r,now:i,focusId:a}){let o=[{key:`call`,header:`Call`,cell:e=>(0,H.jsxs)(`span`,{className:`block min-w-0`,children:[(0,H.jsx)(`span`,{className:`block font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.tool})]})},{key:`result`,header:`Result`,cell:fe},{key:`who`,header:`Decided by`,cell:pe},{key:`when`,header:`When`,cell:e=>{let t=e.decidedAt??e.expiresAt;return(0,H.jsx)(`span`,{title:l(t),children:y(t,i)})}},{key:`note`,header:`Note`,cell:e=>e.decisionNote?(0,H.jsx)(`span`,{className:`break-words`,children:e.decisionNote}):(0,H.jsx)(`span`,{className:`text-soft`,children:`None`}),hideOnMobile:!1}];return(0,H.jsxs)(D,{children:[t&&(0,H.jsx)(`div`,{className:`mb-4`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load decided calls`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:r,children:`Try again`}),children:L(t)})}),n?!t&&(0,H.jsx)(s,{lines:5,height:18}):(0,H.jsx)(f,{caption:`Calls decided earlier`,columns:o,rows:e,rowKey:e=>e.id,selectedKey:a,empty:(0,H.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{de 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 y,Y as ee,Z as b,_ as x,_t as S,c as te,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-BHB_ha4i.js";import{a as P,c as ae,hn as F,l as I,n as oe,o as L,pn as R,r as se,s as z,t as B,u as ce}from"./index-DywhXnhV.js";var V=u(),H=T(),U=/^\[redacted:([^\]]+)\]$/,W=/…\[truncated (\d+) chars\]$/,G=/^\[truncated (\d+) items\]$/;function K(e){if(typeof e!=`string`)return null;let t=U.exec(e);return t?t[1]===`key`||t[1]===`circular`||t[1]===`max-depth`?t[1]:`pattern`:W.test(e)?`chars`:G.test(e)?`items`:null}function q(e,t,n=0){if(n>20)return;let r=K(e);r&&t.add(r),Array.isArray(e)?e.forEach(e=>q(e,t,n+1)):e&&typeof e==`object`&&Object.values(e).forEach(e=>q(e,t,n+1))}var J={key:`[redacted:key]`,pattern:`[redacted:<pattern>]`,circular:`[redacted:circular]`,"max-depth":`[redacted:max-depth]`,chars:`…[truncated N chars]`,items:`[truncated N items]`},Y={key:`Hidden`,pattern:`Hidden`,circular:`Hidden`,"max-depth":`Hidden`,chars:`Cut short`,items:`Cut short`};function X({args:e,error:t,meta:n}){let r=new Set;q(e,r);let i=e=>n?.markers.find(t=>t.marker===J[e])?.meaning,a=e&&typeof e==`object`&&!Array.isArray(e)?Object.entries(e):null;return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,H.jsx)(c,{tone:`warn`,title:`Some inputs could not be read back`,children:t}),a===null?e==null?!t&&(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`The inputs were not recorded.`}):(0,H.jsx)(Z,{value:e,meaning:i}):a.length===0?(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`This call sent no inputs.`}):(0,H.jsx)(`dl`,{className:`divide-y divide-faint overflow-hidden rounded-2xl bg-sunken/60`,children:a.map(([e,t])=>(0,H.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,H.jsx)(`dt`,{className:`mono pt-px text-[12.5px] break-all text-soft`,children:e}),(0,H.jsx)(`dd`,{className:`min-w-0`,children:(0,H.jsx)(Z,{value:t,meaning:i})})]},e))}),r.size>0&&(0,H.jsxs)(`div`,{className:`flex gap-2 text-[12.5px] text-soft`,children:[(0,H.jsx)(h,{name:`eye-off`,size:15,className:`mt-0.5 shrink-0`}),(0,H.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,H.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,H.jsx)(x,{term:`redaction`})]}),[...r].map(e=>(0,H.jsxs)(`p`,{children:[(0,H.jsx)(`code`,{className:`mono text-[11.5px]`,children:J[e]}),`: `,i(e)??`not shown in full`]},e))]})]})]})}function Z({value:t,meaning:n}){let r=K(t);if(r&&r!==`chars`)return(0,H.jsx)(e,{tone:`neutral`,icon:`eye-off`,title:n(r),children:Y[r]});if(typeof t==`string`){let r=W.exec(t),i=r?t.slice(0,r.index):t;return(0,H.jsxs)(`p`,{className:`scrollbar-thin max-h-40 overflow-y-auto text-[13.5px] break-words whitespace-pre-wrap`,children:[i===``?(0,H.jsx)(`span`,{className:`text-soft`,children:`(empty)`}):i,r&&(0,H.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,H.jsx)(`span`,{className:`mono text-[13px]`,children:String(t)}):(0,H.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 Q=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:ee}){let S=ie(),[te,ne]=(0,V.useState)(``),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,A]=(0,V.useState)(t?.rememberDefaults.ttlSeconds??3600),[M,re]=(0,V.useState)(t?.rememberDefaults.maxUses??20),[I,oe]=(0,V.useState)(!1),[R,U]=(0,V.useState)(null),W=z(e.tool),G=F(),K=e.expiresAt-n,q=se(e),J=t?.grantTtlMaxSeconds,Y=h||w!==null;async function Z(t,n={}){T(n.remember?`remember`:n.classify?`classify-${n.classify}`:t),U(null);let r;try{r=await g.decide(a,e.id,t,te.trim(),s,n.classify,n.remember)}catch(e){T(null),Q(e)?(S.show(`warn`,`This call was already answered, or it ran out of time.`),v()):n.remember&&e instanceof m&&e.status===422?U(L(e.message)):S.show(`bad`,L(e.message));return}T(null),t===`denied`?S.show(`ok`,`You said no. ${W.label} will not run, and the AI is told you said no.`):r.remembered?(S.show(`ok`,`Approved. Similar calls won't ask until ${ae(r.remembered.expiresAt)}.`),ee(r.remembered,e.tool)):r.classifyWarning?S.show(`warn`,L(r.classifyWarning)):r.classified&&n.classify?S.show(`ok`,`Approved, and ${W.label} is now labelled "${k[n.classify].label}". Its calls still ask you.`):S.show(`ok`,`Approved. The call can go ahead.`),v()}let le=O!==null&&(J===void 0||O<=J)&&(I||M!==null&&M>=1);return(0,H.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,H.jsxs)(`header`,{className:`flex items-start gap-3`,children:[u&&(0,H.jsx)(`span`,{className:`pt-2.5`,children:(0,H.jsx)(j,{checked:d,onChange:f,disabled:Y,label:(0,H.jsxs)(`span`,{className:`sr-only`,children:[`Select `,W.label]})})}),(0,H.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,H.jsx)(b,{effect:e.effect})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.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:W.label}),(0,H.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-[12.5px] text-soft`,children:[W.server&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{title:W.server,children:G(W.server)}),(0,H.jsx)(`span`,{"aria-hidden":!0,children:`·`})]}),(0,H.jsx)(b,{effect:e.effect,withLabel:!0})]})]})]}),(0,H.jsxs)(`section`,{"aria-label":`What it wants to do`,className:`space-y-2.5`,children:[(0,H.jsx)(`p`,{className:`text-[15px] leading-relaxed [overflow-wrap:anywhere]`,children:B(e)}),(0,H.jsx)(`p`,{className:`text-[14px] text-muted`,children:ce(e)}),e.violations.length>0&&(0,H.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,H.jsxs)(`li`,{className:`flex gap-2`,children:[(0,H.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`min-w-0 break-words`,children:P(t,e.args)})]},t))}),(0,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:K>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,H.jsxs)(`section`,{"aria-label":`The details it would send`,className:`space-y-2`,children:[(0,H.jsx)(`h4`,{className:`eyebrow`,children:`The details it would send`}),(0,H.jsx)(X,{args:e.args,error:e.argsError,meta:t})]}),(0,H.jsxs)(`details`,{className:`group text-[12.5px] text-soft`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer select-none font-medium text-muted`,children:`Details`}),(0,H.jsxs)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1`,children:[(0,H.jsx)(`dt`,{children:`Tool`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.tool})}),(0,H.jsx)(`dt`,{children:`Asked by`}),(0,H.jsxs)(`dd`,{children:[e.actor,` `,(0,H.jsx)(`span`,{title:l(e.createdAt),children:y(e.createdAt,n)})]}),(0,H.jsx)(`dt`,{children:`Session`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.session})}),e.ruleId&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{children:`Rule`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.ruleId})})]}),(0,H.jsx)(`dt`,{children:`Request`}),(0,H.jsxs)(`dd`,{children:[(0,H.jsx)(`code`,{className:`mono break-all`,children:e.id}),`, expires `,l(e.expiresAt)]})]})]}),(0,H.jsxs)(`div`,{className:`mt-auto space-y-3 border-t border-faint pt-4`,children:[(0,H.jsx)(i,{label:`Note for the activity log`,optional:!0,children:(0,H.jsx)(p,{value:te,onChange:ne,placeholder:`Why you said yes or no`,disabled:Y})}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,onClick:()=>Z(`granted`),loading:w===`granted`,disabled:Y,children:`Approve`}),(0,H.jsx)(C,{variant:`secondary`,icon:`x`,onClick:()=>Z(`denied`),loading:w===`denied`,disabled:Y,children:`Say no`}),e.rememberAllowed&&!q&&(0,H.jsx)(C,{variant:`ghost`,icon:E?`chevron`:`chevron-right`,"aria-expanded":E,"aria-controls":`remember-${e.id}`,onClick:()=>D(e=>!e),disabled:Y,children:`Approve and don't ask again`})]}),q&&(0,H.jsxs)(`div`,{className:`space-y-2.5 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsx)(`p`,{className:`text-[13.5px] font-semibold`,children:`Approve and remember this tool as:`}),(0,H.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,H.jsx)(C,{size:`sm`,variant:`secondary`,onClick:()=>Z(`granted`,{classify:e}),loading:w===`classify-${e}`,disabled:Y,title:k[e].explain,children:k[e].label},e))}),(0,H.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,H.jsxs)(`div`,{id:`remember-${e.id}`,className:`space-y-4 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[14px] font-semibold`,children:[`Approve and don't ask again `,(0,H.jsx)(x,{term:`preApproval`})]}),(0,H.jsx)(i,{label:`For how long`,children:(0,H.jsx)(_,{value:O,onChange:A,label:`For how long`,max:J})}),(0,H.jsx)(i,{label:`Up to how many calls`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,H.jsx)(r,{value:I?null:M,onChange:re,min:1,step:1,unit:`calls`,disabled:I||Y,className:`w-40`}),(0,H.jsx)(j,{checked:I,onChange:oe,label:`No limit`,disabled:Y})]})}),(0,H.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.`}),R&&(0,H.jsx)(c,{tone:`danger`,title:`Nothing was approved`,role:`alert`,children:R}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,disabled:!le||Y,loading:w===`remember`,onClick:()=>Z(`granted`,{remember:{ttlSeconds:O,maxUses:I?null:M}}),children:`Approve and remember`}),(0,H.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 de(){let{serverId:e,tenant:r,nav:i,reload:o}=R(),l=ie(),u=I(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),b=i.query.get(`id`),x=b!==null&&(f.data??[]).some(e=>e.id===b),T=i.query.get(`tab`)===`history`||b!==null&&f.data!==null&&!x?`history`:`waiting`,k=e=>M(a(i,{tab:e===`waiting`?null:e})),j=(0,V.useMemo)(()=>[...f.data??[]].filter(e=>e.expiresAt>u).sort((e,t)=>e.createdAt-t.createdAt),[f.data,u]),N=(0,V.useMemo)(()=>(p.data??[]).filter(e=>e.state!==`pending`).sort((e,t)=>(t.decidedAt??t.expiresAt)-(e.decidedAt??e.expiresAt)),[p.data]),[P,F]=(0,V.useState)(!1),[se,B]=(0,V.useState)([]),ce=new Set(j.map(e=>e.id)),U=se.filter(e=>ce.has(e)),[W,G]=(0,V.useState)(null),[K,q]=(0,V.useState)(``),[J,Y]=(0,V.useState)(!1),[X,Z]=(0,V.useState)(null),Q=(0,V.useRef)(!1),de=(0,V.useRef)(null),fe=(0,V.useRef)(null);(0,V.useEffect)(()=>{Q.current&&f.data!==null&&(Q.current=!1,(de.current?.querySelector(`article h3[tabindex]`)??fe.current)?.focus())},[f.data]);let pe=()=>{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(L(e.message))}Y(!1),G(null),q(``),B([]),F(!1),pe();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,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(te,{title:`Waiting for you`,subtitle:`Your AI wanted to do these things. Nothing happens until you decide.`,actions:(0,H.jsx)(C,{variant:P?`primary`:`secondary`,icon:P?`x`:`list`,"aria-pressed":P,disabled:!P&&j.length<2,onClick:()=>{F(e=>!e),B([])},children:P?`Stop selecting`:`Select several`})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,H.jsx)(E,{tone:`hero`,title:`Waiting now`,loading:f.data===null&&!f.error,value:j.length,sub:ve?`Oldest asked ${y(ve.createdAt,u)}`:`Nothing needs you`}),(0,H.jsxs)(`div`,{className:`contents max-sm:hidden`,children:[(0,H.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,H.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,H.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[$&&$.pendingElsewhere>0&&(0,H.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,H.jsxs)(c,{tone:`ok`,title:`Pre-approval created`,role:`status`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{size:`sm`,variant:`secondary`,href:n(i,`/pre-approvals`,{grant:X.grant.id}),children:`Open pre-approval`}),(0,H.jsx)(ne,{icon:`x`,label:`Dismiss message`,size:32,onClick:()=>Z(null)})]}),children:[`Calls like this one to `,z(X.tool).label,` won't ask until `,ae(X.grant.expiresAt),X.grant.maxUses===null?``:`, for up to ${t(X.grant.maxUses,`call`)}`,`.`]})]}),(0,H.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center justify-between gap-3`,children:[(0,H.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,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Oldest first: the call at the top runs out soonest.`})]}),(0,H.jsx)(`div`,{role:`tabpanel`,id:ee(T),"aria-labelledby":d(T),className:`mt-5`,children:T===`waiting`?(0,H.jsxs)(H.Fragment,{children:[P&&j.length>0&&(0,H.jsx)(D,{className:`mb-5`,padded:!1,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-5 py-4`,children:[(0,H.jsxs)(`p`,{className:`min-w-0 flex-1 text-[14px]`,children:[(0,H.jsx)(`span`,{className:`tnum font-semibold`,children:U.length}),` of `,t(j.length,`call`),` selected`]}),(0,H.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>B(U.length===j.length?[]:j.map(e=>e.id)),children:U.length===j.length?`Clear selection`:`Select all`}),(0,H.jsx)(C,{size:`sm`,variant:`primary`,icon:`check`,disabled:U.length===0,onClick:()=>G(`granted`),children:`Approve all`}),(0,H.jsx)(C,{size:`sm`,variant:`secondary`,icon:`x`,disabled:U.length===0,onClick:()=>G(`denied`),children:`Deny all`})]})}),f.error&&(0,H.jsx)(`div`,{className:`mb-5`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load the calls waiting for you`,role:`alert`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:f.reload,children:`Try again`}),children:L(f.error)})}),f.data===null?!f.error&&(0,H.jsx)(`div`,{className:`grid gap-5 xl:grid-cols-2`,children:[0,1].map(e=>(0,H.jsxs)(D,{children:[(0,H.jsx)(s,{height:22,width:`45%`}),(0,H.jsx)(`div`,{className:`mt-5`,children:(0,H.jsx)(s,{lines:4})})]},e))}):j.length===0?(0,H.jsx)(D,{children:(0,H.jsx)(`div`,{ref:fe,tabIndex:-1,className:`outline-none`,children:(0,H.jsxs)(v,{icon:`inbox`,title:`Nothing is waiting for you.`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>k(`history`),children:`Show decided calls`}),(0,H.jsx)(S,{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,H.jsx)(`div`,{ref:de,className:`grid items-start gap-5 xl:grid-cols-2`,children:j.map(t=>(0,H.jsx)(`div`,{className:t.id===b?`rounded-[22px] ring-2 ring-[var(--focus)] ring-offset-2 ring-offset-[var(--bg)]`:void 0,children:(0,H.jsx)(le,{approval:t,meta:h.data,now:u,serverId:e,tenant:r,selecting:P,selected:P&&U.includes(t.id),onSelect:e=>B(n=>e?[...new Set([...n,t.id])]:n.filter(e=>e!==t.id)),locked:J,onDecided:()=>{Q.current=!0,pe()},onRemembered:(e,t)=>Z({grant:e,tool:t})})},t.id))})]}):(0,H.jsx)(me,{rows:N,error:p.error,loading:p.data===null,retry:p.reload,now:u,focusId:b})}),(0,H.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,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>G(null),disabled:J,children:`Go back`}),(0,H.jsx)(C,{variant:W===`granted`?`primary`:`danger`,loading:J,onClick:()=>W&&he(W),children:W===`granted`?`Approve all`:`Deny all`})]}),children:[(0,H.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,H.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.tool})]},e.id))}),(0,H.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 fe(t){return t.decidedBy?.startsWith(`standing-grant:`)?(0,H.jsx)(e,{tone:`ok`,icon:`key`,children:`Let through by a pre-approval`}):t.state===`granted`||t.state===`used`?(0,H.jsx)(e,{tone:`ok`,icon:`check`,children:`Approved`}):t.state===`denied`?(0,H.jsx)(e,{tone:`bad`,icon:`x`,children:`Denied`}):t.state===`expired`?(0,H.jsx)(e,{tone:`neutral`,icon:`clock`,children:`Expired`}):(0,H.jsx)(e,{children:t.state})}function pe(e){return e.decidedBy?e.decidedBy.startsWith(`standing-grant:`)?(0,H.jsxs)(`span`,{children:[`Pre-approval `,(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.decidedBy.slice(15)})]}):e.decidedBy:(0,H.jsx)(`span`,{className:`text-soft`,children:e.state===`expired`?`Nobody answered`:`Not recorded`})}function me({rows:e,error:t,loading:n,retry:r,now:i,focusId:a}){let o=[{key:`call`,header:`Call`,cell:e=>(0,H.jsxs)(`span`,{className:`block min-w-0`,children:[(0,H.jsx)(`span`,{className:`block font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.tool})]})},{key:`result`,header:`Result`,cell:fe},{key:`who`,header:`Decided by`,cell:pe},{key:`when`,header:`When`,cell:e=>{let t=e.decidedAt??e.expiresAt;return(0,H.jsx)(`span`,{title:l(t),children:y(t,i)})}},{key:`note`,header:`Note`,cell:e=>e.decisionNote?(0,H.jsx)(`span`,{className:`break-words`,children:e.decisionNote}):(0,H.jsx)(`span`,{className:`text-soft`,children:`None`}),hideOnMobile:!1}];return(0,H.jsxs)(D,{children:[t&&(0,H.jsx)(`div`,{className:`mb-4`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load decided calls`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:r,children:`Try again`}),children:L(t)})}),n?!t&&(0,H.jsx)(s,{lines:5,height:18}):(0,H.jsx)(f,{caption:`Calls decided earlier`,columns:o,rows:e,rowKey:e=>e.id,selectedKey:a,empty:(0,H.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{de as ApprovalsPage};