durable-streams-yjs
What it does
It shows the AI agent how to keep a shared document in sync between users with Yjs and durable streams over standard HTTP. It is for developers building collaborative editing features.
When to use it
- ✓When you are adding real-time collaborative editing to an app that uses Yjs.
- ✓When you need to show who else is present or where their cursor is.
- ✓When you need to choose between server-sent events and long-polling for syncing.
Skill link
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/sync/durable-streams-yjs/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Set up real-time syncing for my shared notes document using Yjs and an HTTP stream.”
5 new skills a week. 1 minute to read.
How it works
The agent creates a provider that links a Yjs document to a document stream and an awareness stream. It then handles connecting, disconnecting, and status events so the document stays in sync.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Durable Streams — Yjs Sync
Sync Yjs documents over HTTP durable streams. No WebSocket infrastructure needed — uses standard HTTP with SSE or long-poll transport. Built-in persistence through stream history, presence support via awareness streams.
Setup
import { DurableStreamsProvider } from "@durable-streams/y-durable-streams"
import * as Y from "yjs"
import { Awareness } from "y-protocols/awareness"
const doc = new Y.Doc()
const awareness = new Awareness(doc)
const provider = new DurableStreamsProvider({
doc,
documentStream: {
url: "https://your-server.com/v1/stream/doc-updates",
transport: "sse",
},
awarenessStream: {
url: "https://your-server.com/v1/stream/doc-awareness",
protocol: awareness,
transport: "sse",
},
})
provider.on("synced", (synced) => {
console.log("Synced:", synced)
})
provider.on("status", (status) => {
console.log("Status:", status) // "disconnected" | "connecting" | "connected"
})
Core Patterns
Document-only sync (no presence)
import { DurableStreamsProvider } from "@durable-streams/y-durable-streams"
import * as Y from "yjs"
const doc = new Y.Doc()
const provider = new DurableStreamsProvider({
doc,
documentStream: {
url: "https://your-server.com/v1/stream/my-doc",
transport: "sse",
},
})
Manual connect/disconnect
const provider = new DurableStreamsProvider({
doc,
documentStream: { url, transport: "sse" },
connect: false, // Don't auto-connect
})
// Connect when ready
provider.connect()
// Temporarily disconnect (can reconnect later)
provider.disconnect()
// Permanently destroy (cleanup all listeners and timers)
provider.destroy()
Dynamic auth headers
const provider = new DurableStreamsProvider({
doc,
documentStream: {
url: "https://your-server.com/v1/stream/my-doc",
transport: "sse",
headers: {
Authorization: () => `Bearer ${getAccessToken()}`,
},
},
})
Common Mistakes
HIGH Forgetting peer dependencies for Yjs
Wrong:
npm install @durable-streams/y-durable-streams
Correct:
npm install @durable-streams/y-durable-streams yjs y-protocols lib0
yjs, y-protocols, and lib0 are peer dependencies. Missing them causes import errors at runtime.
Source: packages/y-durable-streams/package.json peerDependencies
HIGH Using application/json content type for Yjs streams
Wrong:
documentStream: {
url: "https://server.com/v1/stream/doc-1",
transport: "sse",
contentType: "application/json",
}
Correct:
documentStream: {
url: "https://server.com/v1/stream/doc-1",
transport: "sse",
// Content type defaults to application/octet-stream (binary)
}
Yjs documents use binary encoding (lib0 VarUint8Array). The stream must use application/octet-stream, not application/json. The provider handles this automatically — don't override the content type.
Source: packages/y-durable-streams/src/y-durable-streams.ts BINARY_CONTENT_TYPE
HIGH Not calling destroy() on cleanup
Wrong:
useEffect(() => {
const provider = new DurableStreamsProvider({ doc, documentStream: config })
return () => provider.disconnect() // Only disconnects, doesn't clean up!
}, [])
Correct:
useEffect(() => {
const provider = new DurableStreamsProvider({ doc, documentStream: config })
return () => provider.destroy() // Full cleanup
}, [])
disconnect() only closes the connection — destroy() also removes doc/awareness listeners and clears the 15-second awareness heartbeat interval.
Source: packages/y-durable-streams/README.md API methods
See also
- reading-streams — Yjs provider uses SSE/long-poll transport from the client library
Version
Targets @durable-streams/y-durable-streams v0.2.1.
FAQ
Does it need WebSockets?
No. It is designed to work over standard HTTP using server-sent events or long-polling.
What packages does it need?
The skill lists yjs, y-protocols, and lib0 as peer dependencies that must be installed.
Does the document keep its history?
Yes. Built-in persistence comes from the stream history.
Details
Original description by the author
Yjs CRDT sync over durable streams with @durable-streams/y-durable-streams. DurableStreamsProvider setup, document stream and awareness stream config, transport modes (SSE vs long-poll), provider lifecycle (connect, disconnect, destroy), synced/status/error events, lib0 VarUint8Array framing, awareness heartbeat. Requires yjs, y-protocols, lib0 peer dependencies. Load when integrating Yjs collaborative editing with durable streams.
repo: humanlayer/humanlayer
Popularity
- GitHub stars
- 13k
- Ranking position
- #11392
- License
- Apache-2.0
- Updated
- 10/31/2026
Comments
- …
More skills from this repository
asd-ste100
13kTeaches your agent to rewrite confusing English into short, one-meaning sentences that are easy for people and other software to read.
better-github-skill
13kHelps your agent check a pull request's status, read its review comments, and find why a CI build failed, using ready-made GitHub scripts.
calldiff
13kHelps your agent compare the chains of function calls in a codebase between two git versions, so a code review can see what behavior changed.
chrome-devtools-cli
13kLets your agent control Chrome from the terminal to open pages, click, fill in forms, and take page snapshots for browser automation and testing.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.