Text chats

This commit is contained in:
Alex Gleason committed 2025-12-03 01:05:00 -06:00
1 parent 02dcd5cbe8
commit ab039d2fb7
20 files changed
+944 -158

No files matched your search

+59 -49
View File
@@ -27,6 +27,7 @@ interface ActionsMenuProps {
isBuildLoading?: boolean;
disabled?: boolean;
onFirstInteraction?: () => void;
isChat?: boolean; // Flag to indicate this is a chat, not a project
}
export function ActionsMenu({
@@ -38,6 +39,7 @@ export function ActionsMenu({
isBuildLoading = false,
disabled = false,
onFirstInteraction: _onFirstInteraction,
isChat = false,
}: ActionsMenuProps) {
const [gitHistoryOpen, setGitHistoryOpen] = useState(false);
const [gitDialogOpen, setGitDialogOpen] = useState(false);
@@ -71,65 +73,73 @@ export function ActionsMenu({
New Chat
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setGitHistoryOpen(true)}
disabled={isAnyLoading}
className="gap-2"
>
<History className="h-4 w-4" />
Rollback
</DropdownMenuItem>
{!isChat && (
<>
<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={() => 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={onProjectDetails}
disabled={isAnyLoading}
className="gap-2"
>
<Folder className="h-4 w-4" />
Project Details
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
{/* Dialogs */}
<GitDialog
projectId={projectId}
open={gitDialogOpen}
onOpenChange={setGitDialogOpen}
/>
{/* Dialogs - only show for projects, not chats */}
{!isChat && (
<>
<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}
/>
</>
)}
</>
);
+2
View File
@@ -47,6 +47,7 @@ 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>;
@@ -85,6 +86,7 @@ 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,
+99 -15
View File
@@ -1,16 +1,18 @@
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 } from 'lucide-react';
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, Search, MessageSquare } 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';
@@ -75,6 +77,51 @@ 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 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">
<MessageSquare className="h-4 w-4 text-primary" />
</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;
@@ -92,14 +139,18 @@ export function ProjectSidebar({
}: ProjectSidebarProps) {
const { t } = useTranslation();
const queryClient = useQueryClient();
const { data: projects = [], isLoading, error } = useProjects();
const { data: projects = [], isLoading: isLoadingProjects, error: projectsError } = useProjects();
const { data: chats = [], isLoading: isLoadingChats, error: chatsError } = useChats();
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
const [searchQuery, setSearchQuery] = useState('');
const isMobile = useIsMobile();
const navigate = useNavigate();
// Fast in-memory search filtering
const isLoading = isLoadingProjects || isLoadingChats;
const error = projectsError || chatsError;
// Fast in-memory search filtering for projects
const filteredProjects = useMemo(() => {
if (!searchQuery.trim()) {
return projects;
@@ -112,6 +163,30 @@ 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);
@@ -212,7 +287,7 @@ export function ProjectSidebar({
</div>
{/* Search Input */}
{projects.length > 0 && (
{(projects.length > 0 || chats.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
@@ -237,13 +312,13 @@ export function ProjectSidebar({
</div>
))}
</div>
) : projects.length === 0 ? (
) : combinedItems.length === 0 && projects.length === 0 && chats.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>
) : filteredProjects.length === 0 ? (
) : combinedItems.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>
@@ -251,15 +326,24 @@ export function ProjectSidebar({
</div>
) : (
<div className="space-y-1">
{filteredProjects.map((project) => (
<ProjectItem
key={project.id}
project={project}
isSelected={selectedProject?.id === project.id}
onSelect={onSelectProject}
isFavorite={favorites.includes(project.id)}
/>
))}
{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={() => {}}
/>
)
)}
</div>
)}
</div>
+4
View File
@@ -40,6 +40,7 @@ describe('SentryProvider', () => {
fsPathTmp: '/tmp',
fsPathPlugins: '/plugins',
fsPathTemplates: '/templates',
fsPathChats: '/chats',
};
render(
@@ -77,6 +78,7 @@ describe('SentryProvider', () => {
fsPathTmp: '/tmp',
fsPathPlugins: '/plugins',
fsPathTemplates: '/templates',
fsPathChats: '/chats',
};
render(
@@ -115,6 +117,7 @@ describe('SentryProvider', () => {
fsPathTmp: '/tmp',
fsPathPlugins: '/plugins',
fsPathTemplates: '/templates',
fsPathChats: '/chats',
};
render(
@@ -156,6 +159,7 @@ describe('SentryProvider', () => {
fsPathTmp: '/tmp',
fsPathPlugins: '/plugins',
fsPathTemplates: '/templates',
fsPathChats: '/chats',
};
render(
+22 -2
View File
@@ -59,6 +59,7 @@ 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 {
@@ -72,6 +73,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
onLoadingChange,
isLoading: externalIsLoading,
isBuildLoading: externalIsBuildLoading,
isChat = false,
consoleError,
onDismissConsoleError,
}, ref) => {
@@ -143,7 +145,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
}, [projectId, providerModel]);
// Initialize AI chat with tools
const cwd = `${projectsPath}/${projectId}`;
const { chatsPath } = useFSPaths();
const cwd = isChat ? `${chatsPath}/${projectId}` : `${projectsPath}/${projectId}`;
const esmUrlRef = useRef(config.esmUrl);
const sessionManager = useSessionManager();
@@ -158,6 +161,23 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
// 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(),
// TODO: Add start_project tool here
};
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 }),
@@ -186,7 +206,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
}
return tools;
}, [fs, git, cwd, user, projectId, projectsPath, tmpPath, pluginsPath, config.corsProxy, handleFileChanged]);
}, [isChat, fs, git, cwd, user, projectId, projectsPath, tmpPath, pluginsPath, config.corsProxy, handleFileChanged]);
// MCP tools wrapped for execution
const mcpToolWrappers = useMemo(() => createMCPTools(mcpClients), [mcpClients]);