/** * 工作空间 - 合并 历史记录 / 提示词管理 / 用量统计 */ import { useState, type ReactNode } from 'react'; import { HistoryPanel } from './HistoryPanel'; import { usePrompts } from '../hooks/usePrompts'; import { PromptSidebar } from './PromptSidebar'; import { UsageDashboardContent } from './UsageDashboard'; import type { RoleType, SharedModuleType } from '../types/api'; import { useI18n } from '../i18n'; import { useModalTransition } from '../hooks/useModalTransition'; type WorkspaceModule = 'history' | 'prompts' | 'usage'; interface WorkspaceProps { isOpen: boolean; onClose: () => void; initialModule?: WorkspaceModule; onReusePrompt?: (prompt: string) => void; } export function Workspace({ isOpen, onClose, initialModule = 'history', onReusePrompt }: WorkspaceProps) { const { t } = useI18n(); const { shouldRender, isExiting } = useModalTransition(isOpen, 400); const [activeModule, setActiveModule] = useState(initialModule); const { isLoading: promptsLoading, selection, setSelection, getCurrentContent, setCurrentContent, restoreCurrent, hasOverride, } = usePrompts(); if (!shouldRender) return null; const breadcrumbMap: Record = { history: t('workspace.breadcrumb.history'), prompts: t('workspace.breadcrumb.prompts'), usage: t('workspace.breadcrumb.usage'), }; const railItems: { id: WorkspaceModule; label: string; icon: ReactNode }[] = [ { id: 'history', label: t('workspace.rail.history'), icon: ( ), }, { id: 'prompts', label: t('workspace.rail.prompts'), icon: ( ), }, { id: 'usage', label: t('workspace.rail.usage'), icon: ( ), }, ]; const getPromptTitle = () => { const roleLabels: Record = { problemFraming: t('prompts.role.problemFraming'), conceptDesigner: t('prompts.role.conceptDesigner'), codeGeneration: t('prompts.role.codeGeneration'), codeRetry: t('prompts.role.codeRetry'), codeEdit: t('prompts.role.codeEdit'), }; const sharedLabels: Record = { apiIndex: t('prompts.shared.apiIndex'), specification: t('prompts.shared.specification'), }; if (selection.kind === 'role') { const roleLabel = roleLabels[selection.role]; return selection.promptType === 'system' ? t('prompts.role.systemTitle', { role: roleLabel }) : t('prompts.role.userTitle', { role: roleLabel }); } return sharedLabels[selection.module]; }; const getPromptDescription = () => { if (selection.kind === 'role') { return selection.promptType === 'system' ? t('prompts.role.systemDescription') : t('prompts.role.userDescription'); } return selection.module === 'apiIndex' ? t('prompts.shared.apiIndexDescription') : t('prompts.shared.specificationDescription'); }; const promptContent = getCurrentContent(); const isModified = hasOverride(); return (
{/* 顶栏 */}
{t('workspace.title')}
{activeModule === 'prompts' && isModified && (
{t('prompts.modified')}
)}
Workspace / {breadcrumbMap[activeModule]}
{/* 核心交互区 */}
{/* 左侧 Rail 导航 */} {/* 模块展示区 */}
{activeModule === 'history' && (
)} {activeModule === 'prompts' && (

{getPromptTitle()}

{getPromptDescription()}

{promptsLoading ? (
{t('common.loading')}
) : (