import React, { type Dispatch, type SetStateAction } from 'react'; import { History, Plus } from 'lucide-react'; import type { AIPermissionMode, AISession, ChatMessage, DiscoveredAgent, ExternalAgentConfig, AgentModelPreset, ProviderConfig, UploadedFile } from '../infrastructure/ai/types'; import type { UserSkillOption } from './ai/userSkillsState'; import { Button } from './ui/button'; import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'; import AgentSelector from './ai/AgentSelector'; import ChatInput from './ai/ChatInput'; import ChatMessageList from './ai/ChatMessageList'; import ConversationExport from './ai/ConversationExport'; import { SessionHistoryDrawer, formatRelativeTime } from './AIChatSessionHistoryDrawer'; type Translate = (key: string) => string; type ExportFormat = 'md' | 'json' | 'txt'; type TerminalSessionSummary = { sessionId: string; hostname: string; label: string; connected: boolean; }; interface AIChatPanelContentProps { t: Translate; currentAgentId: string; externalAgents: ExternalAgentConfig[]; discoveredAgents: DiscoveredAgent[]; isDiscovering: boolean; handleAgentChange: (agentId: string) => void; handleEnableDiscoveredAgent: (agent: DiscoveredAgent) => void; rediscover: () => void; handleOpenSettings: () => void; activeSession: AISession | null; handleExport: (format: ExportFormat) => void; showHistory: boolean; setShowHistory: Dispatch>; handleNewChat: () => void; historySessions: AISession[]; activeSessionId: string | null; handleSelectSession: (sessionId: string) => void; handleDeleteSession: (event: React.MouseEvent, sessionId: string) => void; messages: ChatMessage[]; isStreaming: boolean; inputValue: string; setInputValue: (value: string) => void; handleSend: () => void; handleStop: () => void; canSendCurrentAgent: boolean; providerDisplayName?: string; modelDisplayName?: string; agentModelPresets: AgentModelPreset[]; selectedAgentModel: string; handleAgentModelSelect: (modelId: string) => void; cattyConfiguredProviders: ProviderConfig[]; effectiveActiveProvider?: ProviderConfig; effectiveActiveModelId?: string; handleAgentProviderModelSelect: (providerId: string, modelId: string) => void; files: UploadedFile[]; addFiles: (inputFiles: File[]) => Promise; removeFile: (fileId: string) => void; terminalSessions: TerminalSessionSummary[]; selectedUserSkills: UserSkillOption[]; userSkillOptions: UserSkillOption[]; addSelectedUserSkill: (slug: string) => void; removeSelectedUserSkill: (slug: string) => void; globalPermissionMode: AIPermissionMode; setGlobalPermissionMode?: (mode: AIPermissionMode) => void; } export const AIChatPanelContent: React.FC = ({ t, currentAgentId, externalAgents, discoveredAgents, isDiscovering, handleAgentChange, handleEnableDiscoveredAgent, rediscover, handleOpenSettings, activeSession, handleExport, showHistory, setShowHistory, handleNewChat, historySessions, activeSessionId, handleSelectSession, handleDeleteSession, messages, isStreaming, inputValue, setInputValue, handleSend, handleStop, canSendCurrentAgent, providerDisplayName, modelDisplayName, agentModelPresets, selectedAgentModel, handleAgentModelSelect, cattyConfiguredProviders, effectiveActiveProvider, effectiveActiveModelId, handleAgentProviderModelSelect, files, addFiles, removeFile, terminalSessions, selectedUserSkills, userSkillOptions, addSelectedUserSkill, removeSelectedUserSkill, globalPermissionMode, setGlobalPermissionMode }) => (
{/* ── Header ── */}
{t('ai.chat.sessionHistory')} {t('ai.chat.newChat')}
{/* ── Main content ── */} {showHistory ? ( setShowHistory(false)} /> ) : ( <> {/* Chat messages */} {/* Recent sessions (Zed-style, shown when no messages) */} {messages.length === 0 && historySessions.length > 0 && (
{t('ai.chat.recent')}
{historySessions.slice(0, 3).map((session) => ( ))}
)} {/* Input area */} a.id === currentAgentId)?.name} modelPresets={agentModelPresets} selectedModelId={selectedAgentModel} onModelSelect={handleAgentModelSelect} providerSwitcher={ currentAgentId === 'catty' && cattyConfiguredProviders.length > 0 ? { providers: cattyConfiguredProviders, selectedProviderId: effectiveActiveProvider?.id, selectedModelId: effectiveActiveModelId || undefined, onSelect: handleAgentProviderModelSelect, } : undefined } files={files} onAddFiles={addFiles} onRemoveFile={removeFile} hosts={terminalSessions.map(s => ({ sessionId: s.sessionId, hostname: s.hostname, label: s.label, connected: s.connected }))} selectedUserSkills={selectedUserSkills} userSkills={userSkillOptions} onAddUserSkill={addSelectedUserSkill} onRemoveUserSkill={removeSelectedUserSkill} permissionMode={globalPermissionMode} onPermissionModeChange={setGlobalPermissionMode} /> )}
);