"use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; import { Brain, CheckCircle2, Loader2, Search, Sparkles } from "lucide-react"; import { useMemo } from "react"; import { ChainOfThought, ChainOfThoughtContent, ChainOfThoughtItem, ChainOfThoughtStep, ChainOfThoughtTrigger, } from "@/components/prompt-kit/chain-of-thought"; import { cn } from "@/lib/utils"; /** * Types for the deepagent thinking/reasoning tool */ interface ThinkingStep { id: string; title: string; items: string[]; status: "pending" | "in_progress" | "completed"; } interface DeepAgentThinkingArgs { query?: string; context?: string; } interface DeepAgentThinkingResult { steps?: ThinkingStep[]; status?: "thinking" | "searching" | "synthesizing" | "completed"; summary?: string; } /** * Get icon based on step status and type */ function getStepIcon(status: "pending" | "in_progress" | "completed", title: string) { // Check for specific step types based on title keywords const titleLower = title.toLowerCase(); if (status === "in_progress") { return ; } if (status === "completed") { return ; } // Default icons based on step type if (titleLower.includes("search") || titleLower.includes("knowledge")) { return ; } if (titleLower.includes("analy") || titleLower.includes("understand")) { return ; } return ; } /** * Component to display a single thinking step */ function ThinkingStepDisplay({ step }: { step: ThinkingStep }) { const icon = useMemo(() => getStepIcon(step.status, step.title), [step.status, step.title]); return ( {step.title} {step.items.map((item, index) => ( {item} ))} ); } /** * Loading state with animated thinking indicator */ function ThinkingLoadingState({ status }: { status?: string }) { const statusText = useMemo(() => { switch (status) { case "searching": return "Searching knowledge base..."; case "synthesizing": return "Synthesizing response..."; case "thinking": default: return "Thinking..."; } }, [status]); return (
{statusText}
); } /** * DeepAgent Thinking Tool UI Component * * This component displays the agent's chain-of-thought reasoning * when the deepagent is processing a query. It shows thinking steps * in a collapsible, hierarchical format. */ export const DeepAgentThinkingToolUI = makeAssistantToolUI< DeepAgentThinkingArgs, DeepAgentThinkingResult >({ toolName: "deepagent_thinking", render: function DeepAgentThinkingUI({ args, result, status }) { // Loading state - tool is still running if (status.type === "running" || status.type === "requires-action") { return ; } // Incomplete/cancelled state if (status.type === "incomplete") { if (status.reason === "cancelled") { return null; // Don't show anything if cancelled } if (status.reason === "error") { return null; // Don't show error for thinking - it's not critical } } // No result or no steps - don't render anything if (!result?.steps || result.steps.length === 0) { return null; } // Render the chain of thought return (
{result.steps.map((step) => ( ))}
); }, }); /** * Inline Thinking Display Component * * A simpler version that can be used inline with the message content * for displaying reasoning without the full tool UI infrastructure. */ export function InlineThinkingDisplay({ steps, isStreaming = false, className, }: { steps: ThinkingStep[]; isStreaming?: boolean; className?: string; }) { if (steps.length === 0 && !isStreaming) { return null; } return (
{isStreaming && steps.length === 0 ? ( ) : ( {steps.map((step) => ( ))} )}
); } export type { ThinkingStep, DeepAgentThinkingArgs, DeepAgentThinkingResult };