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>
This commit is contained in:
iven
2026-03-17 08:05:07 +08:00
parent adfd7024df
commit f4efc823e2
80 changed files with 9496 additions and 1390 deletions

View File

@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { useGatewayStore } from '../../store/gatewayStore';
import { useChatStore } from '../../store/chatStore';
import { getStoredGatewayToken, setStoredGatewayToken } from '../../lib/gateway-client';
import { silentErrorHandler } from '../../lib/error-utils';
export function General() {
const { connectionState, gatewayVersion, error, connect, disconnect, quickConfig, saveQuickConfig } = useGatewayStore();
@@ -68,7 +69,7 @@ export function General() {
};
const handleConnect = () => {
connect(undefined, gatewayToken || undefined).catch(() => {});
connect(undefined, gatewayToken || undefined).catch(silentErrorHandler('General'));
};
const handleDisconnect = () => { disconnect(); };

View File

@@ -1,5 +1,6 @@
import { FileText, Globe } from 'lucide-react';
import { useGatewayStore } from '../../store/gatewayStore';
import { silentErrorHandler } from '../../lib/error-utils';
export function MCPServices() {
const { quickConfig, saveQuickConfig } = useGatewayStore();
@@ -40,7 +41,7 @@ export function MCPServices() {
{svc.enabled ? '已启用' : '已停用'}
</span>
<button
onClick={() => { toggleService(svc.id).catch(() => {}); }}
onClick={() => { toggleService(svc.id).catch(silentErrorHandler('MCPServices')); }}
className="text-xs px-3 py-1.5 border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors"
>
{svc.enabled ? '停用' : '启用'}

View File

@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { getStoredGatewayToken, getStoredGatewayUrl } from '../../lib/gateway-client';
import { useGatewayStore } from '../../store/gatewayStore';
import { useChatStore } from '../../store/chatStore';
import { silentErrorHandler } from '../../lib/error-utils';
// Helper function to format context window size
function formatContextWindow(tokens?: number): string {
@@ -41,14 +42,14 @@ export function ModelsAPI() {
setTimeout(() => connect(
gatewayUrl || quickConfig.gatewayUrl || 'ws://127.0.0.1:50051/ws',
gatewayToken || quickConfig.gatewayToken || getStoredGatewayToken()
).catch(() => {}), 500);
).catch(silentErrorHandler('ModelsAPI')), 500);
};
const handleSaveGatewaySettings = () => {
saveQuickConfig({
gatewayUrl,
gatewayToken,
}).catch(() => {});
}).catch(silentErrorHandler('ModelsAPI'));
};
const handleRefreshModels = () => {
@@ -222,14 +223,14 @@ export function ModelsAPI() {
type="text"
value={gatewayUrl}
onChange={(e) => setGatewayUrl(e.target.value)}
onBlur={() => { saveQuickConfig({ gatewayUrl }).catch(() => {}); }}
onBlur={() => { saveQuickConfig({ gatewayUrl }).catch(silentErrorHandler('ModelsAPI')); }}
className="w-full bg-transparent border-none outline-none"
/>
<input
type="password"
value={gatewayToken}
onChange={(e) => setGatewayToken(e.target.value)}
onBlur={() => { saveQuickConfig({ gatewayToken }).catch(() => {}); }}
onBlur={() => { saveQuickConfig({ gatewayToken }).catch(silentErrorHandler('ModelsAPI')); }}
placeholder="Gateway auth token"
className="w-full bg-transparent border-none outline-none"
/>

View File

@@ -1,12 +1,13 @@
import { useEffect } from 'react';
import { ExternalLink } from 'lucide-react';
import { useGatewayStore } from '../../store/gatewayStore';
import { silentErrorHandler } from '../../lib/error-utils';
export function Privacy() {
const { quickConfig, workspaceInfo, loadWorkspaceInfo, saveQuickConfig } = useGatewayStore();
useEffect(() => {
loadWorkspaceInfo().catch(() => {});
loadWorkspaceInfo().catch(silentErrorHandler('Privacy'));
}, []);
const optIn = quickConfig.privacyOptIn ?? false;
@@ -27,7 +28,7 @@ export function Privacy() {
<div className="bg-white rounded-xl border border-gray-200 p-6 mb-6 shadow-sm">
<div className="flex justify-between items-start mb-4">
<h3 className="font-medium text-gray-900"></h3>
<Toggle checked={optIn} onChange={(value) => { saveQuickConfig({ privacyOptIn: value }).catch(() => {}); }} />
<Toggle checked={optIn} onChange={(value) => { saveQuickConfig({ privacyOptIn: value }).catch(silentErrorHandler('Privacy')); }} />
</div>
<p className="text-xs text-gray-500 leading-relaxed">
使"设置"退

View File

@@ -15,6 +15,7 @@ import {
ClipboardList,
Clock,
} from 'lucide-react';
import { silentErrorHandler } from '../../lib/error-utils';
import { General } from './General';
import { UsageStats } from './UsageStats';
import { ModelsAPI } from './ModelsAPI';
@@ -169,7 +170,7 @@ function Feedback() {
className="w-full h-40 border border-gray-300 rounded-lg p-3 text-sm resize-none focus:outline-none focus:border-orange-400"
/>
<button
onClick={() => { handleCopy().catch(() => {}); }}
onClick={() => { handleCopy().catch(silentErrorHandler('SettingsLayout')); }}
disabled={!text.trim()}
className="mt-4 px-6 py-2 bg-orange-500 text-white text-sm rounded-lg hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
>

View File

@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { useGatewayStore } from '../../store/gatewayStore';
import { silentErrorHandler } from '../../lib/error-utils';
import { Wrench, Zap, FileCode, Globe, Mail, Database, Search, MessageSquare } from 'lucide-react';
// ZCLAW 内置系统技能
@@ -70,7 +71,7 @@ export function Skills() {
useEffect(() => {
if (connected) {
loadSkillsCatalog().catch(() => {});
loadSkillsCatalog().catch(silentErrorHandler('Skills'));
}
}, [connected]);
@@ -97,7 +98,7 @@ export function Skills() {
<div className="flex justify-between items-center mb-6">
<h1 className="text-xl font-bold text-gray-900"></h1>
<button
onClick={() => { loadSkillsCatalog().catch(() => {}); }}
onClick={() => { loadSkillsCatalog().catch(silentErrorHandler('Skills')); }}
className="text-xs text-gray-500 hover:text-gray-700 px-3 py-1.5 border border-gray-200 rounded-lg transition-colors"
>
@@ -153,7 +154,7 @@ export function Skills() {
className="flex-1 px-3 py-2 border border-gray-200 rounded-lg text-sm bg-gray-50 focus:outline-none"
/>
<button
onClick={() => { handleAddDir().catch(() => {}); }}
onClick={() => { handleAddDir().catch(silentErrorHandler('Skills')); }}
className="text-xs text-gray-500 px-4 py-2 border border-gray-200 rounded-lg hover:text-gray-700 transition-colors"
>

View File

@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { useGatewayStore } from '../../store/gatewayStore';
import { silentErrorHandler } from '../../lib/error-utils';
export function Workspace() {
const {
@@ -11,7 +12,7 @@ export function Workspace() {
const [projectDir, setProjectDir] = useState('~/.openfang/zclaw-workspace');
useEffect(() => {
loadWorkspaceInfo().catch(() => {});
loadWorkspaceInfo().catch(silentErrorHandler('Workspace'));
}, []);
useEffect(() => {
@@ -49,7 +50,7 @@ export function Workspace() {
type="text"
value={projectDir}
onChange={(e) => setProjectDir(e.target.value)}
onBlur={() => { handleWorkspaceBlur().catch(() => {}); }}
onBlur={() => { handleWorkspaceBlur().catch(silentErrorHandler('Workspace')); }}
className="flex-1 px-3 py-2 border border-gray-200 rounded-lg text-sm bg-gray-50 focus:outline-none"
/>
<button className="text-xs px-4 py-2 border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors">
@@ -70,7 +71,7 @@ export function Workspace() {
Agent 访使
</div>
</div>
<Toggle checked={restrictFiles} onChange={(value) => { handleToggle('restrictFiles', value).catch(() => {}); }} />
<Toggle checked={restrictFiles} onChange={(value) => { handleToggle('restrictFiles', value).catch(silentErrorHandler('Workspace')); }} />
</div>
<div className="flex justify-between items-center py-3 border-t border-gray-100">
@@ -78,7 +79,7 @@ export function Workspace() {
<div className="font-medium text-gray-900 mb-1"></div>
<div className="text-xs text-gray-500"></div>
</div>
<Toggle checked={autoSaveContext} onChange={(value) => { handleToggle('autoSaveContext', value).catch(() => {}); }} />
<Toggle checked={autoSaveContext} onChange={(value) => { handleToggle('autoSaveContext', value).catch(silentErrorHandler('Workspace')); }} />
</div>
<div className="flex justify-between items-center py-3 border-t border-gray-100">
@@ -86,7 +87,7 @@ export function Workspace() {
<div className="font-medium text-gray-900 mb-1"></div>
<div className="text-xs text-gray-500"> Agent </div>
</div>
<Toggle checked={fileWatching} onChange={(value) => { handleToggle('fileWatching', value).catch(() => {}); }} />
<Toggle checked={fileWatching} onChange={(value) => { handleToggle('fileWatching', value).catch(silentErrorHandler('Workspace')); }} />
</div>
</div>