@jupyter/chat 0.25.0-alpha.3 → 0.25.0-alpha.5
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/model.d.ts +17 -9
- package/lib/model.js +16 -5
- package/package.json +1 -1
- package/src/model.ts +30 -13
package/lib/model.d.ts
CHANGED
|
@@ -29,9 +29,11 @@ export interface IChatModel extends IDisposable {
|
|
|
29
29
|
*/
|
|
30
30
|
unreadMessages: number[];
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* A promise that resolves, once the model is ready, with the chat's stable
|
|
33
|
+
* id. The id matches the backend's `chat.get_id()` and is guaranteed to be
|
|
34
|
+
* available (and never change) from this point on.
|
|
33
35
|
*/
|
|
34
|
-
readonly ready: Promise<
|
|
36
|
+
readonly ready: Promise<string>;
|
|
35
37
|
/**
|
|
36
38
|
* The awareness channel of the underlying shared document, when the chat is
|
|
37
39
|
* backed by one. Lets extensions read collaborative state attached to the
|
|
@@ -257,13 +259,17 @@ export declare abstract class AbstractChatModel implements IChatModel {
|
|
|
257
259
|
get lastRead(): number;
|
|
258
260
|
set lastRead(value: number);
|
|
259
261
|
/**
|
|
260
|
-
* Promise that resolves when the model is ready.
|
|
262
|
+
* Promise that resolves, when the model is ready, with the chat's stable id.
|
|
261
263
|
*/
|
|
262
|
-
get ready(): Promise<
|
|
264
|
+
get ready(): Promise<string>;
|
|
263
265
|
/**
|
|
264
|
-
*
|
|
266
|
+
* Mark the model as ready, resolving `ready` with the chat's stable id.
|
|
267
|
+
*
|
|
268
|
+
* The id must match the backend's `chat.get_id()`; callers pass the
|
|
269
|
+
* server-authoritative id (WebSocket connection frame, or the synchronized
|
|
270
|
+
* shared-document metadata under RTC).
|
|
265
271
|
*/
|
|
266
|
-
protected setReady(): void;
|
|
272
|
+
protected setReady(id: string): void;
|
|
267
273
|
/**
|
|
268
274
|
* The chat settings.
|
|
269
275
|
*/
|
|
@@ -523,9 +529,11 @@ export declare namespace IChatModel {
|
|
|
523
529
|
*/
|
|
524
530
|
export interface IChatContext {
|
|
525
531
|
/**
|
|
526
|
-
* The
|
|
532
|
+
* The chat's stable id. Always available: a chat context is only created once
|
|
533
|
+
* the model is `ready`, at which point the id is guaranteed to be set (and to
|
|
534
|
+
* match the backend's `chat.get_id()`).
|
|
527
535
|
*/
|
|
528
|
-
readonly id
|
|
536
|
+
readonly id: string;
|
|
529
537
|
/**
|
|
530
538
|
* The name of the chat.
|
|
531
539
|
*/
|
|
@@ -556,7 +564,7 @@ export declare abstract class AbstractChatContext implements IChatContext {
|
|
|
556
564
|
constructor(options: {
|
|
557
565
|
model: IChatModel;
|
|
558
566
|
});
|
|
559
|
-
get id(): string
|
|
567
|
+
get id(): string;
|
|
560
568
|
get name(): string;
|
|
561
569
|
get messages(): IMessageContent[];
|
|
562
570
|
get user(): IUser | undefined;
|
package/lib/model.js
CHANGED
|
@@ -151,16 +151,20 @@ export class AbstractChatModel {
|
|
|
151
151
|
localStorage.setItem(`@jupyter/chat:${this._id}`, JSON.stringify(storage));
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
|
-
* Promise that resolves when the model is ready.
|
|
154
|
+
* Promise that resolves, when the model is ready, with the chat's stable id.
|
|
155
155
|
*/
|
|
156
156
|
get ready() {
|
|
157
157
|
return this._readyDelegate.promise;
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
160
|
+
* Mark the model as ready, resolving `ready` with the chat's stable id.
|
|
161
|
+
*
|
|
162
|
+
* The id must match the backend's `chat.get_id()`; callers pass the
|
|
163
|
+
* server-authoritative id (WebSocket connection frame, or the synchronized
|
|
164
|
+
* shared-document metadata under RTC).
|
|
161
165
|
*/
|
|
162
|
-
setReady() {
|
|
163
|
-
this._readyDelegate.resolve();
|
|
166
|
+
setReady(id) {
|
|
167
|
+
this._readyDelegate.resolve(id);
|
|
164
168
|
}
|
|
165
169
|
/**
|
|
166
170
|
* The chat settings.
|
|
@@ -533,7 +537,14 @@ export class AbstractChatContext {
|
|
|
533
537
|
this._model = options.model;
|
|
534
538
|
}
|
|
535
539
|
get id() {
|
|
536
|
-
|
|
540
|
+
// A chat context is only created once the model is ready (see the
|
|
541
|
+
// AbstractChatModel constructor), so the model's id is guaranteed set here.
|
|
542
|
+
const id = this._model.id;
|
|
543
|
+
if (id === undefined) {
|
|
544
|
+
throw new Error('IChatContext.id was read before the model was ready; ' +
|
|
545
|
+
'a chat context must only be created after `model.ready`.');
|
|
546
|
+
}
|
|
547
|
+
return id;
|
|
537
548
|
}
|
|
538
549
|
get name() {
|
|
539
550
|
return this._model.name;
|
package/package.json
CHANGED
package/src/model.ts
CHANGED
|
@@ -54,9 +54,11 @@ export interface IChatModel extends IDisposable {
|
|
|
54
54
|
unreadMessages: number[];
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* A promise that resolves, once the model is ready, with the chat's stable
|
|
58
|
+
* id. The id matches the backend's `chat.get_id()` and is guaranteed to be
|
|
59
|
+
* available (and never change) from this point on.
|
|
58
60
|
*/
|
|
59
|
-
readonly ready: Promise<
|
|
61
|
+
readonly ready: Promise<string>;
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
64
|
* The awareness channel of the underlying shared document, when the chat is
|
|
@@ -314,7 +316,7 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
314
316
|
this._selectionWatcher = options.selectionWatcher ?? null;
|
|
315
317
|
this._documentManager = options.documentManager ?? null;
|
|
316
318
|
|
|
317
|
-
this._readyDelegate = new PromiseDelegate<
|
|
319
|
+
this._readyDelegate = new PromiseDelegate<string>();
|
|
318
320
|
|
|
319
321
|
this.ready.then(() => {
|
|
320
322
|
this._inputModel.chatContext = this.createChatContext();
|
|
@@ -422,17 +424,21 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
422
424
|
}
|
|
423
425
|
|
|
424
426
|
/**
|
|
425
|
-
* Promise that resolves when the model is ready.
|
|
427
|
+
* Promise that resolves, when the model is ready, with the chat's stable id.
|
|
426
428
|
*/
|
|
427
|
-
get ready(): Promise<
|
|
429
|
+
get ready(): Promise<string> {
|
|
428
430
|
return this._readyDelegate.promise;
|
|
429
431
|
}
|
|
430
432
|
|
|
431
433
|
/**
|
|
432
|
-
*
|
|
434
|
+
* Mark the model as ready, resolving `ready` with the chat's stable id.
|
|
435
|
+
*
|
|
436
|
+
* The id must match the backend's `chat.get_id()`; callers pass the
|
|
437
|
+
* server-authoritative id (WebSocket connection frame, or the synchronized
|
|
438
|
+
* shared-document metadata under RTC).
|
|
433
439
|
*/
|
|
434
|
-
protected setReady(): void {
|
|
435
|
-
this._readyDelegate.resolve();
|
|
440
|
+
protected setReady(id: string): void {
|
|
441
|
+
this._readyDelegate.resolve(id);
|
|
436
442
|
}
|
|
437
443
|
|
|
438
444
|
/**
|
|
@@ -881,7 +887,7 @@ export abstract class AbstractChatModel implements IChatModel {
|
|
|
881
887
|
private _name: string = '';
|
|
882
888
|
private _config: IConfig;
|
|
883
889
|
protected _trans: TranslationBundle;
|
|
884
|
-
private _readyDelegate = new PromiseDelegate<
|
|
890
|
+
private _readyDelegate = new PromiseDelegate<string>();
|
|
885
891
|
private _inputModel: IInputModel;
|
|
886
892
|
private _disposed = new Signal<IChatModel, void>(this);
|
|
887
893
|
private _isDisposed = false;
|
|
@@ -1005,9 +1011,11 @@ export namespace IChatModel {
|
|
|
1005
1011
|
*/
|
|
1006
1012
|
export interface IChatContext {
|
|
1007
1013
|
/**
|
|
1008
|
-
* The
|
|
1014
|
+
* The chat's stable id. Always available: a chat context is only created once
|
|
1015
|
+
* the model is `ready`, at which point the id is guaranteed to be set (and to
|
|
1016
|
+
* match the backend's `chat.get_id()`).
|
|
1009
1017
|
*/
|
|
1010
|
-
readonly id
|
|
1018
|
+
readonly id: string;
|
|
1011
1019
|
/**
|
|
1012
1020
|
* The name of the chat.
|
|
1013
1021
|
*/
|
|
@@ -1040,8 +1048,17 @@ export abstract class AbstractChatContext implements IChatContext {
|
|
|
1040
1048
|
this._model = options.model;
|
|
1041
1049
|
}
|
|
1042
1050
|
|
|
1043
|
-
get id(): string
|
|
1044
|
-
|
|
1051
|
+
get id(): string {
|
|
1052
|
+
// A chat context is only created once the model is ready (see the
|
|
1053
|
+
// AbstractChatModel constructor), so the model's id is guaranteed set here.
|
|
1054
|
+
const id = this._model.id;
|
|
1055
|
+
if (id === undefined) {
|
|
1056
|
+
throw new Error(
|
|
1057
|
+
'IChatContext.id was read before the model was ready; ' +
|
|
1058
|
+
'a chat context must only be created after `model.ready`.'
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
return id;
|
|
1045
1062
|
}
|
|
1046
1063
|
|
|
1047
1064
|
get name(): string {
|