import { CheckIcon, InfoIcon, ShieldCheckIcon, XIcon } from "lucide-react"; import { Dialog } from "radix-ui"; import { containedPortal } from "../ui/portal-container"; import { useRef, useState, type ReactNode, type RefObject } from "react"; import { usePortalTokenStyle } from "../lib/use-portal-token-style"; import { useOpenGeniText } from "../messages/runtime"; const DialogContainedPortal = containedPortal(Dialog.Portal); export type SessionCapabilityFrameProps = { name: string; subtitle: string; logo: string | null; /** A short kind label for the setup dialog's subtitle; the card itself shows none. */ typeLabel: string; /** * A quiet label beside the name, only where it tells a person what they are * trusting (a server someone added by hand). Reviewed services show none. */ badge?: string | undefined; description: string; /** * The description is the agent's reason for asking: keep it to two lines so * a long rationale never pushes the action down. State and guidance copy * stays whole. */ clampDescription?: boolean | undefined; skill: boolean; expanded: boolean; complete: boolean; /** Completion copy must reflect the provider's actual scope of access. */ completeLabel?: string | undefined; actionLabel: string; /** Direct navigation actions should not announce a dialog on the card. */ opensDialog?: boolean; note: string; onOpen(): void; onClose(): void; busy?: boolean; opener?: RefObject; cardRef?: RefObject; children?: ReactNode; /** A catalogue row can own the opener while reusing the same details dialog. */ dialogOnly?: boolean; /** * Replaces the action when the viewer cannot start setup here (the provider * is not configured, or someone else must connect it). Say why and who can. */ actionUnavailable?: ReactNode; /** Host-owned content inside the card, under its status or actions. */ details?: ReactNode; /** Protected setup can stay in the conversation instead of opening a dialog. */ inlineSetup?: ReactNode; }; function Mark({ src, name }: { src: string | null; name: string }) { const [failed, setFailed] = useState(null); return ( {src && failed !== src ? ( setFailed(src)} /> ) : ( name.trim().slice(0, 2).toUpperCase() )} ); } /** The same conversation card in the console and embedded clients. Setup * content owns the provider flow; this frame owns identity and protected focus. */ export function SessionCapabilityFrame({ name, subtitle, logo, typeLabel, badge, description, clampDescription = false, skill, expanded, complete, completeLabel, actionLabel, opensDialog = true, note, onOpen, onClose, busy = false, opener, cardRef, children, dialogOnly = false, actionUnavailable, details, inlineSetup, }: SessionCapabilityFrameProps) { const t = useOpenGeniText(); const localOpener = useRef(null); const localCard = useRef(null); const buttonRef = opener ?? localOpener; const sectionRef = cardRef ?? localCard; const portalStyle = usePortalTokenStyle(sectionRef.current); // A row without a better name is titled by its domain; never say it twice. const shownSubtitle = subtitle.trim().toLowerCase() === name.trim().toLowerCase() ? "" : subtitle; const identity = ( <>

{name}

{shownSubtitle ? {shownSubtitle} : null}
{badge ? {badge} : null} ); return (
{!complete && !dialogOnly && note ? (

{note}

) : null} { if (!open && !busy) onClose(); }} > { if (busy) event.preventDefault(); }} onInteractOutside={(event) => { if (busy) event.preventDefault(); }} onCloseAutoFocus={(event) => { event.preventDefault(); const target = buttonRef.current?.isConnected ? buttonRef.current : sectionRef.current; // Keep the view where the conversation is; focus alone must not scroll. if (target?.isConnected) target.focus({ preventScroll: true }); }} >
{name} {[typeLabel, shownSubtitle].filter(Boolean).join(" ยท ")}
{!busy ? ( ) : null}
{children}
); }