Skip to content

Commit 9a4aebf

Browse files
authored
Remove old autocomplete registry (#187)
1 parent b1993dc commit 9a4aebf

File tree

9 files changed

+2
-311
lines changed

9 files changed

+2
-311
lines changed

docs/source/developers/developing_extensions/extension-providing-chat.md

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -304,90 +304,6 @@ const myChatExtension: JupyterFrontEndPlugin<void> = {
304304
};
305305
```
306306

307-
(autocompletion-registry)=
308-
309-
### autocompletionRegistry
310-
311-
The `autocompletionRegistry` adds autocompletion feature to the chat input. This can be
312-
useful for automating chat messages reading, like in
313-
[jupyter-ai](https://github.com/jupyterlab/jupyter-ai).
314-
315-
It uses the `Autocomplete` from
316-
[Material UI](https://mui.com/material-ui/react-autocomplete/),
317-
and can be customized using its [API](https://mui.com/material-ui/api/autocomplete/).
318-
319-
Several _Autocompletion properties_ objects (implementing
320-
`IAutocompletionCommandsProps`) can be added to the registry.
321-
322-
```{warning}
323-
Currently, only one *autocompletion properties* object can be used for a chat widget,
324-
even if several coexist in the registry.\
325-
The used one will be designed by the widget's option `autocompletionName`, otherwise a
326-
default will be used.
327-
```
328-
329-
An _autocompletion properties_ object needs at least two properties:
330-
331-
- **opener**, a character string that triggers the opening of the popup if entered at
332-
the beginning of the input.\
333-
For example typing `/` could open propositions like (`/ask`, `/help`, ...).
334-
- **commands**, a list of commands or a functions returning a list commands.
335-
336-
```{tip}
337-
The *autocompletion command* is an object containing at least a `label` property, but
338-
which can also contain a `value` property.
339-
```
340-
341-
```{tip}
342-
Adding the `renderOption` in the property `props` of the *autocompletion command* allows
343-
to customize the rendering of the entries. Some documentation about it can be found in
344-
the [Material UI API](https://mui.com/material-ui/api/autocomplete/).
345-
```
346-
347-
Here is a simple example using a commands list (commands list copied from _jupyter-ai_):
348-
349-
{emphasize-lines="2,6,12,13,14,15,16,17,18,25,26,32"}
350-
351-
```typescript
352-
import {
353-
AutocompletionRegistry,
354-
ChatModel,
355-
ChatWidget,
356-
IChatMessage,
357-
IAutocompletionCommandsProps,
358-
INewMessage
359-
} from '@jupyter/chat';
360-
361-
...
362-
363-
const options = ['/ask', '/clear', '/export', '/generate', '/help', '/learn'];
364-
const autocompletionCommands: IAutocompletionCommandsProps = {
365-
opener: '/',
366-
commands: options.map(option => {
367-
return { label: option };
368-
})
369-
};
370-
371-
const myChatExtension: JupyterFrontEndPlugin<void> = {
372-
id: 'myExtension:plugin',
373-
autoStart: true,
374-
requires: [IRenderMimeRegistry],
375-
activate: (app: JupyterFrontEnd, rmRegistry: IRenderMimeRegistry): void => {
376-
const autocompletionRegistry = new AutocompletionRegistry();
377-
autocompletionRegistry.add('default', autocompletionCommands);
378-
379-
const model = new MyModel();
380-
const widget = new ChatWidget({
381-
model,
382-
rmRegistry,
383-
autocompletionRegistry
384-
});
385-
386-
app.shell.add(widget, 'right');
387-
}
388-
};
389-
```
390-
391307
(attachment-opener-registry)=
392308

393309
### attachmentOpenerRegistry

docs/source/developers/developing_extensions/using-chat-extension.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ This token is a pointer to the left panel containing chats.\
3636
It can be used to programmatically open chat in the panel for example, or to list the
3737
opened chats.
3838

39-
### IAutocompletionRegistry
40-
41-
This is the [autocompletion registry](#autocompletion-registry) used by the chat
42-
widgets.
43-
44-
Autocompletion commands can be added to it, and then be used from the chat input.
45-
4639
## Interact with the chat from the backend
4740

4841
`jupyter_collaboration` provides a websocket server to handle every shared document

packages/jupyter-chat/src/components/chat-input.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import React, { useEffect, useRef, useState } from 'react';
1919
import { AttachmentPreviewList } from './attachments';
2020
import { AttachButton, CancelButton, SendButton } from './input';
2121
import { IInputModel, InputModel } from '../input-model';
22-
import { IAutocompletionRegistry } from '../registry';
2322
import { IAttachment, Selection } from '../types';
2423
import { useChatCommands } from './input/use-chat-commands';
2524
import { IChatCommandRegistry } from '../chat-commands';
@@ -297,14 +296,6 @@ export namespace ChatInput {
297296
* The document manager.
298297
*/
299298
documentManager?: IDocumentManager;
300-
/**
301-
* Autocompletion properties.
302-
*/
303-
autocompletionRegistry?: IAutocompletionRegistry;
304-
/**
305-
* Autocompletion name.
306-
*/
307-
autocompletionName?: string;
308299
/**
309300
* Chat command registry.
310301
*/

packages/jupyter-chat/src/components/chat.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import { ChatMessages } from './chat-messages';
1818
import { ChatInput } from './chat-input';
1919
import { AttachmentOpenerContext } from '../context';
2020
import { IChatModel } from '../model';
21-
import {
22-
IAttachmentOpenerRegistry,
23-
IAutocompletionRegistry
24-
} from '../registry';
21+
import { IAttachmentOpenerRegistry } from '../registry';
2522

2623
export function ChatBody(props: Chat.IChatBodyProps): JSX.Element {
2724
const { model } = props;
@@ -49,7 +46,6 @@ export function ChatBody(props: Chat.IChatBodyProps): JSX.Element {
4946
}}
5047
model={model.input}
5148
documentManager={props.documentManager}
52-
autocompletionRegistry={props.autocompletionRegistry}
5349
chatCommandRegistry={props.chatCommandRegistry}
5450
/>
5551
</AttachmentOpenerContext.Provider>
@@ -98,7 +94,6 @@ export function Chat(props: Chat.IOptions): JSX.Element {
9894
model={props.model}
9995
rmRegistry={props.rmRegistry}
10096
documentManager={props.documentManager}
101-
autocompletionRegistry={props.autocompletionRegistry}
10297
chatCommandRegistry={props.chatCommandRegistry}
10398
attachmentOpenerRegistry={props.attachmentOpenerRegistry}
10499
/>
@@ -131,14 +126,6 @@ export namespace Chat {
131126
* The document manager.
132127
*/
133128
documentManager?: IDocumentManager;
134-
/**
135-
* Autocompletion registry.
136-
*/
137-
autocompletionRegistry?: IAutocompletionRegistry;
138-
/**
139-
* Autocompletion name.
140-
*/
141-
autocompletionName?: string;
142129
/**
143130
* Chat command registry.
144131
*/

packages/jupyter-chat/src/registry.ts

Lines changed: 1 addition & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3,130 +3,7 @@
33
* Distributed under the terms of the Modified BSD License.
44
*/
55
import { Token } from '@lumino/coreutils';
6-
import { IAttachment, IAutocompletionCommandsProps } from './types';
7-
8-
/**
9-
* The token for the autocomplete registry, which can be provided by an extension
10-
* using @jupyter/chat package.
11-
*/
12-
export const IAutocompletionRegistry = new Token<IAutocompletionRegistry>(
13-
'@jupyter/chat:IAutocompleteRegistry'
14-
);
15-
16-
/**
17-
* The interface of a registry to provide autocompleters.
18-
*/
19-
export interface IAutocompletionRegistry {
20-
/**
21-
* The default autocompletion name.
22-
*/
23-
default: string | null;
24-
/**
25-
* Get the default autocompletion.
26-
*/
27-
getDefaultCompletion(): IAutocompletionCommandsProps | undefined;
28-
/**
29-
* Return a registered autocomplete props.
30-
*
31-
* @param name - the name of the registered autocomplete props.
32-
*/
33-
get(name: string): IAutocompletionCommandsProps | undefined;
34-
35-
/**
36-
* Register autocomplete props.
37-
*
38-
* @param name - the name for the registration.
39-
* @param autocompletion - the autocomplete props.
40-
*/
41-
add(name: string, autocompletion: IAutocompletionCommandsProps): boolean;
42-
43-
/**
44-
* Remove a registered autocomplete props.
45-
*
46-
* @param name - the name of the autocomplete props.
47-
*/
48-
remove(name: string): boolean;
49-
}
50-
51-
/**
52-
* A registry to provide autocompleters.
53-
*/
54-
export class AutocompletionRegistry implements IAutocompletionRegistry {
55-
/**
56-
* Getter and setter for the default autocompletion name.
57-
*/
58-
get default(): string | null {
59-
return this._default;
60-
}
61-
set default(name: string | null) {
62-
if (name === null || this._autocompletions.has(name)) {
63-
this._default = name;
64-
} else {
65-
console.warn(`There is no registered completer with the name '${name}'`);
66-
}
67-
}
68-
69-
/**
70-
* Get the default autocompletion.
71-
*/
72-
getDefaultCompletion(): IAutocompletionCommandsProps | undefined {
73-
if (this._default === null) {
74-
return undefined;
75-
}
76-
return this._autocompletions.get(this._default);
77-
}
78-
79-
/**
80-
* Return a registered autocomplete props.
81-
*
82-
* @param name - the name of the registered autocomplete props.
83-
*/
84-
get(name: string): IAutocompletionCommandsProps | undefined {
85-
return this._autocompletions.get(name);
86-
}
87-
88-
/**
89-
* Register autocomplete props.
90-
*
91-
* @param name - the name for the registration.
92-
* @param autocompletion - the autocomplete props.
93-
*/
94-
add(
95-
name: string,
96-
autocompletion: IAutocompletionCommandsProps,
97-
isDefault: boolean = false
98-
): boolean {
99-
if (!this._autocompletions.has(name)) {
100-
this._autocompletions.set(name, autocompletion);
101-
if (this._autocompletions.size === 1 || isDefault) {
102-
this.default = name;
103-
}
104-
return true;
105-
} else {
106-
console.warn(`A completer with the name '${name}' is already registered`);
107-
return false;
108-
}
109-
}
110-
111-
/**
112-
* Remove a registered autocomplete props.
113-
*
114-
* @param name - the name of the autocomplete props.
115-
*/
116-
remove(name: string): boolean {
117-
return this._autocompletions.delete(name);
118-
}
119-
120-
/**
121-
* Remove all registered autocompletions.
122-
*/
123-
removeAll(): void {
124-
this._autocompletions.clear();
125-
}
126-
127-
private _default: string | null = null;
128-
private _autocompletions = new Map<string, IAutocompletionCommandsProps>();
129-
}
6+
import { IAttachment } from './types';
1307

1318
/**
1329
* The token for the attachments opener registry, which can be provided by an extension

packages/jupyter-chat/src/types.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ export interface IAttachment {
9595
*/
9696
export interface ISettings {} /* eslint-disable-line @typescript-eslint/no-empty-object-type */
9797

98-
/**
99-
* The autocomplete command type.
100-
*/
101-
export type AutocompleteCommand = {
102-
label: string;
103-
};
104-
10598
/**
10699
* Representation of a selected text.
107100
*/
@@ -122,35 +115,3 @@ export type CellSelection = {
122115
* Selection object (text or cell).
123116
*/
124117
export type Selection = TextSelection | CellSelection;
125-
126-
/**
127-
* The properties of the autocompletion.
128-
*
129-
* The autocompletion component will open if the 'opener' string is typed at the
130-
* beginning of the input field.
131-
*/
132-
export interface IAutocompletionCommandsProps {
133-
/**
134-
* The string that open the completer.
135-
*/
136-
opener: string;
137-
/**
138-
* The list of available commands.
139-
*/
140-
commands?: AutocompleteCommand[] | (() => Promise<AutocompleteCommand[]>);
141-
/**
142-
* The props for the Autocomplete component.
143-
*
144-
* Must be compatible with https://mui.com/material-ui/api/autocomplete/#props.
145-
*
146-
* ## NOTES:
147-
* - providing `options` will overwrite the commands argument.
148-
* - providing `renderInput` will overwrite the input component.
149-
* - providing `renderOptions` allows to customize the rendering of the component.
150-
* - some arguments should not be provided and would be overwritten:
151-
* - inputValue
152-
* - onInputChange
153-
* - onHighlightChange
154-
*/
155-
props?: any;
156-
}

0 commit comments

Comments
 (0)