@anvia/server ​
@anvia/server turns asynchronous events into Fetch Response streams. Its client-protocol helper works with @anvia/client and @anvia/react; generic helpers also support application-defined JSONL or SSE events.
Install ​
pnpm add @anvia/core @anvia/client @anvia/serverReturn an agent stream ​
import { agentToClientStream, parseClientStreamRequest } from '@anvia/client'
import { createClientStreamResponse } from '@anvia/server'
import { supportAgent } from './support-agent'
export async function POST(request: Request) {
const body = parseClientStreamRequest(await request.json())
if (body.type !== 'messages') {
return new Response('Interaction responses are not enabled', { status: 400 })
}
const events = supportAgent.stream({ messages: body.messages })
return createClientStreamResponse({
events: agentToClientStream({
events,
...(body.metadata === undefined ? {} : { metadata: body.metadata }),
}),
format: 'jsonl',
})
}parseClientStreamRequest() validates the public request shape. agentToClientStream() maps runtime events into the stable client protocol, and createClientStreamResponse() frames and serializes them.
Key features ​
createClientStreamResponseandresumeClientStreamResponseserve the Anvia client protocol.createEventStreamResponseandresumeEventStreamResponsetransport generic application events.createJsonlStreamandcreateSseStreamexpose lower-level encoders.createResumableStreampersists generic event envelopes for replay.createMemoryResumableStreamStoreis useful for tests and single-process development.
The package does not authenticate routes, authorize resume cursors, construct agents, or decide which runtime data is safe for a browser. Enforce those boundaries before starting a run.
Runtime compatibility ​
The package is ESM and uses standard Response, ReadableStream, TextEncoder, and Headers APIs. Hosting platforms differ in buffering and execution limits, so verify streaming in the actual deployment environment.
Continue with Server transport, Resumable streams, or the API reference.