ag-ui-protocol / ag-ui-protocol/ag-ui
[Feature]: Add the missing Kotlin EventEncoder to the community Kotlin SDK
- Lingua principale
- Python
- Stelle
- 15.9k
- Fork
- 1.4k
- Merge medio
- 1g 17h
- PR unite (30g)
- 163
Descrizione
### 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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.