# TypeScript AI Agent SDK

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.

div
a
svg
path

    View on GitHub
  
a
svg
path
path
path
path
path

    View Documentation
  
## SDK Installation


```bash
npm install @egain/ai-agent-sdk
```

This package includes TypeScript definitions and supports modern browser builds and Node.js integrations.

## Example Usage


```typescript
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!");
```

## Key Capabilities

- 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.