1
+ import {
2
+ ActiveCellManager ,
3
+ buildChatSidebar ,
4
+ buildErrorWidget ,
5
+ IActiveCellManager
6
+ } from '@jupyter/chat' ;
1
7
import {
2
8
JupyterFrontEnd ,
3
9
JupyterFrontEndPlugin
4
10
} from '@jupyterlab/application' ;
11
+ import { ReactWidget , IThemeManager } from '@jupyterlab/apputils' ;
5
12
import { ICompletionProviderManager } from '@jupyterlab/completer' ;
13
+ import { INotebookTracker } from '@jupyterlab/notebook' ;
14
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
6
15
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
7
16
import { CodestralProvider } from './provider' ;
8
-
9
- import { buildChatSidebar , buildErrorWidget } from '@jupyter/chat' ;
10
- import { ReactWidget , IThemeManager } from '@jupyterlab/apputils' ;
11
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
12
-
13
17
import MistralClient from '@mistralai/mistralai' ;
14
18
15
19
import { CodestralHandler } from './handler' ;
@@ -52,22 +56,36 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
52
56
id : 'jupyterlab-codestral:chat' ,
53
57
description : 'Codestral chat extension' ,
54
58
autoStart : true ,
55
- optional : [ ISettingRegistry , IThemeManager ] ,
59
+ optional : [ INotebookTracker , ISettingRegistry , IThemeManager ] ,
56
60
requires : [ IRenderMimeRegistry ] ,
57
61
activate : async (
58
62
app : JupyterFrontEnd ,
59
63
rmRegistry : IRenderMimeRegistry ,
64
+ notebookTracker : INotebookTracker | null ,
60
65
settingsRegistry : ISettingRegistry | null ,
61
66
themeManager : IThemeManager | null
62
67
) => {
63
- const chatHandler = new CodestralHandler ( { mistralClient } ) ;
68
+ let activeCellManager : IActiveCellManager | null = null ;
69
+ if ( notebookTracker ) {
70
+ activeCellManager = new ActiveCellManager ( {
71
+ tracker : notebookTracker ,
72
+ shell : app . shell
73
+ } ) ;
74
+ }
75
+
76
+ const chatHandler = new CodestralHandler ( {
77
+ mistralClient,
78
+ activeCellManager : activeCellManager
79
+ } ) ;
64
80
65
81
let sendWithShiftEnter = false ;
82
+ let enableCodeToolbar = true ;
66
83
67
84
function loadSetting ( setting : ISettingRegistry . ISettings ) : void {
68
85
sendWithShiftEnter = setting . get ( 'sendWithShiftEnter' )
69
86
. composite as boolean ;
70
- chatHandler . config = { sendWithShiftEnter } ;
87
+ enableCodeToolbar = setting . get ( 'enableCodeToolbar' ) . composite as boolean ;
88
+ chatHandler . config = { sendWithShiftEnter, enableCodeToolbar } ;
71
89
}
72
90
73
91
Promise . all ( [ app . restored , settingsRegistry ?. load ( chatPlugin . id ) ] )
@@ -89,7 +107,11 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
89
107
90
108
let chatWidget : ReactWidget | null = null ;
91
109
try {
92
- chatWidget = buildChatSidebar ( chatHandler , themeManager , rmRegistry ) ;
110
+ chatWidget = buildChatSidebar ( {
111
+ model : chatHandler ,
112
+ themeManager,
113
+ rmRegistry
114
+ } ) ;
93
115
chatWidget . title . caption = 'Codestral Chat' ;
94
116
} catch ( e ) {
95
117
chatWidget = buildErrorWidget ( themeManager ) ;
0 commit comments