@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
22import { Clock3 , Database , Loader2 , Network , Play , RefreshCw , Sparkles } from 'lucide-react'
33import BrainInitModal from '@/components/BrainInitModal'
44import { connectionAPI } from '@/lib/api/client'
5+ import { isInitRunning , isInitFailed , isInitNeedsAttention } from '@/lib/initStage'
56import { DEFAULT_ROLE_FILTERS , ERD3DErrorBoundary , SchemaDiagramFilter , SchemaERD3D } from './SchemaERD3D'
67import styles from './BrainWorkspace.module.css'
78
@@ -23,6 +24,7 @@ const STAGE_LABELS = {
2324 ...Object . fromEntries ( STAGES . map ( ( stage ) => [ stage . key , stage . label ] ) ) ,
2425 COMPLETED : 'Brain ready' ,
2526 FAILED : 'Initialization failed' ,
27+ NEEDS_ATTENTION : 'Needs attention' ,
2628}
2729
2830function stageLabel ( stage ) {
@@ -97,7 +99,7 @@ export default function BrainWorkspace({ connectionId }) {
9799 return undefined
98100 }
99101 const currentStage = status ?. currentStage || status ?. stage || 'NONE'
100- const isRunning = currentStage && ! [ 'NONE' , 'COMPLETED' , 'FAILED' ] . includes ( currentStage )
102+ const isRunning = isInitRunning ( currentStage )
101103 const intervalMs = isRunning ? 4000 : 15000
102104 const intervalId = window . setInterval ( ( ) => {
103105 void loadWorkspace ( { silent : true } )
@@ -111,11 +113,11 @@ export default function BrainWorkspace({ connectionId }) {
111113 )
112114
113115 const currentStage = status ?. currentStage || status ?. stage || 'NONE'
114- const isRunning = currentStage && ! [ 'NONE' , 'COMPLETED' , 'FAILED' ] . includes ( currentStage )
116+ const isRunning = isInitRunning ( currentStage )
115117 const isReady = currentStage === 'COMPLETED' || hasCompletedInit
116118 const progress = Math . max ( 0 , Math . min ( 100 , Number ( status ?. progressPercent ?? status ?. progress ?? ( isReady ? 100 : 0 ) ) ) )
117- const ctaLabel = isRunning ? 'View current status' : isReady ? 'View completed stages' : currentStage === 'FAILED' ? 'View failure details' : 'Initialize Brain'
118- const primaryAutoStart = ! isRunning && ! isReady && currentStage !== 'FAILED'
119+ const ctaLabel = isRunning ? 'View current status' : isReady ? 'View completed stages' : ( isInitFailed ( currentStage ) || isInitNeedsAttention ( currentStage ) ) ? 'View details' : 'Initialize Brain'
120+ const primaryAutoStart = ! isRunning && ! isReady && ! isInitFailed ( currentStage ) && ! isInitNeedsAttention ( currentStage )
119121 const statusText = isRunning
120122 ? `${ stageLabel ( currentStage ) } · ${ progress } %`
121123 : currentStage === 'FAILED'
@@ -308,14 +310,14 @@ export default function BrainWorkspace({ connectionId }) {
308310 { isRunning ? < Loader2 size = { 15 } className = { styles . spinningIcon } /> : < Sparkles size = { 15 } /> }
309311 { ctaLabel }
310312 </ button >
311- { ( ! isRunning && ( isReady || currentStage === 'FAILED' || currentStage === 'NONE' ) ) && (
313+ { ( ! isRunning && ( isReady || isInitFailed ( currentStage ) || isInitNeedsAttention ( currentStage ) || currentStage === 'NONE' ) ) && (
312314 < button
313315 className = { styles . secondaryButton }
314316 onClick = { ( ) => openStatusModal ( true ) }
315317 disabled = { loading }
316318 >
317319 < RefreshCw size = { 15 } />
318- { isReady ? 'Refresh Brain' : currentStage === 'FAILED' ? 'Retry Brain init' : 'Start Brain init' }
320+ { isReady ? 'Refresh Brain' : ( isInitFailed ( currentStage ) || isInitNeedsAttention ( currentStage ) ) ? 'Retry Brain init' : 'Start Brain init' }
319321 </ button >
320322 ) }
321323 { ( ! isRunning && ! forceRebuilding ) && (
0 commit comments