mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Revert "Merge branch 'text-chats' into 'main'"
This reverts commit7badd0113f, reversing changes made to02dcd5cbe8.
This commit is contained in:
26 files changed
+721
-1415
No files matched your search
@@ -13,12 +13,10 @@ import {
|
||||
History,
|
||||
Folder,
|
||||
Rocket,
|
||||
Trash2,
|
||||
} from 'lucide-react';
|
||||
import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog';
|
||||
import { GitDialog } from '@/components/GitDialog';
|
||||
import { DeployDialog } from '@/components/DeployDialog';
|
||||
import { DeleteChatDialog } from '@/components/DeleteChatDialog';
|
||||
|
||||
interface ActionsMenuProps {
|
||||
projectId: string;
|
||||
@@ -29,8 +27,6 @@ interface ActionsMenuProps {
|
||||
isBuildLoading?: boolean;
|
||||
disabled?: boolean;
|
||||
onFirstInteraction?: () => void;
|
||||
isChat?: boolean; // Flag to indicate this is a chat, not a project
|
||||
onChatDeleted?: () => void; // Callback when a chat is deleted
|
||||
}
|
||||
|
||||
export function ActionsMenu({
|
||||
@@ -42,13 +38,10 @@ export function ActionsMenu({
|
||||
isBuildLoading = false,
|
||||
disabled = false,
|
||||
onFirstInteraction: _onFirstInteraction,
|
||||
isChat = false,
|
||||
onChatDeleted,
|
||||
}: ActionsMenuProps) {
|
||||
const [gitHistoryOpen, setGitHistoryOpen] = useState(false);
|
||||
const [gitDialogOpen, setGitDialogOpen] = useState(false);
|
||||
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
|
||||
const [deleteChatOpen, setDeleteChatOpen] = useState(false);
|
||||
|
||||
const isAnyLoading = isLoading || isBuildLoading;
|
||||
|
||||
@@ -69,100 +62,75 @@ export function ActionsMenu({
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
{isChat ? (
|
||||
<DropdownMenuItem
|
||||
onClick={() => setDeleteChatOpen(true)}
|
||||
disabled={isLoading}
|
||||
className="gap-2 text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
Delete Chat
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
<>
|
||||
<DropdownMenuItem
|
||||
onClick={onNewChat}
|
||||
disabled={isLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<MessageSquarePlus className="h-4 w-4" />
|
||||
New Chat
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={onNewChat}
|
||||
disabled={isLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<MessageSquarePlus className="h-4 w-4" />
|
||||
New Chat
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitHistoryOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
Rollback
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitHistoryOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
Rollback
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitDialogOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Repository
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitDialogOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Repository
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setDeployDialogOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<Rocket className="h-4 w-4" />
|
||||
Deploy
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={onProjectDetails}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<Folder className="h-4 w-4" />
|
||||
Project Details
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setDeployDialogOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<Rocket className="h-4 w-4" />
|
||||
Deploy
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={onProjectDetails}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<Folder className="h-4 w-4" />
|
||||
Project Details
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Dialogs - only show for projects, not chats */}
|
||||
{!isChat && (
|
||||
<>
|
||||
<GitDialog
|
||||
projectId={projectId}
|
||||
open={gitDialogOpen}
|
||||
onOpenChange={setGitDialogOpen}
|
||||
/>
|
||||
{/* Dialogs */}
|
||||
<GitDialog
|
||||
projectId={projectId}
|
||||
open={gitDialogOpen}
|
||||
onOpenChange={setGitDialogOpen}
|
||||
/>
|
||||
|
||||
<GitHistoryDialog
|
||||
projectId={projectId}
|
||||
open={gitHistoryOpen}
|
||||
onOpenChange={setGitHistoryOpen}
|
||||
/>
|
||||
<GitHistoryDialog
|
||||
projectId={projectId}
|
||||
open={gitHistoryOpen}
|
||||
onOpenChange={setGitHistoryOpen}
|
||||
/>
|
||||
|
||||
<DeployDialog
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
open={deployDialogOpen}
|
||||
onOpenChange={setDeployDialogOpen}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<DeployDialog
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
open={deployDialogOpen}
|
||||
onOpenChange={setDeployDialogOpen}
|
||||
/>
|
||||
|
||||
{/* Delete Chat Dialog - only show for chats */}
|
||||
{isChat && (
|
||||
<DeleteChatDialog
|
||||
chatId={projectId}
|
||||
chatName={projectName}
|
||||
open={deleteChatOpen}
|
||||
onOpenChange={setDeleteChatOpen}
|
||||
onDeleted={onChatDeleted}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -47,7 +47,6 @@ const AppConfigSchema = z.object({
|
||||
fsPathTmp: z.string().min(1),
|
||||
fsPathPlugins: z.string().min(1),
|
||||
fsPathTemplates: z.string().min(1),
|
||||
fsPathChats: z.string().min(1),
|
||||
sentryDsn: z.string(),
|
||||
sentryEnabled: z.boolean(),
|
||||
}) satisfies z.ZodType<AppConfig>;
|
||||
@@ -86,7 +85,6 @@ export function AppProvider(props: AppProviderProps) {
|
||||
config.fsPathTmp = expandPath(config.fsPathTmp);
|
||||
config.fsPathPlugins = expandPath(config.fsPathPlugins);
|
||||
config.fsPathTemplates = expandPath(config.fsPathTemplates);
|
||||
config.fsPathChats = expandPath(config.fsPathChats);
|
||||
|
||||
const appContextValue: AppContextType = {
|
||||
config,
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { useChatsManager } from '@/hooks/useChatsManager';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
|
||||
interface DeleteChatDialogProps {
|
||||
chatId: string;
|
||||
chatName: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onDeleted?: () => void;
|
||||
}
|
||||
|
||||
export function DeleteChatDialog({
|
||||
chatId,
|
||||
chatName,
|
||||
open,
|
||||
onOpenChange,
|
||||
onDeleted,
|
||||
}: DeleteChatDialogProps) {
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const chatsManager = useChatsManager();
|
||||
const { toast } = useToast();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const handleDelete = async () => {
|
||||
setIsDeleting(true);
|
||||
|
||||
try {
|
||||
await chatsManager.deleteChat(chatId);
|
||||
|
||||
// Invalidate the chats query to refresh the sidebar
|
||||
await queryClient.invalidateQueries({ queryKey: ['chats'] });
|
||||
|
||||
toast({
|
||||
title: 'Chat deleted',
|
||||
description: `${chatName} has been deleted successfully.`,
|
||||
});
|
||||
|
||||
onOpenChange(false);
|
||||
|
||||
// Call the onDeleted callback if provided
|
||||
if (onDeleted) {
|
||||
onDeleted();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete chat:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: 'Failed to delete chat. Please try again.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setIsDeleting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete Chat</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Are you sure you want to delete "{chatName}"? This action cannot be undone and all
|
||||
messages will be permanently deleted.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{isDeleting ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Deleting...
|
||||
</>
|
||||
) : (
|
||||
'Delete'
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, Search, MessageSquareText } from 'lucide-react';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, Search } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { useProjects } from '@/hooks/useProjects';
|
||||
import { useChats } from '@/hooks/useChats';
|
||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import type { Project } from '@/lib/ProjectsManager';
|
||||
import type { Chat } from '@/lib/ChatsManager';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||
@@ -77,56 +75,6 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
|
||||
ProjectItem.displayName = 'ProjectItem';
|
||||
|
||||
interface ChatItemProps {
|
||||
chat: Chat;
|
||||
isSelected: boolean;
|
||||
onSelect: (chat: Chat) => void;
|
||||
}
|
||||
|
||||
const ChatItem: React.FC<ChatItemProps> = ({ chat, isSelected, onSelect }) => {
|
||||
const navigate = useNavigate();
|
||||
const { hasRunningSessions } = useProjectSessionStatus(chat.id);
|
||||
|
||||
const handleClick = () => {
|
||||
onSelect(chat);
|
||||
navigate(`/chat/${chat.id}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"group relative rounded-lg transition-all duration-200 hover:bg-gradient-to-r hover:from-primary/10 hover:to-accent/10",
|
||||
isSelected && "bg-gradient-to-r from-primary/15 to-accent/15 shadow-sm"
|
||||
)}
|
||||
>
|
||||
<div className="w-full px-3 py-2 text-left text-sidebar-foreground">
|
||||
<button
|
||||
onClick={handleClick}
|
||||
className="absolute inset-0"
|
||||
/>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex-shrink-0">
|
||||
{hasRunningSessions ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
) : (
|
||||
<MessageSquareText className="h-4 w-4 text-blue-600 dark:text-blue-400" />
|
||||
)}
|
||||
</div>
|
||||
<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">
|
||||
{chat.name}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
ChatItem.displayName = 'ChatItem';
|
||||
|
||||
interface ProjectSidebarProps {
|
||||
selectedProject: Project | null;
|
||||
onSelectProject: (project: Project | null) => void;
|
||||
@@ -144,18 +92,14 @@ export function ProjectSidebar({
|
||||
}: ProjectSidebarProps) {
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
const { data: projects = [], isLoading: isLoadingProjects, error: projectsError } = useProjects();
|
||||
const { data: chats = [], isLoading: isLoadingChats, error: chatsError } = useChats();
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const isLoading = isLoadingProjects || isLoadingChats;
|
||||
const error = projectsError || chatsError;
|
||||
|
||||
// Fast in-memory search filtering for projects
|
||||
// Fast in-memory search filtering
|
||||
const filteredProjects = useMemo(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
return projects;
|
||||
@@ -168,30 +112,6 @@ export function ProjectSidebar({
|
||||
);
|
||||
}, [projects, searchQuery]);
|
||||
|
||||
// Fast in-memory search filtering for chats
|
||||
const filteredChats = useMemo(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
return chats;
|
||||
}
|
||||
|
||||
const query = searchQuery.toLowerCase();
|
||||
return chats.filter(chat =>
|
||||
chat.id.toLowerCase().includes(query) ||
|
||||
chat.name.toLowerCase().includes(query)
|
||||
);
|
||||
}, [chats, searchQuery]);
|
||||
|
||||
// Combine projects and chats, sorted by lastModified
|
||||
const combinedItems = useMemo(() => {
|
||||
const items: Array<{ type: 'project' | 'chat'; item: Project | Chat; lastModified: Date }> = [
|
||||
...filteredProjects.map(p => ({ type: 'project' as const, item: p, lastModified: p.lastModified })),
|
||||
...filteredChats.map(c => ({ type: 'chat' as const, item: c, lastModified: c.lastModified })),
|
||||
];
|
||||
|
||||
// Sort by lastModified (newest first)
|
||||
return items.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime());
|
||||
}, [filteredProjects, filteredChats]);
|
||||
|
||||
// Custom navigate function that closes sidebar on mobile
|
||||
const navigateAndClose = (path: string) => {
|
||||
navigate(path);
|
||||
@@ -292,7 +212,7 @@ export function ProjectSidebar({
|
||||
</div>
|
||||
|
||||
{/* Search Input */}
|
||||
{(projects.length > 0 || chats.length > 0) && (
|
||||
{projects.length > 0 && (
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none" />
|
||||
<Input
|
||||
@@ -317,13 +237,13 @@ export function ProjectSidebar({
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : combinedItems.length === 0 && projects.length === 0 && chats.length === 0 ? (
|
||||
) : projects.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>
|
||||
<p className="text-xs">{t('createFirstProject')}</p>
|
||||
</div>
|
||||
) : combinedItems.length === 0 ? (
|
||||
) : filteredProjects.length === 0 ? (
|
||||
<div className="text-center p-6 text-muted-foreground">
|
||||
<Search className="h-8 w-8 mx-auto mb-2 opacity-50" />
|
||||
<p className="text-sm">{t('noProjectsFound')}</p>
|
||||
@@ -331,24 +251,15 @@ export function ProjectSidebar({
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
{combinedItems.map(({ type, item }) =>
|
||||
type === 'project' ? (
|
||||
<ProjectItem
|
||||
key={`project-${item.id}`}
|
||||
project={item as Project}
|
||||
isSelected={selectedProject?.id === item.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(item.id)}
|
||||
/>
|
||||
) : (
|
||||
<ChatItem
|
||||
key={`chat-${item.id}`}
|
||||
chat={item as Chat}
|
||||
isSelected={false}
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
{filteredProjects.map((project) => (
|
||||
<ProjectItem
|
||||
key={project.id}
|
||||
project={project}
|
||||
isSelected={selectedProject?.id === project.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(project.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,6 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -78,7 +77,6 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -117,7 +115,6 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -159,7 +156,6 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
};
|
||||
|
||||
render(
|
||||
|
||||
@@ -24,13 +24,12 @@ export function SessionMonitor() {
|
||||
const session = sessionManager.getSession(projectId);
|
||||
if (!session) return;
|
||||
|
||||
// Check if user is currently viewing this project or chat
|
||||
const pathParts = location.pathname.split('/');
|
||||
const currentId = pathParts[2]; // /project/{projectId} or /chat/{chatId}
|
||||
const isCurrentView = session.projectId === currentId;
|
||||
// Check if user is currently viewing this project
|
||||
const currentProjectId = location.pathname.split('/')[2]; // /project/{projectId}
|
||||
const isCurrentProject = session.projectId === currentProjectId;
|
||||
|
||||
// Only show notification if user is not currently viewing this project or chat
|
||||
if (!isCurrentView) {
|
||||
// Only show notification if user is not currently viewing this project
|
||||
if (!isCurrentProject) {
|
||||
toast({
|
||||
title: "AI Session Complete",
|
||||
description: `Finished working on ${session.projectId}`,
|
||||
|
||||
@@ -117,7 +117,7 @@ export const ChatInput = memo(function ChatInput({
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="p-4">
|
||||
<div className="border-t p-4">
|
||||
{/* Chat Input Container */}
|
||||
<div
|
||||
className={`flex flex-col rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all ${
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useRef, useEffect, forwardRef, useImperativeHandle, useMemo, useCallback } from 'react';
|
||||
import { useSearchParams, useNavigate } from 'react-router-dom';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
@@ -36,15 +36,12 @@ import { ShellTool } from '@/lib/tools/ShellTool';
|
||||
import { TypecheckTool } from '@/lib/tools/TypecheckTool';
|
||||
import { ReadConsoleMessagesTool } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { SkillTool } from '@/lib/tools/SkillTool';
|
||||
import { StartProjectTool } from '@/lib/tools/StartProjectTool';
|
||||
import { createMCPTools } from '@/lib/tools/MCPTool';
|
||||
import { ProjectPreviewConsoleError } from '@/lib/consoleMessages';
|
||||
import { toolToOpenAI } from '@/lib/tools/openai-adapter';
|
||||
import { Tool } from '@/lib/tools/Tool';
|
||||
import OpenAI from 'openai';
|
||||
import { useGit } from '@/hooks/useGit';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import type { StartProjectResult } from '@/lib/tools/StartProjectTool';
|
||||
import { Quilly } from '@/components/Quilly';
|
||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||
import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
||||
@@ -62,7 +59,6 @@ interface ChatPaneProps {
|
||||
isBuildLoading?: boolean;
|
||||
consoleError?: ProjectPreviewConsoleError | null;
|
||||
onDismissConsoleError?: () => void;
|
||||
isChat?: boolean; // Flag to indicate this is a chat session, not a project
|
||||
}
|
||||
|
||||
export interface ChatPaneRef {
|
||||
@@ -76,19 +72,16 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onLoadingChange,
|
||||
isLoading: externalIsLoading,
|
||||
isBuildLoading: externalIsBuildLoading,
|
||||
isChat = false,
|
||||
consoleError,
|
||||
onDismissConsoleError,
|
||||
}, ref) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const { fs } = useFS();
|
||||
const { git } = useGit();
|
||||
const { user } = useCurrentUser();
|
||||
const { models } = useProviderModels();
|
||||
const { config } = useAppContext();
|
||||
const projectsManager = useProjectsManager();
|
||||
const { projectsPath, tmpPath, pluginsPath } = useFSPaths();
|
||||
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
@@ -150,8 +143,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}, [projectId, providerModel]);
|
||||
|
||||
// Initialize AI chat with tools
|
||||
const { chatsPath } = useFSPaths();
|
||||
const cwd = isChat ? `${chatsPath}/${projectId}` : `${projectsPath}/${projectId}`;
|
||||
const cwd = `${projectsPath}/${projectId}`;
|
||||
const esmUrlRef = useRef(config.esmUrl);
|
||||
const sessionManager = useSessionManager();
|
||||
|
||||
@@ -161,58 +153,11 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
sessionManager.emit('fileChanged', projectId, filePath);
|
||||
}, [sessionManager, projectId]);
|
||||
|
||||
// Callback for when a project is created via start_project tool
|
||||
const handleProjectCreated = useCallback(async (result: StartProjectResult) => {
|
||||
// Stop current chat generation
|
||||
sessionManager.stopGeneration(projectId);
|
||||
|
||||
// Create a minimal set of tools for the new project session
|
||||
// We don't need the full tools here, just enough to create the session
|
||||
const projectTools: Record<string, OpenAI.Chat.Completions.ChatCompletionTool> = {};
|
||||
const projectCustomTools: Record<string, Tool<unknown>> = {};
|
||||
|
||||
// Load the new project's session
|
||||
await sessionManager.loadSession(
|
||||
result.projectId,
|
||||
projectTools,
|
||||
projectCustomTools,
|
||||
50, // maxSteps
|
||||
undefined, // workingDir (will use default projectsPath)
|
||||
false // isChat (this is a project, not a chat)
|
||||
);
|
||||
|
||||
// Add the initial message to the new project's session
|
||||
await sessionManager.addMessage(result.projectId, {
|
||||
role: 'user',
|
||||
content: result.initialMessage,
|
||||
});
|
||||
|
||||
// Navigate to the new project with autostart
|
||||
navigate(`/project/${result.projectId}?autostart=true&model=${encodeURIComponent(providerModel)}`);
|
||||
}, [sessionManager, projectId, navigate, providerModel]);
|
||||
|
||||
// Fetch MCP tools
|
||||
const { tools: mcpOpenAITools, clients: mcpClients } = useMCPTools();
|
||||
|
||||
// Separate built-in tools from MCP tools for clarity
|
||||
const builtInTools = useMemo(() => {
|
||||
// For chat mode, provide minimal tools (no project-specific tools)
|
||||
if (isChat) {
|
||||
const tools: Record<string, Tool<unknown>> = {
|
||||
nostr_read_nip: new NostrReadNipTool(),
|
||||
nostr_fetch_event: new NostrFetchEventTool(),
|
||||
nostr_read_kind: new NostrReadKindTool(),
|
||||
nostr_read_tag: new NostrReadTagTool(),
|
||||
nostr_read_protocol: new NostrReadProtocolTool(),
|
||||
nostr_read_nips_index: new NostrReadNipsIndexTool(),
|
||||
nostr_generate_kind: new NostrGenerateKindTool(),
|
||||
nostr_publish_events: new NostrPublishEventsTool(),
|
||||
start_project: new StartProjectTool(projectsManager, config, handleProjectCreated),
|
||||
};
|
||||
return tools;
|
||||
}
|
||||
|
||||
// For project mode, provide full set of tools
|
||||
const tools: Record<string, Tool<unknown>> = {
|
||||
git_commit: new GitCommitTool(fs, cwd, git),
|
||||
text_editor_view: new TextEditorViewTool(fs, cwd, { projectsPath }),
|
||||
@@ -241,7 +186,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
|
||||
return tools;
|
||||
}, [isChat, fs, git, cwd, user, projectId, projectsPath, tmpPath, pluginsPath, config, projectsManager, handleProjectCreated, handleFileChanged]);
|
||||
}, [fs, git, cwd, user, projectId, projectsPath, tmpPath, pluginsPath, config.corsProxy, handleFileChanged]);
|
||||
|
||||
// MCP tools wrapped for execution
|
||||
const mcpToolWrappers = useMemo(() => createMCPTools(mcpClients), [mcpClients]);
|
||||
@@ -308,12 +253,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
customTools,
|
||||
onUpdateMetadata,
|
||||
onAIError,
|
||||
workingDir: isChat ? cwd : undefined, // Pass working dir for chats
|
||||
isChat, // Pass isChat flag
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Check if we should show the template info banner
|
||||
useEffect(() => {
|
||||
const checkTemplateInfo = async () => {
|
||||
@@ -455,14 +396,13 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
useEffect(() => {
|
||||
if (autostartedRef.current) return;
|
||||
|
||||
// Only autostart if we have messages (initial message has been added)
|
||||
if (shouldAutostart && providerModel && isConfigured && messages.length > 0) {
|
||||
if (shouldAutostart && providerModel && isConfigured) {
|
||||
// Start AI generation
|
||||
addRecentlyUsedModel(providerModel);
|
||||
startGeneration(providerModel);
|
||||
autostartedRef.current = true;
|
||||
}
|
||||
}, [addRecentlyUsedModel, isConfigured, providerModel, shouldAutostart, startGeneration, messages.length]);
|
||||
}, [addRecentlyUsedModel, isConfigured, providerModel, shouldAutostart, startGeneration]);
|
||||
|
||||
// Simple scroll event listener
|
||||
useEffect(() => {
|
||||
@@ -610,7 +550,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
<div className="h-full flex flex-col relative">
|
||||
|
||||
<div className="flex-1 overflow-y-scroll overflow-x-hidden" ref={scrollAreaRef}>
|
||||
<div className={`p-4 space-y-4 ${isChat ? 'max-w-3xl mx-auto w-full' : ''}`}>
|
||||
<div className="p-4 space-y-4">
|
||||
{/* Template info banner - shown when conditions are met */}
|
||||
{showTemplateInfo && templateInfo && (
|
||||
<div className="flex items-center gap-3 text-xs text-muted-foreground uppercase tracking-wide">
|
||||
@@ -748,29 +688,27 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={`border-t ${isChat ? 'max-w-3xl mx-auto w-full' : ''}`}>
|
||||
<ChatInput
|
||||
isLoading={isLoading}
|
||||
isConfigured={isConfigured}
|
||||
providerModel={providerModel}
|
||||
onProviderModelChange={handleModelChange}
|
||||
onSend={handleSend}
|
||||
onStop={stopGeneration}
|
||||
onFocus={handleTextareaFocus}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
isModelSelectorOpen={isModelSelectorOpen}
|
||||
onModelSelectorOpenChange={setIsModelSelectorOpen}
|
||||
contextUsagePercentage={contextUsagePercentage}
|
||||
currentModelContextLength={currentModel?.contextLength}
|
||||
lastInputTokens={lastInputTokens}
|
||||
totalCost={totalCost}
|
||||
isDragOver={isDragOver}
|
||||
onDragEnter={handleDragEnter}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
/>
|
||||
</div>
|
||||
<ChatInput
|
||||
isLoading={isLoading}
|
||||
isConfigured={isConfigured}
|
||||
providerModel={providerModel}
|
||||
onProviderModelChange={handleModelChange}
|
||||
onSend={handleSend}
|
||||
onStop={stopGeneration}
|
||||
onFocus={handleTextareaFocus}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
isModelSelectorOpen={isModelSelectorOpen}
|
||||
onModelSelectorOpenChange={setIsModelSelectorOpen}
|
||||
contextUsagePercentage={contextUsagePercentage}
|
||||
currentModelContextLength={currentModel?.contextLength}
|
||||
lastInputTokens={lastInputTokens}
|
||||
totalCost={totalCost}
|
||||
isDragOver={isDragOver}
|
||||
onDragEnter={handleDragEnter}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
/>
|
||||
|
||||
{/* Onboarding Dialog */}
|
||||
<OnboardingDialog
|
||||
|
||||
Reference in new issue
Block a user