-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
186 lines (167 loc) · 7.5 KB
/
Copy pathApp.tsx
File metadata and controls
186 lines (167 loc) · 7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { startTransition, useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { ChatView } from '@/components/ChatView'
import { SettingsView } from '@/components/SettingsView'
import PluginsView from '@/components/PluginsView'
import SkillsView from '@/components/SkillsView'
import { CronView } from '@/components/CronView'
import { SoulView } from '@/components/SoulView'
import { Sidebar } from '@/components/sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageToggle } from '@/components/LanguageToggle'
import { StartupScreen } from '@/components/StartupScreen'
import { OnboardView } from '@/components/OnboardView'
import { GatewayRestartBanner } from '@/components/GatewayRestartBanner'
import { useThemeEffect } from '@/store/theme'
import { useAppInit } from '@/hooks/useAppInit'
import { useChatStore } from '@/store/chat'
import { useTitleStore } from '@/store/titles'
import { useAgentStore } from '@/store/agents'
import { MessageCircle, Settings, Plug, Clock, Sparkles, Loader2, Wrench } from 'lucide-react'
export type View = 'chat' | 'soul' | 'cron' | 'settings' | 'plugins' | 'skills'
type OnboardTransitionStage = 'idle' | 'closing' | 'opening'
const RECONFIGURE_SWITCH_DELAY_MS = 180
const RECONFIGURE_OVERLAY_FADE_MS = 360
function App() {
const [currentView, setCurrentView] = useState<View>('chat')
const [isReconfigure, setIsReconfigure] = useState(false)
const [savedApiKey, setSavedApiKey] = useState('')
const [onboardTransitionStage, setOnboardTransitionStage] = useState<OnboardTransitionStage>('idle')
const transitionTimersRef = useRef<number[]>([])
const { t } = useTranslation()
useThemeEffect()
const { showStartup, startupStatus, startupError, needsOnboard, setNeedsOnboard } = useAppInit()
const conversation = useChatStore(s => s.getCurrentConversation())
const titles = useTitleStore(s => s.titles)
const headerTitle = conversation
? (titles[conversation.id.toLowerCase()] || conversation.title)
: ''
const navItems = [
{ id: 'chat' as View, icon: MessageCircle, label: t('nav.chat') },
{ id: 'soul' as View, icon: Sparkles, label: t('nav.soul') },
{ id: 'cron' as View, icon: Clock, label: t('nav.cron') },
{ id: 'plugins' as View, icon: Plug, label: t('nav.plugins') },
{ id: 'skills' as View, icon: Wrench, label: t('nav.skills') },
{ id: 'settings' as View, icon: Settings, label: t('nav.settings') },
]
const clearTransitionTimers = useCallback(() => {
transitionTimersRef.current.forEach(timer => window.clearTimeout(timer))
transitionTimersRef.current = []
}, [])
useEffect(() => () => clearTransitionTimers(), [clearTransitionTimers])
const handleReconfigure = useCallback((apiKey?: string) => {
if (needsOnboard || onboardTransitionStage !== 'idle') return
clearTransitionTimers()
setSavedApiKey(apiKey || '')
setIsReconfigure(true)
setOnboardTransitionStage('closing')
const switchTimer = window.setTimeout(() => {
startTransition(() => setNeedsOnboard(true))
setOnboardTransitionStage('opening')
}, RECONFIGURE_SWITCH_DELAY_MS)
const finishTimer = window.setTimeout(() => {
setOnboardTransitionStage('idle')
transitionTimersRef.current = []
}, RECONFIGURE_SWITCH_DELAY_MS + RECONFIGURE_OVERLAY_FADE_MS)
transitionTimersRef.current = [switchTimer, finishTimer]
}, [clearTransitionTimers, needsOnboard, onboardTransitionStage, setNeedsOnboard])
if (showStartup) {
return <StartupScreen status={startupStatus} error={startupError} />
}
const onboardContent = (
<div className={onboardTransitionStage === 'opening' ? 'animate-in fade-in-0 zoom-in-95 duration-500' : ''}>
<OnboardView
skipEnvCheck={isReconfigure}
initialApiKey={isReconfigure ? savedApiKey : undefined}
onComplete={async (destination = 'settings') => {
clearTransitionTimers()
setOnboardTransitionStage('idle')
setNeedsOnboard(false)
setIsReconfigure(false)
setSavedApiKey('')
await useAgentStore.getState().loadAgents()
setCurrentView(isReconfigure ? 'settings' : destination)
}}
/>
</div>
)
const renderView = () => {
switch (currentView) {
case 'chat': return <ChatView />
case 'soul': return <SoulView />
case 'cron': return <CronView />
case 'plugins': return <PluginsView />
case 'skills': return <SkillsView />
case 'settings': return <SettingsView onReconfigure={handleReconfigure} />
default: return <ChatView />
}
}
const appShell = (
<div
className={`flex h-screen bg-background transform-gpu transition-all duration-300 ease-out ${
onboardTransitionStage === 'closing'
? 'opacity-0 scale-[0.985] translate-y-3 blur-[3px]'
: 'opacity-100 scale-100 translate-y-0 blur-0'
}`}
>
<Sidebar navItems={navItems} currentView={currentView} onViewChange={setCurrentView} />
<div className="flex-1 flex flex-col overflow-hidden">
<div className="subtle-separator-b px-6 py-2.5 flex items-center justify-between bg-background/80 backdrop-blur-md">
<h1 className="text-lg font-semibold truncate flex-1 mr-4">
{currentView === 'chat' && conversation ? headerTitle : ''}
</h1>
<div className="flex items-center gap-1">
<LanguageToggle />
<ThemeToggle />
</div>
</div>
<GatewayRestartBanner />
<div className="flex-1 overflow-hidden">
{renderView()}
</div>
</div>
</div>
)
return (
<>
{needsOnboard ? onboardContent : appShell}
{onboardTransitionStage !== 'idle' && (
<div className="fixed inset-0 z-50 flex items-center justify-center overflow-hidden">
<div
className={`absolute inset-0 bg-background/84 backdrop-blur-xl transition-opacity duration-500 ${
onboardTransitionStage === 'closing' ? 'opacity-100' : 'opacity-0'
}`}
/>
<div
className={`absolute inset-0 bg-gradient-to-b from-primary/10 via-background/40 to-background transition-opacity duration-500 ${
onboardTransitionStage === 'closing' ? 'opacity-100' : 'opacity-0'
}`}
/>
<div
className={`relative mx-4 w-full max-w-md overflow-hidden rounded-2xl border border-primary/15 bg-background/88 px-5 py-4 shadow-2xl backdrop-blur-xl transform-gpu transition-all duration-500 ${
onboardTransitionStage === 'closing'
? 'opacity-100 translate-y-0 scale-100'
: 'opacity-0 -translate-y-4 scale-[0.96]'
}`}
>
<div className="absolute inset-x-8 top-0 h-px bg-gradient-to-r from-transparent via-primary/70 to-transparent" />
<div className="flex items-center gap-3">
<div className="flex h-11 w-11 items-center justify-center rounded-2xl bg-primary/10 text-primary ring-1 ring-primary/10">
<Loader2 className="h-5 w-5 animate-spin" />
</div>
<div className="min-w-0">
<p className="text-sm font-semibold tracking-tight">
{t('settings.reconfigureTransitionTitle')}
</p>
<p className="text-xs text-muted-foreground">
{t('settings.reconfigureTransitionDesc')}
</p>
</div>
</div>
</div>
</div>
)}
</>
)
}
export default App