2025-12-04 07:41:54 -05:00
|
|
|
import { useState, useEffect } from 'react';
|
feat: Major update with validators, skills, dashboard, and docs reorganization
- Add validation framework (config, model, results, study validators)
- Add Claude Code skills (create-study, run-optimization, generate-report,
troubleshoot, analyze-model)
- Add Atomizer Dashboard (React frontend + FastAPI backend)
- Reorganize docs into structured directories (00-09)
- Add neural surrogate modules and training infrastructure
- Add multi-objective optimization support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:23:58 -05:00
|
|
|
import useWebSocket, { ReadyState } from 'react-use-websocket';
|
|
|
|
|
import { WebSocketMessage } from '../types';
|
|
|
|
|
|
|
|
|
|
interface UseOptimizationWebSocketProps {
|
|
|
|
|
studyId: string | null;
|
|
|
|
|
onMessage?: (message: WebSocketMessage) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useOptimizationWebSocket = ({ studyId, onMessage }: UseOptimizationWebSocketProps) => {
|
|
|
|
|
const [socketUrl, setSocketUrl] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (studyId) {
|
|
|
|
|
// In development, we might need to point to localhost:8000 explicitly if not proxied
|
|
|
|
|
// But assuming Vite proxy is set up correctly:
|
|
|
|
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
|
|
|
const host = window.location.host; // This will be localhost:3000 in dev
|
|
|
|
|
// If using proxy in vite.config.ts, this works.
|
|
|
|
|
// If not, we might need to hardcode backend URL for dev:
|
feat(dashboard): Enhanced chat, spec management, and Claude integration
Backend:
- spec.py: New AtomizerSpec REST API endpoints
- spec_manager.py: SpecManager service for unified config
- interview_engine.py: Study creation interview logic
- claude.py: Enhanced Claude API with context
- optimization.py: Extended optimization endpoints
- context_builder.py, session_manager.py: Improved services
Frontend:
- Chat components: Enhanced message rendering, tool call cards
- Hooks: useClaudeCode, useSpecWebSocket, improved useChat
- Pages: Updated Dashboard, Analysis, Insights, Setup, Home
- Components: ParallelCoordinatesPlot, ParetoPlot improvements
- App.tsx: Route updates for canvas/studio
Infrastructure:
- vite.config.ts: Build configuration updates
- start/stop-dashboard.bat: Script improvements
2026-01-20 13:10:47 -05:00
|
|
|
// Use port 8001 to match start-dashboard.bat
|
|
|
|
|
const backendHost = import.meta.env.DEV ? 'localhost:8001' : host;
|
feat: Major update with validators, skills, dashboard, and docs reorganization
- Add validation framework (config, model, results, study validators)
- Add Claude Code skills (create-study, run-optimization, generate-report,
troubleshoot, analyze-model)
- Add Atomizer Dashboard (React frontend + FastAPI backend)
- Reorganize docs into structured directories (00-09)
- Add neural surrogate modules and training infrastructure
- Add multi-objective optimization support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:23:58 -05:00
|
|
|
|
|
|
|
|
setSocketUrl(`${protocol}//${backendHost}/api/ws/optimization/${studyId}`);
|
|
|
|
|
} else {
|
|
|
|
|
setSocketUrl(null);
|
|
|
|
|
}
|
|
|
|
|
}, [studyId]);
|
|
|
|
|
|
|
|
|
|
const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl, {
|
2025-12-04 07:41:54 -05:00
|
|
|
shouldReconnect: (_closeEvent) => true,
|
feat: Major update with validators, skills, dashboard, and docs reorganization
- Add validation framework (config, model, results, study validators)
- Add Claude Code skills (create-study, run-optimization, generate-report,
troubleshoot, analyze-model)
- Add Atomizer Dashboard (React frontend + FastAPI backend)
- Reorganize docs into structured directories (00-09)
- Add neural surrogate modules and training infrastructure
- Add multi-objective optimization support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:23:58 -05:00
|
|
|
reconnectAttempts: 10,
|
|
|
|
|
reconnectInterval: 3000,
|
|
|
|
|
onOpen: () => console.log('WebSocket Connected'),
|
|
|
|
|
onClose: () => console.log('WebSocket Disconnected'),
|
|
|
|
|
onError: (e) => console.error('WebSocket Error:', e),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (lastMessage !== null) {
|
|
|
|
|
try {
|
|
|
|
|
const data = JSON.parse(lastMessage.data) as WebSocketMessage;
|
|
|
|
|
if (onMessage) {
|
|
|
|
|
onMessage(data);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to parse WebSocket message:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [lastMessage, onMessage]);
|
|
|
|
|
|
|
|
|
|
const connectionStatus = {
|
|
|
|
|
[ReadyState.CONNECTING]: 'Connecting',
|
|
|
|
|
[ReadyState.OPEN]: 'Open',
|
|
|
|
|
[ReadyState.CLOSING]: 'Closing',
|
|
|
|
|
[ReadyState.CLOSED]: 'Closed',
|
|
|
|
|
[ReadyState.UNINSTANTIATED]: 'Uninstantiated',
|
|
|
|
|
}[readyState];
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
sendMessage,
|
|
|
|
|
lastMessage,
|
|
|
|
|
readyState,
|
|
|
|
|
connectionStatus,
|
|
|
|
|
};
|
|
|
|
|
};
|