@jupyter/chat 0.8.0 → 0.9.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/lib/components/chat-input.d.ts +3 -11
- package/lib/components/chat-input.js +26 -40
- package/lib/components/chat-messages.d.ts +17 -4
- package/lib/components/chat-messages.js +9 -9
- package/lib/components/chat.d.ts +5 -5
- package/lib/components/chat.js +9 -8
- package/lib/components/code-blocks/copy-button.js +6 -3
- package/lib/components/input/buttons/attach-button.d.ts +6 -0
- package/lib/components/input/{attach-button.js → buttons/attach-button.js} +11 -8
- package/lib/components/input/buttons/cancel-button.d.ts +6 -0
- package/lib/components/input/{cancel-button.js → buttons/cancel-button.js} +5 -7
- package/lib/components/input/buttons/index.d.ts +3 -0
- package/lib/components/input/buttons/index.js +7 -0
- package/lib/components/input/buttons/send-button.d.ts +6 -0
- package/lib/components/input/{send-button.js → buttons/send-button.js} +52 -42
- package/lib/components/input/index.d.ts +3 -3
- package/lib/components/input/index.js +3 -3
- package/lib/components/input/toolbar-registry.d.ts +98 -0
- package/lib/components/input/toolbar-registry.js +85 -0
- package/lib/components/input/use-chat-commands.js +3 -2
- package/lib/components/mui-extras/tooltipped-button.d.ts +1 -1
- package/lib/components/mui-extras/tooltipped-button.js +3 -2
- package/lib/components/mui-extras/tooltipped-icon-button.js +4 -2
- package/lib/input-model.d.ts +41 -0
- package/lib/input-model.js +17 -1
- package/lib/model.d.ts +22 -0
- package/lib/model.js +18 -2
- package/lib/types.d.ts +0 -18
- package/lib/widgets/chat-widget.d.ts +5 -1
- package/lib/widgets/chat-widget.js +7 -1
- package/package.json +1 -1
- package/src/components/chat-input.tsx +40 -65
- package/src/components/chat-messages.tsx +31 -14
- package/src/components/chat.tsx +12 -21
- package/src/components/code-blocks/copy-button.tsx +9 -3
- package/src/components/input/{attach-button.tsx → buttons/attach-button.tsx} +15 -20
- package/src/components/input/{cancel-button.tsx → buttons/cancel-button.tsx} +9 -16
- package/src/components/input/buttons/index.ts +8 -0
- package/src/components/input/{send-button.tsx → buttons/send-button.tsx} +62 -61
- package/src/components/input/index.ts +3 -3
- package/src/components/input/toolbar-registry.tsx +162 -0
- package/src/components/input/use-chat-commands.tsx +8 -2
- package/src/components/mui-extras/tooltipped-button.tsx +4 -2
- package/src/components/mui-extras/tooltipped-icon-button.tsx +5 -2
- package/src/input-model.ts +58 -1
- package/src/model.ts +36 -2
- package/src/types.ts +0 -21
- package/src/widgets/chat-widget.tsx +8 -1
- package/style/base.css +1 -0
- package/style/chat.css +10 -0
- package/style/input.css +32 -0
- package/lib/components/input/attach-button.d.ts +0 -14
- package/lib/components/input/cancel-button.d.ts +0 -11
- package/lib/components/input/send-button.d.ts +0 -18
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IInputModel } from '../../input-model';
|
|
3
|
+
import { ISignal } from '@lumino/signaling';
|
|
4
|
+
/**
|
|
5
|
+
* The toolbar registry interface.
|
|
6
|
+
*/
|
|
7
|
+
export interface IInputToolbarRegistry {
|
|
8
|
+
/**
|
|
9
|
+
* A signal emitting when the items has changed.
|
|
10
|
+
*/
|
|
11
|
+
readonly itemsChanged: ISignal<IInputToolbarRegistry, void>;
|
|
12
|
+
/**
|
|
13
|
+
* Get a toolbar item.
|
|
14
|
+
*/
|
|
15
|
+
get(name: string): InputToolbarRegistry.IToolbarItem | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Get the list of the visible toolbar items in order.
|
|
18
|
+
*/
|
|
19
|
+
getItems(): InputToolbarRegistry.IToolbarItem[];
|
|
20
|
+
/**
|
|
21
|
+
* Add a toolbar item.
|
|
22
|
+
*/
|
|
23
|
+
addItem(name: string, item: InputToolbarRegistry.IToolbarItem): void;
|
|
24
|
+
/**
|
|
25
|
+
* Hide an element.
|
|
26
|
+
*/
|
|
27
|
+
hide(name: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Show an element.
|
|
30
|
+
*/
|
|
31
|
+
show(name: string): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The toolbar registry implementation.
|
|
35
|
+
*/
|
|
36
|
+
export declare class InputToolbarRegistry implements IInputToolbarRegistry {
|
|
37
|
+
/**
|
|
38
|
+
* A signal emitting when the items has changed.
|
|
39
|
+
*/
|
|
40
|
+
get itemsChanged(): ISignal<IInputToolbarRegistry, void>;
|
|
41
|
+
/**
|
|
42
|
+
* Get a toolbar item.
|
|
43
|
+
*/
|
|
44
|
+
get(name: string): InputToolbarRegistry.IToolbarItem | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get the list of the visible toolbar items in order.
|
|
47
|
+
*/
|
|
48
|
+
getItems(): InputToolbarRegistry.IToolbarItem[];
|
|
49
|
+
/**
|
|
50
|
+
* Add a toolbar item.
|
|
51
|
+
*/
|
|
52
|
+
addItem(name: string, item: InputToolbarRegistry.IToolbarItem): void;
|
|
53
|
+
/**
|
|
54
|
+
* Hide an element.
|
|
55
|
+
*/
|
|
56
|
+
hide(name: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Show an element.
|
|
59
|
+
*/
|
|
60
|
+
show(name: string): void;
|
|
61
|
+
private _items;
|
|
62
|
+
private _itemsChanged;
|
|
63
|
+
}
|
|
64
|
+
export declare namespace InputToolbarRegistry {
|
|
65
|
+
/**
|
|
66
|
+
* The toolbar item interface.
|
|
67
|
+
*/
|
|
68
|
+
interface IToolbarItem {
|
|
69
|
+
/**
|
|
70
|
+
* The react functional component with the button.
|
|
71
|
+
*
|
|
72
|
+
* NOTE:
|
|
73
|
+
* This component must be a TooltippedButton for a good integration in the toolbar.
|
|
74
|
+
*/
|
|
75
|
+
element: React.FunctionComponent<IToolbarItemProps>;
|
|
76
|
+
/**
|
|
77
|
+
* The position of the button in the toolbar.
|
|
78
|
+
*/
|
|
79
|
+
position: number;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the button is hidden or not.
|
|
82
|
+
*/
|
|
83
|
+
hidden?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The toolbar item properties, send to the button.
|
|
87
|
+
*/
|
|
88
|
+
interface IToolbarItemProps {
|
|
89
|
+
/**
|
|
90
|
+
* The input model of the input component including the button.
|
|
91
|
+
*/
|
|
92
|
+
model: IInputModel;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The default toolbar registry if none is provided.
|
|
96
|
+
*/
|
|
97
|
+
function defaultToolbarRegistry(): InputToolbarRegistry;
|
|
98
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AttachButton, CancelButton, SendButton } from './buttons';
|
|
2
|
+
import { Signal } from '@lumino/signaling';
|
|
3
|
+
/**
|
|
4
|
+
* The toolbar registry implementation.
|
|
5
|
+
*/
|
|
6
|
+
export class InputToolbarRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._items = new Map();
|
|
9
|
+
this._itemsChanged = new Signal(this);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A signal emitting when the items has changed.
|
|
13
|
+
*/
|
|
14
|
+
get itemsChanged() {
|
|
15
|
+
return this._itemsChanged;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get a toolbar item.
|
|
19
|
+
*/
|
|
20
|
+
get(name) {
|
|
21
|
+
return this._items.get(name);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the list of the visible toolbar items in order.
|
|
25
|
+
*/
|
|
26
|
+
getItems() {
|
|
27
|
+
return Array.from(this._items.values())
|
|
28
|
+
.filter(item => !item.hidden)
|
|
29
|
+
.sort((a, b) => a.position - b.position);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Add a toolbar item.
|
|
33
|
+
*/
|
|
34
|
+
addItem(name, item) {
|
|
35
|
+
if (!this._items.has(name)) {
|
|
36
|
+
this._items.set(name, item);
|
|
37
|
+
this._itemsChanged.emit();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.warn(`A chat input toolbar item '${name}' is already registered`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hide an element.
|
|
45
|
+
*/
|
|
46
|
+
hide(name) {
|
|
47
|
+
const item = this._items.get(name);
|
|
48
|
+
if (item) {
|
|
49
|
+
item.hidden = true;
|
|
50
|
+
this._itemsChanged.emit();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Show an element.
|
|
55
|
+
*/
|
|
56
|
+
show(name) {
|
|
57
|
+
const item = this._items.get(name);
|
|
58
|
+
if (item) {
|
|
59
|
+
item.hidden = false;
|
|
60
|
+
this._itemsChanged.emit();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
(function (InputToolbarRegistry) {
|
|
65
|
+
/**
|
|
66
|
+
* The default toolbar registry if none is provided.
|
|
67
|
+
*/
|
|
68
|
+
function defaultToolbarRegistry() {
|
|
69
|
+
const registry = new InputToolbarRegistry();
|
|
70
|
+
registry.addItem('send', {
|
|
71
|
+
element: SendButton,
|
|
72
|
+
position: 100
|
|
73
|
+
});
|
|
74
|
+
registry.addItem('attach', {
|
|
75
|
+
element: AttachButton,
|
|
76
|
+
position: 20
|
|
77
|
+
});
|
|
78
|
+
registry.addItem('cancel', {
|
|
79
|
+
element: CancelButton,
|
|
80
|
+
position: 10
|
|
81
|
+
});
|
|
82
|
+
return registry;
|
|
83
|
+
}
|
|
84
|
+
InputToolbarRegistry.defaultToolbarRegistry = defaultToolbarRegistry;
|
|
85
|
+
})(InputToolbarRegistry || (InputToolbarRegistry = {}));
|
|
@@ -87,8 +87,9 @@ export function useChatCommands(inputModel, chatCommandRegistry) {
|
|
|
87
87
|
return (React.createElement(Box, { key: key, component: "li", ...listItemProps },
|
|
88
88
|
commandIcon,
|
|
89
89
|
React.createElement("p", { className: "jp-chat-command-name" }, command.name),
|
|
90
|
-
React.createElement(
|
|
91
|
-
|
|
90
|
+
command.description && (React.createElement(React.Fragment, null,
|
|
91
|
+
React.createElement("span", null, " - "),
|
|
92
|
+
React.createElement("p", { className: "jp-chat-command-description" }, command.description)))));
|
|
92
93
|
},
|
|
93
94
|
// always show all options, since command providers should exclusively
|
|
94
95
|
// define what commands are added to the menu.
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Jupyter Development Team.
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
|
-
import React from 'react';
|
|
6
5
|
import { Button } from '@mui/material';
|
|
6
|
+
import React from 'react';
|
|
7
7
|
import { ContrastingTooltip } from './contrasting-tooltip';
|
|
8
|
+
const TOOLTIPPED_WRAP_CLASS = 'jp-chat-tooltipped-wrap';
|
|
8
9
|
/**
|
|
9
10
|
* A component that renders an MUI `Button` with a high-contrast tooltip
|
|
10
11
|
* provided by `ContrastingTooltip`. This component differs from the MUI
|
|
@@ -34,7 +35,7 @@ export function TooltippedButton(props) {
|
|
|
34
35
|
]
|
|
35
36
|
}
|
|
36
37
|
} },
|
|
37
|
-
React.createElement("span", { style: { cursor: 'default' } },
|
|
38
|
+
React.createElement("span", { style: { cursor: 'default' }, className: TOOLTIPPED_WRAP_CLASS },
|
|
38
39
|
React.createElement(Button, { ...props.buttonProps, onClick: props.onClick, disabled: props.disabled, sx: {
|
|
39
40
|
lineHeight: 0,
|
|
40
41
|
...(props.disabled && { opacity: 0.5 }),
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Jupyter Development Team.
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { classes } from '@jupyterlab/ui-components';
|
|
6
6
|
import { IconButton } from '@mui/material';
|
|
7
|
+
import React from 'react';
|
|
7
8
|
import { ContrastingTooltip } from './contrasting-tooltip';
|
|
9
|
+
const TOOLTIPPED_WRAP_CLASS = 'jp-chat-tooltipped-wrap';
|
|
8
10
|
/**
|
|
9
11
|
* A component that renders an MUI `IconButton` with a high-contrast tooltip
|
|
10
12
|
* provided by `ContrastingTooltip`. This component differs from the MUI
|
|
@@ -31,7 +33,7 @@ export function TooltippedIconButton(props) {
|
|
|
31
33
|
]
|
|
32
34
|
}
|
|
33
35
|
} },
|
|
34
|
-
React.createElement("span", { className: props.className },
|
|
36
|
+
React.createElement("span", { className: classes(props.className, TOOLTIPPED_WRAP_CLASS) },
|
|
35
37
|
React.createElement(IconButton, { ...props.iconButtonProps, onClick: props.onClick, disabled: props.disabled, sx: {
|
|
36
38
|
marginLeft: '8px',
|
|
37
39
|
lineHeight: 0,
|
package/lib/input-model.d.ts
CHANGED
|
@@ -3,10 +3,19 @@ import { ISignal } from '@lumino/signaling';
|
|
|
3
3
|
import { IActiveCellManager } from './active-cell-manager';
|
|
4
4
|
import { ISelectionWatcher } from './selection-watcher';
|
|
5
5
|
import { IAttachment } from './types';
|
|
6
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
6
7
|
/**
|
|
7
8
|
* The chat input interface.
|
|
8
9
|
*/
|
|
9
10
|
export interface IInputModel extends IDisposable {
|
|
11
|
+
/**
|
|
12
|
+
* Function to send a message.
|
|
13
|
+
*/
|
|
14
|
+
send: (content: string) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Optional function to cancel edition.
|
|
17
|
+
*/
|
|
18
|
+
cancel: (() => void) | undefined;
|
|
10
19
|
/**
|
|
11
20
|
* The entire input value.
|
|
12
21
|
*/
|
|
@@ -40,6 +49,10 @@ export interface IInputModel extends IDisposable {
|
|
|
40
49
|
* Get the selection watcher.
|
|
41
50
|
*/
|
|
42
51
|
readonly selectionWatcher: ISelectionWatcher | null;
|
|
52
|
+
/**
|
|
53
|
+
* Get the document manager.
|
|
54
|
+
*/
|
|
55
|
+
readonly documentManager: IDocumentManager | null;
|
|
43
56
|
/**
|
|
44
57
|
* The input configuration.
|
|
45
58
|
*/
|
|
@@ -86,6 +99,14 @@ export interface IInputModel extends IDisposable {
|
|
|
86
99
|
*/
|
|
87
100
|
export declare class InputModel implements IInputModel {
|
|
88
101
|
constructor(options: InputModel.IOptions);
|
|
102
|
+
/**
|
|
103
|
+
* Function to send a message.
|
|
104
|
+
*/
|
|
105
|
+
send: (input: string) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Optional function to cancel edition.
|
|
108
|
+
*/
|
|
109
|
+
cancel: (() => void) | undefined;
|
|
89
110
|
/**
|
|
90
111
|
* The entire input value.
|
|
91
112
|
*/
|
|
@@ -120,6 +141,10 @@ export declare class InputModel implements IInputModel {
|
|
|
120
141
|
* Get the selection watcher.
|
|
121
142
|
*/
|
|
122
143
|
get selectionWatcher(): ISelectionWatcher | null;
|
|
144
|
+
/**
|
|
145
|
+
* Get the document manager.
|
|
146
|
+
*/
|
|
147
|
+
get documentManager(): IDocumentManager | null;
|
|
123
148
|
/**
|
|
124
149
|
* The input configuration.
|
|
125
150
|
*/
|
|
@@ -169,12 +194,14 @@ export declare class InputModel implements IInputModel {
|
|
|
169
194
|
* Whether the input model is disposed.
|
|
170
195
|
*/
|
|
171
196
|
get isDisposed(): boolean;
|
|
197
|
+
private _onSend;
|
|
172
198
|
private _value;
|
|
173
199
|
private _cursorIndex;
|
|
174
200
|
private _currentWord;
|
|
175
201
|
private _attachments;
|
|
176
202
|
private _activeCellManager;
|
|
177
203
|
private _selectionWatcher;
|
|
204
|
+
private _documentManager;
|
|
178
205
|
private _config;
|
|
179
206
|
private _valueChanged;
|
|
180
207
|
private _cursorIndexChanged;
|
|
@@ -186,6 +213,16 @@ export declare class InputModel implements IInputModel {
|
|
|
186
213
|
}
|
|
187
214
|
export declare namespace InputModel {
|
|
188
215
|
interface IOptions {
|
|
216
|
+
/**
|
|
217
|
+
* The function that should send the message.
|
|
218
|
+
* @param content - the content of the message.
|
|
219
|
+
* @param model - the model of the input sending the message.
|
|
220
|
+
*/
|
|
221
|
+
onSend: (content: string, model?: InputModel) => void;
|
|
222
|
+
/**
|
|
223
|
+
* Function that should cancel the message edition.
|
|
224
|
+
*/
|
|
225
|
+
onCancel?: () => void;
|
|
189
226
|
/**
|
|
190
227
|
* The initial value of the input.
|
|
191
228
|
*/
|
|
@@ -211,6 +248,10 @@ export declare namespace InputModel {
|
|
|
211
248
|
* Selection watcher.
|
|
212
249
|
*/
|
|
213
250
|
selectionWatcher?: ISelectionWatcher | null;
|
|
251
|
+
/**
|
|
252
|
+
* Document manager.
|
|
253
|
+
*/
|
|
254
|
+
documentManager?: IDocumentManager | null;
|
|
214
255
|
}
|
|
215
256
|
interface IConfig {
|
|
216
257
|
/**
|
package/lib/input-model.js
CHANGED
|
@@ -9,7 +9,14 @@ const WHITESPACE = new Set([' ', '\n', '\t']);
|
|
|
9
9
|
*/
|
|
10
10
|
export class InputModel {
|
|
11
11
|
constructor(options) {
|
|
12
|
-
var _a, _b;
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
/**
|
|
14
|
+
* Function to send a message.
|
|
15
|
+
*/
|
|
16
|
+
this.send = (input) => {
|
|
17
|
+
this._onSend(input, this);
|
|
18
|
+
this.value = '';
|
|
19
|
+
};
|
|
13
20
|
/**
|
|
14
21
|
* Add attachment to send with next message.
|
|
15
22
|
*/
|
|
@@ -48,14 +55,17 @@ export class InputModel {
|
|
|
48
55
|
this._focusInputSignal = new Signal(this);
|
|
49
56
|
this._attachmentsChanged = new Signal(this);
|
|
50
57
|
this._isDisposed = false;
|
|
58
|
+
this._onSend = options.onSend;
|
|
51
59
|
this._value = options.value || '';
|
|
52
60
|
this._attachments = options.attachments || [];
|
|
53
61
|
this.cursorIndex = options.cursorIndex || this.value.length;
|
|
54
62
|
this._activeCellManager = (_a = options.activeCellManager) !== null && _a !== void 0 ? _a : null;
|
|
55
63
|
this._selectionWatcher = (_b = options.selectionWatcher) !== null && _b !== void 0 ? _b : null;
|
|
64
|
+
this._documentManager = (_c = options.documentManager) !== null && _c !== void 0 ? _c : null;
|
|
56
65
|
this._config = {
|
|
57
66
|
...options.config
|
|
58
67
|
};
|
|
68
|
+
this.cancel = options.onCancel;
|
|
59
69
|
}
|
|
60
70
|
/**
|
|
61
71
|
* The entire input value.
|
|
@@ -124,6 +134,12 @@ export class InputModel {
|
|
|
124
134
|
get selectionWatcher() {
|
|
125
135
|
return this._selectionWatcher;
|
|
126
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Get the document manager.
|
|
139
|
+
*/
|
|
140
|
+
get documentManager() {
|
|
141
|
+
return this._documentManager;
|
|
142
|
+
}
|
|
127
143
|
/**
|
|
128
144
|
* The input configuration.
|
|
129
145
|
*/
|
package/lib/model.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
1
2
|
import { CommandRegistry } from '@lumino/commands';
|
|
2
3
|
import { IDisposable } from '@lumino/disposable';
|
|
3
4
|
import { ISignal } from '@lumino/signaling';
|
|
@@ -45,6 +46,10 @@ export interface IChatModel extends IDisposable {
|
|
|
45
46
|
* Get the selection watcher.
|
|
46
47
|
*/
|
|
47
48
|
readonly selectionWatcher: ISelectionWatcher | null;
|
|
49
|
+
/**
|
|
50
|
+
* Get the selection watcher.
|
|
51
|
+
*/
|
|
52
|
+
readonly documentManager: IDocumentManager | null;
|
|
48
53
|
/**
|
|
49
54
|
* A signal emitting when the messages list is updated.
|
|
50
55
|
*/
|
|
@@ -73,6 +78,10 @@ export interface IChatModel extends IDisposable {
|
|
|
73
78
|
* @returns whether the message has been sent or not, or nothing if not needed.
|
|
74
79
|
*/
|
|
75
80
|
sendMessage(message: INewMessage): Promise<boolean | void> | boolean | void;
|
|
81
|
+
/**
|
|
82
|
+
* Clear the message list.
|
|
83
|
+
*/
|
|
84
|
+
clearMessages(): void;
|
|
76
85
|
/**
|
|
77
86
|
* Optional, to update a message from the chat panel.
|
|
78
87
|
*
|
|
@@ -159,6 +168,10 @@ export declare class ChatModel implements IChatModel {
|
|
|
159
168
|
* Get the selection watcher.
|
|
160
169
|
*/
|
|
161
170
|
get selectionWatcher(): ISelectionWatcher | null;
|
|
171
|
+
/**
|
|
172
|
+
* Get the document manager.
|
|
173
|
+
*/
|
|
174
|
+
get documentManager(): IDocumentManager | null;
|
|
162
175
|
/**
|
|
163
176
|
* Timestamp of the last read message in local storage.
|
|
164
177
|
*/
|
|
@@ -207,6 +220,10 @@ export declare class ChatModel implements IChatModel {
|
|
|
207
220
|
* @returns whether the message has been sent or not.
|
|
208
221
|
*/
|
|
209
222
|
sendMessage(message: INewMessage): Promise<boolean | void> | boolean | void;
|
|
223
|
+
/**
|
|
224
|
+
* Clear the message list.
|
|
225
|
+
*/
|
|
226
|
+
clearMessages(): void;
|
|
210
227
|
/**
|
|
211
228
|
* Dispose the chat model.
|
|
212
229
|
*/
|
|
@@ -271,6 +288,7 @@ export declare class ChatModel implements IChatModel {
|
|
|
271
288
|
private _commands?;
|
|
272
289
|
private _activeCellManager;
|
|
273
290
|
private _selectionWatcher;
|
|
291
|
+
private _documentManager;
|
|
274
292
|
private _notificationId;
|
|
275
293
|
private _messagesUpdated;
|
|
276
294
|
private _configChanged;
|
|
@@ -306,5 +324,9 @@ export declare namespace ChatModel {
|
|
|
306
324
|
* Selection watcher.
|
|
307
325
|
*/
|
|
308
326
|
selectionWatcher?: ISelectionWatcher | null;
|
|
327
|
+
/**
|
|
328
|
+
* Document manager.
|
|
329
|
+
*/
|
|
330
|
+
documentManager?: IDocumentManager | null;
|
|
309
331
|
}
|
|
310
332
|
}
|
package/lib/model.js
CHANGED
|
@@ -14,7 +14,7 @@ export class ChatModel {
|
|
|
14
14
|
* Create a new chat model.
|
|
15
15
|
*/
|
|
16
16
|
constructor(options = {}) {
|
|
17
|
-
var _a, _b, _c;
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
18
|
this._messages = [];
|
|
19
19
|
this._unreadMessages = [];
|
|
20
20
|
this._messagesInViewport = [];
|
|
@@ -39,13 +39,16 @@ export class ChatModel {
|
|
|
39
39
|
this._inputModel = new InputModel({
|
|
40
40
|
activeCellManager: options.activeCellManager,
|
|
41
41
|
selectionWatcher: options.selectionWatcher,
|
|
42
|
+
documentManager: options.documentManager,
|
|
42
43
|
config: {
|
|
43
44
|
sendWithShiftEnter: config.sendWithShiftEnter
|
|
44
|
-
}
|
|
45
|
+
},
|
|
46
|
+
onSend: (input) => this.sendMessage({ body: input })
|
|
45
47
|
});
|
|
46
48
|
this._commands = options.commands;
|
|
47
49
|
this._activeCellManager = (_b = options.activeCellManager) !== null && _b !== void 0 ? _b : null;
|
|
48
50
|
this._selectionWatcher = (_c = options.selectionWatcher) !== null && _c !== void 0 ? _c : null;
|
|
51
|
+
this._documentManager = (_d = options.documentManager) !== null && _d !== void 0 ? _d : null;
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
54
|
* The chat model id.
|
|
@@ -89,6 +92,12 @@ export class ChatModel {
|
|
|
89
92
|
get selectionWatcher() {
|
|
90
93
|
return this._selectionWatcher;
|
|
91
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the document manager.
|
|
97
|
+
*/
|
|
98
|
+
get documentManager() {
|
|
99
|
+
return this._documentManager;
|
|
100
|
+
}
|
|
92
101
|
/**
|
|
93
102
|
* Timestamp of the last read message in local storage.
|
|
94
103
|
*/
|
|
@@ -219,6 +228,13 @@ export class ChatModel {
|
|
|
219
228
|
* @returns whether the message has been sent or not.
|
|
220
229
|
*/
|
|
221
230
|
sendMessage(message) { }
|
|
231
|
+
/**
|
|
232
|
+
* Clear the message list.
|
|
233
|
+
*/
|
|
234
|
+
clearMessages() {
|
|
235
|
+
this._messages = [];
|
|
236
|
+
this._messagesUpdated.emit();
|
|
237
|
+
}
|
|
222
238
|
/**
|
|
223
239
|
* Dispose the chat model.
|
|
224
240
|
*/
|
package/lib/types.d.ts
CHANGED
|
@@ -84,21 +84,3 @@ export interface IAttachment {
|
|
|
84
84
|
*/
|
|
85
85
|
export interface ISettings {
|
|
86
86
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Representation of a selected text.
|
|
89
|
-
*/
|
|
90
|
-
export type TextSelection = {
|
|
91
|
-
type: 'text';
|
|
92
|
-
source: string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Representation of a selected cell.
|
|
96
|
-
*/
|
|
97
|
-
export type CellSelection = {
|
|
98
|
-
type: 'cell';
|
|
99
|
-
source: string;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Selection object (text or cell).
|
|
103
|
-
*/
|
|
104
|
-
export type Selection = TextSelection | CellSelection;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Chat } from '../components
|
|
3
|
+
import { Chat, IInputToolbarRegistry } from '../components';
|
|
4
4
|
import { IChatModel } from '../model';
|
|
5
5
|
export declare class ChatWidget extends ReactWidget {
|
|
6
6
|
constructor(options: Chat.IOptions);
|
|
@@ -8,6 +8,10 @@ export declare class ChatWidget extends ReactWidget {
|
|
|
8
8
|
* Get the model of the widget.
|
|
9
9
|
*/
|
|
10
10
|
get model(): IChatModel;
|
|
11
|
+
/**
|
|
12
|
+
* Get the input toolbar registry (if it has been provided when creating the widget).
|
|
13
|
+
*/
|
|
14
|
+
get inputToolbarRegistry(): IInputToolbarRegistry | undefined;
|
|
11
15
|
render(): React.JSX.Element;
|
|
12
16
|
private _chatOptions;
|
|
13
17
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { Chat } from '../components
|
|
7
|
+
import { Chat } from '../components';
|
|
8
8
|
import { chatIcon } from '../icons';
|
|
9
9
|
export class ChatWidget extends ReactWidget {
|
|
10
10
|
constructor(options) {
|
|
@@ -21,6 +21,12 @@ export class ChatWidget extends ReactWidget {
|
|
|
21
21
|
get model() {
|
|
22
22
|
return this._chatOptions.model;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the input toolbar registry (if it has been provided when creating the widget).
|
|
26
|
+
*/
|
|
27
|
+
get inputToolbarRegistry() {
|
|
28
|
+
return this._chatOptions.inputToolbarRegistry;
|
|
29
|
+
}
|
|
24
30
|
render() {
|
|
25
31
|
// The model need to be passed, otherwise it is undefined in the widget in
|
|
26
32
|
// the case of collaborative document.
|