@jupyter/chat 0.23.0-alpha.3 → 0.23.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.
@@ -2,9 +2,6 @@
2
2
  * Copyright (c) Jupyter Development Team.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
- /**
6
- * Example of [Jest](https://jestjs.io/docs/getting-started) unit tests
7
- */
8
5
  import { AbstractChatModel } from '../model';
9
6
  import { MockChatModel, MockChatContext } from './mocks';
10
7
  describe('test chat model', () => {
@@ -125,4 +122,21 @@ describe('test chat model', () => {
125
122
  expect(model.config.sendWithShiftEnter).toBeTruthy();
126
123
  });
127
124
  });
125
+ describe('awareness', () => {
126
+ it('should surface the model awareness on the context', () => {
127
+ class AwareChatModel extends MockChatModel {
128
+ constructor() {
129
+ super(...arguments);
130
+ this.awareness = {};
131
+ }
132
+ }
133
+ const model = new AwareChatModel();
134
+ const context = new MockChatContext({ model });
135
+ expect(context.awareness).toBe(model.awareness);
136
+ });
137
+ it('should be undefined when the model has no awareness', () => {
138
+ const context = new MockChatContext({ model: new MockChatModel() });
139
+ expect(context.awareness).toBeUndefined();
140
+ });
141
+ });
128
142
  });
package/lib/model.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IDocumentManager } from '@jupyterlab/docmanager';
2
2
  import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
3
+ import type { IAwareness } from '@jupyter/ydoc';
3
4
  import { CommandRegistry } from '@lumino/commands';
4
5
  import { IDisposable } from '@lumino/disposable';
5
6
  import { ISignal } from '@lumino/signaling';
@@ -27,6 +28,13 @@ export interface IChatModel extends IDisposable {
27
28
  * The promise resolving when the model is ready.
28
29
  */
29
30
  readonly ready: Promise<void>;
31
+ /**
32
+ * The awareness channel of the underlying shared document, when the chat is
33
+ * backed by one. Lets extensions read collaborative state attached to the
34
+ * chat (e.g. session information published by AI personas) through a
35
+ * supported API instead of reaching into a concrete implementation.
36
+ */
37
+ readonly awareness?: IAwareness;
30
38
  /**
31
39
  * The indexes list of the messages currently in the viewport.
32
40
  */
@@ -470,6 +478,11 @@ export interface IChatContext {
470
478
  * Current user connected with the chat panel
471
479
  */
472
480
  readonly user: IUser | undefined;
481
+ /**
482
+ * The awareness channel of the underlying shared document, when the chat is
483
+ * backed by one.
484
+ */
485
+ readonly awareness?: IAwareness;
473
486
  }
474
487
  /**
475
488
  * An abstract base class implementing `IChatContext`. This can be extended into
@@ -482,6 +495,7 @@ export declare abstract class AbstractChatContext implements IChatContext {
482
495
  get name(): string;
483
496
  get messages(): IMessageContent[];
484
497
  get user(): IUser | undefined;
498
+ get awareness(): IAwareness | undefined;
485
499
  /**
486
500
  * ABSTRACT: Should return a list of users who have connected to this chat.
487
501
  */
package/lib/model.js CHANGED
@@ -488,4 +488,7 @@ export class AbstractChatContext {
488
488
  var _a;
489
489
  return (_a = this._model) === null || _a === void 0 ? void 0 : _a.user;
490
490
  }
491
+ get awareness() {
492
+ return this._model.awareness;
493
+ }
491
494
  }
@@ -133,6 +133,7 @@ export class MultiChatPanel extends PanelWithToolbar {
133
133
  this.open(addChatArgs);
134
134
  },
135
135
  icon: addIcon,
136
+ label: this._trans.__('New chat'),
136
137
  tooltip: this._trans.__('Create a new chat')
137
138
  });
