"use client"; import { useState } from "react"; import type { ToolCallMessagePartProps } from "@assistant-ui/react"; import { ActionBarPrimitive, ComposerPrimitive, ErrorPrimitive, MessagePartPrimitive, MessagePrimitive, ThreadListItemPrimitive, ThreadListPrimitive, ThreadPrimitive, useAuiState, } from "@assistant-ui/react"; import { ActionIcon, Box, Button, Drawer, Group, ScrollArea, Stack, Text, ThemeIcon, Tooltip } from "@mantine/core"; import { useMediaQuery } from "@mantine/hooks"; import { IconActivityHeartbeat, IconAlertTriangle, IconApps, IconArchive, IconArrowUp, IconCheck, IconCopy, IconCommand, IconMenu2, IconHistory, IconPlayerStop, IconPlus, IconRefresh, IconRestore, IconRobot, IconSearch, IconTrash, IconX, } from "@tabler/icons-react"; import { useScopedI18n } from "@homarr/translation/client"; import classes from "./assistant-panel.module.css"; interface AssistantPanelProps { opened: boolean; onClose: () => void; } const TextPart = () => ; const ToolPart = ({ toolName, args, result, isError, status, approval, respondToApproval, }: ToolCallMessagePartProps) => { const t = useScopedI18n("common.assistant"); const completed = status?.type === "complete"; const awaitingApproval = approval !== undefined && approval.approved === undefined && !approval.resolution; const denied = approval?.approved === false; const failed = !denied && (isError === true || status?.type === "incomplete" || (typeof result === "object" && result !== null && "error" in result)); const successful = completed && !denied && !failed; return ( {denied || failed ? : successful ? : } {toolName.replaceAll("_", " ")} {awaitingApproval ? t("approvalRequired") : denied ? t("denied") : failed ? t("failed") : successful ? t("complete") : t("working")} {awaitingApproval && ( {t("approvalDescription")} {JSON.stringify(args)} respondToApproval({ approved: true })}> {t("allowOnce")} respondToApproval({ approved: false })}> {t("deny")} )} {!awaitingApproval && !denied && result !== undefined && ( {typeof result === "string" ? result : JSON.stringify(result)} )} ); }; const MessageActions = () => { const t = useScopedI18n("common.assistant"); return ( ); }; const UserMessage = () => ( ); const RuntimeError = () => { const t = useScopedI18n("common.assistant"); return ( {t("responseError.title")} } > {t("responseError.retry")} ); }; const AssistantMessage = () => ( ); const ThreadListItem = () => { const t = useScopedI18n("common.assistant"); return ( ); }; const ArchivedThreadListItem = () => { const t = useScopedI18n("common.assistant"); return ( ); }; const ThreadHistory = ({ opened, onClose }: { opened: boolean; onClose: () => void }) => { const t = useScopedI18n("common.assistant"); const isMobile = useMediaQuery("(max-width: 48em)"); const hidden = isMobile && !opened; return ( } fullWidth onClick={onClose}> {t("newConversation")} {t("conversations")} {t("archived")} ); }; const EmptyThread = () => { const t = useScopedI18n("common.assistant"); return ( {t("emptyTitle")} {t("emptyDescription")} } > {t("suggestions.health.label")} }> {t("suggestions.explore.label")} }> {t("suggestions.media.label")} }> {t("suggestions.command.label")} ); }; const Composer = () => { const t = useScopedI18n("common.assistant"); const running = useAuiState((state) => state.thread.isRunning); return ( {running ? ( ) : ( )} ); }; export const AssistantPanel = ({ opened, onClose }: AssistantPanelProps) => { const t = useScopedI18n("common.assistant"); const [historyOpened, setHistoryOpened] = useState(false); return ( {t("title")} {t("subtitle")} } closeButtonProps={{ icon: , "aria-label": t("close") }} > setHistoryOpened(false)} /> setHistoryOpened(true)} aria-label={t("openHistory")} > ); };