"use client"; import { memo, useCallback, useState } from "react"; import { Dialog, DialogContent, DialogTitle } from "@kandev/ui/dialog"; import { Button } from "@kandev/ui/button"; import { Label } from "@kandev/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select"; import { IconX, IconRocket } from "@tabler/icons-react"; import { useAppStore } from "@/components/state-provider"; import { useToast } from "@/components/toast-provider"; import { startQuickChat } from "@/lib/api/domains/workspace-api"; import type { Repository } from "@/lib/types/http"; import type { AgentProfileOption } from "@/lib/state/slices/settings/types"; type QuickChatPickerDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; workspaceId: string; }; type FormState = { selectedRepoId: string; setSelectedRepoId: (id: string) => void; selectedAgentId: string; setSelectedAgentId: (id: string) => void; repositories: Repository[]; agentProfiles: AgentProfileOption[]; }; const NONE_VALUE = "__none__"; function QuickChatFormBody({ state }: { state: FormState }) { const { selectedRepoId, setSelectedRepoId, selectedAgentId, setSelectedAgentId } = state; return (

Start a quick conversation with an agent without creating a formal task.

); } /** Dialog to pick repository and agent for a new quick chat session */ export const QuickChatPickerDialog = memo(function QuickChatPickerDialog({ open, onOpenChange, workspaceId, }: QuickChatPickerDialogProps) { const { toast } = useToast(); const openQuickChat = useAppStore((s) => s.openQuickChat); const [isStarting, setIsStarting] = useState(false); const [selectedRepoId, setSelectedRepoId] = useState(""); const [selectedAgentId, setSelectedAgentId] = useState(""); const repositories = useAppStore((s) => s.repositories.itemsByWorkspaceId?.[workspaceId] ?? []); const agentProfiles = useAppStore((s) => s.agentProfiles.items ?? []); const handleStart = useCallback(async () => { if (isStarting) return; setIsStarting(true); try { const response = await startQuickChat(workspaceId, { repository_id: selectedRepoId || undefined, agent_profile_id: selectedAgentId || undefined, }); onOpenChange(false); // Open the quick chat modal with the new session openQuickChat(response.session_id, workspaceId); } catch (error) { toast({ title: "Failed to start quick chat", description: error instanceof Error ? error.message : "Unknown error", variant: "error", }); } finally { setIsStarting(false); } }, [ workspaceId, selectedRepoId, selectedAgentId, isStarting, onOpenChange, openQuickChat, toast, ]); const formState: FormState = { selectedRepoId, setSelectedRepoId, selectedAgentId, setSelectedAgentId, repositories, agentProfiles, }; return ( New Quick Chat

New Quick Chat

); }); /** Alias for backwards compatibility */ export const QuickChatDialog = QuickChatPickerDialog;