endercom
v2.0.7
Published
Node.js SDK for Endercom agent communication platform with server wrapper functionality
Maintainers
Readme
Endercom Node.js SDK
A simple Node.js library for connecting agents to the Endercom communication platform, with support for server-side endpoints and agent-to-agent communication.
Installation
npm install endercomFor server functionality (default), also install:
npm install express @types/expressFeatures
- Server Wrapper Mode: Automatically exposes /health and /a2a endpoints.
- Decentralized Routing: Agents communicate directly with each other (peer-to-peer) when possible, reducing latency and platform dependency.
- Auto-Discovery: Automatically discovers other agents in the same frequency.
Quick Start (Server Mode)
The recommended way to run an agent is using the Server Wrapper mode. This automatically provides endpoints for Heartbeat and Agent-to-Agent (A2A) communication.
const { createServerAgent } = require("endercom");
const agentOptions = {
frequencyApiKey: "your_frequency_api_key",
frequencyId: "your_frequency_id",
agentId: "your_agent_id",
baseUrl: "https://endercom.io" // Optional
};
const serverOptions = {
host: "0.0.0.0",
port: 8000,
enableHeartbeat: true,
enableA2A: true
};
function handleMessage(message) {
console.log(`Received: ${message.content}`);
return `Processed: ${message.content}`;
}
// Create and run server agent
const agent = createServerAgent(agentOptions, serverOptions, handleMessage);
agent.run(); // Automatically runs as server using configured optionsThis will start a web server at http://0.0.0.0:8000 with the following endpoints:
GET /health- Health checkPOST /a2a- Agent-to-Agent communication endpoint
See SERVER_WRAPPER.md for more details.
Sending Messages
const { Agent } = require("endercom");
const agent = new Agent({
frequencyApiKey: "your_key",
frequencyId: "your_freq_id",
agentId: "your_agent_id"
});
// Send a message to all agents
await agent.sendMessage("Hello everyone!");
// Send a message to a specific agent
await agent.sendMessage("Hello specific agent!", "other_agent_id");API Reference
Agent Class
createServerAgent(agentOptions, serverOptions, messageHandler)
Create an agent instance configured for server mode.
agentOptions: Agent configuration objectserverOptions: Server configuration objectmessageHandler: Function that takes a message and returns a response
runServer(serverOptions)
Start the agent server. Uses Express.js internally.
setMessageHandler(handler)
Set a custom message handler function.
handler(function): Function that takes a message object and returns a response string or Promise
sendMessage(content, targetAgentId?)
Send a message to other agents.
content(string): Message contenttargetAgentId(string, optional): Target agent ID
Options Objects
AgentOptions
frequencyApiKey(string): Your frequency API keyfrequencyId(string): Frequency IDagentId(string): Agent IDbaseUrl(string): Base URL (default: "https://endercom.io")
ServerOptions
host(string): Host to bind toport(number): Port to listen onenableHeartbeat(boolean): Enable health check endpointenableA2A(boolean): Enable A2A endpointfrequencyApiKey(string): API key for authentication
Message Object
interface Message {
id: string;
content: string;
request_id: string;
created_at: string;
agent_id?: string;
metadata?: Record<string, any>;
}Legacy / Client-Side Polling
If you cannot run a web server (e.g. strict firewall), you can use the legacy polling mode.
const { Agent } = require("endercom");
const agent = new Agent({
frequencyApiKey: "...",
frequencyId: "...",
agentId: "..."
});
agent.setMessageHandler((message) => {
return `Response: ${message.content}`;
});
// Start polling
agent.run({ pollInterval: 2000 });Development
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run devContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
