Skip to content

Commit 304d9f8

Browse files
authored
Open the AI settings in a side panel in Notebook application (#1309)
1 parent a82eecc commit 304d9f8

File tree

3 files changed

+214
-9
lines changed

3 files changed

+214
-9
lines changed

packages/jupyter-ai/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"dependencies": {
6262
"@emotion/react": "^11.10.5",
6363
"@emotion/styled": "^11.10.5",
64+
"@jupyter-notebook/application": "^7.2.0",
6465
"@jupyter/chat": "^0.8.1",
6566
"@jupyterlab/application": "^4.2.0",
6667
"@jupyterlab/apputils": "^4.2.0",
@@ -75,6 +76,7 @@
7576
"@jupyterlab/services": "^7.2.0",
7677
"@jupyterlab/settingregistry": "^4.2.0",
7778
"@jupyterlab/ui-components": "^4.2.0",
79+
"@lumino/widgets": "^2.3.2",
7880
"@mui/icons-material": "^5.11.0",
7981
"@mui/material": "^5.11.0",
8082
"react": "^18.2.0",

packages/jupyter-ai/src/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { INotebookShell } from '@jupyter-notebook/application';
12
import {
23
JupyterFrontEnd,
34
JupyterFrontEndPlugin
@@ -11,6 +12,7 @@ import {
1112
} from '@jupyterlab/apputils';
1213
import { IDocumentWidget } from '@jupyterlab/docregistry';
1314
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
15+
import { SingletonLayout, Widget } from '@lumino/widgets';
1416

1517
import { chatCommandPlugins } from './chat-commands';
1618
import { completionPlugin } from './completions';
@@ -35,13 +37,19 @@ const plugin: JupyterFrontEndPlugin<void> = {
3537
id: '@jupyter-ai/core:plugin',
3638
autoStart: true,
3739
requires: [IRenderMimeRegistry],
38-
optional: [ICommandPalette, IThemeManager, IJaiCompletionProvider],
40+
optional: [
41+
ICommandPalette,
42+
IThemeManager,
43+
IJaiCompletionProvider,
44+
INotebookShell
45+
],
3946
activate: async (
4047
app: JupyterFrontEnd,
4148
rmRegistry: IRenderMimeRegistry,
4249
palette: ICommandPalette | null,
4350
themeManager: IThemeManager | null,
44-
completionProvider: IJaiCompletionProvider | null
51+
completionProvider: IJaiCompletionProvider | null,
52+
notebookShell: INotebookShell | null
4553
) => {
4654
const openInlineCompleterSettings = () => {
4755
app.commands.execute('settingeditor:open', {
@@ -50,7 +58,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
5058
};
5159

5260
// Create a AI settings widget.
53-
let aiSettings: MainAreaWidget<ReactWidget>;
61+
let aiSettings: Widget;
5462
let settingsWidget: ReactWidget;
5563
try {
5664
settingsWidget = buildAiSettings(
@@ -67,13 +75,20 @@ const plugin: JupyterFrontEndPlugin<void> = {
6775
app.commands.addCommand(CommandIDs.openAiSettings, {
6876
execute: () => {
6977
if (!aiSettings || aiSettings.isDisposed) {
70-
aiSettings = new MainAreaWidget({ content: settingsWidget });
78+
if (notebookShell) {
79+
aiSettings = new Widget();
80+
const layout = new SingletonLayout();
81+
aiSettings.layout = layout;
82+
layout.widget = settingsWidget;
83+
} else {
84+
aiSettings = new MainAreaWidget({ content: settingsWidget });
85+
}
7186
aiSettings.id = 'jupyter-ai-settings';
7287
aiSettings.title.label = 'AI settings';
7388
aiSettings.title.closable = true;
7489
}
7590
if (!aiSettings.isAttached) {
76-
app?.shell.add(aiSettings, 'main');
91+
app?.shell.add(aiSettings, notebookShell ? 'left' : 'main');
7792
}
7893
app.shell.activateById(aiSettings.id);
7994
},

0 commit comments

Comments
 (0)