import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { ChevronDown, ChevronRight } from "lucide-react"; import ReactJsonView from "@microlink/react-json-view"; import { BaseModalTitle } from "#/components/shared/modals/confirmation-modals/base-modal"; import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop"; import { ModalBody } from "#/components/shared/modals/modal-body"; import { cn } from "#/utils/utils"; import { JSON_VIEW_THEME } from "#/utils/constants"; interface SystemMessageModalProps { isOpen: boolean; onClose: () => void; systemMessage: { content: string; tools: Array> | null; openhands_version: string | null; agent_class: string | null; } | null; } interface FunctionData { name?: string; description?: string; parameters?: Record; } interface ToolData { type?: string; function?: FunctionData; name?: string; description?: string; parameters?: Record; } export function SystemMessageModal({ isOpen, onClose, systemMessage, }: SystemMessageModalProps) { const { t } = useTranslation(); const [activeTab, setActiveTab] = useState<"system" | "tools">("system"); const [expandedTools, setExpandedTools] = useState>( {}, ); if (!systemMessage) { return null; } const toggleTool = (index: number) => { setExpandedTools((prev) => ({ ...prev, [index]: !prev[index], })); }; return ( isOpen && (
{systemMessage.agent_class && (
{t("SYSTEM_MESSAGE_MODAL$AGENT_CLASS")} {" "} {systemMessage.agent_class}
)} {systemMessage.openhands_version && (
{t("SYSTEM_MESSAGE_MODAL$OPENHANDS_VERSION")} {" "} {systemMessage.openhands_version}
)}
{systemMessage.tools && systemMessage.tools.length > 0 && ( )}
{activeTab === "system" && (
{systemMessage.content}
)} {activeTab === "tools" && systemMessage.tools && systemMessage.tools.length > 0 && (
{systemMessage.tools.map((tool, index) => { // Extract function data from the nested structure const toolData = tool as ToolData; const functionData = toolData.function || toolData; const name = functionData.name || (toolData.type === "function" && toolData.function?.name) || ""; const description = functionData.description || (toolData.type === "function" && toolData.function?.description) || ""; const parameters = functionData.parameters || (toolData.type === "function" && toolData.function?.parameters) || null; const isExpanded = expandedTools[index] || false; return (
{isExpanded && (

{String(description)}

{/* Parameters section */} {parameters && (

{t("SYSTEM_MESSAGE_MODAL$PARAMETERS")}

)}
)}
); })}
)} {activeTab === "tools" && (!systemMessage.tools || systemMessage.tools.length === 0) && (

{t("SYSTEM_MESSAGE_MODAL$NO_TOOLS")}

)}
) ); }