This commit is contained in:
Chad Curtis committed 2025-09-05 23:21:58 +00:00
1 parent a3d491f1a5
commit 6583e29d08
11 files changed
+144 -902

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import { memo, useState } from 'react';
import { Streamdown } from 'streamdown';
import { Wrench, Eye, FileText, Edit, Package, PackageMinus, GitCommit, BookOpen, Download, Hash, Tag, Network, List, Plus } from 'lucide-react';
import { AIMessage } from '@/hooks/useAIChat';
import type { AIMessage } from '@/lib/SessionManager';
import { cn } from '@/lib/utils';
import OpenAI from 'openai';
@@ -1,34 +0,0 @@
import { Loader2 } from 'lucide-react';
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
import { cn } from '@/lib/utils';
interface ProjectSessionIndicatorProps {
projectId: string;
className?: string;
}
/**
* Small indicator that shows if a project has active AI sessions
* Positioned as a status badge on the folder icon
*/
export function ProjectSessionIndicator({ projectId, className }: ProjectSessionIndicatorProps) {
const { hasActiveSessions, hasRunningSessions } = useProjectSessionStatus(projectId);
if (!hasActiveSessions) {
return null;
}
return (
<div className={cn(
"absolute -bottom-0.5 -right-0.5 flex items-center justify-center",
"bg-background border border-border rounded-full shadow-sm",
className
)}>
{hasRunningSessions ? (
<Loader2 className="h-2.5 w-2.5 animate-spin text-blue-600 dark:text-blue-400" />
) : (
<div className="h-1.5 w-1.5 rounded-full bg-green-500" title="AI session active" />
)}
</div>
);
}
+5 -3
View File
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { Plus, Folder, Download, GitBranch, MoreVertical, Settings, Loader2 } from 'lucide-react';
import { Button } from '@/components/ui/button';
@@ -22,7 +22,7 @@ interface ProjectItemProps {
onSelect: (project: Project) => void;
}
function ProjectItem({ project, isSelected, onSelect }: ProjectItemProps) {
const ProjectItem = memo(({ project, isSelected, onSelect }: ProjectItemProps) => {
const navigate = useNavigate();
const { hasRunningSessions } = useProjectSessionStatus(project.id);
@@ -72,7 +72,9 @@ function ProjectItem({ project, isSelected, onSelect }: ProjectItemProps) {
</div>
</div>
);
}
});
ProjectItem.displayName = 'ProjectItem';
interface ProjectSidebarProps {
selectedProject: Project | null;
-166
View File
@@ -1,166 +0,0 @@
import { useState, useEffect } from 'react';
import { useSessionManager } from '@/hooks/useSessionManager';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Activity, Clock, Loader2, MessageSquare, X } from 'lucide-react';
import type { SessionState } from '@/lib/SessionManager';
import { cn } from '@/lib/utils';
interface SessionStatusIndicatorProps {
className?: string;
currentProjectId?: string;
}
/**
* Component that shows the status of all active AI sessions
*/
export function SessionStatusIndicator({ className, currentProjectId }: SessionStatusIndicatorProps) {
const sessionManager = useSessionManager();
const [sessions, setSessions] = useState<SessionState[]>([]);
const [isOpen, setIsOpen] = useState(false);
// Update sessions when they change
useEffect(() => {
const updateSessions = () => {
setSessions(sessionManager.getAllSessions());
};
// Initial load
updateSessions();
// Subscribe to session changes
sessionManager.on('sessionCreated', updateSessions);
sessionManager.on('sessionUpdated', updateSessions);
sessionManager.on('sessionDeleted', updateSessions);
return () => {
sessionManager.off('sessionCreated', updateSessions);
sessionManager.off('sessionUpdated', updateSessions);
sessionManager.off('sessionDeleted', updateSessions);
};
}, [sessionManager]);
const activeSessions = sessions.filter(session => session.isLoading);
const totalSessions = sessions.length;
if (totalSessions === 0) {
return null;
}
const handleStopSession = (sessionId: string, e: React.MouseEvent) => {
e.stopPropagation();
sessionManager.stopGeneration(sessionId);
};
const handleDeleteSession = (sessionId: string, e: React.MouseEvent) => {
e.stopPropagation();
sessionManager.deleteSession(sessionId);
};
const formatLastActivity = (date: Date) => {
const now = new Date();
const diff = now.getTime() - date.getTime();
const minutes = Math.floor(diff / 60000);
const hours = Math.floor(diff / 3600000);
if (minutes < 1) return 'Just now';
if (minutes < 60) return `${minutes}m ago`;
if (hours < 24) return `${hours}h ago`;
return date.toLocaleDateString();
};
return (
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild>
<Button
variant="ghost"
size="sm"
className={cn(
"h-8 px-2 gap-1 text-xs",
activeSessions.length > 0 && "text-blue-600 dark:text-blue-400",
className
)}
>
{activeSessions.length > 0 ? (
<Loader2 className="h-3 w-3 animate-spin" />
) : (
<Activity className="h-3 w-3" />
)}
<span>{totalSessions}</span>
{activeSessions.length > 0 && (
<Badge variant="secondary" className="h-4 px-1 text-xs">
{activeSessions.length}
</Badge>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-80 p-0" align="end">
<div className="p-3 border-b">
<h4 className="font-semibold text-sm">AI Sessions</h4>
<p className="text-xs text-muted-foreground">
{totalSessions} active session{totalSessions !== 1 ? 's' : ''}
{activeSessions.length > 0 && ` (${activeSessions.length} running)`}
</p>
</div>
<div className="max-h-64 overflow-y-auto">
{sessions.map((session) => (
<div
key={session.id}
className={cn(
"p-3 border-b last:border-b-0 hover:bg-muted/50",
session.projectId === currentProjectId && "bg-primary/5"
)}
>
<div className="flex items-start justify-between gap-2">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<h5 className="font-medium text-sm truncate">
{session.projectName}
</h5>
{session.isLoading && (
<Loader2 className="h-3 w-3 animate-spin text-blue-600" />
)}
</div>
<div className="flex items-center gap-2 mt-1 text-xs text-muted-foreground">
<MessageSquare className="h-3 w-3" />
<span>{session.messages.length} messages</span>
<Clock className="h-3 w-3 ml-1" />
<span>{formatLastActivity(session.lastActivity)}</span>
</div>
{session.streamingMessage?.content && (
<p className="text-xs text-muted-foreground mt-1 truncate">
{session.streamingMessage.content.slice(0, 50)}...
</p>
)}
</div>
<div className="flex items-center gap-1">
{session.isLoading && (
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0"
onClick={(e) => handleStopSession(session.id, e)}
title="Stop generation"
>
<X className="h-3 w-3" />
</Button>
)}
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0 text-destructive hover:text-destructive"
onClick={(e) => handleDeleteSession(session.id, e)}
title="Delete session"
>
<X className="h-3 w-3" />
</Button>
</div>
</div>
</div>
))}
</div>
</PopoverContent>
</Popover>
);
}
+3 -2
View File
@@ -9,6 +9,7 @@ import { useFS } from '@/hooks/useFS';
import { useKeepAlive } from '@/hooks/useKeepAlive';
import { useAIChatSession } from '@/hooks/useAIChatSession';
import type { AIMessage } from '@/lib/SessionManager';
import { ModelSelector } from '@/components/ModelSelector';
@@ -310,7 +311,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
streamingMessage.content ? (
<AIMessageItem
key="streaming-message"
message={streamingMessage as OpenAI.Chat.Completions.ChatCompletionMessageParam}
message={streamingMessage as AIMessage}
isCurrentlyLoading
/>
) : (
@@ -329,7 +330,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
<div className="flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground">
<Loader2 className="h-3 w-3 animate-spin flex-shrink-0" />
<span className="font-medium">
Running {(streamingMessage.tool_calls[0] as OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall).function.name}...
Running {streamingMessage.tool_calls?.[0]?.function?.name || 'tool'}...
</span>
</div>
</div>