"use client"; import { PlugIcon, RefreshCwIcon, ShieldAlertIcon } from "lucide-react"; import { useState, type FormEvent, type ReactNode } from "react"; import { toast } from "sonner"; import { EmptyState, ErrorState, PageHeader } from "@/components/shell/page"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Skeleton } from "@/components/ui/skeleton"; import { Switch } from "@/components/ui/switch"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import { api, ApiError } from "@/lib/api"; import { useAuth } from "@/lib/auth"; import { useI18n } from "@/lib/i18n"; import { useApi } from "@/lib/use-api"; import { cn } from "@/lib/utils"; import type { Connector, GatewayOutcomeOut, ImportReport, McpChange, McpConnection, TenantTool, ToolMode, } from "./types"; const TIER_STYLE = [ "bg-success-soft text-success", "bg-muted text-foreground", "bg-warning-soft text-warning", "bg-destructive/10 text-destructive", ]; export function TierBadge({ tier, testId }: { tier: number; testId?: string }) { return ( T{tier} ); } function errText(err: unknown, fallback: string): string { if (err instanceof ApiError) { const d = (err.body as { detail?: unknown } | undefined)?.detail; if (d && typeof d === "object" && "message" in d) return String((d as { message: string }).message); return err.detail; } return fallback; } function Field({ label, hint, children }: { label: string; hint?: string; children: ReactNode }) { return (
{hint &&

{hint}

}
); } // ---------------------------------------------------------------------------- tools function ToolRow({ tool, owner, onChanged }: { tool: TenantTool; owner: boolean; onChanged: () => void }) { const { t } = useI18n(); const [tier, setTier] = useState(tool.confirmed_tier ?? tool.suggested_tier); const [mode, setMode] = useState(tool.mode === "live" ? "live" : "test"); const [ack, setAck] = useState(false); const [busy, setBusy] = useState(false); const [argsText, setArgsText] = useState("{}"); const [preview, setPreview] = useState(null); const confirm = async () => { setBusy(true); try { await api(`/ext/tools/${encodeURIComponent(tool.name)}/confirm`, { method: "POST", body: { tier, mode, acknowledge_risk: ack }, }); toast.success(t("integrations.confirmed")); onChanged(); } catch (err) { toast.error(errText(err, t("common.error"))); } finally { setBusy(false); } }; const toggle = async (enabled: boolean) => { try { await api(`/ext/tools/${encodeURIComponent(tool.name)}/settings`, { method: "POST", body: { enabled } }); onChanged(); } catch (err) { toast.error(errText(err, t("common.error"))); } }; const dryRun = async () => { let args: unknown; try { args = JSON.parse(argsText); } catch { toast.error(t("integrations.invalidJson")); return; } try { setPreview( await api(`/ext/tools/${encodeURIComponent(tool.name)}/test`, { method: "POST", body: { args }, }), ); } catch (err) { toast.error(errText(err, t("common.error"))); } }; return (
  • {tool.name}

    {tool.description}

    {tool.source} {t("integrations.suggested")} {t("integrations.tier")} {tool.mode === "live" ? t("integrations.live") : t("integrations.test")} {tool.confirmed_tier === null && {t("integrations.unconfirmed")}}
    {tool.blocked_reason && (

    {tool.pending ? t("integrations.changed") : tool.blocked_reason}

    )} {tool.pending && (

    {t("integrations.before")}

    {tool.description}

    {t("integrations.after")}

    {tool.pending.description}

    )}
    {owner && ( <> {tier < tool.suggested_tier && ( )} )}
    {t("integrations.tryIt")}