"use client" import { useMemo } from "react" import { useTranslations } from "next-intl" import { ShieldAlert, Terminal, ListTodo, Compass, FileText, Globe, Search, } from "lucide-react" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { CodeBlock } from "@/components/ai-elements/code-block" import { UnifiedDiffPreview } from "@/components/diff/unified-diff-preview" import { MessageResponse } from "@/components/ai-elements/message" import type { PendingPermission } from "@/contexts/acp-connections-context" import { parsePermissionToolCall } from "@/lib/permission-request" interface PermissionDialogProps { permission: PendingPermission | null onRespond: (requestId: string, optionId: string) => void } function formatKindLabel(kind: string, fallbackLabel: string): string { const normalized = kind.replace(/_/g, " ").trim() return normalized.length > 0 ? normalized : fallbackLabel } export function PermissionDialog({ permission, onRespond, }: PermissionDialogProps) { const t = useTranslations("Folder.chat.permissionDialog") const parsed = useMemo( () => parsePermissionToolCall(permission?.tool_call), [permission?.tool_call] ) if (!permission) return null const hasFileChanges = parsed.fileChanges.length > 0 const hasPlan = parsed.planEntries.length > 0 || Boolean(parsed.planExplanation) const hasPlanMarkdown = Boolean(parsed.planMarkdown) const hasAllowedPrompts = parsed.allowedPrompts.length > 0 const hasWeb = Boolean(parsed.url) || Boolean(parsed.query) const hasStructured = Boolean(parsed.command) || hasFileChanges || hasPlan || hasPlanMarkdown || hasAllowedPrompts || Boolean(parsed.modeTarget) || hasWeb return (
{parsed.title}

{t("subtitle")}

{formatKindLabel(parsed.normalizedKind, t("kindFallbackTool"))}
{parsed.command && (
{t("command")}
{parsed.cwd && (
{t("cwd", { cwd: parsed.cwd })}
)}
)} {hasFileChanges && parsed.diffPreview && ( )} {hasPlan && (
{t("plan")}
{parsed.planExplanation && (

{parsed.planExplanation}

)} {parsed.planEntries.length > 0 && (
{parsed.planEntries.map((entry, index) => (
{entry.text} {entry.status && ( ({entry.status}) )}
))}
)}
)} {hasPlanMarkdown && (
{t("plan")}
{parsed.planMarkdown!}
)} {hasAllowedPrompts && (
{t("allowedActions")}
{parsed.allowedPrompts.map((item, index) => (
{item.tool && ( {item.tool} )} {item.prompt}
))}
)} {parsed.modeTarget && (
{t("targetMode", { mode: parsed.modeTarget })}
)} {hasWeb && (
{parsed.url && (
{parsed.url}
)} {parsed.query && (
{parsed.query}
)} {parsed.prompt && (
{parsed.prompt}
)}
)} {!hasStructured && (
            {parsed.jsonPreview}
          
)}
{permission.options.map((opt) => { const isReject = opt.kind.startsWith("reject") return ( ) })}
) }