Skip to content

Commit b8998ac

Browse files
committed
Add the writer component plugin to alow third party extension to provide it
1 parent 85223cd commit b8998ac

File tree

7 files changed

+77
-13
lines changed

7 files changed

+77
-13
lines changed

packages/jupyter-chat/src/components/messages/writers.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ export type WriterComponentProps = {
183183
writer: IChatModel.IWriter;
184184
};
185185

186+
/**
187+
* The writer component class containing a react component to display with the user
188+
* writing notification.
189+
*/
186190
export class WriterComponent {
187191
/**
188192
* The react component.

packages/jupyter-chat/src/widgets/multichat-panel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import { ChatWidget } from './chat-widget';
3030
import {
3131
Chat,
3232
IInputToolbarRegistry,
33-
IInputToolbarRegistryFactory
33+
IInputToolbarRegistryFactory,
34+
WriterComponent
3435
} from '../components';
3536
import { chatIcon, readIcon } from '../icons';
3637
import { IChatModel } from '../model';
@@ -65,6 +66,7 @@ export class MultiChatPanel extends SidePanel {
6566
this._inputToolbarFactory = options.inputToolbarFactory;
6667
this._messageFooterRegistry = options.messageFooterRegistry;
6768
this._welcomeMessage = options.welcomeMessage;
69+
this._writerComponent = options.writerComponent;
6870

6971
this._getChatNames = options.getChatNames;
7072
this._createModel = options.createModel;
@@ -155,7 +157,8 @@ export class MultiChatPanel extends SidePanel {
155157
attachmentOpenerRegistry: this._attachmentOpenerRegistry,
156158
inputToolbarRegistry,
157159
messageFooterRegistry: this._messageFooterRegistry,
158-
welcomeMessage: this._welcomeMessage
160+
welcomeMessage: this._welcomeMessage,
161+
writerComponent: this._writerComponent
159162
});
160163

161164
const section = new ChatSection({
@@ -273,6 +276,7 @@ export class MultiChatPanel extends SidePanel {
273276
private _inputToolbarFactory?: IInputToolbarRegistryFactory;
274277
private _messageFooterRegistry?: IMessageFooterRegistry;
275278
private _welcomeMessage?: string;
279+
private _writerComponent?: WriterComponent;
276280
private _updateChatListDebouncer: Debouncer;
277281

278282
private _createModel?: (

packages/jupyterlab-chat-extension/src/index.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
InputToolbarRegistry,
1818
MessageFooterRegistry,
1919
SelectionWatcher,
20+
WriterComponent,
2021
chatIcon,
2122
readIcon,
2223
IInputToolbarRegistryFactory,
@@ -58,6 +59,7 @@ import {
5859
IChatPanel,
5960
ISelectionWatcherToken,
6061
IWelcomeMessage,
62+
IWriterComponent,
6163
LabChatModelFactory,
6264
LabChatPanel,
6365
WidgetConfig,
@@ -77,8 +79,10 @@ const pluginIds = {
7779
chatCommands: 'jupyterlab-chat-extension:commands',
7880
chatPanel: 'jupyterlab-chat-extension:chat-panel',
7981
docFactories: 'jupyterlab-chat-extension:factory',
82+
footerRegistry: 'jupyterlab-chat/footerRegistry',
8083
inputToolbarFactory: 'jupyterlab-chat-extension:inputToolbarFactory',
81-
selectionWatcher: 'jupyterlab-chat-extension:selectionWatcher'
84+
selectionWatcher: 'jupyterlab-chat-extension:selectionWatcher',
85+
writerComponentRegistry: 'jupyterlab-chat-extension:writerComponent'
8286
};
8387

8488
/**
@@ -178,7 +182,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
178182
IThemeManager,
179183
IToolbarWidgetRegistry,
180184
ITranslator,
181-
IWelcomeMessage
185+
IWelcomeMessage,
186+
IWriterComponent
182187
],
183188
provides: IChatFactory,
184189
activate: (
@@ -197,7 +202,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
197202
themeManager: IThemeManager | null,
198203
toolbarRegistry: IToolbarWidgetRegistry | null,
199204
translator_: ITranslator | null,
200-
welcomeMessage: string
205+
welcomeMessage: string,
206+
writerComponent: WriterComponent
201207
): IChatFactory => {
202208
const translator = translator_ ?? nullTranslator;
203209

@@ -362,7 +368,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
362368
attachmentOpenerRegistry,
363369
inputToolbarFactory,
364370
messageFooterRegistry,
365-
welcomeMessage
371+
welcomeMessage,
372+
writerComponent
366373
});
367374

368375
// Add the widget to the tracker when it's created
@@ -596,6 +603,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
596603
commands.addCommand(CommandIDs.openChat, {
597604
label: 'Open a chat',
598605
execute: async args => {
606+
console.log('ARG', args);
599607
const inSidePanel: boolean = (args.inSidePanel as boolean) ?? false;
600608
const startup: boolean = (args.startup as boolean) ?? false;
601609
let filepath: string | null = (args.filepath as string) ?? null;
@@ -788,7 +796,8 @@ const chatPanel: JupyterFrontEndPlugin<MultiChatPanel> = {
788796
ILayoutRestorer,
789797
IMessageFooterRegistry,
790798
IThemeManager,
791-
IWelcomeMessage
799+
IWelcomeMessage,
800+
IWriterComponent
792801
],
793802
activate: (
794803
app: JupyterFrontEnd,
@@ -801,7 +810,8 @@ const chatPanel: JupyterFrontEndPlugin<MultiChatPanel> = {
801810
restorer: ILayoutRestorer | null,
802811
messageFooterRegistry: IMessageFooterRegistry,
803812
themeManager: IThemeManager | null,
804-
welcomeMessage: string
813+
welcomeMessage: string,
814+
writerComponent: WriterComponent
805815
): MultiChatPanel => {
806816
const { commands, serviceManager } = app;
807817

@@ -847,7 +857,8 @@ const chatPanel: JupyterFrontEndPlugin<MultiChatPanel> = {
847857
attachmentOpenerRegistry,
848858
inputToolbarFactory,
849859
messageFooterRegistry,
850-
welcomeMessage
860+
welcomeMessage,
861+
writerComponent
851862
});
852863
chatPanel.id = 'JupyterlabChat:sidepanel';
853864

@@ -1002,7 +1013,7 @@ const inputToolbarFactory: JupyterFrontEndPlugin<IInputToolbarRegistryFactory> =
10021013
* Extension providing the message footer registry.
10031014
*/
10041015
const footerRegistry: JupyterFrontEndPlugin<IMessageFooterRegistry> = {
1005-
id: 'jupyterlab-chat/footerRegistry',
1016+
id: pluginIds.footerRegistry,
10061017
description: 'The footer registry plugin.',
10071018
autoStart: true,
10081019
provides: IMessageFooterRegistry,
@@ -1011,6 +1022,19 @@ const footerRegistry: JupyterFrontEndPlugin<IMessageFooterRegistry> = {
10111022
}
10121023
};
10131024

1025+
/**
1026+
* Plugin providing a writer component.
1027+
*/
1028+
const writerComponent: JupyterFrontEndPlugin<WriterComponent> = {
1029+
id: pluginIds.writerComponentRegistry,
1030+
description: 'The writer component registry plugin.',
1031+
autoStart: true,
1032+
provides: IWriterComponent,
1033+
activate: (): WriterComponent => {
1034+
return new WriterComponent();
1035+
}
1036+
};
1037+
10141038
export default [
10151039
activeCellManager,
10161040
attachmentOpeners,
@@ -1022,5 +1046,6 @@ export default [
10221046
inputToolbarFactory,
10231047
selectionWatcher,
10241048
emojiCommandsPlugin,
1025-
mentionCommandsPlugin
1049+
mentionCommandsPlugin,
1050+
writerComponent
10261051
];

packages/jupyterlab-chat/src/factory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IMessageFooterRegistry,
1313
ISelectionWatcher,
1414
IInputToolbarRegistryFactory
15+
WriterComponent
1516
} from '@jupyter/chat';
1617
import { IThemeManager } from '@jupyterlab/apputils';
1718
import { IDocumentManager } from '@jupyterlab/docmanager';
@@ -84,6 +85,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
8485
this._inputToolbarFactory = options.inputToolbarFactory;
8586
this._messageFooterRegistry = options.messageFooterRegistry;
8687
this._welcomeMessage = options.welcomeMessage;
88+
this._writerComponent = options.writerComponent;
8789
}
8890

