@jupyter/chat 0.25.0-alpha.2 → 0.25.0-alpha.4

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 CHANGED
@@ -12,6 +12,10 @@ import { IChatHistory, IConfig, IMessage, IMessageContent, INewMessage, IUser }
12
12
  * The chat model interface.
13
13
  */
14
14
  export interface IChatModel extends IDisposable {
15
+ /**
16
+ * The unique id of the chat, when known. Implemented by `AbstractChatModel`.
17
+ */
18
+ id?: string;
15
19
  /**
16
20
  * The chat model name.
17
21
  */
@@ -25,9 +29,11 @@ export interface IChatModel extends IDisposable {
25
29
  */
26
30
  unreadMessages: number[];
27
31
  /**
28
- * The promise resolving when the model is ready.
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.
29
35
  */
30
- readonly ready: Promise<void>;
36
+ readonly ready: Promise<string>;
31
37
  /**
32
38
  * The awareness channel of the underlying shared document, when the chat is
33
39
  * backed by one. Lets extensions read collaborative state attached to the
@@ -253,13 +259,17 @@ export declare abstract class AbstractChatModel implements IChatModel {
253
259
  get lastRead(): number;
254
260
  set lastRead(value: number);
255
261
  /**
256
- * Promise that resolves when the model is ready.
262
+ * Promise that resolves, when the model is ready, with the chat's stable id.
257
263
  */
258
- get ready(): Promise<void>;
264
+ get ready(): Promise<string>;
259
265
  /**
260
- * Set the model as ready.
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).
261
271
  */
262
- protected setReady(): void;
272
+ protected setReady(id: string): void;
263
273
  /**
264
274
  * The chat settings.
265
275
  */
@@ -518,6 +528,12 @@ export declare namespace IChatModel {
518
528
  * exposing the method that can modify it.
519
529
  */
520
530
  export interface IChatContext {
531
+ /**
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()`).
535
+ */
536
+ readonly id: string;
521
537
  /**
522
538
  * The name of the chat.
523
539
  */
@@ -548,6 +564,7 @@ export declare abstract class AbstractChatContext implements IChatContext {
548
564
  constructor(options: {
549
565
  model: IChatModel;
550
566
  });
567
+ get id(): string;
551
568
  get name(): string;
552
569
  get messages(): IMessageContent[];
553
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
- * Set the model as ready.
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.
@@ -532,6 +536,16 @@ export class AbstractChatContext {
532
536
  constructor(options) {
533
537
  this._model = options.model;
534
538
  }
539
+ get id() {
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;
548
+ }
535
549
  get name() {
536
550
  return this._model.name;
537
551
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/chat",
3
- "version": "0.25.0-alpha.2",
3
+ "version": "0.25.0-alpha.4",
4
4
  "description": "A package that provides UI components that can be used to create a chat in a Jupyterlab extension.",
5
5
  "keywords": [
6
6
  "jupyter",
package/src/model.ts CHANGED
@@ -33,6 +33,11 @@ import {
33
33
  * The chat model interface.
34
34
  */
35
35
  export interface IChatModel extends IDisposable {
36
+ /**
37
+ * The unique id of the chat, when known. Implemented by `AbstractChatModel`.
38
+ */
39
+ id?: string;
40
+
36
41
  /**
37
42
  * The chat model name.
38
43
  */
@@ -49,9 +54,11 @@ export interface IChatModel extends IDisposable {
49
54
  unreadMessages: number[];
50
55
 
51
56
  /**
52
- * The promise resolving when the model is ready.
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.
53
60
  */
54
- readonly ready: Promise<void>;
61
+ readonly ready: Promise<string>;
55
62
 
56
63
  /**
57
64
  * The awareness channel of the underlying shared document, when the chat is
@@ -309,7 +316,7 @@ export abstract class AbstractChatModel implements IChatModel {
309
316
  this._selectionWatcher = options.selectionWatcher ?? null;
310
317
  this._documentManager = options.documentManager ?? null;
311
318
 
312
- this._readyDelegate = new PromiseDelegate<void>();
319
+ this._readyDelegate = new PromiseDelegate<string>();
313
320
 
314
321
  this.ready.then(() => {
315
322
  this._inputModel.chatContext = this.createChatContext();
@@ -417,17 +424,21 @@ export abstract class AbstractChatModel implements IChatModel {
417
424
  }
418
425
 
419
426
  /**
420
- * Promise that resolves when the model is ready.
427
+ * Promise that resolves, when the model is ready, with the chat's stable id.
421
428
  */
422
- get ready(): Promise<void> {
429
+ get ready(): Promise<string> {
423
430
  return this._readyDelegate.promise;
424
431
  }
425
432
 
426
433
  /**
427
- * Set the model as ready.
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).
428
439
  */
429
- protected setReady(): void {
430
- this._readyDelegate.resolve();
440
+ protected setReady(id: string): void {
441
+ this._readyDelegate.resolve(id);
431
442
  }
432
443
 
433
444
  /**
@@ -876,7 +887,7 @@ export abstract class AbstractChatModel implements IChatModel {
876
887
  private _name: string = '';
877
888
  private _config: IConfig;
878
889
  protected _trans: TranslationBundle;
879
- private _readyDelegate = new PromiseDelegate<void>();
890
+ private _readyDelegate = new PromiseDelegate<string>();
880
891
  private _inputModel: IInputModel;
881
892
  private _disposed = new Signal<IChatModel, void>(this);
882
893
  private _isDisposed = false;
@@ -999,6 +1010,12 @@ export namespace IChatModel {
999
1010
  * exposing the method that can modify it.
1000
1011
  */
1001
1012
  export interface IChatContext {
1013
+ /**
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()`).
1017
+ */
1018
+ readonly id: string;
1002
1019
  /**
1003
1020
  * The name of the chat.
1004
1021
  */
@@ -1031,6 +1048,19 @@ export abstract class AbstractChatContext implements IChatContext {
1031
1048
  this._model = options.model;
1032
1049
  }
1033
1050
 
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;
1062
+ }
1063
+
1034
1064
  get name(): string {
1035
1065
  return this._model.name;
1036
1066
  }