1# 🔋 lithium.js - sync for argon23lithium.js is a miniature Negentropy (NIP-77) client, the replication layer for argon.js. It reconciles argon's local events for a filter with each relay's, then fetches only what is missing locally and publishes only what the relay lacks. Apps work fully offline and catch up both ways when a connection returns.45```html6<script src="argon.js"></script>7<script src="lithium.js"></script>89<main nhy-relay="wss://relay.example" nli-sync='{"authors":["<your pubkey>"]}'></main>10```1112On load and whenever the browser comes back online, the author's events are reconciled with every relay in both directions.1314## Attributes1516| attribute | default | description |17|---|---|---|18| `nli-sync` | | JSON filter to reconcile. Runs on page load and on `online` |19| `nli-mode` | both ways | `pull` only fetches, `push` only publishes |2021Relays come from the closest `nhy-relay`, else `nhyCfg.relays`. Leave `limit` out of the filter: relays ignore it for sync.2223## Events2425| event | cancel to | detail |26|---|---|---|27| `nli:sync` | skip this run | `cfg` (`filter`, `relays`, `mode`), editable |28| `nli:synced` | | `cfg`, `result` per relay |29| `nli:error` | | `cfg`, `relay`, `error` (for example the relay's `NEG-ERR` reason) |3031`result` is `{relay, have, need, pulled, pushed}`: `have` and `need` are the ids only this side or only the relay held.3233## Scripting3435```js36let result = await lithium.sync({authors:[pk]}, "wss://relay.example", "pull")37lithium.run(element) // run an nli-sync element now38```3940## Behavior4142- Speaks Negentropy protocol v1 as the initiator. Relays that cap frames (tinyrelay and bindws use 60KB) simply take more rounds.43- A relay ending the exchange with `NEG-CLOSE` (tinyrelay does when the sets already match) counts as done.44- Fetched events are checked with helium.js when it is loaded, and stored through argon.45- Publishing is one event at a time. A `rate-limited: ... retry in Ns` reply waits that long and retries, so a large backlog trickles in at the relay's pace.46- A connection idle for 60 seconds is closed. There is no fallback for relays without NIP-77: the run reports `nli:error`.4748Requires argon.js, and hydrogen.js for the `nli-sync` attribute. Tested against bindws (bind.ws) and tinyrelay.