"use client"; import { useCallback, useEffect, useMemo, useState } from "react"; import { IconInfoCircle, IconLoader2 } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { useAppStore } from "@/components/state-provider"; import { AgentSelector } from "@/components/task-create-dialog-selectors"; import { useAgentProfileOptions } from "@/components/task-create-dialog-options"; import { WorkspaceRepoChips } from "@/components/task-create-dialog-workspace-repo-chips"; import { useRepositoriesState } from "@/components/task-create-dialog-repositories-state"; import { useRepositories } from "@/hooks/domains/workspace/use-repositories"; import type { QuickChatRepositoryInput } from "@/lib/api/domains/workspace-api"; import type { AgentProfileOption } from "@/lib/state/slices"; import type { Repository } from "@/lib/types/http"; import type { QuickChatSessionKind } from "@/lib/state/slices/ui/types"; import { ConfigurationChatToggle } from "./configuration-chat-toggle"; type QuickChatSetupProps = { workspaceId: string; canCreateConfigurationChat: boolean; pendingAgentId: string | null; onStart: (agentId: string, repositories: QuickChatRepositoryInput[]) => void; onCancel: () => void; onKindChange: (kind: QuickChatSessionKind) => void; }; function repositoryAddState(isLoading: boolean, repositoryCount: number, rowCount: number) { if (isLoading) return { canAddMore: false, addHint: "Loading repositories" }; if (repositoryCount === 0) { return { canAddMore: false, addHint: "No repositories available in this workspace" }; } if (rowCount >= repositoryCount) { return { canAddMore: false, addHint: "All workspace repositories are already added" }; } return { canAddMore: true, addHint: undefined }; } function QuickChatIntroduction() { return (

Chat with an agent about an idea, question, or codebase.

Quick chats stay outside your task board.

); } function AgentField({ profiles, value, disabled, onChange, }: { profiles: AgentProfileOption[]; value: string; disabled: boolean; onChange: (value: string) => void; }) { const options = useAgentProfileOptions(profiles); return (

Agent profile

Choose the agent for this conversation.

0 ? "Select agent" : "No agents available"} triggerClassName="h-11 w-full justify-between border border-input bg-background px-3 shadow-xs hover:bg-accent/50 data-[state=open]:border-ring data-[state=open]:ring-[2px] data-[state=open]:ring-ring/35" popoverPortal />
); } type RepositoryFieldProps = { workspaceId: string; repositories: Repository[]; rows: ReturnType["repositories"]; canAddMore: boolean; addHint?: string; onAdd: () => void; onRemove: (key: string) => void; onRepositoryChange: (key: string, value: string) => void; onBranchChange: (key: string, value: string) => void; }; function RepositoryField(props: RepositoryFieldProps) { return (

Repositories (optional)

Add repository context to focus on specific code and branches.

); } function RepositoryContextHelp() { return ( Kandev uses an isolated worktree from the selected branch. Uncommitted local changes are not included. ); } function SetupFooter({ isStarting, startDisabled, onCancel, onStart, }: { isStarting: boolean; startDisabled: boolean; onCancel: () => void; onStart: () => void; }) { return ( ); } export function QuickChatSetup({ workspaceId, canCreateConfigurationChat, pendingAgentId, onStart, onCancel, onKindChange, }: QuickChatSetupProps) { const agentProfiles = useAppStore((state) => state.agentProfiles.items ?? []); const defaultAgentId = useAppStore( (state) => state.workspaces.items.find((workspace) => workspace.id === workspaceId) ?.default_agent_profile_id ?? "", ); const [agentProfileId, setAgentProfileId] = useState(defaultAgentId); useEffect(() => { if (!defaultAgentId) return; setAgentProfileId((current) => current || defaultAgentId); }, [defaultAgentId]); const { repositories, isLoading } = useRepositories(workspaceId, true); const repoState = useRepositoriesState(); const isStarting = pendingAgentId !== null; const hasIncompleteRow = repoState.repositories.some((row) => !row.repositoryId || !row.branch); const { canAddMore, addHint } = repositoryAddState( isLoading, repositories.length, repoState.repositories.length, ); const handleRepositoryChange = useCallback( (key: string, repositoryId: string) => { repoState.updateRepository(key, { repositoryId, localPath: undefined, branch: "" }); }, [repoState], ); const handleBranchChange = useCallback( (key: string, branch: string) => repoState.updateRepository(key, { branch }), [repoState], ); const selectedRepositories = useMemo( () => repoState.repositories .filter((row) => row.repositoryId && row.branch) .map((row) => ({ repository_id: row.repositoryId as string, base_branch: row.branch })), [repoState.repositories], ); const startDisabled = !agentProfileId || hasIncompleteRow || isStarting; return (

Quick Chat

{canCreateConfigurationChat && ( checked && onKindChange("config")} /> )}
onStart(agentProfileId, selectedRepositories)} />
); }