persistent-ai

@ag-ui/encoder (1.0.0)

Published 2026-09-22 14:30:33 +00:00 by ak

Installation

@ag-ui:registry=
npm install @ag-ui/encoder@1.0.0
"@ag-ui/encoder": "1.0.0"

About this package

@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

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

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

Contributing

Bug reports and pull requests are welcome! Please read our contributing guide first.

License

MIT © 2025 AG-UI Protocol Contributors

Dependencies

Dependencies

ID Version
@ag-ui/core 1.0.0
@ag-ui/proto 1.0.0

Development Dependencies

ID Version
@arethetypeswrong/cli ^0.17.4
@vitest/coverage-istanbul ^4.0.18
eslint ^9.37.0
publint ^0.3.12
tsdown ^0.20.1
typescript ^5.8.2
vitest ^4.0.18
Details
npm
2026-09-22 14:30:33 +00:00
93
Markus Ecker
MIT
latest
9.4 KiB
Assets (1)
Versions (1) View all
1.0.0 2026-09-22