2025-06-18 11:03:39 -07:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type React from "react";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
2025-06-18 16:44:41 -07:00
|
|
|
import { ArrowLeft, Search, Filter } from "lucide-react";
|
2025-06-18 11:03:39 -07:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { ThreadDisplayInfo, threadToDisplayInfo } from "@/components/v2/types";
|
|
|
|
|
import { useThreads } from "@/hooks/useThreads";
|
|
|
|
|
import { GraphState } from "@open-swe/shared/open-swe/types";
|
2025-06-18 16:44:41 -07:00
|
|
|
import { ThreadCard } from "@/components/v2/thread-card";
|
|
|
|
|
import { ThemeToggle } from "@/components/theme-toggle";
|
2025-06-18 11:03:39 -07:00
|
|
|
|
|
|
|
|
type FilterStatus = "all" | "running" | "completed" | "failed" | "pending";
|
|
|
|
|
|
|
|
|
|
export default function AllThreadsPage() {
|
|
|
|
|
const router = useRouter();
|
2025-06-18 16:44:41 -07:00
|
|
|
const { threads } = useThreads<GraphState>(
|
|
|
|
|
process.env.NEXT_PUBLIC_MANAGER_ASSISTANT_ID,
|
|
|
|
|
);
|
2025-06-18 11:03:39 -07:00
|
|
|
const [searchQuery, setSearchQuery] = useState("");
|
|
|
|
|
const [statusFilter, setStatusFilter] = useState<FilterStatus>("all");
|
|
|
|
|
|
|
|
|
|
// Convert Thread objects to ThreadDisplayInfo for UI
|
|
|
|
|
const displayThreads: ThreadDisplayInfo[] =
|
|
|
|
|
threads?.map(threadToDisplayInfo) ?? [];
|
|
|
|
|
|
|
|
|
|
// Filter and search threads
|
|
|
|
|
const filteredThreads = displayThreads.filter((thread) => {
|
|
|
|
|
const matchesSearch =
|
|
|
|
|
thread.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
|
|
|
|
thread.repository.toLowerCase().includes(searchQuery.toLowerCase());
|
|
|
|
|
const matchesStatus =
|
|
|
|
|
statusFilter === "all" || thread.status === statusFilter;
|
|
|
|
|
return matchesSearch && matchesStatus;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Group threads by status
|
|
|
|
|
const groupedThreads = {
|
|
|
|
|
running: filteredThreads.filter((t) => t.status === "running"),
|
|
|
|
|
completed: filteredThreads.filter((t) => t.status === "completed"),
|
|
|
|
|
failed: filteredThreads.filter((t) => t.status === "failed"),
|
|
|
|
|
pending: filteredThreads.filter((t) => t.status === "pending"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const statusCounts = {
|
|
|
|
|
all: displayThreads.length,
|
|
|
|
|
running: displayThreads.filter((t) => t.status === "running").length,
|
|
|
|
|
completed: displayThreads.filter((t) => t.status === "completed").length,
|
|
|
|
|
failed: displayThreads.filter((t) => t.status === "failed").length,
|
|
|
|
|
pending: displayThreads.filter((t) => t.status === "pending").length,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="bg-background flex h-screen flex-col">
|
2025-06-18 11:03:39 -07:00
|
|
|
{/* Header */}
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="border-border bg-card border-b px-4 py-3">
|
2025-06-18 11:03:39 -07:00
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
2025-06-18 16:44:41 -07:00
|
|
|
className="text-muted-foreground hover:bg-muted hover:text-foreground h-6 w-6 p-0"
|
2025-06-18 11:03:39 -07:00
|
|
|
onClick={() => router.push("/chat")}
|
|
|
|
|
>
|
|
|
|
|
<ArrowLeft className="h-3 w-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="h-2 w-2 rounded-full bg-green-500"></div>
|
2025-06-18 16:44:41 -07:00
|
|
|
<span className="text-muted-foreground font-mono text-sm">
|
|
|
|
|
All Threads
|
2025-06-18 11:03:39 -07:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="ml-auto flex items-center gap-4">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-muted-foreground text-xs">
|
|
|
|
|
{filteredThreads.length} threads
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ThemeToggle />
|
|
|
|
|
</div>
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Search and Filters */}
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="border-border bg-muted/50 border-b px-4 py-3 dark:bg-gray-950">
|
2025-06-18 11:03:39 -07:00
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="relative max-w-md flex-1">
|
2025-06-18 16:44:41 -07:00
|
|
|
<Search className="text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 transform" />
|
2025-06-18 11:03:39 -07:00
|
|
|
<Input
|
|
|
|
|
placeholder="Search threads..."
|
|
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
2025-06-18 16:44:41 -07:00
|
|
|
className="border-border bg-background text-foreground placeholder:text-muted-foreground pl-10 dark:bg-gray-900"
|
2025-06-18 11:03:39 -07:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1">
|
2025-06-18 16:44:41 -07:00
|
|
|
<Filter className="text-muted-foreground h-4 w-4" />
|
|
|
|
|
<span className="text-muted-foreground mr-2 text-xs">Filter:</span>
|
2025-06-18 11:03:39 -07:00
|
|
|
{(
|
|
|
|
|
[
|
|
|
|
|
"all",
|
|
|
|
|
"running",
|
|
|
|
|
"completed",
|
|
|
|
|
"failed",
|
|
|
|
|
"pending",
|
|
|
|
|
] as FilterStatus[]
|
|
|
|
|
).map((status) => (
|
|
|
|
|
<Button
|
|
|
|
|
key={status}
|
|
|
|
|
variant={statusFilter === status ? "secondary" : "ghost"}
|
|
|
|
|
size="sm"
|
|
|
|
|
className={`h-7 text-xs ${
|
|
|
|
|
statusFilter === status
|
2025-06-18 16:44:41 -07:00
|
|
|
? "bg-muted text-foreground dark:bg-gray-700"
|
|
|
|
|
: "text-muted-foreground hover:bg-muted hover:text-foreground"
|
2025-06-18 11:03:39 -07:00
|
|
|
}`}
|
|
|
|
|
onClick={() => setStatusFilter(status)}
|
|
|
|
|
>
|
|
|
|
|
{status === "all"
|
|
|
|
|
? "All"
|
|
|
|
|
: status.charAt(0).toUpperCase() + status.slice(1)}
|
|
|
|
|
<Badge
|
|
|
|
|
variant="secondary"
|
2025-06-18 16:44:41 -07:00
|
|
|
className="bg-muted/70 text-muted-foreground ml-1 text-xs dark:bg-gray-800"
|
2025-06-18 11:03:39 -07:00
|
|
|
>
|
|
|
|
|
{statusCounts[status]}
|
|
|
|
|
</Badge>
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
<div className="flex-1 overflow-auto">
|
|
|
|
|
<div className="mx-auto max-w-6xl p-4">
|
|
|
|
|
{statusFilter === "all" ? (
|
|
|
|
|
// Show grouped view when "all" is selected
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
{Object.entries(groupedThreads).map(([status, threads]) => {
|
|
|
|
|
if (threads.length === 0) return null;
|
|
|
|
|
return (
|
|
|
|
|
<div key={status}>
|
|
|
|
|
<div className="mb-3 flex items-center gap-2">
|
2025-06-18 16:44:41 -07:00
|
|
|
<h2 className="text-foreground text-base font-semibold capitalize">
|
2025-06-18 11:03:39 -07:00
|
|
|
{status} Threads
|
|
|
|
|
</h2>
|
|
|
|
|
<Badge
|
|
|
|
|
variant="secondary"
|
2025-06-18 16:44:41 -07:00
|
|
|
className="bg-muted/70 text-muted-foreground text-xs dark:bg-gray-800"
|
2025-06-18 11:03:39 -07:00
|
|
|
>
|
|
|
|
|
{threads.length}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid gap-3 md:grid-cols-2 lg:grid-cols-3">
|
|
|
|
|
{threads.map((thread) => (
|
|
|
|
|
<ThreadCard
|
|
|
|
|
key={thread.id}
|
|
|
|
|
thread={thread}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
// Show flat list when specific status is selected
|
|
|
|
|
<div className="grid gap-3 md:grid-cols-2 lg:grid-cols-3">
|
|
|
|
|
{filteredThreads.map((thread) => (
|
|
|
|
|
<ThreadCard
|
|
|
|
|
key={thread.id}
|
|
|
|
|
thread={thread}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{filteredThreads.length === 0 && (
|
|
|
|
|
<div className="py-12 text-center">
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="text-muted-foreground mb-2">No threads found</div>
|
|
|
|
|
<div className="text-muted-foreground/70 text-xs">
|
2025-06-18 11:03:39 -07:00
|
|
|
{searchQuery
|
|
|
|
|
? "Try adjusting your search query"
|
|
|
|
|
: "No threads match the selected filter"}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|