From 38e1c8b2b9b92609358f5549548b9f40fde7fb32 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Tue, 8 Oct 2024 07:33:47 -0700 Subject: [PATCH] tools --- client/src/App.tsx | 58 +++++++++++++--- client/src/components/ToolsTab.tsx | 101 ++++++++++++++++++++++++++++ client/src/components/ToolsTabs.tsx | 0 server/src/client.ts | 27 ++++++++ server/src/index.ts | 13 ++++ 5 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 client/src/components/ToolsTab.tsx delete mode 100644 client/src/components/ToolsTabs.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index f89c8e8..6768047 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,5 +1,12 @@ import { useState, useEffect } from "react"; -import { Send, Bell, Terminal, Files, MessageSquare } from "lucide-react"; +import { + Send, + Bell, + Terminal, + Files, + MessageSquare, + Hammer, +} from "lucide-react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import ConsoleTab from "./components/ConsoleTab"; @@ -8,6 +15,7 @@ import RequestsTab from "./components/RequestsTabs"; import ResourcesTab, { Resource } from "./components/ResourcesTab"; import NotificationsTab from "./components/NotificationsTab"; import PromptsTab, { Prompt } from "./components/PromptsTab"; +import ToolsTab, { Tool as ToolType } from "./components/ToolsTab"; const App = () => { const [socket, setSocket] = useState(null); @@ -18,6 +26,8 @@ const App = () => { const [resourceContent, setResourceContent] = useState(""); const [prompts, setPrompts] = useState([]); const [promptContent, setPromptContent] = useState(""); + const [tools, setTools] = useState([]); + const [toolResult, setToolResult] = useState(""); const [error, setError] = useState(null); useEffect(() => { @@ -44,6 +54,12 @@ const App = () => { } else if (message.type === "prompt") { setPromptContent(JSON.stringify(message.data, null, 2)); setError(null); + } else if (message.type === "tools") { + setTools(message.data.tools); + setError(null); + } else if (message.type === "toolResult") { + setToolResult(JSON.stringify(message.data, null, 2)); + setError(null); } else if (message.type === "error") { setError(message.message); } @@ -71,6 +87,7 @@ const App = () => { null, ); const [selectedPrompt, setSelectedPrompt] = useState(null); + const [selectedTool, setSelectedTool] = useState(null); const listResources = () => { sendWebSocketMessage({ type: "listResources" }); @@ -88,6 +105,14 @@ const App = () => { sendWebSocketMessage({ type: "getPrompt", name }); }; + const listTools = () => { + sendWebSocketMessage({ type: "listTools" }); + }; + + const callTool = (name: string, params: Record) => { + sendWebSocketMessage({ type: "callTool", name, params }); + }; + return (
@@ -96,14 +121,6 @@ const App = () => {
- - - Requests - - - - Notifications - Resources @@ -112,7 +129,19 @@ const App = () => { Prompts - + + + Requests + + + + Notifications + + + + Tools + + Console @@ -139,6 +168,15 @@ const App = () => { promptContent={promptContent} error={error} /> +
diff --git a/client/src/components/ToolsTab.tsx b/client/src/components/ToolsTab.tsx new file mode 100644 index 0000000..11bee39 --- /dev/null +++ b/client/src/components/ToolsTab.tsx @@ -0,0 +1,101 @@ +import { TabsContent } from "@/components/ui/tabs"; +import { Button } from "@/components/ui/button"; +import { Textarea } from "@/components/ui/textarea"; +import { Send, AlertCircle } from "lucide-react"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { useState } from "react"; + +export type Tool = { + name: string; +}; + +const ToolsTab = ({ + tools, + listTools, + callTool, + selectedTool, + setSelectedTool, + toolResult, + error, +}: { + tools: Tool[]; + listTools: () => void; + callTool: (name: string, params: Record) => void; + selectedTool: Tool | null; + setSelectedTool: (tool: Tool) => void; + toolResult: string; + error: string | null; +}) => { + const [params, setParams] = useState(""); + + return ( + +
+
+

Tools

+
+
+ +
+ {tools.map((tool, index) => ( +
setSelectedTool(tool)} + > + {tool.name} +
+ ))} +
+
+
+ +
+
+

+ {selectedTool ? selectedTool.name : "Select a tool"} +

+
+
+ {error ? ( + + + Error + {error} + + ) : selectedTool ? ( +
+