1
+ import { INotebookShell } from '@jupyter-notebook/application' ;
1
2
import {
2
3
JupyterFrontEnd ,
3
4
JupyterFrontEndPlugin
@@ -11,6 +12,7 @@ import {
11
12
} from '@jupyterlab/apputils' ;
12
13
import { IDocumentWidget } from '@jupyterlab/docregistry' ;
13
14
import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
15
+ import { SingletonLayout , Widget } from '@lumino/widgets' ;
14
16
15
17
import { chatCommandPlugins } from './chat-commands' ;
16
18
import { completionPlugin } from './completions' ;
@@ -35,13 +37,19 @@ const plugin: JupyterFrontEndPlugin<void> = {
35
37
id : '@jupyter-ai/core:plugin' ,
36
38
autoStart : true ,
37
39
requires : [ IRenderMimeRegistry ] ,
38
- optional : [ ICommandPalette , IThemeManager , IJaiCompletionProvider ] ,
40
+ optional : [
41
+ ICommandPalette ,
42
+ IThemeManager ,
43
+ IJaiCompletionProvider ,
44
+ INotebookShell
45
+ ] ,
39
46
activate : async (
40
47
app : JupyterFrontEnd ,
41
48
rmRegistry : IRenderMimeRegistry ,
42
49
palette : ICommandPalette | null ,
43
50
themeManager : IThemeManager | null ,
44
- completionProvider : IJaiCompletionProvider | null
51
+ completionProvider : IJaiCompletionProvider | null ,
52
+ notebookShell : INotebookShell | null
45
53
) => {
46
54
const openInlineCompleterSettings = ( ) => {
47
55
app . commands . execute ( 'settingeditor:open' , {
@@ -50,7 +58,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
50
58
} ;
51
59
52
60
// Create a AI settings widget.
53
- let aiSettings : MainAreaWidget < ReactWidget > ;
61
+ let aiSettings : Widget ;
54
62
let settingsWidget : ReactWidget ;
55
63
try {
56
64
settingsWidget = buildAiSettings (
@@ -67,13 +75,20 @@ const plugin: JupyterFrontEndPlugin<void> = {
67
75
app . commands . addCommand ( CommandIDs . openAiSettings , {
68
76
execute : ( ) => {
69
77
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
+ }
71
86
aiSettings . id = 'jupyter-ai-settings' ;
72
87
aiSettings . title . label = 'AI settings' ;
73
88
aiSettings . title . closable = true ;
74
89
}
75
90
if ( ! aiSettings . isAttached ) {
76
- app ?. shell . add ( aiSettings , 'main' ) ;
91
+ app ?. shell . add ( aiSettings , notebookShell ? 'left' : 'main' ) ;
77
92
}
78
93
app . shell . activateById ( aiSettings . id ) ;
79
94
} ,
0 commit comments