remove Command verbiage, refactor slightly
This commit is contained in:
@@ -19,7 +19,7 @@ import ResourcesTab, { Resource } from "./components/ResourcesTab";
|
|||||||
import NotificationsTab from "./components/NotificationsTab";
|
import NotificationsTab from "./components/NotificationsTab";
|
||||||
import PromptsTab, { Prompt } from "./components/PromptsTab";
|
import PromptsTab, { Prompt } from "./components/PromptsTab";
|
||||||
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
|
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
|
||||||
import CommandHistory from "./components/CommandHistory";
|
import History from "./components/CommandHistory";
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [socket, setSocket] = useState<WebSocket | null>(null);
|
const [socket, setSocket] = useState<WebSocket | null>(null);
|
||||||
@@ -40,8 +40,8 @@ const App = () => {
|
|||||||
"/Users/ashwin/code/example-servers/build/everything/index.js",
|
"/Users/ashwin/code/example-servers/build/everything/index.js",
|
||||||
);
|
);
|
||||||
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
|
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
|
||||||
const [commandHistory, setCommandHistory] = useState<
|
const [requestHistory, setRequestHistory] = useState<
|
||||||
Array<{ command: string; response: string | null }>
|
Array<{ request: string; response: string | null }>
|
||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -59,34 +59,28 @@ const App = () => {
|
|||||||
if (message.type === "resources") {
|
if (message.type === "resources") {
|
||||||
setResources(message.data.resources);
|
setResources(message.data.resources);
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "resource") {
|
} else if (message.type === "resource") {
|
||||||
setResourceContent(JSON.stringify(message.data, null, 2));
|
setResourceContent(JSON.stringify(message.data, null, 2));
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "prompts") {
|
} else if (message.type === "prompts") {
|
||||||
setPrompts(message.data.prompts);
|
setPrompts(message.data.prompts);
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "prompt") {
|
} else if (message.type === "prompt") {
|
||||||
setPromptContent(JSON.stringify(message.data, null, 2));
|
setPromptContent(JSON.stringify(message.data, null, 2));
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "tools") {
|
} else if (message.type === "tools") {
|
||||||
setTools(message.data.tools);
|
setTools(message.data.tools);
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "toolResult") {
|
} else if (message.type === "toolResult") {
|
||||||
setToolResult(JSON.stringify(message.data, null, 2));
|
setToolResult(JSON.stringify(message.data, null, 2));
|
||||||
setError(null);
|
setError(null);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "error") {
|
} else if (message.type === "error") {
|
||||||
setError(message.message);
|
setError(message.message);
|
||||||
updateCommandHistory(message);
|
|
||||||
} else if (message.type === "connected") {
|
} else if (message.type === "connected") {
|
||||||
setMcpConnected(true);
|
setMcpConnected(true);
|
||||||
updateCommandHistory(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateRequestHistory(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = () => {
|
ws.onerror = () => {
|
||||||
@@ -101,13 +95,13 @@ const App = () => {
|
|||||||
return () => ws.close();
|
return () => ws.close();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const updateCommandHistory = (response: unknown) => {
|
const updateRequestHistory = (response: unknown) => {
|
||||||
setCommandHistory((prev) => {
|
setRequestHistory((prev) => {
|
||||||
const lastCommand = prev[prev.length - 1];
|
const lastRequest = prev[prev.length - 1];
|
||||||
if (lastCommand && lastCommand.response === null) {
|
if (lastRequest && lastRequest.response === null) {
|
||||||
const updatedHistory = [...prev];
|
const updatedHistory = [...prev];
|
||||||
updatedHistory[updatedHistory.length - 1] = {
|
updatedHistory[updatedHistory.length - 1] = {
|
||||||
...lastCommand,
|
...lastRequest,
|
||||||
response: JSON.stringify(response),
|
response: JSON.stringify(response),
|
||||||
};
|
};
|
||||||
return updatedHistory;
|
return updatedHistory;
|
||||||
@@ -120,9 +114,9 @@ const App = () => {
|
|||||||
if (socket) {
|
if (socket) {
|
||||||
console.log("Sending WebSocket message:", message);
|
console.log("Sending WebSocket message:", message);
|
||||||
socket.send(JSON.stringify(message));
|
socket.send(JSON.stringify(message));
|
||||||
setCommandHistory((prev) => [
|
setRequestHistory((prev) => [
|
||||||
...prev,
|
...prev,
|
||||||
{ command: JSON.stringify(message), response: null },
|
{ request: JSON.stringify(message), response: null },
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -260,7 +254,7 @@ const App = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<CommandHistory commandHistory={commandHistory} />
|
<History requestHistory={requestHistory} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Copy } from "lucide-react";
|
import { Copy } from "lucide-react";
|
||||||
|
|
||||||
const CommandHistory = ({
|
const History = ({
|
||||||
commandHistory,
|
requestHistory,
|
||||||
}: {
|
}: {
|
||||||
commandHistory: Array<{ command: string; response: string | null }>;
|
requestHistory: Array<{ request: string; response: string | null }>;
|
||||||
}) => {
|
}) => {
|
||||||
const [expandedCommands, setExpandedCommands] = useState<{
|
const [expandedRequests, setExpandedRequests] = useState<{
|
||||||
[key: number]: boolean;
|
[key: number]: boolean;
|
||||||
}>({});
|
}>({});
|
||||||
|
|
||||||
const toggleCommandExpansion = (index: number) => {
|
const toggleRequestExpansion = (index: number) => {
|
||||||
setExpandedCommands((prev) => ({ ...prev, [index]: !prev[index] }));
|
setExpandedRequests((prev) => ({ ...prev, [index]: !prev[index] }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyToClipboard = (text: string) => {
|
const copyToClipboard = (text: string) => {
|
||||||
@@ -20,12 +20,12 @@ const CommandHistory = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-64 bg-white shadow-md p-4 overflow-y-auto">
|
<div className="w-64 bg-white shadow-md p-4 overflow-y-auto">
|
||||||
<h2 className="text-lg font-semibold mb-4">Command History</h2>
|
<h2 className="text-lg font-semibold mb-4">History</h2>
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{commandHistory
|
{requestHistory
|
||||||
.slice()
|
.slice()
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((cmd, index) => (
|
.map((request, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className="text-sm text-gray-600 bg-gray-100 p-2 rounded"
|
className="text-sm text-gray-600 bg-gray-100 p-2 rounded"
|
||||||
@@ -33,52 +33,52 @@ const CommandHistory = ({
|
|||||||
<div
|
<div
|
||||||
className="flex justify-between items-center cursor-pointer"
|
className="flex justify-between items-center cursor-pointer"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
toggleCommandExpansion(commandHistory.length - 1 - index)
|
toggleRequestExpansion(requestHistory.length - 1 - index)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<span className="font-mono">
|
<span className="font-mono">
|
||||||
{commandHistory.length - index}.{" "}
|
{requestHistory.length - index}.{" "}
|
||||||
{JSON.parse(cmd.command).type}
|
{JSON.parse(request.request).type}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{expandedCommands[commandHistory.length - 1 - index]
|
{expandedRequests[requestHistory.length - 1 - index]
|
||||||
? "▼"
|
? "▼"
|
||||||
: "▶"}
|
: "▶"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{expandedCommands[commandHistory.length - 1 - index] && (
|
{expandedRequests[requestHistory.length - 1 - index] && (
|
||||||
<>
|
<>
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<div className="flex justify-between items-center mb-1">
|
<div className="flex justify-between items-center mb-1">
|
||||||
<span className="font-semibold text-blue-600">
|
<span className="font-semibold text-blue-600">
|
||||||
Command:
|
Request:
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={() => copyToClipboard(cmd.command)}
|
onClick={() => copyToClipboard(request.request)}
|
||||||
className="text-blue-500 hover:text-blue-700"
|
className="text-blue-500 hover:text-blue-700"
|
||||||
>
|
>
|
||||||
<Copy size={16} />
|
<Copy size={16} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<pre className="whitespace-pre-wrap break-words bg-blue-50 p-2 rounded">
|
<pre className="whitespace-pre-wrap break-words bg-blue-50 p-2 rounded">
|
||||||
{JSON.stringify(JSON.parse(cmd.command), null, 2)}
|
{JSON.stringify(JSON.parse(request.request), null, 2)}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
{cmd.response && (
|
{request.response && (
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<div className="flex justify-between items-center mb-1">
|
<div className="flex justify-between items-center mb-1">
|
||||||
<span className="font-semibold text-green-600">
|
<span className="font-semibold text-green-600">
|
||||||
Response:
|
Response:
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={() => copyToClipboard(cmd.response!)}
|
onClick={() => copyToClipboard(request.response!)}
|
||||||
className="text-blue-500 hover:text-blue-700"
|
className="text-blue-500 hover:text-blue-700"
|
||||||
>
|
>
|
||||||
<Copy size={16} />
|
<Copy size={16} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<pre className="whitespace-pre-wrap break-words bg-green-50 p-2 rounded">
|
<pre className="whitespace-pre-wrap break-words bg-green-50 p-2 rounded">
|
||||||
{JSON.stringify(JSON.parse(cmd.response), null, 2)}
|
{JSON.stringify(JSON.parse(request.response), null, 2)}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -91,4 +91,4 @@ const CommandHistory = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CommandHistory;
|
export default History;
|
||||||
Reference in New Issue
Block a user