river-ts-streaming

Unify typed SSE and WebSocket streaming with river.ts.

106|3|Updated Jun 6, 2024
One-click install
npx skills add https://github.com/Bewinxed/river.ts --skill river-ts-streaming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: river-ts-streaming
Source: https://github.com/Bewinxed/river.ts/tree/main
Command: npx skills add https://github.com/Bewinxed/river.ts --skill river-ts-streaming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill unifies Server-Sent Events (SSE) and WebSocket communications under a single, type-safe model using river.ts, reducing boilerplate and type drift when building real-time apps.

Core Features & Use Cases

  • Type-safe event schemas via RiverEvents builder
  • SSE streaming on server with RiverEmitter
  • Client-side consumption with RiverClient
  • WebSocket adapter with RiverSocketAdapter and RPC-style requests
  • Streaming with chunked data
  • Cross-protocol interoperability

Quick Start

Define your events with RiverEvents and build the event map. Initialize RiverEmitter on the server to stream events to connected clients. On the client, use RiverClient to subscribe to events and optionally use RiverSocketAdapter for WebSocket RPC.

Frequently Asked Questions about river-ts-streaming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Server-Sent Events and WebSocket streams type-safe in TypeScript?

Type-safe SSE and WebSocket streams are achieved by defining event schemas with the RiverEvents builder, then unifying client and server concerns using river.ts to prevent type drift in real-time apps. This reduces boilerplate across both protocols.

What's the best way to unify SSE and WebSocket real-time events under a single model?

Unifying SSE and WebSocket events under a single model requires using river.ts, which provides RiverEmitter for server streaming and RiverClient for client consumption, alongside RiverSocketAdapter for cross-protocol interoperability and WebSocket RPC.

How do I stream chunked data over SSE or WebSocket while maintaining event types?

Streaming chunked data over SSE or WebSocket while maintaining event types is handled by defining your events with RiverEvents, initializing RiverEmitter on the server, and consuming the typed, chunked stream via RiverClient.

Can I use WebSocket RPC and SSE interchangeably with TypeScript?

Yes, you can use WebSocket RPC and SSE interchangeably by applying the RiverSocketAdapter for WebSocket RPC-style requests and RiverEmitter for SSE streaming, ensuring cross-protocol interoperability with a single type-safe event map.

Do I need a specific TypeScript project setup to use river.ts for real-time streaming?

Yes, implementing type-safe real-time streaming requires a TypeScript project setup and the river.ts dependency. You must first define events with RiverEvents before building and deploying the server and client streaming logic.