Skip to content

Commit 86bda50

Browse files
committed
move registry to jupyter-chat
1 parent e401a5d commit 86bda50

File tree

4 files changed

+38
-42
lines changed

4 files changed

+38
-42
lines changed

packages/jupyter-chat/src/chat-commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
*/
55

66
export * from './types';
7-
export * from './tokens';
7+
export * from './registry';

packages/jupyter-chat/src/chat-commands/tokens.ts renamed to packages/jupyter-chat/src/chat-commands/registry.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ export interface IChatCommandRegistry {
2626
): void;
2727
}
2828

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+
2965
export const IChatCommandRegistry = new Token<IChatCommandRegistry>(
3066
'@jupyter/chat:IChatCommandRegistry'
3167
);

python/jupyterlab-chat/src/chat-commands/plugins.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
77

8-
import { IChatCommandRegistry } from '@jupyter/chat';
9-
import { ChatCommandRegistry } from './registry';
8+
import { IChatCommandRegistry, ChatCommandRegistry } from '@jupyter/chat';
109

1110
export const chatCommandRegistryPlugin: JupyterFrontEndPlugin<IChatCommandRegistry> =
1211
{

python/jupyterlab-chat/src/chat-commands/registry.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,3 @@
22
* Copyright (c) Jupyter Development Team.
33
* Distributed under the terms of the Modified BSD License.
44
*/
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-
}

0 commit comments

Comments
 (0)