> ## Documentation Index
> Fetch the complete documentation index at: https://haiprotocol.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HAIP TypeScript SDK

> Complete TypeScript SDK for the Human-Agent Interaction Protocol

## Overview

The HAIP TypeScript SDK provides a complete implementation of the Human-Agent Interaction Protocol, enabling developers to build real-time, multi-modal applications with AI agents. The SDK is production-ready with comprehensive test coverage and supports all major transport protocols.

<CardGroup cols={2}>
  <Card title="Protocol Compliant" icon="bolt" href="/sdk/client">
    Full HAIP 1.1.2 protocol implementation with comprehensive event handling.
  </Card>

  <Card title="Multi-Transport Support" icon="network-wired" href="/sdk/transports">
    WebSocket, SSE, and HTTP streaming transports with automatic fallback.
  </Card>

  <Card title="Tool Integration" icon="wrench" href="/sdk/tools">
    Built-in support for Model Context Protocol (MCP) tool lifecycle management.
  </Card>

  <Card title="Flow Control" icon="sliders" href="/sdk/flow-control">
    Credit-based flow control with automatic back-pressure management.
  </Card>

  <Card title="Error Handling" icon="circle-xmark" href="/sdk/error-handling">
    Comprehensive error handling with automatic recovery and reconnection.
  </Card>

  <Card title="Performance Monitoring" icon="chart-bar" href="/sdk/client">
    Real-time performance metrics and connection state monitoring.
  </Card>
</CardGroup>

## Quick Start

```bash theme={null}
npm install @haip/sdk
```

```typescript theme={null}
import { createHAIPClient } from "@haip/sdk";

async function main() {
  const client = createHAIPClient({
    url: "ws://localhost:8080",
  });

  client.authenticate(() => {
    // You should send a token here.
    return {
      token: "Bearer TOKEN",
    };
  });

  try {
    await client.connect();

    const transaction = await client.startTransaction("echo", {});

    transaction.on("message", (message: any) => {
      console.log("🤖 Agent:", message.payload);
    });

    console.log("✅ Sending to transaction:", "Hello! Can you echo this?");
    transaction.sendTextMessage("Hello! Can you echo this?");
  } catch (error) {
    console.error("Error:", error);
    await client.disconnect();
  }
}

main();
```

## Architecture

The SDK is built with a modular architecture that separates concerns and provides flexibility:

<Steps>
  <Step title="Client Layer">
    High-level client interface that manages connection lifecycle, handshakes,
    and protocol state.
  </Step>

  <Step title="Transport Layer">
    Pluggable transport implementations for different communication protocols.
  </Step>

  <Step title="Protocol Layer">
    Core protocol implementation with message validation, flow control, and
    event handling.
  </Step>

  <Step title="Utility Layer">
    Helper functions for message creation, validation, and common operations.
  </Step>
</Steps>

## Supported Environments

* **Node.js**: Full support with WebSocket and HTTP Streaming transports
* **Browser**: Full support with WebSocket, SSE, and HTTP Streaming transports
* **TypeScript**: Complete type definitions and IntelliSense support
* **JavaScript**: Full compatibility with ES6+ features

## Transport Options

| Transport      | Node.js | Browser | Features                                       |
| -------------- | ------- | ------- | ---------------------------------------------- |
| WebSocket      | ✅       | ✅       | Real-time, bidirectional, binary support       |
| SSE            | ❌       | ✅       | Server-sent events, HTTP POST for sending      |
| HTTP Streaming | ✅       | ✅       | Fetch-based streaming, universal compatibility |

## Protocol Support

The SDK implements the complete HAIP v1.1.2 specification.

<Card title="View the spec" icon="book-open" href="/protocol/openapi" horizontal>
  OpenAPI Specification
</Card>

## Getting Started

Choose your next step:

<CardGroup cols={2}>
  <Card title="Installation" href="/sdk/installation" icon="download">
    Learn how to install and configure the SDK in your project.
  </Card>

  <Card title="Quick Start Guide" href="/sdk/quickstart" icon="play">
    Get up and running with a simple example in minutes.
  </Card>

  <Card title="Client API" href="/sdk/client" icon="code">
    Explore the main client interface and its methods.
  </Card>

  <Card title="Examples" href="/examples/basic-chat" icon="book-open">
    Browse complete examples for common use cases.
  </Card>
</CardGroup>

{" "}