138
139
  addChat.addClass(ADD_BUTTON_CLASS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/chat",
3
- "version": "0.23.0-alpha.3",
3
+ "version": "0.23.0",
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",
@@ -46,6 +46,7 @@
46
46
  "@emotion/react": "^11.10.5",
47
47
  "@emotion/styled": "^11.10.5",
48
48
  "@jupyter/react-components": "^0.15.2",
49
+ "@jupyter/ydoc": "^3.0.0 || ^4.0.0",
49
50
  "@jupyterlab/application": "^4.6.0",
50
51
  "@jupyterlab/apputils": "^4.7.0",
51
52
  "@jupyterlab/codeeditor": "^4.6.0",
@@ -7,6 +7,8 @@
7
7
  * Example of [Jest](https://jestjs.io/docs/getting-started) unit tests
8
8
  */
9
9
 
10
+ import type { IAwareness } from '@jupyter/ydoc';
11
+
10
12
  import { AbstractChatModel, IChatContext, IChatModel } from '../model';
11
13
  import { IMessage, IMessageContent, INewMessage } from '../types';
12
14
  import { MockChatModel, MockChatContext } from './mocks';
@@ -149,4 +151,20 @@ describe('test chat model', () => {
149
151
  expect(model.config.sendWithShiftEnter).toBeTruthy();
150
152
  });
151
153
  });
154
+
155
+ describe('awareness', () => {
156
+ it('should surface the model awareness on the context', () => {
157
+ class AwareChatModel extends MockChatModel {
158
+ readonly awareness = {} as IAwareness;
159
+ }
160
+ const model = new AwareChatModel();
161
+ const context = new MockChatContext({ model });
162
+ expect(context.awareness).toBe(model.awareness);
163
+ });
164
+
165
+ it('should be undefined when the model has no awareness', () => {
166
+ const context = new MockChatContext({ model: new MockChatModel() });
167
+ expect(context.awareness).toBeUndefined();
168
+ });
169
+ });
152
170
  });
package/src/model.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  nullTranslator,
10
10
  TranslationBundle
11
11
  } from '@jupyterlab/translation';
12
+ import type { IAwareness } from '@jupyter/ydoc';
12
13
  import { ArrayExt } from '@lumino/algorithm';
13
14
  import { CommandRegistry } from '@lumino/commands';
14
15
  import { PromiseDelegate } from '@lumino/coreutils';
@@ -53,6 +54,14 @@ export interface IChatModel extends IDisposable {
53
54
  */
54
55
  readonly ready: Promise<void>;
55
56
 
57
+ /**
58
+ * The awareness channel of the underlying shared document, when the chat is
59
+ * backed by one. Lets extensions read collaborative state attached to the
60
+ * chat (e.g. session information published by AI personas) through a
61
+ * supported API instead of reaching into a concrete implementation.
62
+ */
63
+ readonly awareness?: IAwareness;
64
+
56
65
  /**
57
66
  * The indexes list of the messages currently in the viewport.
58
67
  */
@@ -894,6 +903,11 @@ export interface IChatContext {
894
903
  * Current user connected with the chat panel
895
904
  */
896
905
  readonly user: IUser | undefined;
906
+ /**
907
+ * The awareness channel of the underlying shared document, when the chat is
908
+ * backed by one.
909
+ */
910
+ readonly awareness?: IAwareness;
897
911
  }
898
912
 
899
913
  /**
@@ -917,6 +931,10 @@ export abstract class AbstractChatContext implements IChatContext {
917
931
  return this._model?.user;
918
932
  }
919
933
 
934
+ get awareness(): IAwareness | undefined {
935
+ return this._model.awareness;
936
+ }
937
+
920
938
  /**
921
939
  * ABSTRACT: Should return a list of users who have connected to this chat.
922
940
  */
@@ -102,6 +102,7 @@ export class MultiChatPanel extends PanelWithToolbar {
102
102
  this.open(addChatArgs);
103
103
  },
104
104
  icon: addIcon,
105
+ label: this._trans.__('New chat'),
105
106
  tooltip: this._trans.__('Create a new chat')
106
107
  });
107
108
  addChat.addClass(ADD_BUTTON_CLASS);