# @ag-ui/encoder

> Event encoding utilities for the **Agent-User Interaction (AG-UI) Protocol**.

Latest version **1.0.1** (published 2026-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ag-ui/encoder
pnpm add @ag-ui/encoder
yarn add @ag-ui/encoder
bun add @ag-ui/encoder
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score; popular repo.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2026-09-29 |
| First published | 2025-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16038 |
| Author | Markus Ecker |
| Maintainers | _mme, copilotkit |

## Links

- npm: https://www.npmjs.com/package/@ag-ui/encoder
- Repository: https://github.com/ag-ui-protocol/ag-ui
- Homepage: https://github.com/ag-ui-protocol/ag-ui#readme
- Issues: https://github.com/ag-ui-protocol/ag-ui/issues
- npm.io page: https://npm.io/package/@ag-ui/encoder

## Recent versions

- 1.0.1 (latest) — 2026-09-29
- 1.0.0-canary.1789569879.0 (canary) — 2026-09-16
- 0.0.50-alpha.0 (alpha) — 2026-04-02
- 1.0.0 — 2026-09-17
- 0.0.59 — 2026-08-27
- 0.0.59-canary.1787220377.0 — 2026-08-20
- 0.0.58 — 2026-08-14
- 0.0.59-canary.1786716392.0 — 2026-08-14
- 0.0.59-canary.1786549251.0 — 2026-08-12
- 0.0.59-canary.1785518626.0 — 2026-07-31
- 0.1.1-canary.beta.0 — 2026-07-30
- 0.0.58-canary.beta.0 — 2026-07-28
- 0.0.59-canary.1784325892.0 — 2026-07-17
- 0.0.57 — 2026-06-12
- 0.0.56 — 2026-06-09
- … 62 more at https://npm.io/package/@ag-ui/encoder/versions

## README

# @ag-ui/encoder

Event encoding utilities for the **Agent-User Interaction (AG-UI) Protocol**.

`@ag-ui/encoder` handles content negotiation and format encoding for AG-UI events. It automatically chooses between Server-Sent Events (JSON) and Protocol Buffers based on client `Accept` headers, ensuring optimal transport efficiency.

## Installation

```bash
npm install @ag-ui/encoder
pnpm add @ag-ui/encoder
yarn add @ag-ui/encoder
```

## Features

- 🎯 **Content negotiation** – Automatic format selection based on `Accept` headers
- 📦 **Dual encoding** – SSE (JSON) and Protocol Buffer support
- ⚡ **Efficient binary** – Length-prefixed protobuf encoding for high-throughput scenarios
- 🔄 **Seamless fallback** – Graceful degradation to SSE when protobuf isn't supported

## Quick example

```ts
import { EventEncoder } from "@ag-ui/encoder";
import { EventType } from "@ag-ui/core";

const encoder = new EventEncoder({
  accept: "application/vnd.ag-ui.event+proto, text/event-stream",
});

const event = {
  type: EventType.TEXT_MESSAGE_CONTENT,
  messageId: "msg_123",
  delta: "Hello, world!",
};

// Returns protobuf-encoded binary data
const encoded = encoder.encodeBinary(event);
```

## Documentation

- Concepts & architecture: [`docs/concepts`](https://docs.ag-ui.com/concepts/architecture)
- Full API reference: [`docs/sdk/js/encoder`](https://docs.ag-ui.com/sdk/js/encoder)

## Contributing

Bug reports and pull requests are welcome! Please read our [contributing guide](https://docs.ag-ui.com/development/contributing) first.

## License

MIT © 2025 AG-UI Protocol Contributors

---
_Source: https://npm.io/package/@ag-ui/encoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
