Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: opt-in via the initial chat participant message VSCODE-568 #775

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default class MDBExtensionController implements vscode.Disposable {
new PlaygroundDiagnosticsCodeActionProvider();
this._participantController = new ParticipantController({
connectionController: this._connectionController,
storageController: this._storageController,
});
this._playgroundController = new PlaygroundController({
connectionController: this._connectionController,
Expand Down
23 changes: 23 additions & 0 deletions src/participant/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as vscode from 'vscode';
import { createLogger } from '../logging';
import type ConnectionController from '../connectionController';
import EXTENSION_COMMANDS from '../commands';
import type { StorageController } from '../storage';
import { StorageVariables } from '../storage';

const log = createLogger('participant');

Expand Down Expand Up @@ -38,14 +40,18 @@ export class ParticipantController {
_participant?: vscode.ChatParticipant;
_chatResult: ChatResult;
_connectionController: ConnectionController;
_storageController: StorageController;

constructor({
connectionController,
storageController,
}: {
connectionController: ConnectionController;
storageController: StorageController;
}) {
this._chatResult = { metadata: { command: '' } };
this._connectionController = connectionController;
this._storageController = storageController;
}

createParticipant(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -311,6 +317,23 @@ export class ParticipantController {
stream: vscode.ChatResponseStream,
token: vscode.CancellationToken
): Promise<ChatResult> {
const hasBeenShownWelcomeMessageAlready = !!this._storageController.get(
StorageVariables.COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE
);

if (!hasBeenShownWelcomeMessageAlready) {
stream.markdown(
vscode.l10n.t(`
Welcome to MongoDB Participant!\n\n
Interact with your MongoDB clusters and generate MongoDB-related code more efficiently with intelligent AI-powered feature, available today in the MongoDB extension.\n\n
Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more information.`)
);
void this._storageController.update(
StorageVariables.COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE,
true
);
}

if (request.command === 'query') {
this._chatResult = await this.handleQueryRequest({
request,
Expand Down
2 changes: 2 additions & 0 deletions src/storage/storageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum StorageVariables {
GLOBAL_ANONYMOUS_ID = 'GLOBAL_ANONYMOUS_ID',
// Only exists on workspaceState.
WORKSPACE_SAVED_CONNECTIONS = 'WORKSPACE_SAVED_CONNECTIONS',
COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE = 'COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE',
}

// Typically variables default to 'GLOBAL' scope.
Expand Down Expand Up @@ -52,6 +53,7 @@ interface StorageVariableContents {
[StorageVariables.GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW]: boolean;
[StorageVariables.GLOBAL_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.WORKSPACE_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE]: boolean;
}
type StoredVariableName = keyof StorageVariableContents;
type StoredItem<T extends StoredVariableName> = StorageVariableContents[T];
Expand Down
1 change: 1 addition & 0 deletions src/test/suite/editors/playgroundController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ suite('Playground Controller Test Suite', function () {
);
testParticipantController = new ParticipantController({
connectionController: testConnectionController,
storageController: testStorageController,
});
testPlaygroundController = new PlaygroundController({
connectionController: testConnectionController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {

testParticipantController = new ParticipantController({
connectionController: testConnectionController,
storageController: testStorageController,
});

sandbox.replace(
Expand Down
1 change: 1 addition & 0 deletions src/test/suite/language/languageServerController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ suite('Language Server Controller Test Suite', () => {
);
testParticipantController = new ParticipantController({
connectionController: testConnectionController,
storageController: testStorageController,
});
testPlaygroundController = new PlaygroundController({
connectionController: testConnectionController,
Expand Down
Loading