|
| 1 | +--- |
| 2 | +title: SDK + Collaboration Sessions |
| 3 | +sidebarTitle: SDK + Collaboration |
| 4 | +description: How SDK sessions relate to Yjs collaboration sessions in SuperDoc |
| 5 | +keywords: "sdk collaboration, yjs session, superdoc session, liveblocks sdk, hocuspocus sdk" |
| 6 | +--- |
| 7 | + |
| 8 | +Use this guide when you are combining: |
| 9 | + |
| 10 | +- The SuperDoc SDK (`@superdoc-dev/sdk` or `superdoc-sdk`) for headless/document automation |
| 11 | +- SuperDoc real-time collaboration (Yjs providers like Liveblocks, Hocuspocus, or SuperDoc Yjs) |
| 12 | + |
| 13 | +## Two session types |
| 14 | + |
| 15 | +These are different concepts: |
| 16 | + |
| 17 | +- **Collaboration session**: a shared Yjs room/document (`ydoc` + provider) used by browser editors. |
| 18 | +- **SDK session**: a SuperDoc Document Engine editing session created by `doc.open`. |
| 19 | + |
| 20 | +The SDK does not directly attach to a provider object. It operates through Document Engine sessions. |
| 21 | + |
| 22 | +## SuperDoc JS collaboration contract |
| 23 | + |
| 24 | +In the browser, SuperDoc uses a provider-agnostic contract: |
| 25 | + |
| 26 | +```javascript |
| 27 | +import * as Y from "yjs"; |
| 28 | +import { LiveblocksYjsProvider } from "@liveblocks/yjs"; |
| 29 | +import { SuperDoc } from "superdoc"; |
| 30 | + |
| 31 | +const ydoc = new Y.Doc(); |
| 32 | +const provider = new LiveblocksYjsProvider(room, ydoc); |
| 33 | + |
| 34 | +new SuperDoc({ |
| 35 | + selector: "#editor", |
| 36 | + modules: { |
| 37 | + collaboration: { ydoc, provider }, |
| 38 | + }, |
| 39 | +}); |
| 40 | +``` |
| 41 | + |
| 42 | +See [Collaboration Configuration](/modules/collaboration/configuration) for details. |
| 43 | + |
| 44 | +## Using SDK sessions with collaboration-enabled documents |
| 45 | + |
| 46 | +The SDK can work against a document that is also edited collaboratively, but interaction is through SDK/CLI session APIs. |
| 47 | + |
| 48 | +```ts |
| 49 | +import { createSuperDocClient } from "@superdoc-dev/sdk"; |
| 50 | + |
| 51 | +const client = createSuperDocClient(); |
| 52 | +await client.connect(); |
| 53 | + |
| 54 | +await client.doc.open({ doc: "./contract.docx" }); |
| 55 | + |
| 56 | +const sessions = await client.doc.session.list(); |
| 57 | +console.log(sessions); |
| 58 | +``` |
| 59 | + |
| 60 | +You can target a specific active SDK session: |
| 61 | + |
| 62 | +```ts |
| 63 | +await client.doc.session.setDefault({ id: "session-id" }); |
| 64 | +await client.doc.info(); |
| 65 | +``` |
| 66 | + |
| 67 | +## Provider choice is unchanged |
| 68 | + |
| 69 | +Provider setup still happens in your app using SuperDoc JS: |
| 70 | + |
| 71 | +- [Liveblocks](/guides/collaboration/liveblocks) |
| 72 | +- [Hocuspocus](/guides/collaboration/hocuspocus) |
| 73 | +- [SuperDoc Yjs](/guides/collaboration/superdoc-yjs) |
| 74 | + |
| 75 | +The SDK integration pattern does not change by provider. |
| 76 | + |
| 77 | +## Practical guidance |
| 78 | + |
| 79 | +- Use collaboration providers for multi-user real-time editing UX. |
| 80 | +- Use SDK sessions for backend automation, workflows, and deterministic operations. |
| 81 | +- Keep the distinction explicit in your architecture: provider state vs SDK/CLI session state. |
0 commit comments