diff --git a/src/index.ts b/src/index.ts index ba7279c..376ab2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -291,14 +291,27 @@ const plugin: JupyterFrontEndPlugin = { inputToolbarFactory, attachmentOpenerRegistry, createModel: async (name?: string) => { - const model = modelRegistry.createModel(name); + let model = name ? modelRegistry.get(name) : undefined; + if (!model) { + model = modelRegistry.createModel(name); + } + chatPanel.updateChatList(); return { model }; }, + getChatNames: async () => { + const names = modelRegistry.getAll().map(model => model.name); + const arr: { [key: string]: string } = {}; + for (const name of names) { + arr[name] = name; + } + return arr; + }, renameChat: async (oldName: string, newName: string) => { const model = modelRegistry.get(oldName); const concurrencyModel = modelRegistry.get(newName); if (model && !concurrencyModel) { model.name = newName; + chatPanel.updateChatList(); return true; } return false; @@ -371,8 +384,6 @@ const plugin: JupyterFrontEndPlugin = { widget.disposed.connect(() => { // Dispose of the approval buttons widget when the chat is disposed. approvalButton.dispose(); - // Remove the model from the registry when the widget is disposed. - modelRegistry.remove(model.name); }); }); @@ -515,11 +526,6 @@ function registerCommands( model.agentManager.activeProviderChanged.connect(() => tracker.save(widget) ); - - // Remove the model from the registry when the widget is disposed. - widget.disposed.connect(() => { - modelRegistry.remove(model.name); - }); }; commands.addCommand(CommandIds.openChat, {