Langsung ke konten
Skillpedia
Website & UI (frontend)7.6k Β· #13174

real-time-collab

Fungsinya

Skill ini menjelaskan cara membangun penyuntingan kolaboratif real-time di aplikasi agent-native, dengan memakai Yjs dan TipTap agar suntingan bergabung dengan rapi. Skill ini untuk pengembang yang menambahkan dokumen bersama atau memperbaiki masalah sinkronisasi.

Kapan dipakai

  • βœ“Saat Anda menambahkan penyuntingan kolaboratif langsung ke dokumen di aplikasi.
  • βœ“Ketika dua orang atau agent menyunting dokumen yang sama dan perubahan hilang.
  • βœ“Saat Anda perlu memperbaiki masalah sinkronisasi antara pengguna dan agent.

Link skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-collab/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-collab/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBisakah Anda membiarkan dua orang menyunting dokumen yang sama secara bersamaan, dan menampilkan suntingan AI kepada keduanya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Suntingan disimpan sebagai dokumen bersama yang menggabungkan perubahan secara otomatis. Pembaruan didorong ke pengguna, dengan cadangan berupa pemeriksaan berkala jika koneksi langsung terputus.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Real-Time Collaboration

Rule

Collaborative editing uses Yjs CRDT via TipTap. The agent and human users are equal participants β€” both edit the same Y.Doc and changes merge cleanly without conflicts. Always choose an explicit access mode on createCollabPlugin.

How It Works

  • Y.Doc stores the document as a Y.XmlFragment (ProseMirror node tree)
  • TipTap's Collaboration extension binds the editor to the Y.XmlFragment via ySyncPlugin
  • CollaborationCaret extension renders remote users' cursors with names and colors
  • SSE fast-path β€” /_agent-native/poll-events EventSource delivers collab events push-style; while SSE is healthy the collab poll interval relaxes to ~12 s
  • Polling fallback β€” /_agent-native/poll is polled every 2 s when SSE drops mid-session. On serverless, /events answers 204 up front (poll-live) and this client relaxes to ~12 s, because /poll is the only channel.
  • Collab poll boost β€” while the awareness set shows another visible human on the doc (agent and hidden tabs do not count), the connection holds acquireCollabPollBoost() and the shared transport polls every 2.5 s whenever no stream is connected: a no-op while SSE or the hosted gateway is live. A joiner is noticed on the existing user's next ~12 s collab poll (the joiner sees them at once), a leaver within one poll plus the 30 s awareness TTL. The boost lapses after 3 minutes with no input and no remote events. Lone tabs pay nothing extra. Events under the request source a connection posts with (any app-chosen tab id, not only getBrowserTabId()) are this tab's own and never count. A read-only viewer must join the doc too (Design's useViewerPresence; it never uses the ydoc), or it never sees an editor and stays on the idle cadence. A viewer on a different screen than the editor shares no doc with them; its own collab poll sees the design's resource-scoped events from other tabs and starts the boost (60 s) itself.
  • Update batching β€” local Yjs updates are debounced ~80 ms and coalesced with Y.mergeUpdates before sending; flushed immediately on visibilitychange / pagehide
  • SQL _collab_docs table persists Yjs state as base64 in Postgres. Tombstone compaction fires automatically when the stored blob exceeds 4Γ— the fresh encoded size.

Agent + Human Editing

  1. Human edits β†’ TipTap β†’ ySyncPlugin β†’ Y.XmlFragment β†’ POST /_agent-native/collab/:docId/update
  2. Agent edits β†’ action edits canonical SQL content + bumps updatedAt β†’ change-sync refetch β†’ the open editor reconciles the new content into the live Y.Doc (see below) β†’ poll update β†’ all clients

Both produce Yjs operations that merge cleanly. Agent edits appear without destroying cursor position, selection, or undo history.

The agent does not push edits into Yjs in-process and does not call any localhost probe β€” those approaches silently no-op on serverless (the action runs in a different process). The peer-editor model below replaced them.

Agent Edits As A Real-Time Peer Editor

SQL is the durable source of truth for document body content. The agent action edits the canonical content column and bumps updatedAt. No localhost calls, no in-process Yjs mutation.

The open editor reconciles authoritative external content into the live Y.Doc. The updatedAt bump flows through change-sync, which refetches the record. The lead client applies the new content via setContent, producing Yjs operations that merge with concurrent human edits. Every connected client receives the result through normal Yjs sync.

The updatedAt gate

// In the editor's reconcile effect
if (loaded.updatedAt > lastAppliedUpdatedAt.current) {
  applyAuthoritativeContent(loaded.content); // adopt
  lastAppliedUpdatedAt.current = loaded.updatedAt;
}
// else: lagging poll / stale snapshot β†’ ignore

Without the gate, a slightly-behind poll response re-applies old content and the edit "reverts on next poll". A fresh mount always adopts whatever content it loaded.

Lead-client election

Exactly ONE connected client applies the authoritative snapshot; the rest receive it through Yjs sync:

import { isReconcileLeadClient } from "@agent-native/core/client/collab";

if (
  loaded.updatedAt > lastAppliedUpdatedAt.current &&
  isReconcileLeadClient(awareness, ydoc.clientID)
) {
  applyAuthoritativeContent(loaded.content);
}

The agent's awareness entry (`AGENT

Pertanyaan umum

Bisakah agent dan orang menyunting bersama?

Bisa. Skill ini memperlakukan agent dan pengguna manusia sebagai peserta yang setara di dokumen yang sama.

Bagaimana kursor pengguna lain ditampilkan?

Ekstensi kursor menampilkan kursor pengguna jarak jauh beserta nama dan warnanya.

Apa yang terjadi jika koneksi langsung terputus?

Aplikasi kembali melakukan polling ke server setiap beberapa detik.

Detail

Deskripsi asli dari pembuat

Multi-user collaborative editing with Yjs CRDT, SSE fast-path transport, and granular server-side merge. Use when adding real-time collaborative editing to a template, debugging sync issues, or understanding how the agent and humans edit documents simultaneously.

repo: BuilderIO/agent-native

Popularitas

Bintang GitHub
7.6k
Peringkat
#13174
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa