60 lines · 3.3 KBRaw
| 1 | import { AgentAvatar, Ago, Button, cn } from "@refs/design-system"; |
| 2 | import { useFetcher } from "react-router"; |
| 3 | import type { PermissionRequest } from "@refs/backend/contract"; |
| 4 | |
| 5 | import { Link } from "react-router"; |
| 6 | |
| 7 | type Request = PermissionRequest & { readonly repo?: string }; |
| 8 | |
| 9 | /** Tool approvals: the one place amber appears. The amber ring and dot show only when the viewer can decide. */ |
| 10 | export function PermissionRequests({ requests, now }: { requests: readonly Request[]; now: number }) { |
| 11 | if (!requests.length) return null; |
| 12 | return ( |
| 13 | <section className="flex min-w-0 flex-col gap-3 [overflow-wrap:anywhere]" aria-label="Agents waiting for approval"> |
| 14 | {requests.map((request) => ( |
| 15 | <div key={`${request.session}:${request.requestId}`} className={cn("flex min-w-0 flex-col gap-3 rounded-panel bg-panel p-4 shadow-card", request.canDecide && "shadow-[0_0_0_1px_color-mix(in_oklab,var(--needs)_65%,transparent),0_0_0_4px_var(--needs-tint)]")}> |
| 16 | <div className="flex min-w-0 items-start gap-2.5"> |
| 17 | <AgentAvatar name={request.agent} size="sm" /> |
| 18 | <p className="m-0 min-w-0 flex-1 text-compact leading-snug text-muted"> |
| 19 | <span className="font-medium text-ink">{request.agent}</span> wants to use <code className="font-mono text-xs text-ink">{request.tool}</code> |
| 20 | <span className="block text-xs text-faint"> |
| 21 | <Ago at={request.at} now={now} /> |
| 22 | {request.repo && ( |
| 23 | <> |
| 24 | {" · "} |
| 25 | <Link to={`/${request.repo}`} className="hover:text-accent-text"> |
| 26 | {request.repo} |
| 27 | </Link> |
| 28 | </> |
| 29 | )} |
| 30 | </span> |
| 31 | </p> |
| 32 | {request.canDecide && <span aria-label="Needs your answer" role="img" className="needs-pulse mt-1.5 size-2 shrink-0 rounded-full bg-needs" />} |
| 33 | </div> |
| 34 | {request.description && <p className="m-0 text-compact text-ink">{request.description}</p>} |
| 35 | {request.preview && <pre className="m-0 max-h-48 min-w-0 overflow-auto rounded-control bg-sunken p-3 font-mono text-xs whitespace-pre-wrap shadow-[inset_0_0_0_1px_var(--hairline)] text-muted [overflow-wrap:anywhere]">{request.preview}</pre>} |
| 36 | {request.canDecide ? <Decide request={request} /> : <p className="m-0 text-compact text-muted">Waiting for the agent's human to answer.</p>} |
| 37 | </div> |
| 38 | ))} |
| 39 | </section> |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | function Decide({ request }: { request: Request }) { |
| 44 | const fetcher = useFetcher(); |
| 45 | const deciding = fetcher.formData?.get("behavior"); |
| 46 | return ( |
| 47 | <fetcher.Form method="post" className="flex flex-wrap gap-2"> |
| 48 | <input type="hidden" name="intent" value="permission" /> |
| 49 | <input type="hidden" name="session" value={request.session} /> |
| 50 | <input type="hidden" name="request" value={request.requestId} /> |
| 51 | {request.repo && <input type="hidden" name="repo" value={request.repo} />} |
| 52 | <Button type="submit" name="behavior" value="allow" variant="primary" loading={deciding === "allow"} disabled={deciding !== undefined}> |
| 53 | Allow |
| 54 | </Button> |
| 55 | <Button type="submit" name="behavior" value="deny" variant="secondary" loading={deciding === "deny"} disabled={deciding !== undefined}> |
| 56 | Deny |
| 57 | </Button> |
| 58 | </fetcher.Form> |
| 59 | ); |
| 60 | } |