-
+
{isLoading ? (
@@ -208,7 +227,7 @@ export function ProjectSidebar({
))}
- ) : projects.length === 0 ? (
+ ) : items.length === 0 ? (
{t('noProjectsYet')}
@@ -216,13 +235,13 @@ export function ProjectSidebar({
) : (
- {projects.map((project) => (
-
(
+
))}
diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx
index ba1fe434..38695173 100644
--- a/src/components/SettingsLayout.tsx
+++ b/src/components/SettingsLayout.tsx
@@ -7,7 +7,7 @@ import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-re
import { ProjectSidebar } from '@/components/ProjectSidebar';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useIsMobile } from '@/hooks/useIsMobile';
-import { type Project } from '@/lib/ProjectsManager';
+import { type ChatItem } from '@/lib/ProjectsManager';
import { useCallback } from 'react';
import { cn } from '@/lib/utils';
@@ -72,14 +72,14 @@ export function SettingsLayout() {
const isMobile = useIsMobile();
const projectsManager = useProjectsManager();
- const [_projects, setProjects] = useState
([]);
+ const [_projects, setProjects] = useState([]);
const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
const [hasSetInitialState, setHasSetInitialState] = useState(false);
const loadProjects = useCallback(async () => {
try {
await projectsManager.init();
- const projectList = await projectsManager.getProjects();
+ const projectList = await projectsManager.getAllChatItems();
setProjects(projectList);
// Set initial sidebar state based on projects and device type
@@ -104,10 +104,14 @@ export function SettingsLayout() {
loadProjects();
}, [loadProjects]);
- const handleProjectSelect = (project: Project | null) => {
- if (project) {
+ const handleProjectSelect = (item: ChatItem | null) => {
+ if (item) {
setIsSidebarVisible(false); // Collapse sidebar on mobile navigation
- navigate(`/project/${project.id}`);
+ if (item.type === 'project') {
+ navigate(`/project/${item.id}`);
+ } else {
+ navigate(`/chat/${item.id}`);
+ }
} else {
navigate('/');
}
@@ -145,10 +149,10 @@ export function SettingsLayout() {
/>
{
+ selectedItem={null}
+ onSelectItem={(item) => {
setIsSidebarVisible(false);
- handleProjectSelect(project);
+ handleProjectSelect(item);
}}
onClose={() => setIsSidebarVisible(false)}
/>
@@ -168,8 +172,8 @@ export function SettingsLayout() {
{isSidebarVisible && (
setIsSidebarVisible(false)}
/>
diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx
index 78021f31..8c9c2014 100644
--- a/src/components/Shakespeare/ChatPane.tsx
+++ b/src/components/Shakespeare/ChatPane.tsx
@@ -55,6 +55,7 @@ interface ChatPaneProps {
isBuildLoading?: boolean;
consoleError?: ProjectPreviewConsoleError | null;
onDismissConsoleError?: () => void;
+ isTextChat?: boolean; // Whether this is a text chat (no tools) vs a project chat
}
export interface ChatPaneRef {
@@ -70,6 +71,7 @@ export const ChatPane = forwardRef(({
isBuildLoading: externalIsBuildLoading,
consoleError,
onDismissConsoleError,
+ isTextChat = false,
}, ref) => {
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
@@ -132,8 +134,13 @@ export const ChatPane = forwardRef(({
}, [projectId, providerModel]);
// Initialize AI chat with tools
- const cwd = `/projects/${projectId}`;
+ const cwd = isTextChat ? `/chats/${projectId}` : `/projects/${projectId}`;
const customTools = useMemo(() => {
+ // For text chats, return empty tools object
+ if (isTextChat) {
+ return {};
+ }
+
const baseTools = {
git_commit: new GitCommitTool(fs, cwd, git),
text_editor_view: new TextEditorViewTool(fs, cwd),
@@ -163,7 +170,7 @@ export const ChatPane = forwardRef(({
}
return baseTools;
- }, [fs, git, cwd, user, projectId]);
+ }, [fs, git, cwd, user, projectId, isTextChat]);
// Convert tools to OpenAI format
const tools = useMemo(() => {
@@ -215,6 +222,7 @@ export const ChatPane = forwardRef(({
customTools,
onUpdateMetadata,
onAIError,
+ isTextChat,
});
// Handle console error help requests
diff --git a/src/hooks/useAIChat.ts b/src/hooks/useAIChat.ts
index a6c1418f..835375fc 100644
--- a/src/hooks/useAIChat.ts
+++ b/src/hooks/useAIChat.ts
@@ -13,6 +13,7 @@ interface UseAIChatSessionOptions {
maxSteps?: number;
onUpdateMetadata?: (title: string, description: string) => void;
onAIError?: (error: Error) => void;
+ isTextChat?: boolean;
}
interface StreamingMessage {
@@ -32,7 +33,8 @@ export function useAIChat({
customTools = {},
maxSteps = 50,
onUpdateMetadata,
- onAIError
+ onAIError,
+ isTextChat = false
}: UseAIChatSessionOptions) {
const sessionManager = useSessionManager();
const { isConfigured } = useAISettings();
@@ -46,14 +48,14 @@ export function useAIChat({
const initSession = useCallback(async () => {
// Load or update session
- const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps);
+ const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps, isTextChat);
// Initialize individual state variables from existing session
setMessages([...session.messages]);
setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined);
setIsLoading(session.isLoading);
setTotalCost(session.totalCost || 0);
setLastInputTokens(session.lastInputTokens || 0);
- }, [sessionManager, projectId, tools, customTools, maxSteps]);
+ }, [sessionManager, projectId, tools, customTools, maxSteps, isTextChat]);
// Initialize session
useEffect(() => {
diff --git a/src/hooks/useProjects.test.tsx b/src/hooks/useProjects.test.tsx
index 1af5c241..9200dc6e 100644
--- a/src/hooks/useProjects.test.tsx
+++ b/src/hooks/useProjects.test.tsx
@@ -25,21 +25,24 @@ function createTestWrapper() {
vi.mock('./useProjectsManager', () => ({
useProjectsManager: () => ({
init: vi.fn().mockResolvedValue(undefined),
- getProjects: vi.fn().mockResolvedValue([
+ getAllChatItems: vi.fn().mockResolvedValue([
{
id: 'project-1',
name: 'Project 1',
lastModified: new Date('2023-01-01'),
+ type: 'project' as const,
},
{
id: 'project-2',
name: 'Project 2',
lastModified: new Date('2023-01-02'),
+ type: 'project' as const,
},
{
id: 'project-3',
name: 'Project 3',
lastModified: new Date('2023-01-03'),
+ type: 'project' as const,
},
] as Project[]),
}),
diff --git a/src/hooks/useProjects.ts b/src/hooks/useProjects.ts
index 4951e311..869bab2f 100644
--- a/src/hooks/useProjects.ts
+++ b/src/hooks/useProjects.ts
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useLocalStorage } from '@/hooks/useLocalStorage';
-import type { Project } from '@/lib/ProjectsManager';
+import type { ChatItem } from '@/lib/ProjectsManager';
export function useProjects() {
const projectsManager = useProjectsManager();
@@ -9,12 +9,12 @@ export function useProjects() {
return useQuery({
queryKey: ['projects'],
- queryFn: async (): Promise => {
+ queryFn: async (): Promise => {
await projectsManager.init();
- const projects = await projectsManager.getProjects();
-
- // Sort projects: favorites first, then by lastModified (newest first)
- return projects.sort((a, b) => {
+ const items = await projectsManager.getAllChatItems();
+
+ // Sort items: favorites first, then by lastModified (newest first)
+ return items.sort((a, b) => {
const aIsFavorite = favorites.includes(a.id);
const bIsFavorite = favorites.includes(b.id);
diff --git a/src/lib/DotAI.ts b/src/lib/DotAI.ts
index 56864b77..772ab00b 100644
--- a/src/lib/DotAI.ts
+++ b/src/lib/DotAI.ts
@@ -8,10 +8,10 @@ export class DotAI {
readonly historyDir: string;
readonly workingDir: string;
- constructor(fs: JSRuntimeFS, workingDir: string = "/") {
+ constructor(fs: JSRuntimeFS, workingDir: string = "/", customHistoryDir?: string) {
this.fs = fs;
this.workingDir = workingDir;
- this.historyDir = join(workingDir, ".git", "ai", "history");
+ this.historyDir = customHistoryDir || join(workingDir, ".git", "ai", "history");
}
/** Generate a unique session name based on the current date and time */
diff --git a/src/lib/ProjectsManager.ts b/src/lib/ProjectsManager.ts
index 11b57787..bad4f228 100644
--- a/src/lib/ProjectsManager.ts
+++ b/src/lib/ProjectsManager.ts
@@ -17,8 +17,19 @@ export interface Project {
name: string;
path: string;
lastModified: Date;
+ type: 'project';
}
+export interface TextChat {
+ id: string;
+ name: string;
+ path: string;
+ lastModified: Date;
+ type: 'chat';
+}
+
+export type ChatItem = Project | TextChat;
+
export interface ProjectsManagerOptions {
fs: JSRuntimeFS;
git: Git;
@@ -28,11 +39,13 @@ export class ProjectsManager {
fs: JSRuntimeFS;
git: Git;
dir: string;
+ chatsDir: string;
constructor(options: ProjectsManagerOptions) {
this.fs = options.fs;
this.git = options.git;
this.dir = '/projects';
+ this.chatsDir = '/chats';
}
async init() {
@@ -41,6 +54,11 @@ export class ProjectsManager {
} catch {
// Directory might already exist
}
+ try {
+ await this.fs.mkdir(this.chatsDir);
+ } catch {
+ // Directory might already exist
+ }
}
async createProject(name: string, customId?: string): Promise {
@@ -264,6 +282,7 @@ export class ProjectsManager {
name: projectName,
path: projectPath,
lastModified: timestamp,
+ type: 'project' as const,
};
} catch (error) {
// Clean up on error (only if this was a new project creation)
@@ -317,6 +336,7 @@ export class ProjectsManager {
name: this.formatProjectName(id), // Use formatted directory name
path: projectPath,
lastModified: timestamp,
+ type: 'project' as const,
};
} catch (error) {
// Clean up the directory that was created if cloning fails
@@ -348,6 +368,7 @@ export class ProjectsManager {
name: this.formatProjectName(dir), // Convert directory name to readable format
path: projectPath,
lastModified: modifiedDate,
+ type: 'project' as const,
};
projects.push(project);
@@ -375,6 +396,7 @@ export class ProjectsManager {
name: this.formatProjectName(id), // Convert directory name to readable format
path: projectPath,
lastModified: modifiedDate,
+ type: 'project' as const,
};
}
@@ -508,6 +530,7 @@ export class ProjectsManager {
name: this.formatProjectName(newId),
path: newPath,
lastModified: timestamp,
+ type: 'project' as const,
};
}
@@ -658,4 +681,180 @@ export class ProjectsManager {
return '/' + normalized.join('/');
}
+
+ // Text Chat Methods
+
+ async createTextChat(name: string): Promise {
+ const id = await this.generateUniqueChatId(name);
+ const chatPath = `${this.chatsDir}/${id}`;
+
+ // Create the chat directory
+ await this.fs.mkdir(chatPath, { recursive: true });
+
+ // Create a metadata file
+ const metadata = {
+ name,
+ createdAt: new Date().toISOString(),
+ };
+ await this.fs.writeFile(`${chatPath}/metadata.json`, JSON.stringify(metadata, null, 2));
+
+ const stats = await this.fs.stat(chatPath);
+ const timestamp = stats.mtimeMs ? new Date(stats.mtimeMs) : new Date();
+
+ return {
+ id,
+ name,
+ path: chatPath,
+ lastModified: timestamp,
+ type: 'chat',
+ };
+ }
+
+ async getTextChats(): Promise {
+ try {
+ const chatDirs = await this.fs.readdir(this.chatsDir);
+ const chats: TextChat[] = [];
+
+ for (const dir of chatDirs) {
+ const chatPath = `${this.chatsDir}/${dir}`;
+
+ try {
+ const stats = await this.fs.stat(chatPath);
+ if (stats.isDirectory()) {
+ // Try to read metadata
+ let name = this.formatProjectName(dir);
+ try {
+ const metadataContent = await this.fs.readFile(`${chatPath}/metadata.json`, 'utf8');
+ const metadata = JSON.parse(metadataContent);
+ name = metadata.name || name;
+ } catch {
+ // If metadata doesn't exist, use formatted directory name
+ }
+
+ const modifiedDate = stats.mtimeMs ? new Date(stats.mtimeMs) : new Date();
+ const chat: TextChat = {
+ id: dir,
+ name,
+ path: chatPath,
+ lastModified: modifiedDate,
+ type: 'chat',
+ };
+
+ chats.push(chat);
+ }
+ } catch {
+ // Skip if we can't stat the directory
+ }
+ }
+
+ return chats.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime());
+ } catch {
+ return [];
+ }
+ }
+
+ async getTextChat(id: string): Promise {
+ try {
+ const chatPath = `${this.chatsDir}/${id}`;
+ const stats = await this.fs.stat(chatPath);
+
+ if (stats.isDirectory()) {
+ // Try to read metadata
+ let name = this.formatProjectName(id);
+ try {
+ const metadataContent = await this.fs.readFile(`${chatPath}/metadata.json`, 'utf8');
+ const metadata = JSON.parse(metadataContent);
+ name = metadata.name || name;
+ } catch {
+ // If metadata doesn't exist, use formatted directory name
+ }
+
+ const modifiedDate = stats.mtimeMs ? new Date(stats.mtimeMs) : new Date();
+ return {
+ id,
+ name,
+ path: chatPath,
+ lastModified: modifiedDate,
+ type: 'chat',
+ };
+ }
+
+ return null;
+ } catch {
+ return null;
+ }
+ }
+
+ async deleteTextChat(chatId: string): Promise {
+ const chatPath = `${this.chatsDir}/${chatId}`;
+ await this.deleteDirectory(chatPath);
+ }
+
+ async renameTextChat(oldId: string, newName: string): Promise {
+ const oldChat = await this.getTextChat(oldId);
+ if (!oldChat) {
+ throw new Error(`Chat with ID "${oldId}" does not exist`);
+ }
+
+ const chatPath = `${this.chatsDir}/${oldId}`;
+
+ // Update metadata with new name
+ const metadata = {
+ name: newName,
+ createdAt: new Date().toISOString(),
+ };
+ await this.fs.writeFile(`${chatPath}/metadata.json`, JSON.stringify(metadata, null, 2));
+
+ // Use current timestamp for modification time
+ const timestamp = new Date();
+
+ return {
+ id: oldId,
+ name: newName,
+ path: chatPath,
+ lastModified: timestamp,
+ type: 'chat',
+ };
+ }
+
+ async getAllChatItems(): Promise {
+ const [projects, textChats] = await Promise.all([
+ this.getProjects(),
+ this.getTextChats(),
+ ]);
+
+ // Add type field to projects
+ const projectsWithType: Project[] = projects.map(p => ({ ...p, type: 'project' as const }));
+
+ // Combine and sort by lastModified
+ const allItems: ChatItem[] = [...projectsWithType, ...textChats];
+ return allItems.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime());
+ }
+
+ private async generateUniqueChatId(name: string): Promise {
+ const baseSlug = name
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, '-')
+ .replace(/^-+|-+$/g, '');
+
+ let slug = baseSlug;
+ let counter = 1;
+
+ while (await this.chatExists(slug)) {
+ slug = `${baseSlug}-${counter}`;
+ counter++;
+ }
+
+ return slug;
+ }
+
+ private async chatExists(id: string): Promise {
+ try {
+ const chatPath = `${this.chatsDir}/${id}`;
+ await this.fs.stat(chatPath);
+ return true;
+ } catch {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts
index 7f9431ee..7912d291 100644
--- a/src/lib/SessionManager.ts
+++ b/src/lib/SessionManager.ts
@@ -35,6 +35,7 @@ export interface SessionState {
abortController?: AbortController;
totalCost?: number; // Total cost in USD for this session
lastInputTokens?: number; // Input tokens from the last AI request
+ isTextChat?: boolean; // Whether this is a text chat (no tools) vs a project chat
}
export interface SessionManagerEvents {
@@ -72,20 +73,23 @@ export class SessionManager {
}
/**
- * Create a new session for a project
+ * Create a new session for a project or text chat
*/
async loadSession(
projectId: string,
tools: Record,
customTools: Record>,
- maxSteps?: number
+ maxSteps?: number,
+ isTextChat?: boolean
): Promise {
let messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [];
let sessionName = DotAI.generateSessionName();
// Try to load existing history
try {
- const dotAI = new DotAI(this.fs, `/projects/${projectId}`);
+ const workingDir = isTextChat ? `/chats/${projectId}` : `/projects/${projectId}`;
+ const historyDir = isTextChat ? `${workingDir}/history` : undefined;
+ const dotAI = new DotAI(this.fs, workingDir, historyDir);
const lastSession = await dotAI.readLastSessionHistory();
if (lastSession) {
messages = lastSession.messages;
@@ -104,6 +108,7 @@ export class SessionManager {
lastActivity: new Date(),
totalCost: 0,
lastInputTokens: 0,
+ isTextChat,
...this.sessions.get(projectId),
messages,
sessionName,
@@ -226,8 +231,9 @@ export class SessionManager {
tool_calls: undefined
};
+ const cwd = session.isTextChat ? `/chats/${projectId}` : `/projects/${projectId}`;
const systemPrompt = await makeSystemPrompt({
- cwd: `/projects/${projectId}`,
+ cwd,
fs: this.fs,
mode: "agent",
name: "Shakespeare",
@@ -549,7 +555,9 @@ export class SessionManager {
if (!session) return;
try {
- const dotAI = new DotAI(this.fs, `/projects/${session.projectId}`);
+ const workingDir = session.isTextChat ? `/chats/${session.projectId}` : `/projects/${session.projectId}`;
+ const historyDir = session.isTextChat ? `${workingDir}/history` : undefined;
+ const dotAI = new DotAI(this.fs, workingDir, historyDir);
await dotAI.setHistory(session.sessionName, session.messages);
} catch (error) {
console.warn('Failed to save session history:', error);
diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts
index 6a0256d0..f90963f7 100644
--- a/src/lib/i18n.ts
+++ b/src/lib/i18n.ts
@@ -84,6 +84,7 @@ const resources = {
// Project Sidebar
newProject: 'New Project',
+ newChat: 'New Chat',
importRepository: 'Import Repository',
noProjectsYet: 'No projects yet',
createFirstProject: 'Create your first project to get started',
@@ -395,6 +396,7 @@ const resources = {
// Project Sidebar
newProject: 'Novo Projeto',
+ newChat: 'Nova Conversa',
importRepository: 'Importar Repositório',
noProjectsYet: 'Nenhum projeto ainda',
createFirstProject: 'Crie seu primeiro projeto para começar',
@@ -706,6 +708,7 @@ const resources = {
// Project Sidebar
newProject: '新项目',
+ newChat: '新对话',
importRepository: '导入仓库',
noProjectsYet: '还没有项目',
createFirstProject: '创建您的第一个项目开始使用',
@@ -1017,6 +1020,7 @@ const resources = {
// Project Sidebar
newProject: 'Sabon Aikin',
+ newChat: 'Sabuwar Hira',
importRepository: 'Shigo da Repository',
noProjectsYet: 'Babu ayyuka har yanzu',
createFirstProject: 'Ƙirƙiri aikin farko don farawa',
@@ -1328,6 +1332,7 @@ const resources = {
// Project Sidebar
newProject: 'Iṣẹ akanṣe Tuntun',
+ newChat: 'Ibaraẹnisọrọ Tuntun',
importRepository: 'Gbe Repository wọle',
noProjectsYet: 'Ko si awọn iṣẹ akanṣe sibẹsibẹ',
createFirstProject: 'Ṣẹda iṣẹ akanṣe akọkọ rẹ lati bẹrẹ',
@@ -1634,6 +1639,7 @@ const resources = {
// Project Sidebar
newProject: 'Ọrụ Ọhụrụ',
+ newChat: 'Mkparịta Ụka Ọhụrụ',
importRepository: 'Bubata Repository',
noProjectsYet: 'Enwebeghị ọrụ ọ bụla',
createFirstProject: 'Mepụta ọrụ mbụ gị iji malite',
diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx
index e2c4232e..edefd422 100644
--- a/src/pages/Index.tsx
+++ b/src/pages/Index.tsx
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
-import { useNavigate } from 'react-router-dom';
+import { useNavigate, useSearchParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useAIProjectId } from '@/hooks/useAIProjectId';
@@ -25,6 +25,8 @@ import { ShakespeareLogo } from '@/components/ShakespeareLogo';
export default function Index() {
const { t } = useTranslation();
+ const [searchParams] = useSearchParams();
+ const mode = searchParams.get('mode'); // 'chat' for text chat, null for project
const [prompt, setPrompt] = useState('');
const [isCreating, setIsCreating] = useState(false);
const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', '');
@@ -184,11 +186,76 @@ export default function Index() {
const handleCreateProject = async () => {
if (!prompt.trim() || !providerModel.trim()) return;
- // Clear stored prompt when creating project
+ // Clear stored prompt when creating project/chat
setStoredPrompt('');
setIsCreating(true);
try {
+ // For text chat mode, create a text chat instead of a project
+ if (mode === 'chat') {
+ // Create text chat
+ const chat = await projectsManager.createTextChat(prompt.trim());
+
+ // Build message content as text parts
+ const contentParts: Array = [];
+
+ // Add user input as text part if present
+ if (prompt.trim()) {
+ contentParts.push({
+ type: 'text',
+ text: prompt.trim()
+ });
+ }
+
+ // Process attached files and add as separate text parts
+ if (attachedFiles.length > 0) {
+ const filePromises = attachedFiles.map(async (file) => {
+ try {
+ const savedPath = await saveFileToTmp(fs, file);
+ return `Added file: ${savedPath}`;
+ } catch (error) {
+ console.error('Failed to save file:', error);
+ return `Failed to save file: ${file.name}`;
+ }
+ });
+
+ const fileResults = await Promise.all(filePromises);
+
+ // Add each file as a separate text part
+ fileResults.forEach(fileResult => {
+ contentParts.push({
+ type: 'text',
+ text: fileResult
+ });
+ });
+ }
+
+ // Store the initial message in chat history using DotAI
+ const dotAI = new DotAI(fs, chat.path);
+ const sessionName = DotAI.generateSessionName();
+
+ // Create initial message with content parts
+ const initialMessage: AIMessage = {
+ role: 'user',
+ content: contentParts.length === 1 ? contentParts[0].text : contentParts
+ };
+ await dotAI.setHistory(sessionName, [initialMessage]);
+
+ // Add model to recently used
+ addRecentlyUsedModel(providerModel.trim());
+
+ // Clear attached files after successful creation
+ setAttachedFiles([]);
+
+ // Navigate to the chat with autostart parameter and model
+ const searchParams = new URLSearchParams({
+ autostart: 'true',
+ ...(providerModel.trim() && { model: providerModel.trim() })
+ });
+ navigate(`/chat/${chat.id}?${searchParams.toString()}`);
+ return;
+ }
+
// Use AI to generate project ID
const projectId = await generateProjectId(providerModel, prompt.trim());
@@ -272,10 +339,10 @@ export default function Index() {
- {t('buildNostrApps')}
+ {mode === 'chat' ? 'Start a new chat' : t('buildNostrApps')}
- {t('whatToBuild')}
+ {mode === 'chat' ? 'What would you like to talk about?' : t('whatToBuild')}
diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx
index 87a3af2e..1f3d2f15 100644
--- a/src/pages/ProjectView.tsx
+++ b/src/pages/ProjectView.tsx
@@ -193,13 +193,17 @@ export function ProjectView() {
{/* Sidebar - positioned above the backdrop */}
{
- setProject(selectedProject);
+ selectedItem={project}
+ onSelectItem={(selectedItem) => {
setIsSidebarVisible(false); // Always collapse sidebar on mobile navigation
- if (selectedProject) {
- setMobileView('chat'); // Switch to chat view when selecting a project
- navigate(`/project/${selectedProject.id}`);
+ if (selectedItem) {
+ if (selectedItem.type === 'project') {
+ setProject(selectedItem);
+ setMobileView('chat'); // Switch to chat view when selecting a project
+ navigate(`/project/${selectedItem.id}`);
+ } else {
+ navigate(`/chat/${selectedItem.id}`);
+ }
} else {
navigate('/');
}
@@ -308,11 +312,15 @@ export function ProjectView() {
{/* Fixed Sidebar */}
{
- setProject(selectedProject);
- if (selectedProject) {
- navigate(`/project/${selectedProject.id}`);
+ selectedItem={project}
+ onSelectItem={(selectedItem) => {
+ if (selectedItem) {
+ if (selectedItem.type === 'project') {
+ setProject(selectedItem);
+ navigate(`/project/${selectedItem.id}`);
+ } else {
+ navigate(`/chat/${selectedItem.id}`);
+ }
} else {
navigate('/');
}
diff --git a/src/pages/TextChatView.tsx b/src/pages/TextChatView.tsx
new file mode 100644
index 00000000..d1714b68
--- /dev/null
+++ b/src/pages/TextChatView.tsx
@@ -0,0 +1,224 @@
+import { useState, useEffect, useCallback, useRef } from 'react';
+import { useParams } from 'react-router-dom';
+import type { TextChat } from '@/lib/ProjectsManager';
+import { useProjectsManager } from '@/hooks/useProjectsManager';
+import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane';
+import { ProjectSidebar } from '@/components/ProjectSidebar';
+import { Button } from '@/components/ui/button';
+import { Skeleton } from '@/components/ui/skeleton';
+import { ArrowLeft, Menu } from 'lucide-react';
+import { useNavigate } from 'react-router-dom';
+import { useIsMobile } from '@/hooks/useIsMobile';
+
+export function TextChatView() {
+ const { chatId } = useParams<{ chatId: string }>();
+ const [chat, setChat] = useState(null);
+ const [isLoading, setIsLoading] = useState(true);
+ const [isAILoading, setIsAILoading] = useState(false);
+
+ const projectsManager = useProjectsManager();
+ const chatPaneRef = useRef(null);
+ const navigate = useNavigate();
+ const isMobile = useIsMobile();
+
+ const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
+
+ const loadChat = useCallback(async () => {
+ if (!chatId) return;
+
+ try {
+ const chatData = await projectsManager.getTextChat(chatId);
+ setChat(chatData);
+ } catch (error) {
+ console.error('Failed to load chat:', error);
+ } finally {
+ setIsLoading(false);
+ }
+ }, [chatId, projectsManager]);
+
+ useEffect(() => {
+ loadChat();
+ }, [loadChat]);
+
+ const handleNewChat = () => {
+ if (chatPaneRef.current) {
+ chatPaneRef.current.startNewSession();
+ }
+ };
+
+ const handleAILoadingChange = (loading: boolean) => {
+ setIsAILoading(loading);
+ };
+
+ if (!chat && !isLoading) {
+ return (
+
+
+
Chat Not Found
+
+
+
+ );
+ }
+
+ if (isMobile) {
+ return (
+
+
+
+
+
+
+ {chat ? (
+
+ {chat.name}
+
+ ) : (
+
+ )}
+
+
+
+
+
+ {/* Mobile Sidebar Overlay */}
+ {isSidebarVisible && (
+
+
setIsSidebarVisible(false)}
+ />
+
+
{
+ setIsSidebarVisible(false);
+ if (selectedItem) {
+ if (selectedItem.type === 'project') {
+ navigate(`/project/${selectedItem.id}`);
+ } else {
+ navigate(`/chat/${selectedItem.id}`);
+ }
+ } else {
+ navigate('/');
+ }
+ }}
+ onClose={() => setIsSidebarVisible(false)}
+ />
+
+
+ )}
+
+
+ {chat ? (
+
+ ) : (
+
+
+
+
+
+
+ )}
+
+
+ );
+ }
+
+ return (
+
+ {/* Fixed Sidebar */}
+
+
{
+ if (selectedItem) {
+ if (selectedItem.type === 'project') {
+ navigate(`/project/${selectedItem.id}`);
+ } else {
+ navigate(`/chat/${selectedItem.id}`);
+ }
+ } else {
+ navigate('/');
+ }
+ }}
+ onToggleSidebar={() => setIsSidebarVisible(!isSidebarVisible)}
+ className="h-full"
+ />
+
+
+ {/* Main Content Area */}
+
+
+
+ {/* Chat Header */}
+
+
+
+ {!isSidebarVisible && (
+
+ )}
+
+
+ {chat ? (
+
+ {chat.name}
+
+ ) : (
+
+ )}
+
+
+
+
+
+ {/* Chat Content */}
+
+ {chat ? (
+
+ ) : (
+
+
+
+
+
+
+ )}
+
+
+
+
+
+ );
+}