diff --git a/package.json b/package.json index af3d61b5105..1afafefb41e 100644 --- a/package.json +++ b/package.json @@ -2185,6 +2185,15 @@ }, "when": "false" } + ], + "chatParticipants": [ + { + "id": "jupyter.jupyterAgent", + "fullName": "Jupyter", + "name": "jupyter", + "description": "%jupyter.chatParticipant.description%", + "isSticky": true + } ] }, "enabledApiProposals": [ diff --git a/package.nls.json b/package.nls.json index a499a01d894..f5aa9341e7a 100644 --- a/package.nls.json +++ b/package.nls.json @@ -243,5 +243,6 @@ "jupyter.languageModelTools.configure_notebook.displayName": "Configure Jupyter Notebook", "jupyter.languageModelTools.configure_notebook.userDescription": "Ensure Notebook is ready for use, such as running cells.", "jupyter.languageModelTools.notebook_list_packages.userDescription": "Lists Python packages available in the selected Notebook Kernel.", - "jupyter.languageModelTools.notebook_install_packages.userDescription": "Installs Python packages in the selected Notebook Kernel." + "jupyter.languageModelTools.notebook_install_packages.userDescription": "Installs Python packages in the selected Notebook Kernel.", + "jupyter.chatParticipant.description": "Ask questions about Jupyter notebooks, kernels, and data science in VS Code." } diff --git a/src/standalone/chat/agent.node.ts b/src/standalone/chat/agent.node.ts new file mode 100644 index 00000000000..86e2edf5542 --- /dev/null +++ b/src/standalone/chat/agent.node.ts @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import * as vscode from 'vscode'; +import { logger } from '../../platform/logging'; + +const JUPYTER_AGENT_ID = 'jupyter.jupyterAgent'; + +/** + * Creates and registers a Jupyter chat participant (agent) that can handle + * user requests for Jupyter notebook assistance. + */ +export function registerJupyterChatAgent(context: vscode.ExtensionContext): void { + const agent = vscode.chat.createChatParticipant(JUPYTER_AGENT_ID, handleChatRequest); + agent.iconPath = new vscode.ThemeIcon('notebook'); + + context.subscriptions.push(agent); + logger.info('Jupyter Chat Agent registered'); +} + +/** + * Handles incoming chat requests to the Jupyter agent. + */ +async function handleChatRequest( + _request: vscode.ChatRequest, + _context: vscode.ChatContext, + stream: vscode.ChatResponseStream, + token: vscode.CancellationToken +): Promise { + if (token.isCancellationRequested) { + return undefined; + } + + try { + // Stream a response to the user + stream.markdown(`I'm the Jupyter assistant. I can help you work with Jupyter notebooks.\n\n`); + stream.markdown( + `I can assist with:\n` + + `- Configuring notebooks and kernels\n` + + `- Installing packages in notebook kernels\n` + + `- Listing installed packages\n` + + `- Restarting kernels\n\n` + ); + stream.markdown(`To get started, open a Jupyter notebook and I'll help you configure and work with it.`); + + return {}; + } catch (error) { + logger.error('Error handling Jupyter chat request', error); + stream.markdown( + `An error occurred while processing your request. Please check your input and try again, or report an issue if the problem persists.` + ); + return undefined; + } +} diff --git a/src/standalone/chat/extension.node.ts b/src/standalone/chat/extension.node.ts index b3b56f54c91..bb432eb833e 100644 --- a/src/standalone/chat/extension.node.ts +++ b/src/standalone/chat/extension.node.ts @@ -16,8 +16,12 @@ import { ConfigurePythonNotebookTool } from './configureNotebook.python.node'; import { ConfigureNonPythonNotebookTool } from './configureNotebook.other.node'; import { RestartKernelTool } from './restartKernelTool.node'; import { INotebookCommandHandler } from '../../notebooks/notebookCommandListener'; +import { registerJupyterChatAgent } from './agent.node'; export async function activate(context: vscode.ExtensionContext, serviceContainer: IServiceContainer): Promise { + // Register the Jupyter Chat Agent + registerJupyterChatAgent(context); + context.subscriptions.push( vscode.lm.registerTool( InstallPackagesTool.toolName,