import { useState } from "react"; import { CodeBlock } from "~/components/code/CodeBlock"; import type { AISpanData, ToolDefinition } from "./types"; import { Paragraph } from "~/components/primitives/Paragraph"; export function AIToolsInventory({ aiData }: { aiData: AISpanData }) { const defs = aiData.toolDefinitions ?? []; const calledNames = getCalledToolNames(aiData); if (defs.length === 0) { return (
No tool definitions available for this span.
); } return (
{defs.map((def) => { const wasCalled = calledNames.has(def.name); return ; })}
); } function ToolDefRow({ def, wasCalled }: { def: ToolDefinition; wasCalled: boolean }) { const [showSchema, setShowSchema] = useState(false); return (
{def.name} {wasCalled ? "called" : "not called"}
{def.description && (

{def.description}

)} {def.parametersJson && (
{showSchema && (
)}
)}
); } function getCalledToolNames(aiData: AISpanData): Set { const names = new Set(); if (!aiData.items) return names; for (const item of aiData.items) { if (item.type === "tool-use") { for (const tool of item.tools) { names.add(tool.toolName); } } } return names; }