@toolplex/client
Version:
The official ToolPlex client for AI agent tool discovery and execution
28 lines (27 loc) • 921 B
JavaScript
class CallToolObserver {
constructor() {
this.serverToolCalls = new Map();
}
// Record a call to a tool on a server
recordCall(serverId, toolName) {
if (!this.serverToolCalls.has(serverId)) {
this.serverToolCalls.set(serverId, new Set());
}
this.serverToolCalls.get(serverId).add(toolName);
}
// Check if a server was called at all
wasServerCalled(serverId) {
return (this.serverToolCalls.has(serverId) &&
this.serverToolCalls.get(serverId).size > 0);
}
// Check if a specific tool was called on a server
wasToolCalled(serverId, toolName) {
return (this.serverToolCalls.has(serverId) &&
this.serverToolCalls.get(serverId).has(toolName));
}
// Optionally, clear all records (for testing or reset)
clear() {
this.serverToolCalls.clear();
}
}
export default CallToolObserver;