-
Notifications
You must be signed in to change notification settings - Fork 3
Discover and execute JupyterLab commands #4
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
Zsailer
merged 3 commits into
jupyter-ai-contrib:main
from
jtpio:discover-execute-commands
Sep 16, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
22 changes: 22 additions & 0 deletions
22
jupyterlab_commands_toolkit/events/jupyterlab-command-result.yml
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,22 @@ | ||
| "$id": https://events.jupyter.org/jupyterlab_command_toolkit/lab_command_result/v1 | ||
| version: 1 | ||
| title: A JupyterLab Command Execution Result | ||
| personal-data: true | ||
| description: | | ||
| Result of a JupyterLab Command execution | ||
| type: object | ||
| required: | ||
| - requestId | ||
| - success | ||
| properties: | ||
| requestId: | ||
| type: string | ||
| description: The unique identifier for the command request | ||
| success: | ||
| type: boolean | ||
| description: Whether the command executed successfully | ||
| result: | ||
| description: The result data from the command execution | ||
| error: | ||
| type: string | ||
| description: Error message if the command failed |
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,50 +1,55 @@ | ||
| """JupyterLab Commands toolkit for Jupyter AI""" | ||
| from jupyter_ai.tools.models import Tool, Toolkit | ||
|
|
||
| from typing import Optional | ||
| from .tools import ( | ||
| open_document, | ||
| open_markdown_file_in_preview_mode, | ||
| clear_all_outputs_in_notebook, | ||
| show_diff_of_current_notebook, | ||
| INSERT_MODE | ||
| ) | ||
|
|
||
| # Create the toolkit | ||
| toolkit = Toolkit( | ||
| name="jupyterlab_commands_toolkit", | ||
| description="""A comprehensive toolkit for controlling JupyterLab interface and performing notebook operations through AI commands. | ||
| This toolkit provides programmatic access to JupyterLab's core functionality, enabling AI assistants to: | ||
| **Document Management:** | ||
| - Open files, notebooks, and documents with precise control over layout positioning | ||
| - Support for split-pane layouts (top, left, right, bottom) and tab management | ||
| - Open markdown files in rendered preview mode for better readability | ||
| **Notebook Operations:** | ||
| - Clear all cell outputs in the active notebook for cleanup and sharing | ||
| - Display git diffs for notebooks using nbdime visualization | ||
| - Maintain notebook structure while performing operations | ||
| **Layout Control:** | ||
| - Split current workspace into multiple panes | ||
| - Merge content with adjacent areas | ||
| - Create new tabs before or after current position | ||
| - Flexible positioning options for optimal workspace organization | ||
| **Key Features:** | ||
| - Event-driven architecture using JupyterLab's command system | ||
| - Seamless integration with Jupyter AI for natural language control | ||
| - Support for relative file paths from server root directory | ||
| - Comprehensive error handling and user feedback | ||
| - Compatible with JupyterLab 4.0+ and modern Jupyter environments | ||
| Use these tools to programmatically manage your JupyterLab workspace, organize documents, and perform common notebook operations through conversational AI interfaces.""" | ||
| ) | ||
|
|
||
| # Add tools to the toolkit | ||
| toolkit.add_tool(Tool(callable=open_document, read=True)) | ||
| toolkit.add_tool(Tool(callable=open_markdown_file_in_preview_mode, read=True)) | ||
| toolkit.add_tool(Tool(callable=clear_all_outputs_in_notebook, read=True)) | ||
| toolkit.add_tool(Tool(callable=show_diff_of_current_notebook, read=True)) | ||
|
|
||
| try: | ||
| from jupyter_ai.tools.models import Tool, Toolkit | ||
|
|
||
| from typing import Optional | ||
| from .tools import ( | ||
| open_document, | ||
| open_markdown_file_in_preview_mode, | ||
| clear_all_outputs_in_notebook, | ||
| show_diff_of_current_notebook, | ||
| INSERT_MODE, | ||
| ) | ||
|
|
||
| # Create the toolkit | ||
| toolkit = Toolkit( | ||
| name="jupyterlab_commands_toolkit", | ||
| description="""A comprehensive toolkit for controlling JupyterLab interface and performing notebook operations through AI commands. | ||
| This toolkit provides programmatic access to JupyterLab's core functionality, enabling AI assistants to: | ||
| **Document Management:** | ||
| - Open files, notebooks, and documents with precise control over layout positioning | ||
| - Support for split-pane layouts (top, left, right, bottom) and tab management | ||
| - Open markdown files in rendered preview mode for better readability | ||
| **Notebook Operations:** | ||
| - Clear all cell outputs in the active notebook for cleanup and sharing | ||
| - Display git diffs for notebooks using nbdime visualization | ||
| - Maintain notebook structure while performing operations | ||
| **Layout Control:** | ||
| - Split current workspace into multiple panes | ||
| - Merge content with adjacent areas | ||
| - Create new tabs before or after current position | ||
| - Flexible positioning options for optimal workspace organization | ||
| **Key Features:** | ||
| - Event-driven architecture using JupyterLab's command system | ||
| - Seamless integration with Jupyter AI for natural language control | ||
| - Support for relative file paths from server root directory | ||
| - Comprehensive error handling and user feedback | ||
| - Compatible with JupyterLab 4.0+ and modern Jupyter environments | ||
| Use these tools to programmatically manage your JupyterLab workspace, organize documents, and perform common notebook operations through conversational AI interfaces.""", | ||
| ) | ||
|
|
||
| # Add tools to the toolkit | ||
| toolkit.add_tool(Tool(callable=open_document, read=True)) | ||
| toolkit.add_tool(Tool(callable=open_markdown_file_in_preview_mode, read=True)) | ||
| toolkit.add_tool(Tool(callable=clear_all_outputs_in_notebook, read=True)) | ||
| toolkit.add_tool(Tool(callable=show_diff_of_current_notebook, read=True)) | ||
| except ImportError: | ||
| # If jupyter-ai is not available, the AI toolkit won't be available | ||
| toolkit = None | ||
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.