Add real-time collaboration with page history

Pages are now shared Yjs documents. docwell-server relays the y-websocket
protocol at /collab (token sent as the first message), flushes updates to
page_yupdates every second, and compacts them into page_ydoc with yrs
compiled to WebAssembly under wazero (ADR-3) after 30 s idle or when the
last editor leaves. Compaction refreshes content_json/content_text and
records page_versions; versions can be listed, previewed and restored.

The editor connects through a small y-protocols provider with carets and
presence. Pages saved before this change are seeded from content_json.
The yrs module lives in Server/ycrdt-wasm and is built by go generate,
CI and the Dockerfiles rather than committed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tajniak81andClaude Opus 5.5 committed 2026-10-31 11:52:55 +01:00
1 parent abf55a426b
commit 5e1dcf4291
45 files changed
+3480 -213

No files matched your search

+6
View File
@@ -26,6 +26,7 @@ export type PageRef = Schemas["PageRef"];
export type Page = Schemas["Page"];
export type TrashedPage = Schemas["TrashedPage"];
export type PageContent = Schemas["PageContent"];
export type PageVersion = Schemas["PageVersion"];
export type CreateSpaceRequest = { name: string; description?: string; icon?: string; visibility?: SpaceVisibility };
export type UpdateSpaceRequest = Partial<Pick<Space, "name" | "description" | "icon" | "visibility" | "defaultRole">>;
@@ -169,6 +170,11 @@ export function createClient(opts: ClientOptions) {
/** Replaces the page's document; content is Tiptap JSON with type "doc". */
saveContent: (id: string, content: Record<string, unknown>) =>
request<PageContent>("PUT", `/api/v1/pages/${encodeURIComponent(id)}/content`, { content }),
versions: (id: string) => request<PageVersion[]>("GET", `/api/v1/pages/${encodeURIComponent(id)}/versions`),
version: (id: string, versionId: string) =>
request<PageContent>("GET", `/api/v1/pages/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}`),
restoreVersion: (id: string, versionId: string) =>
post<PageContent>(`/api/v1/pages/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/restore`),
move: (id: string, parent: string, index: number) =>
post<Page>(`/api/v1/pages/${encodeURIComponent(id)}/move`, { parent, index }),
trash: (id: string) => request<void>("DELETE", `/api/v1/pages/${encodeURIComponent(id)}`),
+141 -2
View File
@@ -549,9 +549,9 @@ export interface paths {
};
cookie?: never;
};
/** The page's document as Tiptap JSON (null for a page that was never edited) */
/** The page's document as Tiptap JSON (null for a page that was never edited). Editors sync the live document over the WebSocket at /collab instead (y-websocket protocol; send the session token as the first, text, message). */
get: operations["getPageContent"];
/** Replace the page's document (editor). Last write wins until the collab relay lands; the server derives the plain text and word count. */
/** Replace the page's document (editor). The change is applied as an edit to the live document, so open editors see it at once. */
put: operations["savePageContent"];
post?: never;
delete?: never;
@@ -560,6 +560,65 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v1/pages/{id}/versions": {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
/** The page's history, newest first. A version is recorded at most every 10 minutes while people edit, and when the last editor leaves. */
get: operations["listPageVersions"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/pages/{id}/versions/{versionId}": {
parameters: {
query?: never;
header?: never;
path: {
id: string;
versionId: string;
};
cookie?: never;
};
/** One version's document */
get: operations["getPageVersion"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/pages/{id}/versions/{versionId}/restore": {
parameters: {
query?: never;
header?: never;
path: {
id: string;
versionId: string;
};
cookie?: never;
};
get?: never;
put?: never;
/** Make an old version the page's document again (editor). It is applied as a new edit, so open editors update live and the current text stays in the history. */
post: operations["restorePageVersion"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/pages/{id}/move": {
parameters: {
query?: never;
@@ -755,6 +814,13 @@ export interface components {
} | null;
updated: string;
};
PageVersion: {
id: string;
/** @description Name (or email) of the last person who edited before it was taken */
author: string;
label: string;
created: string;
};
TrashedPage: {
id: string;
title: string;
@@ -1948,6 +2014,79 @@ export interface operations {
404: components["responses"]["Error"];
};
};
listPageVersions: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["PageVersion"][];
};
};
404: components["responses"]["Error"];
};
};
getPageVersion: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
versionId: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["PageContent"];
};
};
404: components["responses"]["Error"];
};
};
restorePageVersion: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
versionId: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["PageContent"];
};
};
400: components["responses"]["Error"];
403: components["responses"]["Error"];
404: components["responses"]["Error"];
};
};
movePage: {
parameters: {
query?: never;