@jupyter/chat 0.11.0 → 0.13.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-messages.d.ts +4 -0
- package/lib/components/chat-messages.js +37 -32
- package/lib/components/chat.d.ts +4 -0
- package/lib/components/chat.js +1 -1
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/{markdown-renderer.d.ts → messages/message-renderer.d.ts} +10 -4
- package/lib/components/{markdown-renderer.js → messages/message-renderer.js} +11 -34
- package/lib/components/messages/welcome.d.ts +8 -0
- package/lib/components/messages/welcome.js +41 -0
- package/lib/components/scroll-container.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/input-model.d.ts +9 -0
- package/lib/input-model.js +8 -0
- package/lib/markdown-renderer.d.ts +38 -0
- package/lib/markdown-renderer.js +54 -0
- package/lib/model.d.ts +66 -5
- package/lib/model.js +44 -1
- package/package.json +2 -1
- package/src/components/chat-messages.tsx +50 -35
- package/src/components/chat.tsx +5 -0
- package/src/components/index.ts +0 -1
- package/src/components/{markdown-renderer.tsx → messages/message-renderer.tsx} +16 -42
- package/src/components/messages/welcome.tsx +52 -0
- package/src/components/scroll-container.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/input-model.ts +14 -0
- package/src/markdown-renderer.ts +78 -0
- package/src/model.ts +108 -7
- package/style/chat.css +4 -0
package/src/model.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
7
|
+
import { ArrayExt } from '@lumino/algorithm';
|
|
7
8
|
import { CommandRegistry } from '@lumino/commands';
|
|
8
9
|
import { IDisposable } from '@lumino/disposable';
|
|
9
10
|
import { ISignal, Signal } from '@lumino/signaling';
|
|
@@ -59,6 +60,11 @@ export interface IChatModel extends IDisposable {
|
|
|
59
60
|
*/
|
|
60
61
|
readonly input: IInputModel;
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The current writer list.
|
|
65
|
+
*/
|
|
66
|
+
readonly writers: IChatModel.IWriter[];
|
|
67
|
+
|
|
62
68
|
/**
|
|
63
69
|
* Get the active cell manager.
|
|
64
70
|
*/
|
|
@@ -82,7 +88,7 @@ export interface IChatModel extends IDisposable {
|
|
|
82
88
|
/**
|
|
83
89
|
* A signal emitting when the messages list is updated.
|
|
84
90
|
*/
|
|
85
|
-
|
|
91
|
+
readonly configChanged: ISignal<IChatModel, IConfig>;
|
|
86
92
|
|
|
87
93
|
/**
|
|
88
94
|
* A signal emitting when unread messages change.
|
|
@@ -97,7 +103,12 @@ export interface IChatModel extends IDisposable {
|
|
|
97
103
|
/**
|
|
98
104
|
* A signal emitting when the writers change.
|
|
99
105
|
*/
|
|
100
|
-
readonly writersChanged?: ISignal<IChatModel,
|
|
106
|
+
readonly writersChanged?: ISignal<IChatModel, IChatModel.IWriter[]>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A signal emitting when the message edition input changed change.
|
|
110
|
+
*/
|
|
111
|
+
readonly messageEditionAdded: ISignal<IChatModel, IChatModel.IMessageEdition>;
|
|
101
112
|
|
|
102
113
|
/**
|
|
103
114
|
* Send a message, to be defined depending on the chosen technology.
|
|
@@ -172,12 +183,22 @@ export interface IChatModel extends IDisposable {
|
|
|
172
183
|
/**
|
|
173
184
|
* Update the current writers list.
|
|
174
185
|
*/
|
|
175
|
-
updateWriters(writers:
|
|
186
|
+
updateWriters(writers: IChatModel.IWriter[]): void;
|
|
176
187
|
|
|
177
188
|
/**
|
|
178
189
|
* Create the chat context that will be passed to the input model.
|
|
179
190
|
*/
|
|
180
191
|
createChatContext(): IChatContext;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Get the input model of the edited message, given its id.
|
|
195
|
+
*/
|
|
196
|
+
getEditionModel(messageID: string): IInputModel | undefined;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Add an input model of the edited message.
|
|
200
|
+
*/
|
|
201
|
+
addEditionModel(messageID: string, inputModel: IInputModel): void;
|
|
181
202
|
}
|
|
182
203
|
|
|
183
204
|
/**
|
|
@@ -256,6 +277,13 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
256
277
|
return this._inputModel;
|
|
257
278
|
}
|
|
258
279
|
|
|
280
|
+
/**
|
|
281
|
+
* The current writer list.
|
|
282
|
+
*/
|
|
283
|
+
get writers(): IChatModel.IWriter[] {
|
|
284
|
+
return this._writers;
|
|
285
|
+
}
|
|
286
|
+
|
|
259
287
|
/**
|
|
260
288
|
* Get the active cell manager.
|
|
261
289
|
*/
|
|
@@ -418,10 +446,17 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
418
446
|
/**
|
|
419
447
|
* A signal emitting when the writers change.
|
|
420
448
|
*/
|
|
421
|
-
get writersChanged(): ISignal<IChatModel,
|
|
449
|
+
get writersChanged(): ISignal<IChatModel, IChatModel.IWriter[]> {
|
|
422
450
|
return this._writersChanged;
|
|
423
451
|
}
|
|
424
452
|
|
|
453
|
+
/**
|
|
454
|
+
* A signal emitting when the message edition input changed change.
|
|
455
|
+
*/
|
|
456
|
+
get messageEditionAdded(): ISignal<IChatModel, IChatModel.IMessageEdition> {
|
|
457
|
+
return this._messageEditionAdded;
|
|
458
|
+
}
|
|
459
|
+
|
|
425
460
|
/**
|
|
426
461
|
* Send a message, to be defined depending on the chosen technology.
|
|
427
462
|
* Default to no-op.
|
|
@@ -546,8 +581,18 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
546
581
|
* Update the current writers list.
|
|
547
582
|
* This implementation only propagate the list via a signal.
|
|
548
583
|
*/
|
|
549
|
-
updateWriters(writers:
|
|
550
|
-
|
|
584
|
+
updateWriters(writers: IChatModel.IWriter[]): void {
|
|
585
|
+
const compareWriters = (a: IChatModel.IWriter, b: IChatModel.IWriter) => {
|
|
586
|
+
return (
|
|
587
|
+
a.user.username === b.user.username &&
|
|
588
|
+
a.user.display_name === b.user.display_name &&
|
|
589
|
+
a.messageID === b.messageID
|
|
590
|
+
);
|
|
591
|
+
};
|
|
592
|
+
if (!ArrayExt.shallowEqual(this._writers, writers, compareWriters)) {
|
|
593
|
+
this._writers = writers;
|
|
594
|
+
this._writersChanged.emit(writers);
|
|
595
|
+
}
|
|
551
596
|
}
|
|
552
597
|
|
|
553
598
|
/**
|
|
@@ -555,6 +600,28 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
555
600
|
*/
|
|
556
601
|
abstract createChatContext(): IChatContext;
|
|
557
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Get the input model of the edited message, given its id.
|
|
605
|
+
*/
|
|
606
|
+
getEditionModel(messageID: string): IInputModel | undefined {
|
|
607
|
+
return this._messageEditions.get(messageID);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Add an input model of the edited message.
|
|
612
|
+
*/
|
|
613
|
+
addEditionModel(messageID: string, inputModel: IInputModel): void {
|
|
614
|
+
// Dispose of an hypothetic previous model for this message.
|
|
615
|
+
this.getEditionModel(messageID)?.dispose();
|
|
616
|
+
|
|
617
|
+
this._messageEditions.set(messageID, inputModel);
|
|
618
|
+
this._messageEditionAdded.emit({ id: messageID, model: inputModel });
|
|
619
|
+
|
|
620
|
+
inputModel.onDisposed.connect(() => {
|
|
621
|
+
this._messageEditions.delete(messageID);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
558
625
|
/**
|
|
559
626
|
* Add unread messages to the list.
|
|
560
627
|
* @param indexes - list of new indexes.
|
|
@@ -617,11 +684,17 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
617
684
|
private _selectionWatcher: ISelectionWatcher | null;
|
|
618
685
|
private _documentManager: IDocumentManager | null;
|
|
619
686
|
private _notificationId: string | null = null;
|
|
687
|
+
private _writers: IChatModel.IWriter[] = [];
|
|
688
|
+
private _messageEditions = new Map<string, IInputModel>();
|
|
620
689
|
private _messagesUpdated = new Signal<IChatModel, void>(this);
|
|
621
690
|
private _configChanged = new Signal<IChatModel, IConfig>(this);
|
|
622
691
|
private _unreadChanged = new Signal<IChatModel, number[]>(this);
|
|
623
692
|
private _viewportChanged = new Signal<IChatModel, number[]>(this);
|
|
624
|
-
private _writersChanged = new Signal<IChatModel,
|
|
693
|
+
private _writersChanged = new Signal<IChatModel, IChatModel.IWriter[]>(this);
|
|
694
|
+
private _messageEditionAdded = new Signal<
|
|
695
|
+
IChatModel,
|
|
696
|
+
IChatModel.IMessageEdition
|
|
697
|
+
>(this);
|
|
625
698
|
}
|
|
626
699
|
|
|
627
700
|
/**
|
|
@@ -662,6 +735,34 @@ export namespace IChatModel {
|
|
|
662
735
|
*/
|
|
663
736
|
documentManager?: IDocumentManager | null;
|
|
664
737
|
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Representation of a message edition.
|
|
741
|
+
*/
|
|
742
|
+
export interface IMessageEdition {
|
|
743
|
+
/**
|
|
744
|
+
* The id of the edited message.
|
|
745
|
+
*/
|
|
746
|
+
id: string;
|
|
747
|
+
/**
|
|
748
|
+
* The model of the input editing the message.
|
|
749
|
+
*/
|
|
750
|
+
model: IInputModel;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Writer interface, including the message ID if the writer is editing a message.
|
|
755
|
+
*/
|
|
756
|
+
export interface IWriter {
|
|
757
|
+
/**
|
|
758
|
+
* The user currently writing.
|
|
759
|
+
*/
|
|
760
|
+
user: IUser;
|
|
761
|
+
/**
|
|
762
|
+
* The message ID (optional)
|
|
763
|
+
*/
|
|
764
|
+
messageID?: string;
|
|
765
|
+
}
|
|
665
766
|
}
|
|
666
767
|
|
|
667
768
|
/**
|
package/style/chat.css
CHANGED
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
* See: https://jupyterlab.readthedocs.io/en/latest/extension/extension_migration.html#css-styling
|
|
27
27
|
* See also: https://github.com/jupyterlab/jupyter-ai/issues/1090
|
|
28
28
|
*/
|
|
29
|
+
.jp-ThemedContainer .jp-chat-rendered-markdown.jp-chat-welcome-message {
|
|
30
|
+
padding: 0 1em;
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
.jp-ThemedContainer .jp-chat-rendered-markdown .jp-RenderedHTMLCommon {
|
|
30
34
|
padding-right: 0;
|
|
31
35
|
}
|