jupyter-chat-example 0.8.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # jupyter-chat-example
2
+
3
+ A simple extension providing a chat side bar.
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2
+ declare const _default: JupyterFrontEndPlugin<void>[];
3
+ export default _default;
package/lib/index.js ADDED
@@ -0,0 +1,98 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { ActiveCellManager, AttachmentOpenerRegistry, buildChatSidebar, ChatModel, SelectionWatcher } from '@jupyter/chat';
6
+ import { IThemeManager } from '@jupyterlab/apputils';
7
+ import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
8
+ import { INotebookTracker } from '@jupyterlab/notebook';
9
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
10
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
11
+ import { UUID } from '@lumino/coreutils';
12
+ class MyChatModel extends ChatModel {
13
+ sendMessage(newMessage) {
14
+ var _a;
15
+ const message = {
16
+ body: newMessage.body,
17
+ id: (_a = newMessage.id) !== null && _a !== void 0 ? _a : UUID.uuid4(),
18
+ type: 'msg',
19
+ time: Date.now() / 1000,
20
+ sender: { username: 'me' },
21
+ attachments: this.input.attachments
22
+ };
23
+ this.messageAdded(message);
24
+ this.input.clearAttachments();
25
+ }
26
+ }
27
+ /*
28
+ * Extension providing a chat panel.
29
+ */
30
+ const plugin = {
31
+ id: 'jupyter-chat-example:plugin',
32
+ description: 'The chat panel widget.',
33
+ autoStart: true,
34
+ requires: [IRenderMimeRegistry],
35
+ optional: [
36
+ IDefaultFileBrowser,
37
+ INotebookTracker,
38
+ ISettingRegistry,
39
+ IThemeManager
40
+ ],
41
+ activate: (app, rmRegistry, filebrowser, notebookTracker, settingRegistry, themeManager) => {
42
+ // Track the current active cell.
43
+ let activeCellManager = null;
44
+ if (notebookTracker) {
45
+ activeCellManager = new ActiveCellManager({
46
+ tracker: notebookTracker,
47
+ shell: app.shell
48
+ });
49
+ }
50
+ // Track the current selection.
51
+ const selectionWatcher = new SelectionWatcher({
52
+ shell: app.shell
53
+ });
54
+ const model = new MyChatModel({ activeCellManager, selectionWatcher });
55
+ // Update the settings when they change.
56
+ function loadSetting(setting) {
57
+ model.config = {
58
+ sendWithShiftEnter: setting.get('sendWithShiftEnter')
59
+ .composite,
60
+ stackMessages: setting.get('stackMessages').composite,
61
+ unreadNotifications: setting.get('unreadNotifications')
62
+ .composite,
63
+ enableCodeToolbar: setting.get('enableCodeToolbar').composite
64
+ };
65
+ }
66
+ // Init the settings.
67
+ if (settingRegistry) {
68
+ // Wait for the application to be restored and for the settings to be loaded.
69
+ Promise.all([
70
+ app.restored,
71
+ settingRegistry.load('jupyter-chat-example:plugin')
72
+ ])
73
+ .then(([, setting]) => {
74
+ // Read the settings
75
+ loadSetting(setting);
76
+ // Listen for the plugin setting changes
77
+ setting.changed.connect(loadSetting);
78
+ })
79
+ .catch(reason => {
80
+ console.error(`Something went wrong when reading the settings.\n${reason}`);
81
+ });
82
+ }
83
+ // Create the attachment opener registry.
84
+ const attachmentOpenerRegistry = new AttachmentOpenerRegistry();
85
+ attachmentOpenerRegistry.set('file', (attachment) => {
86
+ app.commands.execute('docmanager:open', { path: attachment.value });
87
+ });
88
+ const panel = buildChatSidebar({
89
+ model,
90
+ rmRegistry,
91
+ themeManager,
92
+ documentManager: filebrowser === null || filebrowser === void 0 ? void 0 : filebrowser.model.manager,
93
+ attachmentOpenerRegistry
94
+ });
95
+ app.shell.add(panel, 'left');
96
+ }
97
+ };
98
+ export default [plugin];
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "jupyter-chat-example",
3
+ "version": "0.8.0",
4
+ "description": "A chat extension providing a chat as example",
5
+ "keywords": [
6
+ "jupyter",
7
+ "jupyterlab",
8
+ "jupyterlab-extension"
9
+ ],
10
+ "homepage": "https://github.com/jupyterlab/jupyter-chat",
11
+ "bugs": {
12
+ "url": "https://github.com/jupyterlab/jupyter-chat/issues"
13
+ },
14
+ "license": "BSD-3-Clause",
15
+ "author": {
16
+ "name": "Jupyter Development Team",
17
+ "email": "jupyter@googlegroups.com"
18
+ },
19
+ "files": [
20
+ "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21
+ "style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22
+ "src/**/*.{ts,tsx}",
23
+ "schema/*.json"
24
+ ],
25
+ "main": "lib/index.js",
26
+ "types": "lib/index.d.ts",
27
+ "style": "style/index.css",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/jupyterlab/jupyter-chat.git"
31
+ },
32
+ "scripts": {
33
+ "build": "jlpm build:lib && jlpm build:labextension:dev",
34
+ "build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension",
35
+ "build:labextension": "jupyter labextension build .",
36
+ "build:labextension:dev": "jupyter labextension build --development True .",
37
+ "build:lib": "tsc --sourceMap",
38
+ "build:lib:prod": "tsc",
39
+ "clean": "jlpm clean:lib",
40
+ "clean:lib": "rimraf lib tsconfig.tsbuildinfo",
41
+ "clean:lintcache": "rimraf .eslintcache .stylelintcache",
42
+ "clean:labextension": "rimraf jupyterlab_chat/labextension jupyterlab_chat/_version.py",
43
+ "clean:all": "jlpm clean:lib && jlpm clean:labextension && jlpm clean:lintcache",
44
+ "install:extension": "jlpm build"
45
+ },
46
+ "dependencies": {
47
+ "@jupyter/chat": "^0.8.0",
48
+ "@jupyterlab/application": "^4.2.0",
49
+ "@jupyterlab/apputils": "^4.3.0",
50
+ "@jupyterlab/notebook": "^4.2.0",
51
+ "@jupyterlab/rendermime": "^4.2.0",
52
+ "@jupyterlab/settingregistry": "^4.2.0",
53
+ "@lumino/coreutils": "^2.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@jupyterlab/builder": "^4.2.0",
57
+ "@types/json-schema": "^7.0.11",
58
+ "@types/react": "^18.2.0",
59
+ "@types/react-addons-linked-state-mixin": "^0.14.22",
60
+ "css-loader": "^6.7.1",
61
+ "mkdirp": "^1.0.3",
62
+ "npm-run-all": "^4.1.5",
63
+ "rimraf": "^5.0.1",
64
+ "source-map-loader": "^1.0.2",
65
+ "style-loader": "^3.3.1",
66
+ "typescript": "~5.0.2"
67
+ },
68
+ "sideEffects": [
69
+ "style/*.css",
70
+ "style/index.js"
71
+ ],
72
+ "styleModule": "style/index.js",
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "jupyterlab": {
77
+ "discovery": {
78
+ "server": {
79
+ "managers": [
80
+ "pip"
81
+ ],
82
+ "base": {
83
+ "name": "jupyter_chat_example"
84
+ }
85
+ }
86
+ },
87
+ "extension": true,
88
+ "outputDir": "jupyter_chat_example/labextension",
89
+ "schemaDir": "schema",
90
+ "sharedPackages": {
91
+ "@jupyter/chat": {
92
+ "bundled": true,
93
+ "singleton": true
94
+ }
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "title": "Chat",
3
+ "description": "Configuration for the chat widgets",
4
+ "type": "object",
5
+ "properties": {
6
+ "sendWithShiftEnter": {
7
+ "description": "Whether to send a message via Shift-Enter instead of Enter.",
8
+ "type": "boolean",
9
+ "default": false,
10
+ "readOnly": false
11
+ },
12
+ "stackMessages": {
13
+ "description": "Whether to stack consecutive messages from same user.",
14
+ "type": "boolean",
15
+ "default": true,
16
+ "readOnly": false
17
+ },
18
+ "unreadNotifications": {
19
+ "description": "Whether to enable or not the notifications on unread messages.",
20
+ "type": "boolean",
21
+ "default": true,
22
+ "readOnly": false
23
+ },
24
+ "enableCodeToolbar": {
25
+ "description": "Whether to enable or not the code toolbar.",
26
+ "type": "boolean",
27
+ "default": true,
28
+ "readOnly": false
29
+ }
30
+ },
31
+ "additionalProperties": false
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,132 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import {
7
+ ActiveCellManager,
8
+ AttachmentOpenerRegistry,
9
+ buildChatSidebar,
10
+ ChatModel,
11
+ IAttachment,
12
+ IChatMessage,
13
+ INewMessage,
14
+ SelectionWatcher
15
+ } from '@jupyter/chat';
16
+ import {
17
+ JupyterFrontEnd,
18
+ JupyterFrontEndPlugin
19
+ } from '@jupyterlab/application';
20
+ import { IThemeManager } from '@jupyterlab/apputils';
21
+ import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
22
+ import { INotebookTracker } from '@jupyterlab/notebook';
23
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
24
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
25
+ import { UUID } from '@lumino/coreutils';
26
+
27
+ class MyChatModel extends ChatModel {
28
+ sendMessage(
29
+ newMessage: INewMessage
30
+ ): Promise<boolean | void> | boolean | void {
31
+ const message: IChatMessage = {
32
+ body: newMessage.body,
33
+ id: newMessage.id ?? UUID.uuid4(),
34
+ type: 'msg',
35
+ time: Date.now() / 1000,
36
+ sender: { username: 'me' },
37
+ attachments: this.input.attachments
38
+ };
39
+ this.messageAdded(message);
40
+ this.input.clearAttachments();
41
+ }
42
+ }
43
+
44
+ /*
45
+ * Extension providing a chat panel.
46
+ */
47
+ const plugin: JupyterFrontEndPlugin<void> = {
48
+ id: 'jupyter-chat-example:plugin',
49
+ description: 'The chat panel widget.',
50
+ autoStart: true,
51
+ requires: [IRenderMimeRegistry],
52
+ optional: [
53
+ IDefaultFileBrowser,
54
+ INotebookTracker,
55
+ ISettingRegistry,
56
+ IThemeManager
57
+ ],
58
+ activate: (
59
+ app: JupyterFrontEnd,
60
+ rmRegistry: IRenderMimeRegistry,
61
+ filebrowser: IDefaultFileBrowser | null,
62
+ notebookTracker: INotebookTracker | null,
63
+ settingRegistry: ISettingRegistry | null,
64
+ themeManager: IThemeManager | null
65
+ ): void => {
66
+ // Track the current active cell.
67
+ let activeCellManager: ActiveCellManager | null = null;
68
+ if (notebookTracker) {
69
+ activeCellManager = new ActiveCellManager({
70
+ tracker: notebookTracker,
71
+ shell: app.shell
72
+ });
73
+ }
74
+
75
+ // Track the current selection.
76
+ const selectionWatcher = new SelectionWatcher({
77
+ shell: app.shell
78
+ });
79
+
80
+ const model = new MyChatModel({ activeCellManager, selectionWatcher });
81
+
82
+ // Update the settings when they change.
83
+ function loadSetting(setting: ISettingRegistry.ISettings): void {
84
+ model.config = {
85
+ sendWithShiftEnter: setting.get('sendWithShiftEnter')
86
+ .composite as boolean,
87
+ stackMessages: setting.get('stackMessages').composite as boolean,
88
+ unreadNotifications: setting.get('unreadNotifications')
89
+ .composite as boolean,
90
+ enableCodeToolbar: setting.get('enableCodeToolbar').composite as boolean
91
+ };
92
+ }
93
+
94
+ // Init the settings.
95
+ if (settingRegistry) {
96
+ // Wait for the application to be restored and for the settings to be loaded.
97
+ Promise.all([
98
+ app.restored,
99
+ settingRegistry.load('jupyter-chat-example:plugin')
100
+ ])
101
+ .then(([, setting]) => {
102
+ // Read the settings
103
+ loadSetting(setting);
104
+
105
+ // Listen for the plugin setting changes
106
+ setting.changed.connect(loadSetting);
107
+ })
108
+ .catch(reason => {
109
+ console.error(
110
+ `Something went wrong when reading the settings.\n${reason}`
111
+ );
112
+ });
113
+ }
114
+
115
+ // Create the attachment opener registry.
116
+ const attachmentOpenerRegistry = new AttachmentOpenerRegistry();
117
+ attachmentOpenerRegistry.set('file', (attachment: IAttachment) => {
118
+ app.commands.execute('docmanager:open', { path: attachment.value });
119
+ });
120
+
121
+ const panel = buildChatSidebar({
122
+ model,
123
+ rmRegistry,
124
+ themeManager,
125
+ documentManager: filebrowser?.model.manager,
126
+ attachmentOpenerRegistry
127
+ });
128
+ app.shell.add(panel, 'left');
129
+ }
130
+ };
131
+
132
+ export default [plugin];
package/style/base.css ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ /*
7
+ See the JupyterLab Developer Guide for useful CSS Patterns:
8
+
9
+ https://jupyterlab.readthedocs.io/en/stable/developer/css.html
10
+ */
11
+
12
+ @import url('~jupyterlab-chat/style/index.css');
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ @import url('base.css');
package/style/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import './base.css';