Skip to content

Proposal: Generalize River’s core for broader SSE use cases #4

@justsomelegs

Description

@justsomelegs

I know the v2 rewrite of River is still in the very early stages, and this maybe this is more of a v3 idea.

While the project is currently focused on AI streams, I think it would be really interesting if the core primitives were designed for any kind of SSE stream, with the AI-specific features built on top of those.

That approach could open the library up to a wider range of use cases:

  • Live Data Feeds
  • Collaborative Apps
  • Durable Event Logs
  • Notification Streams
  • Sync-engines

and of course, AI and LLM Streams

I imagine River could become to SSE/streams what better-auth is to authentication, providing a strong foundation that can be extended with plugins for AI and other specialized features.

Just thinking out loud here. I’ll be using the library whichever direction it goes as, but thought this might be worth considering.

EDIT:

very crude and inspired idea but I was thinking something like this for the end developer:

export const server = riverServer({
	plugins: [AI(), auth()] // wouldn't matter the order just provides the functions to the server (server.ai / sever.auth)
	streams: {
		notifications: {
			schema: z.object({ userId: z.string(), text: z.string() }),
				runner: async (args) => { }
		},
		livePrices: {
			schema: z.object({ symbol: z.string(), price: z.number(), ts: z.number() }),
			runner: async (args) => { }
		},
		ai:  {
			schema: z.object({ role: z.enum(['assistant', 'user']), content: z.string() }),
			runner: async (args) => { }
		}
	},
	//examples below if you wanted to go past streams
	queries: {},
	mutations: {},
	sockets: {},
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions