spillway

Gleam protocol logic for collaborative systems

Control the Fluid protocol before it reaches the floodplain.

Spillway extracts the typed core of Fluid Framework sessions: sequencing, message validation, nacks, signals, summaries, and scoped JWT checks for BEAM systems that need predictable collaborative flow.

current_sn steady
  1. connectvalidate scope
  2. submit opassign sequence
  3. broadcasttrim history

A narrow layer with firm gates.

Session admission

Validate tenant, document, expiration, and scope before a client enters the collaborative channel.

Ordered operations

Track connected clients, client sequence numbers, reference sequence numbers, and minimum sequence progression.

Protocol responses

Build nacks, summaries, acks, and signals with typed constructors instead of ad-hoc JSON shapes.

The public API names the pressure points.

Spillway keeps wire-format concerns explicit: clients join, ops receive sequence numbers, claims are checked, and invalid messages become protocol nacks.

import spillway

let state = spillway.new_sequence_state()
let joined = spillway.client_join(state, "client-7", 0)

case spillway.assign_sequence_number(joined, "client-7", 1, 0) {
  Ok(result) -> result
  Error(reason) -> reason
}

Add the gate, not the whole dam.

Spillway is intentionally small: Gleam stdlib plus JSON, ready to sit under a server layer that owns transport and persistence.

gleam add spillway