@toolplex/client
Version:
The official ToolPlex client for AI agent tool discovery and execution
36 lines (35 loc) • 1.22 kB
JavaScript
class InstallObserver {
constructor() {
this.serverInstallActions = new Map();
}
// Record an install action on a server
recordInstall(serverId) {
this.recordAction(serverId, "install");
}
// Record an uninstall action on a server
recordUninstall(serverId) {
this.recordAction(serverId, "uninstall");
}
// Check if a server has been installed
wasServerInstalled(serverId) {
return (this.serverInstallActions.has(serverId) &&
this.serverInstallActions.get(serverId).has("install"));
}
// Check if a server has been uninstalled
wasServerUninstalled(serverId) {
return (this.serverInstallActions.has(serverId) &&
this.serverInstallActions.get(serverId).has("uninstall"));
}
// Optionally, clear all records (for testing or reset)
clear() {
this.serverInstallActions.clear();
}
// Private method to record an action
recordAction(serverId, action) {
if (!this.serverInstallActions.has(serverId)) {
this.serverInstallActions.set(serverId, new Set());
}
this.serverInstallActions.get(serverId).add(action);
}
}
export default InstallObserver;