durable-streams-yjs
Skill này làm gì
Skill chỉ cho agent AI cách giữ tài liệu dùng chung đồng bộ giữa người dùng bằng Yjs và durable streams qua HTTP chuẩn. Skill dành cho lập trình viên xây tính năng soạn thảo cộng tác.
Khi nào nên dùng
- ✓Khi bạn đang thêm soạn thảo cộng tác theo thời gian thực vào một ứng dụng dùng Yjs.
- ✓Khi bạn cần hiển thị ai đang có mặt hoặc con trỏ của họ đang ở đâu.
- ✓Khi bạn cần chọn giữa server-sent events và long-polling để đồng bộ.
Liên kết skill
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/sync/durable-streams-yjs/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thiết lập đồng bộ thời gian thực cho tài liệu ghi chú dùng chung của tôi bằng Yjs và một HTTP stream.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tạo một provider liên kết tài liệu Yjs với stream tài liệu và stream awareness. Sau đó agent xử lý kết nối, ngắt kết nối và các sự kiện trạng thái để tài liệu luôn đồng bộ.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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.
Câu hỏi thường gặp
Nó có cần WebSocket không?
Không. Nó được thiết kế để chạy qua HTTP chuẩn bằng server-sent events hoặc long-polling.
Nó cần những gói nào?
Skill liệt kê yjs, y-protocols và lib0 là các peer dependency cần được cài.
Tài liệu có giữ lịch sử không?
Có. Lưu trữ tích hợp đến từ lịch sử của stream.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 13k
- Vị trí xếp hạng
- #11392
- Giấy phép
- Apache-2.0
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
asd-ste100
13kDạy agent của bạn viết lại tiếng Anh khó hiểu thành câu ngắn, mỗi câu một nghĩa, dễ đọc đối với con người và phần mềm khác.
better-github-skill
13kGiúp agent của bạn kiểm tra trạng thái pull request, đọc bình luận review và tìm lý do bản build CI thất bại, bằng các script GitHub có sẵn.
calldiff
13kGiúp agent của bạn so sánh chuỗi lời gọi hàm trong một codebase giữa hai phiên bản git, để review code thấy hành vi nào đã thay đổi.
chrome-devtools-cli
13kCho phép agent của bạn điều khiển Chrome từ terminal để mở trang, nhấp, điền biểu mẫu và chụp snapshot trang cho tự động hóa và kiểm thử trình duyệt.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.