diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts deleted file mode 100644 index f45be401..00000000 --- a/src/hooks/useChat.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { useState, useCallback } from 'react'; -import { useAISettings } from '@/contexts/AISettingsContext'; - -export interface Message { - id: string; - role: 'user' | 'assistant'; - content: string; - timestamp: Date; -} - -export function useChat() { - const { settings } = useAISettings(); - const [messages, setMessages] = useState([]); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - const sendMessage = useCallback(async (content: string) => { - if (!settings.apiKey) { - setError('API key not configured'); - return; - } - - setIsLoading(true); - setError(null); - - const userMessage: Message = { - id: Date.now().toString(), - role: 'user', - content, - timestamp: new Date(), - }; - - setMessages(prev => [...prev, userMessage]); - - try { - const response = await fetch(`${settings.baseUrl}/chat/completions`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${settings.apiKey}`, - }, - body: JSON.stringify({ - model: settings.model, - messages: [ - ...messages.map(m => ({ role: m.role, content: m.content })), - { role: 'user', content } - ], - stream: false, - max_tokens: 1000, - }), - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const data = await response.json(); - const assistantMessage: Message = { - id: (Date.now() + 1).toString(), - role: 'assistant', - content: data.choices[0]?.message?.content || 'No response received', - timestamp: new Date(), - }; - - setMessages(prev => [...prev, assistantMessage]); - } catch (err) { - setError(err instanceof Error ? err.message : 'An error occurred'); - // Remove the user message if there was an error - setMessages(prev => prev.slice(0, -1)); - } finally { - setIsLoading(false); - } - }, [settings, messages]); - - return { - messages, - isLoading, - error, - sendMessage, - }; -} diff --git a/src/lib/ai-chat.ts b/src/lib/ai-chat.ts deleted file mode 100644 index db3bb67e..00000000 --- a/src/lib/ai-chat.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { openai } from '@ai-sdk/openai'; -import { streamText, tool } from 'ai'; -import { z } from 'zod'; -import { contextualAITools } from './ai-tools'; - -const fileOperationSchema = z.object({ - filePath: z.string(), - content: z.string().optional(), -}); - -const buildSchema = z.object({}); - -export async function createAIChat(projectId: string, messages: Array<{ role: 'user' | 'assistant'; content: string }>) { - // Set the project context for the AI tools - contextualAITools.setCurrentProjectId(projectId); - - const result = await streamText({ - model: openai('gpt-4-turbo-preview'), - messages, - tools: { - readFile: tool({ - description: 'Read the contents of a file in the project', - parameters: fileOperationSchema, - execute: async ({ filePath }) => { - return await contextualAITools.readFile(filePath); - }, - }), - writeFile: tool({ - description: 'Write content to a file in the project', - parameters: fileOperationSchema, - execute: async ({ filePath, content }) => { - return await contextualAITools.writeFile(filePath, content || ''); - }, - }), - deleteFile: tool({ - description: 'Delete a file from the project', - parameters: fileOperationSchema, - execute: async ({ filePath }) => { - return await contextualAITools.deleteFile(filePath); - }, - }), - listFiles: tool({ - description: 'List files in a directory', - parameters: fileOperationSchema, - execute: async ({ filePath }) => { - return await contextualAITools.listFiles(filePath); - }, - }), - fileExists: tool({ - description: 'Check if a file exists', - parameters: fileOperationSchema, - execute: async ({ filePath }) => { - return await contextualAITools.fileExists(filePath); - }, - }), - buildProject: tool({ - description: 'Build the project using Vite', - parameters: buildSchema, - execute: async () => { - return await contextualAITools.buildProject(); - }, - }), - getProjectStructure: tool({ - description: 'Get the complete file structure of the project', - parameters: buildSchema, - execute: async () => { - return await contextualAITools.getProjectStructure(); - }, - }), - searchFiles: tool({ - description: 'Search for files containing specific text', - parameters: z.object({ - query: z.string(), - }), - execute: async ({ query }) => { - return await contextualAITools.searchFiles(query); - }, - }), - }, - system: `You are an AI assistant helping users build custom Nostr websites. You have access to tools that allow you to read, write, and manage files in the project, as well as build the project. - -Key capabilities: -- Read and write files in the project -- List directory contents -- Check if files exist -- Build the project using Vite -- Get project structure overview -- Search through files - -Guidelines: -- Always check if files exist before writing to avoid overwriting -- Provide helpful explanations of what you're doing -- Suggest improvements and best practices -- Use modern React patterns and TypeScript -- Follow Nostr protocol standards when relevant -- Ensure the project builds successfully - -The project uses: -- React 18 with TypeScript -- Vite for building -- TailwindCSS for styling -- Nostrify for Nostr integration -- shadcn/ui components - -When creating new components or pages, follow the existing patterns in the codebase.` - }); - - return result; -} \ No newline at end of file diff --git a/src/lib/debug-fs.ts b/src/lib/debug-fs.ts deleted file mode 100644 index 20a1a523..00000000 --- a/src/lib/debug-fs.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { fsManager } from './fs'; - -export async function debugProjectFiles(projectId: string) { - console.log('=== Debugging project files ==='); - console.log('Project ID:', projectId); - - try { - const rootFiles = await fsManager.listFiles(projectId, ''); - console.log('Root files:', rootFiles); - - for (const file of rootFiles) { - const filePath = `${fsManager['dir']}/${projectId}/${file}`; - try { - const stat = await fsManager['fs'].promises.stat(filePath); - console.log(`${file}: ${stat.isDirectory() ? 'directory' : 'file'}`); - - if (stat.isDirectory() && file !== '.git') { - const subFiles = await fsManager.listFiles(projectId, file); - console.log(` ${file}/ contents:`, subFiles); - } - } catch (error) { - console.error(`Error accessing ${file}:`, error); - } - } - } catch (error) { - console.error('Error listing files:', error); - } -} \ No newline at end of file