import React, { useState } from "react"; import { useRenderTool } from "./use-render-tool"; type DefaultRenderProps = { /** The name of the tool being called. */ name: string; /** The parsed parameters passed to the tool call. */ parameters: unknown; /** Current execution status of the tool call. */ status: "inProgress" | "executing" | "complete"; /** The tool call result string, available only when `status` is `"complete"`. */ result: string | undefined; }; /** * Registers a wildcard (`"*"`) tool-call renderer via `useRenderTool`. * * - Call with no config to use CopilotKit's built-in default tool-call card. * - Pass `config.render` to replace the default UI with your own fallback renderer. * * This is useful when you want a generic renderer for tools that do not have a * dedicated `useRenderTool({ name: "..." })` registration. * * @param config - Optional custom wildcard render function. * @param deps - Optional dependencies to refresh registration. * * @example * ```tsx * useDefaultRenderTool(); * ``` * * @example * ```tsx * useDefaultRenderTool({ * render: ({ name, status }) =>
{name}: {status}
, * }); * ``` * * @example * ```tsx * useDefaultRenderTool( * { * render: ({ name, result }) => ( * * ), * }, * [compactMode], * ); * ``` */ export function useDefaultRenderTool( config?: { render?: (props: DefaultRenderProps) => React.ReactElement; }, deps?: ReadonlyArray, ): void { useRenderTool( { name: "*", render: config?.render ?? DefaultToolCallRenderer, }, deps, ); } function DefaultToolCallRenderer({ name, parameters, status, result, }: DefaultRenderProps): React.ReactElement { const [isExpanded, setIsExpanded] = useState(false); const statusString = String(status) as | "inProgress" | "executing" | "complete"; const isActive = statusString === "inProgress" || statusString === "executing"; const isComplete = statusString === "complete"; const statusLabel = isActive ? "Running" : isComplete ? "Done" : status; const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa"; const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5"; const badgeColor = isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46"; return (
{/* Header row — always visible */}
setIsExpanded(!isExpanded)} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "10px", cursor: "pointer", userSelect: "none", }} >
{name}
{statusLabel}
{/* Expandable details */} {isExpanded && (
Arguments
                {JSON.stringify(parameters ?? {}, null, 2)}
              
{result !== undefined && (
Result
                  {typeof result === "string"
                    ? result
                    : JSON.stringify(result, null, 2)}
                
)}
)}
); }