@tinyweb_dev/agent-framework-protocol
v0.4.0
Published
Wire-format types and stream codecs. Install this in your frontend bundle if you want type-safe AgentEvents on the client without pulling the whole agent runtime.
Downloads
387
Readme
@tinyweb-agent-framework/protocol
Wire-format types and stream codecs. Install this in your frontend bundle if you want type-safe AgentEvents on the client without pulling the whole agent runtime.
Types
import { type AgentEvent, isAgentEvent } from "@tinyweb-agent-framework/protocol"AgentEvent is a tagged union: text-delta | text-end | reasoning-delta | tool-call | tool-result | tool-error | step-finish | finish | error.
SSE codec
import { encodeSSE, decodeSSE, toReadableStream, fromReadableStream } from "@tinyweb-agent-framework/protocol"
// Server
const stream = toReadableStream(asyncIterableOfEvents)
// Client
for await (const ev of fromReadableStream(response.body!)) {
if (ev.type === "text-delta") output += ev.text
}Vercel AI SDK bridge
import { toAISDKDataStream, toAISDKReadableStream, AI_SDK_HEADERS } from "@tinyweb-agent-framework/protocol"
return new Response(toAISDKReadableStream(agent.run({ prompt })), { headers: AI_SDK_HEADERS })This lets you use Vercel AI SDK's useChat() hook on the client unchanged.
License
MIT
