File tree 4 files changed +38
-42
lines changed
packages/jupyter-chat/src/chat-commands
python/jupyterlab-chat/src/chat-commands 4 files changed +38
-42
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
export * from './types' ;
7
- export * from './tokens ' ;
7
+ export * from './registry ' ;
Original file line number Diff line number Diff line change @@ -26,6 +26,42 @@ export interface IChatCommandRegistry {
26
26
) : void ;
27
27
}
28
28
29
+ /**
30
+ * Default chat command registry implementation.
31
+ */
32
+ export class ChatCommandRegistry implements IChatCommandRegistry {
33
+ constructor ( ) {
34
+ this . _providers = new Map < string , IChatCommandProvider > ( ) ;
35
+ }
36
+
37
+ addProvider ( provider : IChatCommandProvider ) : void {
38
+ this . _providers . set ( provider . id , provider ) ;
39
+ }
40
+
41
+ getProviders ( ) : IChatCommandProvider [ ] {
42
+ return Array . from ( this . _providers . values ( ) ) ;
43
+ }
44
+
45
+ handleChatCommand (
46
+ command : ChatCommand ,
47
+ currentWord : string ,
48
+ replaceCurrentWord : ( newWord : string ) => void
49
+ ) {
50
+ const provider = this . _providers . get ( command . providerId ) ;
51
+ if ( ! provider ) {
52
+ console . error (
53
+ 'Error in handling chat command: No command provider has an ID of ' +
54
+ command . providerId
55
+ ) ;
56
+ return ;
57
+ }
58
+
59
+ provider . handleChatCommand ( command , currentWord , replaceCurrentWord ) ;
60
+ }
61
+
62
+ private _providers : Map < string , IChatCommandProvider > ;
63
+ }
64
+
29
65
export const IChatCommandRegistry = new Token < IChatCommandRegistry > (
30
66
'@jupyter/chat:IChatCommandRegistry'
31
67
) ;
Original file line number Diff line number Diff line change 5
5
6
6
import { JupyterFrontEndPlugin } from '@jupyterlab/application' ;
7
7
8
- import { IChatCommandRegistry } from '@jupyter/chat' ;
9
- import { ChatCommandRegistry } from './registry' ;
8
+ import { IChatCommandRegistry , ChatCommandRegistry } from '@jupyter/chat' ;
10
9
11
10
export const chatCommandRegistryPlugin : JupyterFrontEndPlugin < IChatCommandRegistry > =
12
11
{
Original file line number Diff line number Diff line change 2
2
* Copyright (c) Jupyter Development Team.
3
3
* Distributed under the terms of the Modified BSD License.
4
4
*/
5
-
6
- import {
7
- ChatCommand ,
8
- IChatCommandRegistry ,
9
- IChatCommandProvider
10
- } from '@jupyter/chat' ;
11
-
12
- export class ChatCommandRegistry implements IChatCommandRegistry {
13
- constructor ( ) {
14
- this . _providers = new Map < string , IChatCommandProvider > ( ) ;
15
- }
16
-
17
- addProvider ( provider : IChatCommandProvider ) : void {
18
- this . _providers . set ( provider . id , provider ) ;
19
- }
20
-
21
- getProviders ( ) : IChatCommandProvider [ ] {
22
- return Array . from ( this . _providers . values ( ) ) ;
23
- }
24
-
25
- handleChatCommand (
26
- command : ChatCommand ,
27
- currentWord : string ,
28
- replaceCurrentWord : ( newWord : string ) => void
29
- ) {
30
- const provider = this . _providers . get ( command . providerId ) ;
31
- if ( ! provider ) {
32
- console . error (
33
- 'Error in handling chat command: No command provider has an ID of ' +
34
- command . providerId
35
- ) ;
36
- return ;
37
- }
38
-
39
- provider . handleChatCommand ( command , currentWord , replaceCurrentWord ) ;
40
- }
41
-
42
- private _providers : Map < string , IChatCommandProvider > ;
43
- }
You can’t perform that action at this time.
0 commit comments