jupyter-chat-example 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.js +36 -20
  2. package/package.json +2 -2
  3. package/src/index.ts +44 -24
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Jupyter Development Team.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
- import { ActiveCellManager, AttachmentOpenerRegistry, buildChatSidebar, AbstractChatModel, SelectionWatcher, AbstractChatContext } from '@jupyter/chat';
5
+ import { AbstractChatContext, AbstractChatModel, ActiveCellManager, AttachmentOpenerRegistry, MultiChatPanel, SelectionWatcher } from '@jupyter/chat';
6
6
  import { IThemeManager } from '@jupyterlab/apputils';
7
7
  import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
8
8
  import { INotebookTracker } from '@jupyterlab/notebook';
@@ -29,6 +29,10 @@ class ChatContext extends AbstractChatContext {
29
29
  }
30
30
  }
31
31
  class MyChatModel extends AbstractChatModel {
32
+ constructor(options) {
33
+ super(options);
34
+ this.setReady();
35
+ }
32
36
  sendMessage(newMessage) {
33
37
  var _a;
34
38
  const message = {
@@ -73,22 +77,7 @@ const plugin = {
73
77
  const selectionWatcher = new SelectionWatcher({
74
78
  shell: app.shell
75
79
  });
76
- const model = new MyChatModel({
77
- activeCellManager,
78
- selectionWatcher,
79
- documentManager: filebrowser === null || filebrowser === void 0 ? void 0 : filebrowser.model.manager
80
- });
81
- // Update the settings when they change.
82
- function loadSetting(setting) {
83
- model.config = {
84
- sendWithShiftEnter: setting.get('sendWithShiftEnter')
85
- .composite,
86
- stackMessages: setting.get('stackMessages').composite,
87
- unreadNotifications: setting.get('unreadNotifications')
88
- .composite,
89
- enableCodeToolbar: setting.get('enableCodeToolbar').composite
90
- };
91
- }
80
+ let config = {};
92
81
  // Init the settings.
93
82
  if (settingRegistry) {
94
83
  // Wait for the application to be restored and for the settings to be loaded.
@@ -97,6 +86,20 @@ const plugin = {
97
86
  settingRegistry.load('jupyter-chat-example:plugin')
98
87
  ])
99
88
  .then(([, setting]) => {
89
+ function loadSetting(setting) {
90
+ config = {
91
+ sendWithShiftEnter: setting.get('sendWithShiftEnter')
92
+ .composite,
93
+ stackMessages: setting.get('stackMessages').composite,
94
+ unreadNotifications: setting.get('unreadNotifications')
95
+ .composite,
96
+ enableCodeToolbar: setting.get('enableCodeToolbar')
97
+ .composite
98
+ };
99
+ panel.sections.forEach(section => {
100
+ section.model.config = config;
101
+ });
102
+ }
100
103
  // Read the settings
101
104
  loadSetting(setting);
102
105
  // Listen for the plugin setting changes
@@ -111,12 +114,25 @@ const plugin = {
111
114
  attachmentOpenerRegistry.set('file', (attachment) => {
112
115
  app.commands.execute('docmanager:open', { path: attachment.value });
113
116
  });
114
- const panel = buildChatSidebar({
115
- model,
117
+ const createModel = async () => {
118
+ const model = new MyChatModel({
119
+ activeCellManager,
120
+ selectionWatcher,
121
+ documentManager: filebrowser === null || filebrowser === void 0 ? void 0 : filebrowser.model.manager,
122
+ config
123
+ });
124
+ model.name = UUID.uuid4();
125
+ return { model };
126
+ };
127
+ const panel = new MultiChatPanel({
116
128
  rmRegistry,
117
129
  themeManager,
118
130
  attachmentOpenerRegistry,
119
- welcomeMessage
131
+ welcomeMessage,
132
+ createModel: createModel,
133
+ // No op, since the chat are transient, but it need to be provided to have the
134
+ // button in the toolbar.
135
+ renameChat: async (oldName, newName) => true
120
136
  });
121
137
  app.shell.add(panel, 'left');
122
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyter-chat-example",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "A chat extension providing a chat as example",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -44,7 +44,7 @@
44
44
  "install:extension": "jlpm build"
45
45
  },
46
46
  "dependencies": {
47
- "@jupyter/chat": "^0.17.0",
47
+ "@jupyter/chat": "^0.18.0",
48
48
  "@jupyterlab/application": "^4.2.0",
49
49
  "@jupyterlab/apputils": "^4.3.0",
50
50
  "@jupyterlab/notebook": "^4.2.0",
package/src/index.ts CHANGED
@@ -4,16 +4,18 @@
4
4
  */
5
5
 
6
6
  import {
7
+ AbstractChatContext,
8
+ AbstractChatModel,
7
9
  ActiveCellManager,
8
10
  AttachmentOpenerRegistry,
9
- buildChatSidebar,
10
- AbstractChatModel,
11
11
  IAttachment,
12
12
  IChatMessage,
13
+ IChatContext,
14
+ IConfig,
13
15
  INewMessage,
16
+ MultiChatPanel,
14
17
  SelectionWatcher,
15
- IChatContext,
16
- AbstractChatContext
18
+ IChatModel
17
19
  } from '@jupyter/chat';
18
20
  import {
19
21
  JupyterFrontEnd,
@@ -48,6 +50,11 @@ class ChatContext extends AbstractChatContext {
48
50
  }
49
51
 
50
52
  class MyChatModel extends AbstractChatModel {
53
+ constructor(options: IChatModel.IOptions) {
54
+ super(options);
55
+ this.setReady();
56
+ }
57
+
51
58
  sendMessage(
52
59
  newMessage: INewMessage
53
60
  ): Promise<boolean | void> | boolean | void {
@@ -104,23 +111,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
104
111
  shell: app.shell
105
112
  });
106
113
 
107
- const model = new MyChatModel({
108
- activeCellManager,
109
- selectionWatcher,
110
- documentManager: filebrowser?.model.manager
111
- });
112
-
113
- // Update the settings when they change.
114
- function loadSetting(setting: ISettingRegistry.ISettings): void {
115
- model.config = {
116
- sendWithShiftEnter: setting.get('sendWithShiftEnter')
117
- .composite as boolean,
118
- stackMessages: setting.get('stackMessages').composite as boolean,
119
- unreadNotifications: setting.get('unreadNotifications')
120
- .composite as boolean,
121
- enableCodeToolbar: setting.get('enableCodeToolbar').composite as boolean
122
- };
123
- }
114
+ let config: IConfig = {};
124
115
 
125
116
  // Init the settings.
126
117
  if (settingRegistry) {
@@ -130,6 +121,21 @@ const plugin: JupyterFrontEndPlugin<void> = {
130
121
  settingRegistry.load('jupyter-chat-example:plugin')
131
122
  ])
132
123
  .then(([, setting]) => {
124
+ function loadSetting(setting: ISettingRegistry.ISettings) {
125
+ config = {
126
+ sendWithShiftEnter: setting.get('sendWithShiftEnter')
127
+ .composite as boolean,
128
+ stackMessages: setting.get('stackMessages').composite as boolean,
129
+ unreadNotifications: setting.get('unreadNotifications')
130
+ .composite as boolean,
131
+ enableCodeToolbar: setting.get('enableCodeToolbar')
132
+ .composite as boolean
133
+ };
134
+
135
+ panel.sections.forEach(section => {
136
+ section.model.config = config;
137
+ });
138
+ }
133
139
  // Read the settings
134
140
  loadSetting(setting);
135
141
 
@@ -149,12 +155,26 @@ const plugin: JupyterFrontEndPlugin<void> = {
149
155
  app.commands.execute('docmanager:open', { path: attachment.value });
150
156
  });
151
157
 
152
- const panel = buildChatSidebar({
153
- model,
158
+ const createModel = async (): Promise<MultiChatPanel.IAddChatArgs> => {
159
+ const model = new MyChatModel({
160
+ activeCellManager,
161
+ selectionWatcher,
162
+ documentManager: filebrowser?.model.manager,
163
+ config
164
+ });
165
+ model.name = UUID.uuid4();
166
+ return { model };
167
+ };
168
+
169
+ const panel = new MultiChatPanel({
154
170
  rmRegistry,
155
171
  themeManager,
156
172
  attachmentOpenerRegistry,
157
- welcomeMessage
173
+ welcomeMessage,
174
+ createModel: createModel,
175
+ // No op, since the chat are transient, but it need to be provided to have the
176
+ // button in the toolbar.
177
+ renameChat: async (oldName: string, newName: string) => true
158
178
  });
159
179
  app.shell.add(panel, 'left');
160
180
  }