2025-06-18 11:03:39 -07:00
|
|
|
"use client";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-07-03 16:01:52 -04:00
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
|
|
|
import { FilePlus2, Archive, Zap } from "lucide-react";
|
2025-06-18 11:03:39 -07:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { ThreadDisplayInfo } from "./types";
|
|
|
|
|
import { TerminalInput } from "./terminal-input";
|
|
|
|
|
import { useFileUpload } from "@/hooks/useFileUpload";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "../ui/tooltip";
|
|
|
|
|
import { Label } from "../ui/label";
|
|
|
|
|
import { ContentBlocksPreview } from "../thread/ContentBlocksPreview";
|
2025-06-18 16:44:41 -07:00
|
|
|
import { ThemeToggle } from "../theme-toggle";
|
2025-06-19 12:28:06 -07:00
|
|
|
import { ThreadCard, ThreadCardLoading } from "./thread-card";
|
2025-06-23 17:18:28 -07:00
|
|
|
import { GitHubInstallationBanner } from "../github/installation-banner";
|
2025-06-23 15:06:26 -07:00
|
|
|
import { QuickActions } from "./quick-actions";
|
|
|
|
|
import { useState } from "react";
|
2025-06-23 17:52:55 -07:00
|
|
|
import { GitHubLogoutButton } from "../github/github-oauth-button";
|
2025-06-30 16:43:09 -06:00
|
|
|
import { MANAGER_GRAPH_ID } from "@open-swe/shared/constants";
|
2025-07-03 16:01:52 -04:00
|
|
|
import { TooltipIconButton } from "../ui/tooltip-icon-button";
|
2025-06-18 11:03:39 -07:00
|
|
|
|
|
|
|
|
interface DefaultViewProps {
|
|
|
|
|
threads: ThreadDisplayInfo[];
|
2025-06-19 12:28:06 -07:00
|
|
|
threadsLoading: boolean;
|
2025-06-18 11:03:39 -07:00
|
|
|
}
|
|
|
|
|
|
2025-06-19 12:28:06 -07:00
|
|
|
export function DefaultView({ threads, threadsLoading }: DefaultViewProps) {
|
2025-06-18 11:03:39 -07:00
|
|
|
const router = useRouter();
|
2025-06-23 15:06:26 -07:00
|
|
|
const [quickActionPrompt, setQuickActionPrompt] = useState("");
|
2025-06-18 11:03:39 -07:00
|
|
|
const apiUrl: string | undefined = process.env.NEXT_PUBLIC_API_URL ?? "";
|
2025-06-30 16:43:09 -06:00
|
|
|
const assistantId: string | undefined = MANAGER_GRAPH_ID;
|
2025-06-18 11:03:39 -07:00
|
|
|
const {
|
|
|
|
|
contentBlocks,
|
|
|
|
|
setContentBlocks,
|
|
|
|
|
handleFileUpload,
|
|
|
|
|
dropRef,
|
|
|
|
|
removeBlock,
|
|
|
|
|
dragOver,
|
|
|
|
|
handlePaste,
|
|
|
|
|
} = useFileUpload();
|
2025-07-03 16:01:52 -04:00
|
|
|
const [autoAccept, setAutoAccept] = useState(false);
|
2025-06-18 11:03:39 -07:00
|
|
|
|
2025-06-30 16:43:09 -06:00
|
|
|
if (!apiUrl) {
|
|
|
|
|
return <div>Missing API URL environment variable</div>;
|
2025-06-18 11:03:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-1 flex-col">
|
|
|
|
|
{/* Header */}
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="border-border bg-card border-b px-4 py-2">
|
2025-06-18 11:03:39 -07:00
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<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">
|
|
|
|
|
Open SWE
|
|
|
|
|
</span>
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
2025-06-18 16:44:41 -07:00
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-muted-foreground text-xs">ready</span>
|
|
|
|
|
<div className="bg-muted h-1 w-1 rounded-full"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<ThemeToggle />
|
2025-06-23 17:52:55 -07:00
|
|
|
<GitHubLogoutButton />
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Main Content */}
|
2025-06-20 12:57:23 -07:00
|
|
|
<div className="flex-1 overflow-y-auto">
|
2025-06-18 11:03:39 -07:00
|
|
|
<div className="mx-auto max-w-4xl space-y-6 p-4">
|
2025-06-23 17:18:28 -07:00
|
|
|
<GitHubInstallationBanner />
|
2025-06-18 11:03:39 -07:00
|
|
|
{/* Terminal Chat Input */}
|
|
|
|
|
<Card
|
|
|
|
|
className={cn(
|
2025-06-18 16:44:41 -07:00
|
|
|
"border-border bg-card py-0 dark:bg-gray-950",
|
2025-06-18 11:03:39 -07:00
|
|
|
dragOver
|
|
|
|
|
? "border-primary border-2 border-dotted"
|
|
|
|
|
: "border border-solid",
|
|
|
|
|
)}
|
|
|
|
|
ref={dropRef}
|
|
|
|
|
>
|
|
|
|
|
<CardContent className="p-4">
|
|
|
|
|
<ContentBlocksPreview
|
|
|
|
|
blocks={contentBlocks}
|
|
|
|
|
onRemove={removeBlock}
|
|
|
|
|
/>
|
|
|
|
|
<input
|
|
|
|
|
id="file-input"
|
|
|
|
|
type="file"
|
|
|
|
|
onChange={handleFileUpload}
|
|
|
|
|
multiple
|
|
|
|
|
accept="image/jpeg,image/png,image/gif,image/webp,application/pdf"
|
|
|
|
|
className="hidden"
|
|
|
|
|
/>
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<TerminalInput
|
|
|
|
|
placeholder="Describe your coding task or ask a question..."
|
|
|
|
|
apiUrl={apiUrl}
|
|
|
|
|
assistantId={assistantId}
|
|
|
|
|
contentBlocks={contentBlocks}
|
|
|
|
|
setContentBlocks={setContentBlocks}
|
|
|
|
|
onPaste={handlePaste}
|
2025-06-23 15:06:26 -07:00
|
|
|
quickActionPrompt={quickActionPrompt}
|
|
|
|
|
setQuickActionPrompt={setQuickActionPrompt}
|
2025-07-03 16:01:52 -04:00
|
|
|
autoAcceptPlan={autoAccept}
|
|
|
|
|
setAutoAcceptPlan={setAutoAccept}
|
2025-06-18 11:03:39 -07:00
|
|
|
/>
|
2025-07-03 16:01:52 -04:00
|
|
|
<div className="flex items-center gap-2">
|
2025-06-18 11:03:39 -07:00
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>
|
|
|
|
|
<Label
|
|
|
|
|
htmlFor="file-input"
|
2025-06-18 16:44:41 -07:00
|
|
|
className="text-muted-foreground hover:text-foreground flex cursor-pointer items-center justify-center rounded-full bg-inherit"
|
2025-06-18 11:03:39 -07:00
|
|
|
>
|
|
|
|
|
<FilePlus2 className="size-4" />
|
|
|
|
|
</Label>
|
|
|
|
|
</TooltipTrigger>
|
2025-07-03 16:01:52 -04:00
|
|
|
<TooltipContent side="bottom">
|
|
|
|
|
Attach files
|
|
|
|
|
</TooltipContent>
|
2025-06-18 11:03:39 -07:00
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
2025-07-03 16:01:52 -04:00
|
|
|
<TooltipIconButton
|
|
|
|
|
variant={autoAccept ? "brand" : "ghost"}
|
|
|
|
|
tooltip="Automatically accept the plan"
|
|
|
|
|
className={cn(
|
|
|
|
|
autoAccept
|
|
|
|
|
? "text-secondary"
|
|
|
|
|
: "text-muted-foreground hover:text-foreground",
|
|
|
|
|
)}
|
|
|
|
|
onClick={() => setAutoAccept((prev) => !prev)}
|
|
|
|
|
side="bottom"
|
|
|
|
|
>
|
|
|
|
|
<Zap className="size-4" />
|
|
|
|
|
</TooltipIconButton>
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Recent & Running Threads */}
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 flex items-center justify-between">
|
2025-06-18 16:44:41 -07:00
|
|
|
<h2 className="text-foreground text-base font-semibold">
|
2025-06-18 11:03:39 -07:00
|
|
|
Recent & Running Threads
|
|
|
|
|
</h2>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
2025-06-18 16:44:41 -07:00
|
|
|
className="border-border text-muted-foreground hover:text-foreground h-7 text-xs"
|
2025-06-18 11:03:39 -07:00
|
|
|
onClick={() => router.push("/chat/threads")}
|
|
|
|
|
>
|
|
|
|
|
View All
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-06-19 12:28:06 -07:00
|
|
|
{threadsLoading || threads.length ? (
|
|
|
|
|
<div className="grid gap-3 md:grid-cols-2">
|
|
|
|
|
{threadsLoading && threads.length === 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<ThreadCardLoading />
|
|
|
|
|
<ThreadCardLoading />
|
|
|
|
|
<ThreadCardLoading />
|
|
|
|
|
<ThreadCardLoading />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{threads.slice(0, 4).map((thread) => (
|
|
|
|
|
<ThreadCard
|
|
|
|
|
key={thread.id}
|
|
|
|
|
thread={thread}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
<span className="text-muted-foreground flex items-center gap-2">
|
|
|
|
|
<Archive className="size-4" />
|
|
|
|
|
<span className="text-sm">No threads found</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
2025-06-23 15:06:26 -07:00
|
|
|
<QuickActions setQuickActionPrompt={setQuickActionPrompt} />
|
2025-06-18 11:03:39 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|