Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/jupyter-chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export * from './registers';
export * from './selection-watcher';
export * from './types';
export * from './widgets';
export * from './widgets/multiChatPanel';
export * from './token';
23 changes: 23 additions & 0 deletions packages/jupyter-chat/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IUser
} from './types';
import { replaceMentionToSpan } from './utils';
import { PromiseDelegate } from '@lumino/coreutils';

/**
* The chat model interface.
Expand All @@ -40,6 +41,11 @@ export interface IChatModel extends IDisposable {
*/
unreadMessages: number[];

/**
* The promise resolving when the model is ready.
*/
readonly ready: Promise<void>;

/**
* The indexes list of the messages currently in the viewport.
*/
Expand Down Expand Up @@ -241,6 +247,8 @@ export abstract class AbstractChatModel implements IChatModel {
this._activeCellManager = options.activeCellManager ?? null;
this._selectionWatcher = options.selectionWatcher ?? null;
this._documentManager = options.documentManager ?? null;

this._readyDelegate = new PromiseDelegate<void>();
}

/**
Expand Down Expand Up @@ -328,6 +336,20 @@ export abstract class AbstractChatModel implements IChatModel {
localStorage.setItem(`@jupyter/chat:${this._id}`, JSON.stringify(storage));
}

/**
* Promise that resolves when the model is ready.
*/
get ready(): Promise<void> {
return this._readyDelegate.promise;
}

/**
* Mark the model as ready.
*/
protected markReady(): void {
this._readyDelegate.resolve();
}

/**
* The chat settings.
*/
Expand Down Expand Up @@ -677,6 +699,7 @@ export abstract class AbstractChatModel implements IChatModel {
private _id: string | undefined;
private _name: string = '';
private _config: IConfig;
private _readyDelegate = new PromiseDelegate<void>();
private _inputModel: IInputModel;
private _isDisposed = false;
private _commands?: CommandRegistry;
Expand Down
26 changes: 26 additions & 0 deletions packages/jupyter-chat/src/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

import { Token } from '@lumino/coreutils';
import { IInputToolbarRegistry } from './index';

/**
* A factory interface for creating a new Input Toolbar Registry
* for each Chat Panel.
*/
export interface IInputToolbarRegistryFactory {
/**
* Create a new input toolbar registry instance.
*/
create: () => IInputToolbarRegistry;
}

/**
* The token of the factory to create an input toolbar registry.
*/
export const IInputToolbarRegistryFactory =
new Token<IInputToolbarRegistryFactory>(
'@jupyter/chat:IInputToolbarRegistryFactory'
);
66 changes: 66 additions & 0 deletions packages/jupyter-chat/src/utils/renameDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
import '../../style/input.css';

export async function showRenameDialog(
currentName: string
): Promise<string | null> {
return new Promise(resolve => {
const modal = document.createElement('div');
modal.className = 'rename-modal';

const dialog = document.createElement('div');
dialog.className = 'rename-dialog';
modal.appendChild(dialog);

const title = document.createElement('h3');
title.textContent = 'Rename Chat';
dialog.appendChild(title);

const input = document.createElement('input');
input.type = 'text';
input.value = currentName;
dialog.appendChild(input);

const buttons = document.createElement('div');
buttons.className = 'rename-buttons';

const cancelBtn = document.createElement('button');
cancelBtn.textContent = 'Cancel';
cancelBtn.className = 'cancel-btn';
cancelBtn.onclick = () => {
document.body.removeChild(modal);
resolve(null);
};
buttons.appendChild(cancelBtn);

const okBtn = document.createElement('button');
okBtn.textContent = 'Rename';
okBtn.className = 'rename-ok';
okBtn.onclick = () => {
const val = input.value.trim();
if (val) {
document.body.removeChild(modal);
resolve(val);
} else {
input.focus();
}
};
buttons.appendChild(okBtn);

dialog.appendChild(buttons);

document.body.appendChild(modal);
input.focus();

input.addEventListener('keydown', e => {
if (e.key === 'Enter') {
okBtn.click();
} else if (e.key === 'Escape') {
cancelBtn.click();
}
});
});
}
1 change: 1 addition & 0 deletions packages/jupyter-chat/src/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export * from './chat-error';
export * from './chat-sidebar';
export * from './chat-widget';
export * from './multiChatPanel';
Loading