Skip to content

Commit 04982b7

Browse files
committed
Add the writer component plugin to alow third party extension to provide it
1 parent 2af4817 commit 04982b7

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
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/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
} from '@jupyter/chat';
@@ -58,6 +59,7 @@ import {
5859
IInputToolbarRegistryFactory,
5960
ISelectionWatcherToken,
6061
IWelcomeMessage,
62+
IWriterComponent,
6163
LabChatModel,
6264
LabChatModelFactory,
6365
LabChatPanel,
@@ -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
/**
@@ -126,7 +130,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
126130
IThemeManager,
127131
IToolbarWidgetRegistry,
128132
ITranslator,
129-
IWelcomeMessage
133+
IWelcomeMessage,
134+
IWriterComponent
130135
],
131136
provides: IChatFactory,
132137
activate: (
@@ -145,7 +150,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
145150
themeManager: IThemeManager | null,
146151
toolbarRegistry: IToolbarWidgetRegistry | null,
147152
translator_: ITranslator | null,
148-
welcomeMessage: string
153+
welcomeMessage: string,
154+
writerComponent: WriterComponent
149155
): IChatFactory => {
150156
const translator = translator_ ?? nullTranslator;
151157

@@ -310,7 +316,8 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
310316
attachmentOpenerRegistry,
311317
inputToolbarFactory,
312318
messageFooterRegistry,
313-
welcomeMessage
319+
welcomeMessage,
320+
writerComponent
314321
});
315322

316323
// Add the widget to the tracker when it's created
@@ -558,6 +565,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
558565
commands.addCommand(CommandIDs.openChat, {
559566
label: 'Open a chat',
560567
execute: async args => {
568+
console.log('ARG', args);
561569
const inSidePanel: boolean = (args.inSidePanel as boolean) ?? false;
562570
const startup: boolean = (args.startup as boolean) ?? false;
563571
let filepath: string | null = (args.filepath as string) ?? null;
@@ -708,7 +716,8 @@ const chatPanel: JupyterFrontEndPlugin<ChatPanel> = {
708716
ILayoutRestorer,
709717
IMessageFooterRegistry,
710718
IThemeManager,
711-
IWelcomeMessage
719+
IWelcomeMessage,
720+
IWriterComponent
712721
],
713722
activate: (
714723
app: JupyterFrontEnd,
@@ -721,7 +730,8 @@ const chatPanel: JupyterFrontEndPlugin<ChatPanel> = {
721730
restorer: ILayoutRestorer | null,
722731
messageFooterRegistry: IMessageFooterRegistry,
723732
themeManager: IThemeManager | null,
724-
welcomeMessage: string
733+
welcomeMessage: string,
734+
writerComponent: WriterComponent
725735
): ChatPanel => {
726736
const { commands } = app;
727737

@@ -740,7 +750,8 @@ const chatPanel: JupyterFrontEndPlugin<ChatPanel> = {
740750
attachmentOpenerRegistry,
741751
inputToolbarFactory,
742752
messageFooterRegistry,
743-
welcomeMessage
753+
welcomeMessage,
754+
writerComponent
744755
});
745756
chatPanel.id = 'JupyterlabChat:sidepanel';
746757
chatPanel.title.icon = chatIcon;
@@ -857,7 +868,7 @@ const inputToolbarFactory: JupyterFrontEndPlugin<IInputToolbarRegistryFactory> =
857868
* Extension providing the message footer registry.
858869
*/
859870
const footerRegistry: JupyterFrontEndPlugin<IMessageFooterRegistry> = {
860-
id: 'jupyterlab-chat/footerRegistry',
871+
id: pluginIds.footerRegistry,
861872
description: 'The footer registry plugin.',
862873
autoStart: true,
863874
provides: IMessageFooterRegistry,
@@ -866,6 +877,19 @@ const footerRegistry: JupyterFrontEndPlugin<IMessageFooterRegistry> = {
866877
}
867878
};
868879

880+
/**
881+
* Plugin providing a writer component.
882+
*/
883+
const writerComponent: JupyterFrontEndPlugin<WriterComponent> = {
884+
id: pluginIds.writerComponentRegistry,
885+
description: 'The writer component registry plugin.',
886+
autoStart: true,
887+
provides: IWriterComponent,
888+
activate: (): WriterComponent => {
889+
return new WriterComponent();
890+
}
891+
};
892+
869893
export default [
870894
activeCellManager,
871895
attachmentOpeners,
@@ -877,5 +901,6 @@ export default [
877901
inputToolbarFactory,
878902
selectionWatcher,
879903
emojiCommandsPlugin,
880-
mentionCommandsPlugin
904+
mentionCommandsPlugin,
905+
writerComponent
881906
];

packages/jupyterlab-chat/src/factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
IChatCommandRegistry,
1111
IInputToolbarRegistry,
1212
IMessageFooterRegistry,
13-
ISelectionWatcher
13+
ISelectionWatcher,
14+
WriterComponent
1415
} from '@jupyter/chat';
1516
import { IThemeManager } from '@jupyterlab/apputils';
1617
import { IDocumentManager } from '@jupyterlab/docmanager';
@@ -87,6 +88,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
8788
this._inputToolbarFactory = options.inputToolbarFactory;
8889
this._messageFooterRegistry = options.messageFooterRegistry;
8990
this._welcomeMessage = options.welcomeMessage;
91+
this._writerComponent = options.writerComponent;
9092
}
9193

