From 82cff2aef6103241fa2d86eb0343b9c978297324 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 29 Nov 2024 13:30:58 +0100 Subject: [PATCH] only range --- src/participant/participant.ts | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/participant/participant.ts b/src/participant/participant.ts index 02ebb395e..02906c83a 100644 --- a/src/participant/participant.ts +++ b/src/participant/participant.ts @@ -73,7 +73,8 @@ export type RunParticipantCodeCommandArgs = { runnableContent: string; }; -export type ParticipantCommand = '/query' | '/schema' | '/docs'; +export type ParticipantCommandName = 'query' | 'schema' | 'docs'; +export type ParticipantCommand = `/${ParticipantCommandName}`; const MAX_MARKDOWN_LIST_LENGTH = 10; @@ -179,6 +180,8 @@ export default class ParticipantController { message, isNewChat = false, isPartialQuery = false, + source, + command, ...otherOptions } = options; @@ -189,9 +192,26 @@ export default class ParticipantController { ); } + if (source) { + if (isNewChat) { + this._telemetryService.trackCopilotParticipantChatOpenedFromAction({ + source, + }); + } + if (!isPartialQuery) { + this._telemetryService.trackCopilotParticipantPromptSubmittedFromAction( + { + source, + } + ); + } + } + + const commandPrefix = command ? `/${command} ` : ''; + return await vscode.commands.executeCommand('workbench.action.chat.open', { ...otherOptions, - query: `@MongoDB ${message}`, + query: `@MongoDB ${commandPrefix}${message}`, isPartialQuery, }); } @@ -207,7 +227,7 @@ export default class ParticipantController { ...inputBoxOptions } = options; - this._telemetryService.trackCopilotParticipantSubmittedFromInputBox({ + this._telemetryService.trackCopilotParticipantPromptSubmittedFromAction({ source, }); @@ -236,14 +256,15 @@ export default class ParticipantController { message: `I want to ask questions about the \`${databaseName}\` database.`, isNewChat: true, }); - } - if (treeItem instanceof CollectionTreeItem) { + } else if (treeItem instanceof CollectionTreeItem) { const { databaseName, collectionName } = treeItem; await this.sendMessageToParticipant({ message: `I want to ask questions about the \`${databaseName}\` database's \`${collectionName}\` collection.`, isNewChat: true, }); + } else { + throw new Error('Unsupported tree item type'); } await this.sendMessageToParticipant({ @@ -1949,7 +1970,7 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i } catch (error) { this._telemetryService.trackCopilotParticipantError( error, - request.command || 'generic' + (request.command as ParticipantCommandName) || 'generic' ); // Re-throw other errors so they show up in the UI. throw error;