Raiff1982 commited on
Commit
1b1180b
·
verified ·
1 Parent(s): 61e3f86

Upload 4 files

Browse files
Files changed (4) hide show
  1. App.tsx +264 -0
  2. index.css +94 -0
  3. main.tsx +10 -0
  4. vite-env.d.ts +1 -0
App.tsx ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState, useEffect, useRef } from 'react';
2
+ import { Zap, Brain, Settings, Moon, ChevronRight, Send, Bot, Server, Sparkles, Circle, User, AlertCircle } from 'lucide-react';
3
+ import { createClient } from '@supabase/supabase-js';
4
+ import ChatInterface from './components/ChatInterface';
5
+ import VisualizationPanel from './components/VisualizationPanel';
6
+ import Sidebar from './components/Sidebar';
7
+ import Header from './components/Header';
8
+ import CognitionCocooner from './services/CognitionCocooner';
9
+ import AICore from './services/AICore';
10
+ import { CodetteResponse } from './components/CodetteComponents';
11
+
12
+ interface Message {
13
+ role: string;
14
+ content: string;
15
+ timestamp: Date;
16
+ metadata?: CodetteResponse;
17
+ }
18
+
19
+ // Initialize Supabase client
20
+ const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
21
+ const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
22
+
23
+ if (!supabaseUrl || !supabaseKey) {
24
+ throw new Error('Missing Supabase environment variables');
25
+ }
26
+
27
+ const supabase = createClient(supabaseUrl, supabaseKey);
28
+
29
+ const App: React.FC = () => {
30
+ const [sidebarOpen, setSidebarOpen] = useState(true);
31
+ const [darkMode, setDarkMode] = useState(false);
32
+ const [messages, setMessages] = useState<Message[]>([]);
33
+ const [aiState, setAiState] = useState({
34
+ quantumState: [0.3, 0.7, 0.5],
35
+ chaosState: [0.2, 0.8, 0.4, 0.6],
36
+ activePerspectives: ['newton', 'davinci', 'neural_network', 'philosophical'],
37
+ ethicalScore: 0.93,
38
+ processingPower: 0.72
39
+ });
40
+ const [cocoons, setCocoons] = useState<Array<{id: string, type: string, wrapped: any}>>([]);
41
+ const [isProcessing, setIsProcessing] = useState(false);
42
+ const [isAdmin, setIsAdmin] = useState(false);
43
+ const [error, setError] = useState<string | null>(null);
44
+ const [currentUserId, setCurrentUserId] = useState<string | null>(null);
45
+
46
+ const aiCore = useRef<AICore | null>(null);
47
+ const cocooner = useRef(new CognitionCocooner());
48
+
49
+ useEffect(() => {
50
+ try {
51
+ aiCore.current = new AICore();
52
+ setError(null);
53
+ } catch (err: any) {
54
+ console.error('Error initializing AI Core:', err);
55
+ setError(err.message);
56
+ }
57
+ }, []);
58
+
59
+ useEffect(() => {
60
+ // Check if user is already authenticated
61
+ const checkAuth = async () => {
62
+ try {
63
+ const { data: { session }, error } = await supabase.auth.getSession();
64
+
65
+ if (error) {
66
+ console.error('Auth check error:', error.message);
67
+ return;
68
+ }
69
+
70
+ if (session?.user) {
71
+ setCurrentUserId(session.user.id);
72
+ const { data: { role } } = await supabase.rpc('get_user_role');
73
+ setIsAdmin(role === 'admin');
74
+ }
75
+ } catch (error: any) {
76
+ console.error('Auth check error:', error.message);
77
+ }
78
+ };
79
+
80
+ checkAuth();
81
+ }, []);
82
+
83
+ useEffect(() => {
84
+ if (!error) {
85
+ setMessages([
86
+ {
87
+ role: 'assistant',
88
+ content: 'Hello! I am Codette, an advanced AI assistant with recursive reasoning, self-learning capabilities, and multi-agent intelligence. How can I assist you today?',
89
+ timestamp: new Date(),
90
+ metadata: {
91
+ text: 'Hello! I am Codette, an advanced AI assistant with recursive reasoning, self-learning capabilities, and multi-agent intelligence. How can I assist you today?',
92
+ instabilityFlag: false,
93
+ perspectivesUsed: ['greeting', 'introduction'],
94
+ cocoonLog: ['Initializing Codette AI...', 'Quantum state stabilized'],
95
+ forceRefresh: () => handleForceRefresh('Hello! I am Codette, an advanced AI assistant with recursive reasoning, self-learning capabilities, and multi-agent intelligence. How can I assist you today?')
96
+ }
97
+ }
98
+ ]);
99
+ }
100
+ }, [error]);
101
+
102
+ const handleForceRefresh = async (content: string) => {
103
+ if (!aiCore.current) return;
104
+
105
+ setIsProcessing(true);
106
+ try {
107
+ const response = await aiCore.current.processInput(content, true, currentUserId || undefined);
108
+
109
+ const assistantMessage: Message = {
110
+ role: 'assistant',
111
+ content: response,
112
+ timestamp: new Date(),
113
+ metadata: {
114
+ text: response,
115
+ instabilityFlag: Math.random() > 0.8,
116
+ perspectivesUsed: aiState.activePerspectives.slice(0, 3),
117
+ cocoonLog: [`Regenerating response for: ${content}`, `Generated new response at ${new Date().toISOString()}`],
118
+ forceRefresh: () => handleForceRefresh(content)
119
+ }
120
+ };
121
+
122
+ setMessages(prev => [...prev.slice(0, -1), assistantMessage]);
123
+ } catch (error) {
124
+ console.error('Error regenerating response:', error);
125
+ } finally {
126
+ setIsProcessing(false);
127
+ }
128
+ };
129
+
130
+ const toggleSidebar = () => {
131
+ setSidebarOpen(!sidebarOpen);
132
+ };
133
+
134
+ const toggleDarkMode = () => {
135
+ setDarkMode(!darkMode);
136
+ document.documentElement.classList.toggle('dark');
137
+ };
138
+
139
+ const sendMessage = async (content: string) => {
140
+ if (!aiCore.current) {
141
+ setError('AI Core is not initialized. Please check your configuration.');
142
+ return;
143
+ }
144
+
145
+ const userMessage: Message = {
146
+ role: 'user',
147
+ content,
148
+ timestamp: new Date()
149
+ };
150
+
151
+ setMessages(prev => [...prev, userMessage]);
152
+ setIsProcessing(true);
153
+
154
+ try {
155
+ await new Promise(resolve => setTimeout(resolve, 1500));
156
+
157
+ const thought = { query: content, timestamp: new Date() };
158
+ const cocoonId = cocooner.current.wrap(thought);
159
+ setCocoons(prev => [...prev, {
160
+ id: cocoonId,
161
+ type: 'prompt',
162
+ wrapped: thought
163
+ }]);
164
+
165
+ const response = await aiCore.current.processInput(content, false, currentUserId || undefined);
166
+
167
+ setAiState(prev => ({
168
+ ...prev,
169
+ quantumState: [Math.random(), Math.random(), Math.random()].map(v => v.toFixed(2)).map(Number),
170
+ chaosState: [Math.random(), Math.random(), Math.random(), Math.random()].map(v => v.toFixed(2)).map(Number),
171
+ ethicalScore: Number((prev.ethicalScore + Math.random() * 0.1 - 0.05).toFixed(2)),
172
+ processingPower: Number((prev.processingPower + Math.random() * 0.1 - 0.05).toFixed(2))
173
+ }));
174
+
175
+ const assistantMessage: Message = {
176
+ role: 'assistant',
177
+ content: response,
178
+ timestamp: new Date(),
179
+ metadata: {
180
+ text: response,
181
+ instabilityFlag: Math.random() > 0.8,
182
+ perspectivesUsed: aiState.activePerspectives.slice(0, 3),
183
+ cocoonLog: [`Processing query: ${content}`, `Generated response at ${new Date().toISOString()}`],
184
+ forceRefresh: () => handleForceRefresh(content)
185
+ }
186
+ };
187
+
188
+ setMessages(prev => [...prev, assistantMessage]);
189
+ } catch (error: any) {
190
+ console.error('Error processing message:', error);
191
+
192
+ setMessages(prev => [...prev, {
193
+ role: 'system',
194
+ content: 'An error occurred while processing your request. Please check your configuration and try again.',
195
+ timestamp: new Date()
196
+ }]);
197
+ } finally {
198
+ setIsProcessing(false);
199
+ }
200
+ };
201
+
202
+ if (error) {
203
+ return (
204
+ <div className={`min-h-screen flex items-center justify-center p-4 ${darkMode ? 'dark bg-gray-900 text-white' : 'bg-gray-50 text-gray-900'}`}>
205
+ <div className={`max-w-md w-full p-6 rounded-lg shadow-lg ${darkMode ? 'bg-gray-800' : 'bg-white'}`}>
206
+ <div className="flex items-center justify-center mb-4">
207
+ <AlertCircle className="text-red-500" size={48} />
208
+ </div>
209
+ <h1 className="text-xl font-bold text-center mb-4">Configuration Error</h1>
210
+ <p className="text-center mb-6">{error}</p>
211
+ <div className={`p-4 rounded-md ${darkMode ? 'bg-gray-700' : 'bg-gray-100'}`}>
212
+ <p className="text-sm">
213
+ Please ensure you have:
214
+ <ol className="list-decimal ml-5 mt-2 space-y-1">
215
+ <li>Created a .env file</li>
216
+ <li>Added your OpenAI API key to the .env file</li>
217
+ <li>Added your Supabase configuration</li>
218
+ </ol>
219
+ </p>
220
+ </div>
221
+ </div>
222
+ </div>
223
+ );
224
+ }
225
+
226
+ return (
227
+ <div className={`flex flex-col h-screen transition-colors duration-300 ${darkMode ? 'dark bg-gray-900 text-white' : 'bg-gray-50 text-gray-900'}`}>
228
+ <Header
229
+ toggleSidebar={toggleSidebar}
230
+ toggleDarkMode={toggleDarkMode}
231
+ darkMode={darkMode}
232
+ aiState={aiState}
233
+ />
234
+
235
+ <div className="flex flex-1 overflow-hidden">
236
+ <Sidebar
237
+ isOpen={sidebarOpen}
238
+ cocoons={cocoons}
239
+ aiState={aiState}
240
+ darkMode={darkMode}
241
+ supabase={supabase}
242
+ isAdmin={isAdmin}
243
+ setIsAdmin={setIsAdmin}
244
+ />
245
+
246
+ <main className="flex-1 flex flex-col md:flex-row overflow-hidden">
247
+ <ChatInterface
248
+ messages={messages}
249
+ sendMessage={sendMessage}
250
+ isProcessing={isProcessing}
251
+ darkMode={darkMode}
252
+ />
253
+
254
+ <VisualizationPanel
255
+ aiState={aiState}
256
+ darkMode={darkMode}
257
+ />
258
+ </main>
259
+ </div>
260
+ </div>
261
+ );
262
+ };
263
+
264
+ export default App;
index.css ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ :root {
6
+ --primary: #1E3A8A;
7
+ --secondary: #7E22CE;
8
+ --accent: #0D9488;
9
+ --background: #F9FAFB;
10
+ --foreground: #111827;
11
+ }
12
+
13
+ .dark {
14
+ --primary: #3B82F6;
15
+ --secondary: #8B5CF6;
16
+ --accent: #10B981;
17
+ --background: #111827;
18
+ --foreground: #F9FAFB;
19
+ }
20
+
21
+ body {
22
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
23
+ margin: 0;
24
+ padding: 0;
25
+ box-sizing: border-box;
26
+ }
27
+
28
+ /* Animation for neural pulses */
29
+ @keyframes pulse {
30
+ 0% {
31
+ transform: scale(1);
32
+ opacity: 1;
33
+ }
34
+ 50% {
35
+ transform: scale(1.2);
36
+ opacity: 0.8;
37
+ }
38
+ 100% {
39
+ transform: scale(1);
40
+ opacity: 1;
41
+ }
42
+ }
43
+
44
+ /* Animation for typing indicators */
45
+ @keyframes bounce {
46
+ 0%, 100% {
47
+ transform: translateY(0);
48
+ }
49
+ 50% {
50
+ transform: translateY(-4px);
51
+ }
52
+ }
53
+
54
+ .typing-dot {
55
+ animation: bounce 1s infinite;
56
+ }
57
+
58
+ /* Custom scrollbar */
59
+ ::-webkit-scrollbar {
60
+ width: 8px;
61
+ height: 8px;
62
+ }
63
+
64
+ ::-webkit-scrollbar-track {
65
+ background: transparent;
66
+ }
67
+
68
+ ::-webkit-scrollbar-thumb {
69
+ background: rgba(156, 163, 175, 0.5);
70
+ border-radius: 4px;
71
+ }
72
+
73
+ ::-webkit-scrollbar-thumb:hover {
74
+ background: rgba(156, 163, 175, 0.7);
75
+ }
76
+
77
+ /* Transitions */
78
+ .transition-all {
79
+ transition-property: all;
80
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
81
+ transition-duration: 300ms;
82
+ }
83
+
84
+ .transition-opacity {
85
+ transition-property: opacity;
86
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
87
+ transition-duration: 150ms;
88
+ }
89
+
90
+ .transition-transform {
91
+ transition-property: transform;
92
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
93
+ transition-duration: 150ms;
94
+ }
main.tsx ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { StrictMode } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import App from './App.tsx';
4
+ import './index.css';
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>
10
+ );
vite-env.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ /// <reference types="vite/client" />