ag-ui-protocol / ag-ui-protocol/ag-ui

[Feature]: Add the missing Kotlin EventEncoder to the community Kotlin SDK

Abierto
#2,170 0 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Python
Estrellas
15.9k
Forks
1.4k
Merge medio
1 d 17 h
PR fusionados (30 d)
163

Descripción

### Pre-flight Checklist

- [x] I have searched existing issues and this hasn't been requested yet.

### Problem or Motivation

The community **Kotlin** SDK (`sdks/community/kotlin`) is currently **client-only** - it ships
`kotlin-core` (event/message types + `AgUiJson`), `kotlin-client` (HTTP/SSE agent, `SseParser`,
`EventVerifier`, state), and `kotlin-tools`. It has **no `EventEncoder`**, which both reference
SDKs ship as their single server-side serialization primitive:

- TypeScript: `@ag-ui/encoder` — `class EventEncoder({ accept })` with `getContentType()` /
`encode()` / `encodeSSE()` (+ proto path via `@ag-ui/proto`).
- Python: `ag_ui.encoder` - `EventEncoder(accept=None)` with `get_content_type()` -> `"text/event-stream"`
and `encode()` -> `data: {json}\n\n` (SSE-only; declares the proto media type but has no binary codec).

Because Kotlin has no equivalent, anyone standing up an AG-UI **server** in Kotlin today has to
reach past the SDK into `AgUiJson` / `BaseEvent.serializer()` and hand-roll the `data: … \n\n`
framing themselves. That's the one gap between the Kotlin SDK and the TS/Python SDKs on the
server side (the event model and client are already at parity).

### Proposed Solution

Add a small **`:kotlin-encoder`** SDK module (`com.ag-ui.community:kotlin-encoder`, KMP JVM
target) with an `EventEncoder` that mirrors the TS/Python shape:

- `getContentType()` → `"text/event-stream"` (SSE-only for now, matching the Python encoder;
a `TODO` marks proto negotiation from `Accept` once a Kotlin proto codec exists).
- `encode(event)` / `encodeSSE(event)` → canonical `data: {json}\n\n` (byte-identical to TS
`encodeSSE` / Python `_encode_sse`).
- `encodeToJson(event)` → the unframed JSON body, for transports that add their own SSE framing
(Spring MVC `SseEmitter`, Jakarta `SseEventSink`) so they don't double-frame — keeps the SDK
the single serialization entry point.

Reuses `com.agui.core.types.*` from `kotlin-core`; no model changes. Byte-exact unit tests.

### Alternatives Considered

_No response_

### Additional Context

This issue is **only** the encoder SDK primitive. I also have Kotlin **server-starter examples** ready to offer as a **follow-up** if that's something you'd welcome.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.