import { useEffect, useState } from "react"; import { api, get } from "../api"; import { useT } from "../i18n"; import { toast } from "../dialogs"; import { Icon } from "./Icon"; /** "bash:git status" → "git status"; tool names stay. */ const label = (key: string) => (key.startsWith("bash:") ? `$ ${key.slice(5)}` : key); /** What the user allowed "for this project" (all chats of the folder) – with a way to revoke it. */ export function ProjectPermissions({ sessionId, cwd, onClose }: { sessionId: string; cwd: string; onClose: () => void }) { const t = useT(); const [keys, setKeys] = useState(); useEffect(() => { get(`/sessions/${sessionId}/approvals`).then(setKeys, (e) => (toast(e.message), setKeys([]))); }, [sessionId]); const revoke = async (key: string) => { try { await api(`/sessions/${sessionId}/approvals`, { method: "DELETE", json: { key } }); setKeys((k) => k?.filter((x) => x !== key)); } catch (e: any) { toast(e.message); } }; return (
e.stopPropagation()}>

{t("permProject.title")}

{t("permProject.intro")}

{cwd}
{keys === undefined ? (
…
) : keys.length === 0 ? (

{t("permProject.empty")}

) : (
    {keys.map((k) => (
  • {label(k)}
  • ))}
)}
); }