-
Notifications
You must be signed in to change notification settings - Fork 7
Add compatibility with Jupyter Collaboration v4 #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3f0f101
standardize labextension plugin IDs
dlqqq e9fb09b
disable jupyter_collaboration extensions thru metadata
dlqqq a959471
fix missing plugin error, now works w/ JCollab4
dlqqq 89ca2bf
add new JCollab 4 + JSD dev env, remove old ones
dlqqq 9014a58
add jupyter_events integration
dlqqq b9f778b
fix wrong room_id doc comment
dlqqq f89bd82
add JCollab Python API
dlqqq 17f9fca
use same event schema IDs as jupyter_collaboration
dlqqq 6aed3da
fix JAI compatibility issue
dlqqq 1ce7e7d
remove custom type only supported in Py >3.12
dlqqq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name: serverdocs-jcollab | ||
| channels: | ||
| - conda-forge | ||
| dependencies: | ||
| - python | ||
| - nodejs=22 | ||
| - uv | ||
| - jupyterlab | ||
| - pip: | ||
| - jupyterlab>=4.4.0,<5.0.0 | ||
| - jupyter_collaboration~=4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| { | ||
| "ServerApp": { | ||
| "jpserver_extensions": { | ||
| "jupyter_server_documents": true | ||
| "jupyter_server_documents": true, | ||
| "jupyter_server_ydoc": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from pathlib import Path | ||
|
|
||
| EVENTS_DIR = Path(__file__).parent | ||
|
|
||
| # Use the same schema ID as `jupyter_collaboration` for compatibility | ||
| JSD_ROOM_EVENT_URI = "https://schema.jupyter.org/jupyter_collaboration/session/v1" | ||
| JSD_AWARENESS_EVENT_URI = "https://schema.jupyter.org/jupyter_collaboration/awareness/v1" | ||
|
|
||
| JSD_ROOM_EVENT_SCHEMA = EVENTS_DIR / "room.yaml" | ||
| JSD_AWARENESS_EVENT_SCHEMA = EVENTS_DIR / "awareness.yaml" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| "$id": https://schema.jupyter.org/jupyter_collaboration/awareness/v1 | ||
| "$schema": "http://json-schema.org/draft-07/schema" | ||
| version: "1" | ||
| title: Collaborative awareness events | ||
| personal-data: true | ||
| description: | | ||
| Awareness events emitted from server-side during a collaborative session. | ||
| type: object | ||
| required: | ||
| - roomid | ||
| - username | ||
| - action | ||
| properties: | ||
| roomid: | ||
| type: string | ||
| description: | | ||
| Room ID. Usually composed by the file type, format and ID. | ||
| username: | ||
| type: string | ||
| description: | | ||
| The name of the user who joined or left room. | ||
| action: | ||
| enum: | ||
| - join | ||
| - leave | ||
| description: | | ||
| Possible values: | ||
| 1. join | ||
| 2. leave | ||
| msg: | ||
| type: string | ||
| description: | | ||
| Optional event message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| "$id": https://schema.jupyter.org/jupyter_collaboration/session/v1 | ||
| "$schema": "http://json-schema.org/draft-07/schema" | ||
| version: "1" | ||
| title: Room events | ||
| personal-data: true | ||
| description: | | ||
| An event emitted by a collaboration room. | ||
| type: object | ||
| required: | ||
| - level | ||
| - room | ||
| - path | ||
| properties: | ||
| level: | ||
| enum: | ||
| - INFO | ||
| - DEBUG | ||
| - WARNING | ||
| - ERROR | ||
| - CRITICAL | ||
| description: | | ||
| Message type. | ||
| room: | ||
| type: string | ||
| description: | | ||
| Room ID. This is a composite ID that takes the format `{file_format}:{file_type}:{file_id}`. | ||
| path: | ||
| type: string | ||
| description: | | ||
| Path of the file. | ||
| store: | ||
| type: string | ||
| description: | | ||
| The store used to track the document history. | ||
| action: | ||
| enum: | ||
| - initialize | ||
| - load | ||
| - save | ||
| - overwrite | ||
| - clean | ||
| description: | | ||
| Action performed in a room during a collaborative session. | ||
| Possible values: | ||
| 1. initialize | ||
| Initialize a room by loading the content from the contents manager or a store. | ||
| 2. load | ||
| Load the content from the contents manager. | ||
| 3. save | ||
| Save the content with the contents manager. | ||
| 4. overwrite | ||
| Overwrite the content in a room with content from the contents manager. | ||
| This can happen when multiple rooms access the same file or when a user | ||
| modifies the file outside Jupyter Server (e.g. using a different app). | ||
| 5. clean | ||
| Clean the room once is empty (aka there is no more users connected to it). | ||
| msg: | ||
| type: string | ||
| description: | | ||
| Event message. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .jcollab_api import JCollabAPI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from __future__ import annotations | ||
| from jupyter_ydoc.ybasedoc import YBaseDoc | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Callable, Literal | ||
| from jupyter_server_fileid.manager import BaseFileIdManager | ||
| from ..rooms import YRoomManager | ||
|
|
||
|
|
||
| class JCollabAPI: | ||
| """ | ||
| Provides the Python API provided by `jupyter_collaboration~=4.0` under | ||
| `self.settings["jupyter_server_ydoc"]`. | ||
| """ | ||
| fileid_manager: BaseFileIdManager | ||
| yroom_manager: YRoomManager | ||
|
|
||
| def __init__(self, get_fileid_manager: Callable[[], BaseFileIdManager], yroom_manager: YRoomManager): | ||
| self._get_fileid_manager = get_fileid_manager | ||
| self.yroom_manager = yroom_manager | ||
|
|
||
| @property | ||
| def fileid_manager(self) -> BaseFileIdManager: | ||
| return self._get_fileid_manager() | ||
|
|
||
| async def get_document( | ||
| self, | ||
| *, | ||
| path: str | None = None, | ||
| content_type: str | None = None, | ||
| file_format: Literal["json", "text"] | None = None, | ||
| room_id: str | None = None, | ||
| copy: bool = True, | ||
| ) -> YBaseDoc: | ||
| """ | ||
| Returns the Jupyter YDoc for a collaborative room. | ||
|
|
||
| You need to provide either a ``room_id`` or the ``path``, | ||
| the ``content_type`` and the ``file_format``. | ||
|
|
||
| The `copy` argument is ignored by `jupyter_server_documents`. | ||
| """ | ||
|
|
||
| # Raise exception if required arguments are not given | ||
| if room_id is None and (path is None or content_type is None or file_format is None): | ||
| raise ValueError( | ||
| "You need to provide either a ``room_id`` or the ``path``, the ``content_type`` and the ``file_format``." | ||
| ) | ||
|
|
||
| # Compute room_id if not given | ||
| if room_id is None: | ||
| file_id = self.fileid_manager.index(path) | ||
| room_id = f"{file_format}:{content_type}:{file_id}" | ||
|
|
||
| # Get or create room using `room_id` | ||
| room = self.yroom_manager.get_room(room_id) | ||
| if not room: | ||
| raise ValueError( | ||
| f"Could not get room using room ID '{room_id}'." | ||
| ) | ||
|
|
||
| # Return the Jupyter YDoc once ready | ||
| return await room.get_jupyter_ydoc() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.