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 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 .github/workflows/actions/test-and-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ runs:
shell: bash

- name: Run Tests
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: |
npm run test
shell: bash
Expand Down
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';
import { GenericPrompt } from './prompts/generic';
import { CHAT_PARTICIPANT_ID } from './constants';
import { QueryPrompt } from './prompts/query';
Expand Down Expand Up @@ -40,14 +42,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 @@ -278,6 +284,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
2 changes: 1 addition & 1 deletion src/test/suite/views/webview-app/overview-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('OverviewPage test suite', function () {
describe('Connection Form', function () {
// Rendering the connection form takes ~4 seconds, so we need to increase the timeout.
// Not sure on the cause of this slowdown, it could be animation based.
this.timeout(10000);
this.timeout(20000);
it('is able to open and close the new connection form', async function () {
render(<OverviewPage />);

Expand Down
Loading