import { ReactNode } from "react"; import { XCircle, CheckCircle, Sparkles, RotateCcw } from "lucide-react"; import { Button } from "../DesignSystem/Button"; import { Link } from "@tanstack/react-router"; import { useOllamaHelp } from "../../features/Terminal/useOllamaHelp"; import { useAppSelector } from "../../app/hooks"; import { ExecutionResult } from "./commandUtils"; import { CommandBlock } from "./CommandBlock"; interface CommandWithAIProps { command: string; title: string; icon?: ReactNode; borderColor?: string; headerButtons?: ReactNode; statusBar?: ReactNode; className?: string; copied: boolean; onCopy?: () => void; result?: ExecutionResult | null; onDismissResult?: () => void; cwd?: string; } export function CommandWithAI({ command, title, icon, borderColor, headerButtons, statusBar, className = "", copied, onCopy, result, onDismissResult, cwd = "", }: CommandWithAIProps) { const { getSuggestion, suggestion, isLoading: isGettingSuggestion, error: suggestionError, clearSuggestion, lastPrompt, } = useOllamaHelp(); const ollamaEnabled = useAppSelector((s) => s.settings.ollama.enabled); const handleAskForHelp = async () => { if (!result || result.exitCode === 0) return; await getSuggestion(command, result.output, result.exitCode, cwd); }; const handleRetryAiHelp = async () => { if (!result || result.exitCode === 0) return; clearSuggestion(); await getSuggestion(command, result.output, result.exitCode, cwd); }; // Determine border color based on result // Format duration for display const formatDuration = (ms: number): string => { if (ms < 1000) { return `${Math.round(ms)}ms`; } else if (ms < 60000) { return `${(ms / 1000).toFixed(1)}s`; } else { const minutes = Math.floor(ms / 60000); const seconds = ((ms % 60000) / 1000).toFixed(1); return `${minutes}m ${seconds}s`; } }; let computedBorderColor = borderColor; if (result) { computedBorderColor = result.exitCode !== -1 ? result.exitCode === 0 ? "border-ctp-green" : "border-ctp-red" : "border-ctp-surface0"; } // Enhanced status bar with result info let enhancedStatusBar = statusBar; // -1 => command still running if (result && result.exitCode !== -1) { const resultStatusBar = (
{lastPrompt.trim()}
ollama pull qwen3:8b
. Check out the{" "}
Ollama tutorial
{" "}
for more information.
>
) : (
<>
Looks like we weren't able to call Ollama. Please make
sure Ollama is running. If you haven't already, visit the{" "}
Ollama tutorial
{" "}
for help with installation and setup.
>
)}