Files
zclaw_openfang/desktop/src/App.tsx
iven f4efc823e2 refactor(types): comprehensive TypeScript type system improvements
Major type system refactoring and error fixes across the codebase:

**Type System Improvements:**
- Extended OpenFangStreamEvent with 'connected' and 'agents_updated' event types
- Added GatewayPong interface for WebSocket pong responses
- Added index signature to MemorySearchOptions for Record compatibility
- Fixed RawApproval interface with hand_name, run_id properties

**Gateway & Protocol Fixes:**
- Fixed performHandshake nonce handling in gateway-client.ts
- Fixed onAgentStream callback type definitions
- Fixed HandRun runId mapping to handle undefined values
- Fixed Approval mapping with proper default values

**Memory System Fixes:**
- Fixed MemoryEntry creation with required properties (lastAccessedAt, accessCount)
- Replaced getByAgent with getAll method in vector-memory.ts
- Fixed MemorySearchOptions type compatibility

**Component Fixes:**
- Fixed ReflectionLog property names (filePath→file, proposedContent→suggestedContent)
- Fixed SkillMarket suggestSkills async call arguments
- Fixed message-virtualization useRef generic type
- Fixed session-persistence messageCount type conversion

**Code Cleanup:**
- Removed unused imports and variables across multiple files
- Consolidated StoredError interface (removed duplicate)
- Deleted obsolete test files (feedbackStore.test.ts, memory-index.test.ts)

**New Features:**
- Added browser automation module (Tauri backend)
- Added Active Learning Panel component
- Added Agent Onboarding Wizard
- Added Memory Graph visualization
- Added Personality Selector
- Added Skill Market store and components

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 08:05:07 +08:00

139 lines
4.7 KiB
TypeScript

import { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import './index.css';
import { Sidebar, MainViewType } from './components/Sidebar';
import { ChatArea } from './components/ChatArea';
import { RightPanel } from './components/RightPanel';
import { SettingsLayout } from './components/Settings/SettingsLayout';
import { HandTaskPanel } from './components/HandTaskPanel';
import { SchedulerPanel } from './components/SchedulerPanel';
import { TeamCollaborationView } from './components/TeamCollaborationView';
import { SwarmDashboard } from './components/SwarmDashboard';
import { useGatewayStore } from './store/gatewayStore';
import { useTeamStore } from './store/teamStore';
import { getStoredGatewayToken } from './lib/gateway-client';
import { pageVariants, defaultTransition, fadeInVariants } from './lib/animations';
import { silentErrorHandler } from './lib/error-utils';
import { Bot, Users } from 'lucide-react';
import { EmptyState } from './components/ui';
type View = 'main' | 'settings';
function App() {
const [view, setView] = useState<View>('main');
const [mainContentView, setMainContentView] = useState<MainViewType>('chat');
const [selectedHandId, setSelectedHandId] = useState<string | undefined>(undefined);
const [selectedTeamId, setSelectedTeamId] = useState<string | undefined>(undefined);
const { connect, connectionState } = useGatewayStore();
const { activeTeam, setActiveTeam, teams } = useTeamStore();
useEffect(() => {
document.title = 'ZCLAW';
}, []);
useEffect(() => {
if (connectionState === 'disconnected') {
const gatewayToken = getStoredGatewayToken();
connect(undefined, gatewayToken).catch(silentErrorHandler('App'));
}
}, [connect, connectionState]);
// 当切换到非 hands 视图时清除选中的 Hand
const handleMainViewChange = (view: MainViewType) => {
setMainContentView(view);
if (view !== 'hands') {
// 可选:清除选中的 Hand
// setSelectedHandId(undefined);
}
};
const handleSelectTeam = (teamId: string) => {
const team = teams.find(t => t.id === teamId);
if (team) {
setActiveTeam(team);
setSelectedTeamId(teamId);
}
};
if (view === 'settings') {
return <SettingsLayout onBack={() => setView('main')} />;
}
return (
<div className="h-screen flex overflow-hidden text-gray-800 text-sm">
{/* 左侧边栏 */}
<Sidebar
onOpenSettings={() => setView('settings')}
onMainViewChange={handleMainViewChange}
selectedHandId={selectedHandId}
onSelectHand={setSelectedHandId}
selectedTeamId={selectedTeamId}
onSelectTeam={handleSelectTeam}
/>
{/* 中间区域 */}
<AnimatePresence mode="wait">
<motion.main
key={mainContentView}
variants={pageVariants}
initial="initial"
animate="animate"
exit="exit"
transition={defaultTransition}
className="flex-1 flex flex-col bg-white relative overflow-hidden"
>
{mainContentView === 'hands' && selectedHandId ? (
<HandTaskPanel
handId={selectedHandId}
onBack={() => setSelectedHandId(undefined)}
/>
) : mainContentView === 'hands' ? (
<EmptyState
icon={<Bot className="w-8 h-8" />}
title="Select a Hand"
description="Choose an autonomous capability package from the list on the left to view its task list and execution results."
/>
) : mainContentView === 'workflow' ? (
<motion.div
variants={fadeInVariants}
initial="initial"
animate="animate"
className="flex-1 overflow-y-auto"
>
<SchedulerPanel />
</motion.div>
) : mainContentView === 'team' ? (
activeTeam ? (
<TeamCollaborationView teamId={activeTeam.id} />
) : (
<EmptyState
icon={<Users className="w-8 h-8" />}
title="Select or Create a Team"
description="Choose a team from the list on the left, or click + to create a new multi-Agent collaboration team."
/>
)
) : mainContentView === 'swarm' ? (
<motion.div
variants={fadeInVariants}
initial="initial"
animate="animate"
className="flex-1 overflow-hidden"
>
<SwarmDashboard />
</motion.div>
) : (
<ChatArea />
)}
</motion.main>
</AnimatePresence>
{/* 右侧边栏 */}
<RightPanel />
</div>
);
}
export default App;