
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@elementaio/koine
Advanced tools
Zero-dependency TypeScript client for Koine embedded chat: one WebSocket, typed events, idempotent sends, automatic reconnect, exact cursor catch-up.
Zero-dependency TypeScript client for Koine embedded chat.
One WebSocket per device. Your backend mints a short-TTL JWT; you hand it to the
client and it speaks the Koine wire protocol for you — idempotent sends with ack
tracking, typed events, automatic reconnect with backoff, and exact
cursor-based catch-up (it remembers the highest seq it has seen per
conversation and re-syncs the gap on reconnect, once).
Runs in the browser and in Node 22+ — both expose a global WebSocket.
npm install @elementaio/koine
import { KoineClient } from "@elementaio/koine";
const koine = new KoineClient({
url: "wss://chat.example.com/ws",
token: jwtFromYourBackend, // HS256, signed with the secret you share with Koine
device: "web-1", // stable per device → resumes cursors on reconnect
});
koine.on("message", (m) => render(m.conv, m.from, m.payload, m.seq));
koine.on("receipt", (r) => markRead(r.conv, r.from, r.seq));
koine.on("typing", (t) => showTyping(t.conv, t.from));
koine.on("error", (e) => console.warn("koine:", e.reason));
koine.connect();
// Idempotent send — the returned promise resolves with the durable seq.
const ack = await koine.send("general", "hello");
console.log("stored as seq", ack.seq);
// Live signals and read state:
koine.typing("general");
koine.read("general", ack.seq);
koine.presence("alice");
By default the client reconnects on an unexpected drop (exponential backoff with jitter) and, once reconnected, re-syncs every conversation it has seen from its cursor — so you get exactly the messages you missed, once. After a full page reload, seed the cursors from your own persisted state first:
koine.setCursor("general", lastSeqYouRendered);
koine.connect();
| Method | Purpose |
|---|---|
connect() / close() | open the socket (reconnects are automatic) / close for good |
send(conv, payload, { id?, kind? }) | send; resolves with the ack (kind: "ephemeral" = live-only) |
read(conv, seq) | advance your read watermark |
typing(conv) | ephemeral typing signal |
readState(conv, seq) | ask group read state (seen-by count) |
presence(user) | ask if a user is online / last-seen |
sync(conv, after?) | explicit catch-up (defaults to the tracked cursor) |
cursor(conv) / setCursor(conv, seq) | read / seed catch-up state |
on(event, handler) / off(...) | subscribe / unsubscribe |
connected | is the socket open right now |
Events: open, close, reconnecting, message, ack, receipt,
sync_page, read_state, presence, system, typing, error — all typed.
| Option | Default | Meaning |
|---|---|---|
url / token | (required) | gateway URL and the client JWT |
device | random | stable device id; resumes this device's cursors |
WebSocket | globalThis.WebSocket | inject an implementation if none is global |
autoReconnect | true | reconnect on unexpected close |
autoResync | true | re-sync tracked conversations on reconnect |
reconnectBackoffMs | exp + jitter | (attempt) => ms schedule |
ackTimeoutMs | 10000 | how long send() waits for its ack before rejecting |
The full wire protocol is documented in docs/PROTOCOL.md.
npm install
npm test # builds, then runs the node:test suite against a mock socket
MIT © Emad Jumaah
FAQs
Zero-dependency TypeScript client for Koine embedded chat: one WebSocket, typed events, idempotent sends, automatic reconnect, exact cursor catch-up.
The npm package @elementaio/koine receives a total of 4 weekly downloads. As such, @elementaio/koine popularity was classified as not popular.
We found that @elementaio/koine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.