8991
/**
@@ -99,6 +101,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
99101
context.attachmentOpenerRegistry = this._attachmentOpenerRegistry;
100102
context.messageFooterRegistry = this._messageFooterRegistry;
101103
context.welcomeMessage = this._welcomeMessage;
104+
context.writerComponent = this._writerComponent;
102105
if (this._inputToolbarFactory) {
103106
context.inputToolbarRegistry = this._inputToolbarFactory.create();
104107
}
@@ -125,6 +128,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
125128
private _inputToolbarFactory?: IInputToolbarRegistryFactory;
126129
private _messageFooterRegistry?: IMessageFooterRegistry;
127130
private _welcomeMessage?: string;
131+
private _writerComponent?: WriterComponent;
128132
}
129133

130134
export namespace ChatWidgetFactory {
@@ -137,6 +141,7 @@ export namespace ChatWidgetFactory {
137141
inputToolbarRegistry?: IInputToolbarRegistry;
138142
messageFooterRegistry?: IMessageFooterRegistry;
139143
welcomeMessage?: string;
144+
writerComponent?: WriterComponent;
140145
}
141146

142147
export interface IOptions<T extends LabChatPanel>
@@ -148,6 +153,7 @@ export namespace ChatWidgetFactory {
148153
inputToolbarFactory?: IInputToolbarRegistryFactory;
149154
messageFooterRegistry?: IMessageFooterRegistry;
150155
welcomeMessage?: string;
156+
writerComponent?: WriterComponent;
151157
}
152158
}
153159

packages/jupyterlab-chat/src/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ export class LabChatModel
353353
if (state.isWriting !== undefined && state.isWriting !== false) {
354354
const writer: IChatModel.IWriter = {
355355
user: state.user,
356-
messageID: state.isWriting === true ? undefined : state.isWriting
356+
messageID: state.isWriting === true ? undefined : state.isWriting,
357+
typingIndicator: state.typingIndicator
357358
};
358359
writers.push(writer);
359360
}

packages/jupyterlab-chat/src/token.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
chatIcon,
99
IActiveCellManager,
1010
ISelectionWatcher,
11-
ChatWidget
11+
ChatWidget,
12+
WriterComponent
1213
} from '@jupyter/chat';
1314
import { WidgetTracker } from '@jupyterlab/apputils';
1415
import { DocumentRegistry } from '@jupyterlab/docregistry';
@@ -143,3 +144,10 @@ export const ISelectionWatcherToken = new Token<ISelectionWatcher>(
143144
export const IWelcomeMessage = new Token<string>(
144145
'jupyterlab-chat:IWelcomeMessage'
145146
);
147+
148+
/**
149+
* The token to add a component to the writing notification.
150+
*/
151+
export const IWriterComponent = new Token<WriterComponent>(
152+
'jupyterlab-chat:IWriterComponent'
153+
);

packages/jupyterlab-chat/src/widget.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@
33
* Distributed under the terms of the Modified BSD License.
44
*/
55

6+
<<<<<<< HEAD
67
import { ChatWidget, IChatModel } from '@jupyter/chat';
8+
=======
9+
import {
10+
ChatWidget,
11+
IAttachmentOpenerRegistry,
12+
IChatCommandRegistry,
13+
IChatModel,
14+
IInputToolbarRegistry,
15+
IMessageFooterRegistry,
16+
readIcon,
17+
WriterComponent
18+
} from '@jupyter/chat';
19+
import { Contents } from '@jupyterlab/services';
20+
import { IThemeManager } from '@jupyterlab/apputils';
21+
import { PathExt } from '@jupyterlab/coreutils';
22+
>>>>>>> 04982b7 (Add the writer component plugin to alow third party extension to provide it)
723
import { DocumentWidget } from '@jupyterlab/docregistry';
824

925
import { LabChatModel } from './model';

0 commit comments

Comments
 (0)