From 64a556531acf1d225353d2d00f8d87d999c9e152 Mon Sep 17 00:00:00 2001 From: soovittt Date: Sat, 13 Dec 2025 17:47:12 -0800 Subject: [PATCH] fix: Remove unused imports, variables, and fix type issues - Remove unused imports (useAction, StudioLayout, StudioTopBar, etc.) from EnvironmentEditor - Remove unused variables (selectedObjectId, sceneError, handleSave function) - Fix unused parameter by prefixing with underscore (_envId) - Fix CodeViewTab file_type type instead of using 'as any' - Format code with prettier --- app/components/CodeValidationPanel.tsx | 3 +- app/components/CodeViewTab.tsx | 6 +- app/components/EnvironmentCard.tsx | 2 +- app/components/EnvironmentEditor.tsx | 133 ++++--------------------- app/lib/sceneClient.ts | 16 +-- convex/trainingLogs.ts | 2 - 6 files changed, 35 insertions(+), 127 deletions(-) diff --git a/app/components/CodeValidationPanel.tsx b/app/components/CodeValidationPanel.tsx index f56c891..4544efe 100644 --- a/app/components/CodeValidationPanel.tsx +++ b/app/components/CodeValidationPanel.tsx @@ -110,8 +110,7 @@ export function CodeValidationPanel({ envSpec, onClose }: CodeValidationPanelPro (i) => i.message.toLowerCase().includes('reward') || i.category === 'security' ) const terminationIssues = review.issues.filter( - (i) => - i.message.toLowerCase().includes('terminat') || i.message.toLowerCase().includes('step') + (i) => i.message.toLowerCase().includes('terminat') || i.message.toLowerCase().includes('step') ) const apiIssues = review.issues.filter((i) => i.category === 'api_compliance') diff --git a/app/components/CodeViewTab.tsx b/app/components/CodeViewTab.tsx index ed7a84a..4786170 100644 --- a/app/components/CodeViewTab.tsx +++ b/app/components/CodeViewTab.tsx @@ -22,7 +22,9 @@ const FILE_OPTIONS = [ ] export function CodeViewTab({ envSpec }: CodeViewTabProps) { - const [selectedFileType, setSelectedFileType] = useState('environment') + const [selectedFileType, setSelectedFileType] = useState< + 'environment' | 'training' | 'config' | 'skypilot' | 'readme' | 'env_spec' + >('environment') const [code, setCode] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) @@ -63,7 +65,7 @@ export function CodeViewTab({ envSpec }: CodeViewTabProps) { const startTime = performance.now() const response = await generateCode({ env_spec: envSpec, - file_type: selectedFileType as any, + file_type: selectedFileType, training_config: trainingConfig, algorithm: algorithm, }) diff --git a/app/components/EnvironmentCard.tsx b/app/components/EnvironmentCard.tsx index 787e0cd..4e63813 100644 --- a/app/components/EnvironmentCard.tsx +++ b/app/components/EnvironmentCard.tsx @@ -162,7 +162,7 @@ export function EnvironmentCard({ env, onUpdate }: EnvironmentCardProps) { } return ( -
diff --git a/app/components/EnvironmentEditor.tsx b/app/components/EnvironmentEditor.tsx index aea8f80..a42f320 100644 --- a/app/components/EnvironmentEditor.tsx +++ b/app/components/EnvironmentEditor.tsx @@ -1,6 +1,6 @@ import { useState, useMemo, useEffect, useRef } from 'react' import { useNavigate } from '@tanstack/react-router' -import { useQuery, useMutation, useAction } from 'convex/react' +import { useQuery, useMutation } from 'convex/react' import { api } from '../../convex/_generated/api.js' import { useAuth } from '~/lib/auth' import { EnvSpec, createDefaultEnvSpec, Vec2 } from '~/lib/envSpec' @@ -10,12 +10,6 @@ import { HistoryManager } from '~/lib/historyManager' import { createScene, createSceneVersion, updateScene, getScene } from '~/lib/sceneClient' import { envSpecToSceneGraph, envSpecToRLConfig } from '~/lib/envSpecToSceneGraph' import { sceneGraphToEnvSpec } from '~/lib/sceneGraphToEnvSpec' -import { StudioLayout } from './StudioLayout' -import { StudioTopBar } from './StudioTopBar' -import { StudioSidebar } from './StudioSidebar' -import { StudioPropertiesPanel } from './StudioPropertiesPanel' -import { StudioBottomPanel } from './StudioBottomPanel' -import { EnvironmentCanvas } from './EnvironmentCanvas' import { CreateRun } from './CreateRun' import { EnhancedImportDialog } from './EnhancedImportDialog' import { CodeReviewPanel } from './CodeReviewPanel' @@ -52,7 +46,6 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { const [showCodeReview, setShowCodeReview] = useState(false) const [exportedFiles, setExportedFiles] = useState | null>(null) const [showValidation, setShowValidation] = useState(false) - const [selectedObjectId, setSelectedObjectId] = useState() const [selectedAssetId, setSelectedAssetId] = useState() const [rolloutState, setRolloutState] = useState<{ agents: Array<{ id: string; position: Vec2 }> @@ -61,13 +54,11 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { // Try to load from Scene Service first, fallback to old system const [sceneData, setSceneData] = useState<{ scene: any; activeVersion: any } | null>(null) const [sceneLoading, setSceneLoading] = useState(false) - const [sceneError, setSceneError] = useState(null) // Load from Scene Service if id is provided useEffect(() => { if (id !== 'new' && user?._id) { setSceneLoading(true) - setSceneError(null) getScene(id) .then((data) => { setSceneData(data) @@ -76,7 +67,6 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { .catch((err) => { // Scene not found in new system - fallback to old system console.log('Scene not found in Scene Service, falling back to old system:', err) - setSceneError(err.message) setSceneLoading(false) }) } @@ -147,7 +137,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { const hasAutoCreatedRef = useRef(false) // Keep a ref to the current localEnvSpec for auto-creation const localEnvSpecRef = useRef(localEnvSpec) - + useEffect(() => { // Only reset if we just navigated TO 'new' from a different page if (id === 'new' && prevIdRef.current !== 'new') { @@ -156,7 +146,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { } prevIdRef.current = id }, [id]) - + // Auto-create environment when user navigates to /environments/new useEffect(() => { if (id === 'new' && user?._id && !hasAutoCreatedRef.current) { @@ -166,9 +156,12 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { const currentSpec = localEnvSpecRef.current if (id === 'new' && user?._id && !hasAutoCreatedRef.current && currentSpec) { hasAutoCreatedRef.current = true - - console.log('Auto-creating environment...', { userId: user._id, specName: currentSpec.name }) - + + console.log('Auto-creating environment...', { + userId: user._id, + specName: currentSpec.name, + }) + try { // Convert EnvSpec to sceneGraph + rlConfig const sceneGraph = envSpecToSceneGraph(currentSpec) @@ -203,10 +196,13 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { // Update scene with projectId await updateScene(sceneId, { projectId: envId }) - + console.log('Successfully created environment in both systems:', { sceneId, envId }) } catch (oldSystemError) { - console.error('Failed to save to old system (CRITICAL - environment won\'t show in list):', oldSystemError) + console.error( + "Failed to save to old system (CRITICAL - environment won't show in list):", + oldSystemError + ) // This is actually critical - if Convex creation fails, the environment won't show in the list // because the list queries Convex, not Scene Service alert('Failed to create environment in database. Please try again.') @@ -276,7 +272,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { useEffect(() => { localEnvSpecRef.current = localEnvSpec }, [localEnvSpec]) - + // Sync localEnvSpec when envSpec changes (e.g., template loaded or name updated from database) // BUT: Don't overwrite if we just set it manually (e.g., from template selection or name change) useEffect(() => { @@ -284,7 +280,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { if (isUpdatingNameRef.current) { return } - + if (id === 'new') { // Only sync on initial mount, not after manual changes if (!manuallySetRef.current) { @@ -415,13 +411,13 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { } else { // Set flag to prevent sync from overwriting our local change isUpdatingNameRef.current = true - + // Update both top-level name and envSpec.name to keep them in sync const updatedSpec = { ...localEnvSpec, name } - + // Update local state immediately for instant UI feedback setLocalEnvSpec(updatedSpec) - + try { // Update in Convex (old system) await updateMutation({ @@ -429,7 +425,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { name, envSpec: updatedSpec, // Also update envSpec.name }) - + // Also update Scene Service if scene exists if (sceneData?.scene) { try { @@ -546,7 +542,7 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { } } - const handleDuplicate = async (envId: string) => { + const handleDuplicate = async (_envId: string) => { // TODO: Implement duplicate alert('Duplicate coming soon!') } @@ -560,93 +556,6 @@ export function EnvironmentEditor({ id: propId }: EnvironmentEditorProps = {}) { setShowImport(false) } - const handleSave = async () => { - if (!user?._id) { - alert('Please log in to create environments') - return - } - try { - // Convert EnvSpec to sceneGraph + rlConfig - const sceneGraph = envSpecToSceneGraph(localEnvSpec) - const rlConfig = envSpecToRLConfig(localEnvSpec) - - let sceneId: string - let envId: string - - if (id === 'new') { - // Create new scene in Scene Service (primary) - const scene = await createScene({ - projectId: '', // Will be set after creating environment - name: localEnvSpec.name || 'Untitled Environment', - description: localEnvSpec.metadata?.notes, - mode: localEnvSpec.world.coordinateSystem === 'grid' ? 'grid' : '2d', - environmentSettings: {}, - createdBy: user._id, - }) - sceneId = scene.id - - // Create initial version - await createSceneVersion(scene.id, { - sceneGraph, - rlConfig, - createdBy: user._id, - }) - - // Also save to old system for backward compatibility - try { - envId = await createMutation({ - ownerId: user._id, - name: localEnvSpec.name || 'Untitled Environment', - envSpec: localEnvSpec, - }) - - // Update scene with projectId - await updateScene(sceneId, { projectId: envId }) - } catch (oldSystemError) { - console.warn('Failed to save to old system (non-critical):', oldSystemError) - // Use scene ID as environment ID - envId = sceneId - } - } else { - // Update existing scene - sceneId = id - - // Update scene metadata if name changed - if (localEnvSpec.name && sceneData?.scene.name !== localEnvSpec.name) { - await updateScene(sceneId, { - name: localEnvSpec.name, - description: localEnvSpec.metadata?.notes, - }) - } - - // Create new version - await createSceneVersion(sceneId, { - sceneGraph, - rlConfig, - createdBy: user._id, - }) - - // Also update old system for backward compatibility - try { - await updateMutation({ - id: id as any, - name: localEnvSpec.name || 'Untitled Environment', - envSpec: localEnvSpec, - }) - } catch (oldSystemError) { - console.warn('Failed to update old system (non-critical):', oldSystemError) - } - - envId = id - } - - navigate({ to: '/environments/$id', params: { id: envId } }) - } catch (error) { - console.error('Failed to save environment:', error) - alert('Failed to save environment: ' + (error as Error).message) - } - } - if (isLoading && id !== 'new') { return (
diff --git a/app/lib/sceneClient.ts b/app/lib/sceneClient.ts index 2ac0a0b..986daa6 100644 --- a/app/lib/sceneClient.ts +++ b/app/lib/sceneClient.ts @@ -82,7 +82,7 @@ export async function getSceneByProjectId( const convexModule = await import('./convex') // Access the httpClient - it's not exported, so we need to use the api object const { api: convexApi } = await import('../../convex/_generated/api') - + // Use the Convex HTTP client via the api object // We need to query scenes:listByProject const convexUrl = import.meta.env.VITE_CONVEX_URL || import.meta.env.VITE_CONVEX_DEV_URL || '' @@ -90,7 +90,7 @@ export async function getSceneByProjectId( console.warn('Convex URL not configured') return null } - + // Query Convex HTTP API directly const response = await fetch(`${convexUrl}/api/query`, { method: 'POST', @@ -100,23 +100,23 @@ export async function getSceneByProjectId( args: { projectId }, }), }) - + const result = await response.json() - + if (result.status === 'error') { console.warn('Failed to find scene by projectId:', result.errorMessage) return null } - + const scenes = result.status === 'success' ? result.value : result - + if (!scenes || scenes.length === 0) { return null } - + // Get the first scene (there should only be one per project) const sceneData = scenes[0] - + // Now get the full scene with active version using the scene ID return await getScene(sceneData._id) } catch (error) { diff --git a/convex/trainingLogs.ts b/convex/trainingLogs.ts index a0ec1fc..18edf11 100644 --- a/convex/trainingLogs.ts +++ b/convex/trainingLogs.ts @@ -48,5 +48,3 @@ export const clear = mutation({ return { deleted: logs.length } }, }) - -