9294
/**
@@ -102,6 +104,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
102104
context.attachmentOpenerRegistry = this._attachmentOpenerRegistry;
103105
context.messageFooterRegistry = this._messageFooterRegistry;
104106
context.welcomeMessage = this._welcomeMessage;
107+
context.writerComponent = this._writerComponent;
105108
if (this._inputToolbarFactory) {
106109
context.inputToolbarRegistry = this._inputToolbarFactory.create();
107110
}
@@ -128,6 +131,7 @@ export class ChatWidgetFactory extends ABCWidgetFactory<
128131
private _inputToolbarFactory?: IInputToolbarRegistryFactory;
129132
private _messageFooterRegistry?: IMessageFooterRegistry;
130133
private _welcomeMessage?: string;
134+
private _writerComponent?: WriterComponent;
131135
}
132136

133137
export namespace ChatWidgetFactory {
@@ -140,6 +144,7 @@ export namespace ChatWidgetFactory {
140144
inputToolbarRegistry?: IInputToolbarRegistry;
141145
messageFooterRegistry?: IMessageFooterRegistry;
142146
welcomeMessage?: string;
147+
writerComponent?: WriterComponent;
143148
}
144149

145150
export interface IOptions<T extends LabChatPanel>
@@ -151,6 +156,7 @@ export namespace ChatWidgetFactory {
151156
inputToolbarFactory?: IInputToolbarRegistryFactory;
152157
messageFooterRegistry?: IMessageFooterRegistry;
153158
welcomeMessage?: string;
159+
writerComponent?: WriterComponent;
154160
}
155161
}
156162

packages/jupyterlab-chat/src/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ export class LabChatModel
362362
if (state.isWriting !== undefined && state.isWriting !== false) {
363363
const writer: IChatModel.IWriter = {
364364
user: state.user,
365-
messageID: state.isWriting === true ? undefined : state.isWriting
365+
messageID: state.isWriting === true ? undefined : state.isWriting,
366+
typingIndicator: state.typingIndicator
366367
};
367368
writers.push(writer);
368369
}

packages/jupyterlab-chat/src/token.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
IActiveCellManager,
1010
ISelectionWatcher,
1111
ChatWidget,
12-
IInputToolbarRegistry
12+
IInputToolbarRegistry,
13+
WriterComponent
1314
} from '@jupyter/chat';
1415
import { WidgetTracker } from '@jupyterlab/apputils';
1516
import { DocumentRegistry } from '@jupyterlab/docregistry';
@@ -153,3 +154,10 @@ export const IInputToolbarRegistryFactory =
153154
export const IWelcomeMessage = new Token<string>(
154155
'jupyterlab-chat:IWelcomeMessage'
155156
);
157+
158+
/**
159+
* The token to add a component to the writing notification.
160+
*/
161+
export const IWriterComponent = new Token<WriterComponent>(
162+
'jupyterlab-chat:IWriterComponent'
163+
);

packages/jupyterlab-chat/src/widget.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
IChatModel,
1111
IInputToolbarRegistry,
1212
IMessageFooterRegistry,
13-
readIcon
13+
readIcon,
14+
WriterComponent
1415
} from '@jupyter/chat';
1516
import { Contents } from '@jupyterlab/services';
1617
import { IThemeManager } from '@jupyterlab/apputils';
@@ -115,6 +116,7 @@ export class ChatPanel extends SidePanel {
115116
this._inputToolbarFactory = options.inputToolbarFactory;
116117
this._messageFooterRegistry = options.messageFooterRegistry;
117118
this._welcomeMessage = options.welcomeMessage;
119+
this._writerComponent = options.writerComponent;
118120

119121
const addChat = new CommandToolbarButton({
120122
commands: this._commands,
@@ -204,7 +206,8 @@ export class ChatPanel extends SidePanel {
204206
attachmentOpenerRegistry: this._attachmentOpenerRegistry,
205207
inputToolbarRegistry,
206208
messageFooterRegistry: this._messageFooterRegistry,
207-
welcomeMessage: this._welcomeMessage
209+
welcomeMessage: this._welcomeMessage,
210+
writerComponent: this._writerComponent
208211
});
209212

210213
this.addWidget(
@@ -328,6 +331,7 @@ export class ChatPanel extends SidePanel {
328331
private _inputToolbarFactory?: IInputToolbarRegistryFactory;
329332
private _messageFooterRegistry?: IMessageFooterRegistry;
330333
private _welcomeMessage?: string;
334+
private _writerComponent?: WriterComponent;
331335
}
332336

333337
/**
@@ -348,6 +352,7 @@ export namespace ChatPanel {
348352
inputToolbarFactory?: IInputToolbarRegistryFactory;
349353
messageFooterRegistry?: IMessageFooterRegistry;
350354
welcomeMessage?: string;
355+
writerComponent?: WriterComponent;
351356
}
352357
}
353358

0 commit comments

Comments
 (0)