mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Enable text chats
This commit is contained in:
16 files changed
+649
-95
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { type Project } from '@/lib/ProjectsManager';
|
||||
import { type ChatItem } from '@/lib/ProjectsManager';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -9,7 +9,7 @@ import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
|
||||
interface AppLayoutProps {
|
||||
children: React.ReactNode;
|
||||
selectedProject?: Project | null;
|
||||
selectedProject?: ChatItem | null;
|
||||
title?: string;
|
||||
showSidebar?: boolean;
|
||||
headerContent?: React.ReactNode;
|
||||
@@ -21,7 +21,7 @@ export function AppLayout({
|
||||
showSidebar = true,
|
||||
headerContent
|
||||
}: AppLayoutProps) {
|
||||
const [_projects, setProjects] = useState<Project[]>([]);
|
||||
const [_projects, setProjects] = useState<ChatItem[]>([]);
|
||||
const projectsManager = useProjectsManager();
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
@@ -34,7 +34,7 @@ export function AppLayout({
|
||||
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
|
||||
@@ -59,10 +59,14 @@ export function AppLayout({
|
||||
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('/');
|
||||
}
|
||||
@@ -101,10 +105,10 @@ export function AppLayout({
|
||||
{/* Sidebar - positioned above the backdrop */}
|
||||
<div className="relative left-0 top-0 h-full w-80 max-w-[80vw] bg-background border-r shadow-lg z-10">
|
||||
<ProjectSidebar
|
||||
selectedProject={selectedProject}
|
||||
onSelectProject={(project) => {
|
||||
selectedItem={selectedProject}
|
||||
onSelectItem={(item) => {
|
||||
setIsSidebarVisible(false); // Always collapse sidebar on mobile navigation
|
||||
handleProjectSelect(project);
|
||||
handleProjectSelect(item);
|
||||
}}
|
||||
onClose={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
@@ -125,8 +129,8 @@ export function AppLayout({
|
||||
{showSidebar && isSidebarVisible && (
|
||||
<div className="w-80 border-r bg-sidebar transition-all duration-300">
|
||||
<ProjectSidebar
|
||||
selectedProject={selectedProject}
|
||||
onSelectProject={handleProjectSelect}
|
||||
selectedItem={selectedProject}
|
||||
onSelectItem={handleProjectSelect}
|
||||
className="h-screen sticky top-0"
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
|
||||
@@ -54,8 +54,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -70,8 +70,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
onToggleSidebar={mockToggle}
|
||||
/>
|
||||
</TestApp>
|
||||
@@ -88,8 +88,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -101,8 +101,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -115,8 +115,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -128,8 +128,8 @@ describe('ProjectSidebar', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
selectedItem={null}
|
||||
onSelectItem={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle } from 'lucide-react';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, MessageSquare } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
@@ -9,25 +9,29 @@ import { useProjects } from '@/hooks/useProjects';
|
||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import type { Project } from '@/lib/ProjectsManager';
|
||||
import type { ChatItem } from '@/lib/ProjectsManager';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||
|
||||
interface ProjectItemProps {
|
||||
project: Project;
|
||||
interface ChatItemProps {
|
||||
item: ChatItem;
|
||||
isSelected: boolean;
|
||||
onSelect: (project: Project) => void;
|
||||
onSelect: (item: ChatItem) => void;
|
||||
isFavorite?: boolean;
|
||||
}
|
||||
|
||||
const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect, isFavorite }) => {
|
||||
const ChatItemComponent: React.FC<ChatItemProps> = ({ item, isSelected, onSelect, isFavorite }) => {
|
||||
const navigate = useNavigate();
|
||||
const { hasRunningSessions } = useProjectSessionStatus(project.id);
|
||||
const { hasRunningSessions } = useProjectSessionStatus(item.id);
|
||||
|
||||
const handleClick = () => {
|
||||
onSelect(project);
|
||||
navigate(`/project/${project.id}`);
|
||||
onSelect(item);
|
||||
if (item.type === 'project') {
|
||||
navigate(`/project/${item.id}`);
|
||||
} else {
|
||||
navigate(`/chat/${item.id}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -46,6 +50,8 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
<div className="flex-shrink-0">
|
||||
{hasRunningSessions ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
) : item.type === 'chat' ? (
|
||||
<MessageSquare className="h-4 w-4 text-accent" />
|
||||
) : (
|
||||
<Folder className="h-4 w-4 text-primary" />
|
||||
)}
|
||||
@@ -53,7 +59,7 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
<div className="flex justify-between gap-2 flex-1 min-w-0">
|
||||
<div className="min-w-0 flex-1 flex items-center">
|
||||
<h3 className="font-medium text-sm truncate">
|
||||
{project.name}
|
||||
{item.name}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
@@ -72,26 +78,26 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
);
|
||||
};
|
||||
|
||||
ProjectItem.displayName = 'ProjectItem';
|
||||
ChatItemComponent.displayName = 'ChatItemComponent';
|
||||
|
||||
interface ProjectSidebarProps {
|
||||
selectedProject: Project | null;
|
||||
onSelectProject: (project: Project | null) => void;
|
||||
selectedItem: ChatItem | null;
|
||||
onSelectItem: (item: ChatItem | null) => void;
|
||||
className?: string;
|
||||
onToggleSidebar?: () => void;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export function ProjectSidebar({
|
||||
selectedProject,
|
||||
onSelectProject,
|
||||
selectedItem,
|
||||
onSelectItem,
|
||||
className,
|
||||
onToggleSidebar,
|
||||
onClose
|
||||
}: ProjectSidebarProps) {
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
const { data: items = [], isLoading, error } = useProjects();
|
||||
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
|
||||
|
||||
const isMobile = useIsMobile();
|
||||
@@ -106,10 +112,15 @@ export function ProjectSidebar({
|
||||
};
|
||||
|
||||
const handleNewProject = () => {
|
||||
onSelectProject(null);
|
||||
onSelectItem(null);
|
||||
navigateAndClose('/');
|
||||
};
|
||||
|
||||
const handleNewChat = () => {
|
||||
onSelectItem(null);
|
||||
navigateAndClose('/?mode=chat');
|
||||
};
|
||||
|
||||
const handleToggleSidebar = () => {
|
||||
if (onToggleSidebar) {
|
||||
onToggleSidebar();
|
||||
@@ -166,7 +177,7 @@ export function ProjectSidebar({
|
||||
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<div className="p-2">
|
||||
<div className="mb-2">
|
||||
<div className="mb-2 space-y-2">
|
||||
<div className="relative rounded-md bg-gradient-to-r from-primary to-accent hover:from-primary/90 hover:to-accent/90 transition-all duration-200">
|
||||
<div className="flex">
|
||||
<button
|
||||
@@ -195,6 +206,14 @@ export function ProjectSidebar({
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleNewChat}
|
||||
className="w-full bg-gradient-to-r from-accent to-primary hover:from-accent/90 hover:to-primary/90 transition-all duration-200"
|
||||
size="sm"
|
||||
>
|
||||
<MessageSquare className="h-4 w-4 mr-2" />
|
||||
{t('newChat')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
@@ -208,7 +227,7 @@ export function ProjectSidebar({
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : projects.length === 0 ? (
|
||||
) : items.length === 0 ? (
|
||||
<div className="text-center p-6 text-muted-foreground">
|
||||
<Folder className="h-8 w-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">{t('noProjectsYet')}</p>
|
||||
@@ -216,13 +235,13 @@ export function ProjectSidebar({
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
{projects.map((project) => (
|
||||
<ProjectItem
|
||||
key={project.id}
|
||||
project={project}
|
||||
isSelected={selectedProject?.id === project.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(project.id)}
|
||||
{items.map((item) => (
|
||||
<ChatItemComponent
|
||||
key={item.id}
|
||||
item={item}
|
||||
isSelected={selectedItem?.id === item.id}
|
||||
onSelect={onSelectItem}
|
||||
isFavorite={favorites.includes(item.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -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<Project[]>([]);
|
||||
const [_projects, setProjects] = useState<ChatItem[]>([]);
|
||||
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() {
|
||||
/>
|
||||
<div className="relative left-0 top-0 h-full w-80 max-w-[80vw] bg-background border-r shadow-lg z-10">
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={(project) => {
|
||||
selectedItem={null}
|
||||
onSelectItem={(item) => {
|
||||
setIsSidebarVisible(false);
|
||||
handleProjectSelect(project);
|
||||
handleProjectSelect(item);
|
||||
}}
|
||||
onClose={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
@@ -168,8 +172,8 @@ export function SettingsLayout() {
|
||||
{isSidebarVisible && (
|
||||
<div className="w-80 border-r bg-sidebar flex-shrink-0">
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={handleProjectSelect}
|
||||
selectedItem={null}
|
||||
onSelectItem={handleProjectSelect}
|
||||
className="h-full"
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
|
||||
@@ -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<ChatPaneRef, ChatPaneProps>(({
|
||||
isBuildLoading: externalIsBuildLoading,
|
||||
consoleError,
|
||||
onDismissConsoleError,
|
||||
isTextChat = false,
|
||||
}, ref) => {
|
||||
const { t } = useTranslation();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -132,8 +134,13 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}, [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<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
|
||||
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<ChatPaneRef, ChatPaneProps>(({
|
||||
customTools,
|
||||
onUpdateMetadata,
|
||||
onAIError,
|
||||
isTextChat,
|
||||
});
|
||||
|
||||
// Handle console error help requests
|
||||
|
||||
Reference in new issue
Block a user