Skip to content

Commit 8a26405

Browse files
authored
Chat tracker token (#307)
* Add a widget tracker token in @jupyter/chat to have a unique tracker that can be used by external extensions * Add a token/plugin for the chat config * Fix restoration for main area widget * Fix ui test * lint * Add a note about the chat tracker in the documentation
1 parent 36068a4 commit 8a26405

File tree

9 files changed

+209
-114
lines changed

9 files changed

+209
-114
lines changed

docs/source/developers/developing_extensions/extension-providing-chat.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,18 @@ const myChatExtension: JupyterFrontEndPlugin<void> = {
379379
}
380380
};
381381
```
382+
383+
## Make the chats discoverable for third party extensions
384+
385+
The `jupyter/chat` package provides an `IChatTracker` token. This token is a generic
386+
token that can be exposed by any extension providing a chat. It is designed to expose
387+
an `IWidgetTracker` tracking either `ChatWidget` or `MainAreaWidget<ChatWidget>`, in
388+
order to allow tracking both chats in main area chats and those in side panel.
389+
To be available for others extensions, this token must be exposed by the developers
390+
of the extension providing the chat(s), with a dedicated plugin.
391+
392+
```{note}
393+
Since the token is generic, a configuration with multiple extensions providing chat(s)
394+
will create a conflict. One of the plugins exposing the `IChatTracker` token will have
395+
to be disabled (and the chats from that extension will no longer be tracked).
396+
```

docs/source/developers/developing_extensions/using-chat-extension.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ This token is composed of:
2525
- `tracker`, a widget tracker that allows to track all the opened chats, and to
2626
retrieve the current one.
2727

28-
```{caution}
29-
Currently the widget tracker only tracks the main area widgets, not the ones opened in
30-
the side panel.
31-
```
32-
3328
### IChatPanel
3429

3530
This token is a pointer to the left panel containing chats.\

packages/jupyter-chat/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export * from './markdown-renderer';
1111
export * from './model';
1212
export * from './registers';
1313
export * from './selection-watcher';
14+
export * from './tokens';
1415
export * from './types';
1516
export * from './widgets';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Jupyter Development Team.
3+
* Distributed under the terms of the Modified BSD License.
4+
*/
5+
6+
import { IWidgetTracker, MainAreaWidget } from '@jupyterlab/apputils';
7+
import { Token } from '@lumino/coreutils';
8+
9+
import { ChatWidget } from './widgets';
10+
11+
/**
12+
* the chat tracker type.
13+
*/
14+
export type IChatTracker = IWidgetTracker<
15+
ChatWidget | MainAreaWidget<ChatWidget>
16+
>;
17+
18+
/**
19+
* A chat tracker token.
20+
*/
21+
export const IChatTracker = new Token<IChatTracker>(
22+
'@jupyter/chat:IChatTracker',
23+
'The chat widget tracker'
24+
);

packages/jupyter-chat/src/widgets/chat-widget.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Chat, IInputToolbarRegistry, MESSAGE_CLASS } from '../components';
1515
import { chatIcon } from '../icons';
1616
import { IChatModel } from '../model';
1717
import {
18+
ChatArea,
1819
IFileAttachment,
1920
INotebookAttachment,
2021
INotebookAttachmentCell
@@ -71,6 +72,13 @@ export class ChatWidget extends ReactWidget {
7172
return this._chatOptions.model;
7273
}
7374

75+
/**
76+
* The area where the chat is opened.
77+
*/
78+
get area(): ChatArea | undefined {
79+
return this._chatOptions.area;
80+
}
81+
7482
/**
7583
* Get the input toolbar registry (if it has been provided when creating the widget).
7684
*/

0 commit comments

Comments
 (0)