Build a component that handles real-time updates from a WebSocket connection.
Implement reconcile_updates(events) for sequenced snapshot and update messages. Buffer updates that arrive before a missing sequence, apply them once the gap closes, ignore stale or duplicate updates, and let newer snapshots replace local state. Return the final state and the sequence numbers of applied updates.
Input is a list of event dictionaries. Each snapshot has type, seq, and state; each update has type, seq, key, and value. The output is a dictionary with state and applied fields.
def reconcile_updates(events):