Skip to content

featherweight.adapters.vercel

vercel

The Vercel AI SDK adapter: the UI message stream, for useChat and the other clients of the AI SDK.

It reads a request into a ChatInput, and translates the AG-UI events of a StreamingRun into the parts of the UI message stream. It is not a server: it gives you the strings, you send them with any web framework.

chat_input = parse_request(await request.json())
run = runner.stream(Support, chat_input)
return StreamingResponse(encode(run), headers=HEADERS)

Written against the protocol as documented at ai-sdk.dev (checked 2026-11-19): see docs/streaming.md.

Translator

Translator()

Turns the events of one run into the parts of the stream, one event at a time. A part is a dict; encode sends them as server-sent events. A custom event is a data part (data-<name>, transient: the client gets it with onData, and it is not kept in the message); the events that have no part (state, activity, the opaque value of a thought) are dropped.

parse_request

parse_request(
    body: dict[str, Any] | str | bytes | list[Any],
) -> ChatInput

The request of useChat ({"id": ..., "messages": [UIMessage, ...]}, or just the list of messages) as a ChatInput. id, the chat's id, becomes the thread_id. Raises BadRequest for a body that cannot be read or a history that ChatInput refuses (a system message, a last message that is not the user's).

to_agui_messages

to_agui_messages(
    ui_messages: list[dict[str, Any]],
) -> list[Message]

UIMessages as AG-UI messages. An assistant UIMessage with tool parts becomes the messages the model saw: an assistant message with its tool calls, then the tool results, then the next step's assistant message, and so on.

translate

translate(events: Iterable[BaseEvent]) -> list[str]

The events of a whole run as server-sent events, ending with [DONE]. For tests and replays; use encode to stream.

encode async

encode(run: StreamingRun) -> AsyncGenerator[str, None]

The server-sent events of a run, as it streams, ending with [DONE]. Send them with the headers in HEADERS. Stopping the iteration (a client that went away) stops the run.