The @egain/ai-agent-sdk package is a TypeScript-first SDK for embedding eGain AI Agent conversations in browser and Node.js applications. It provides WebSocket communication, authentication helpers, typed events, reconnection, message queuing, transcript handling, and context persistence.
npm install @egain/ai-agent-sdkThis package includes TypeScript definitions and supports modern browser builds and Node.js integrations.
import { AiAgent } from "@egain/ai-agent-sdk";
const agent = new AiAgent({
id: "your-agent-id",
endpoint: "https://your-endpoint.com",
auth: { type: "pre-auth", accessToken: "your-access-token" },
autoConnect: true
});
await agent.initialize();
agent.on("agentMessage", (event) => {
console.log("Agent:", event.payload.message?.content);
});
await agent.send("Hello, agent!");- Real-time bidirectional messaging over WebSocket.
- Anonymous, pre-authenticated, PKCE, and client credentials authentication strategies.
- Automatic reconnection with offline message queuing.
- Strongly typed events and message payloads.
- Transcript storage, filtering, serialization, and export support.
- Context caching and restoration across reconnects.