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(participant): in-app notification to introduce users to copilot extension VSCODE-633 #875

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 51 additions & 0 deletions src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default class MDBExtensionController implements vscode.Disposable {
this.registerCommands();
this.showOverviewPageIfRecentlyInstalled();
void this.showSurveyForEstablishedUsers();
void this.showCopilotIntroductionForEstablishedUsers();
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
}

registerCommands = (): void => {
Expand Down Expand Up @@ -918,6 +919,56 @@ export default class MDBExtensionController implements vscode.Disposable {
}
}

async showCopilotIntroductionForEstablishedUsers(): Promise<void> {
const hasBeenShownAlready =
this._storageController.get(
StorageVariables.GLOBAL_COPILOT_INTRODUCTION_SHOWN
) === true;

// Show the toast when it hasn't been show to the
// user yet, and they have saved connections
// -> they haven't just started using this extension.
if (hasBeenShownAlready || !this._connectionStorage.hasSavedConnections()) {
return;
}

const copilot = vscode.extensions.getExtension('github.copilot-chat');

const action = 'Chat with @MongoDB';
const text =
'Generate queries, interact with documentation, and explore your database schema using the MongoDB Copilot extension. Give it a try!';
const result = await vscode.window.showInformationMessage(
text,
{},
{
title: action,
}
);
if (result?.title === action) {
await vscode.commands.executeCommand('workbench.action.chat.newChat');
await vscode.commands.executeCommand(
'workbench.action.chat.clearHistory'
);
await vscode.commands.executeCommand('workbench.action.chat.open', {
query: '@MongoDB',
isPartialQuery: true,
});
this._telemetryService.trackCopilotIntroductionClicked({
is_copilot_active: !!copilot?.isActive,
});
} else {
this._telemetryService.trackCopilotIntroductionDismissed({
is_copilot_active: !!copilot?.isActive,
});
}

// Whether action was taken or the prompt dismissed, we won't show this again.
void this._storageController.update(
StorageVariables.GLOBAL_COPILOT_INTRODUCTION_SHOWN,
true
);
}

async showSurveyForEstablishedUsers(): Promise<void> {
const surveyId = '9viN9wcbsC3zvHyg7';

Expand Down
2 changes: 2 additions & 0 deletions src/storage/storageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum StorageVariables {
// Only exists on globalState.
GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW = 'GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW',
GLOBAL_SURVEY_SHOWN = 'GLOBAL_SURVEY_SHOWN',
GLOBAL_COPILOT_INTRODUCTION_SHOWN = 'GLOBAL_COPILOT_INTRODUCTION_SHOWN',
GLOBAL_SAVED_CONNECTIONS = 'GLOBAL_SAVED_CONNECTIONS',
// Analytics user identify.
GLOBAL_USER_ID = 'GLOBAL_USER_ID',
Expand Down Expand Up @@ -53,6 +54,7 @@ interface StorageVariableContents {
[StorageVariables.GLOBAL_ANONYMOUS_ID]: string;
[StorageVariables.GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW]: boolean;
[StorageVariables.GLOBAL_SURVEY_SHOWN]: string;
[StorageVariables.GLOBAL_COPILOT_INTRODUCTION_SHOWN]: boolean;
[StorageVariables.GLOBAL_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.WORKSPACE_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE]: boolean;
Expand Down
19 changes: 18 additions & 1 deletion src/telemetry/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export type ParticipantResponseProperties = {
output_length: number;
};

export type CopilotIntroductionProperties = {
is_copilot_active: boolean;
};

export function chatResultFeedbackKindToTelemetryValue(
kind: vscode.ChatResultFeedbackKind
): TelemetryFeedbackKind {
Expand Down Expand Up @@ -167,7 +171,8 @@ type TelemetryEventProperties =
| ParticipantFeedbackProperties
| ParticipantResponseFailedProperties
| ParticipantPromptProperties
| ParticipantResponseProperties;
| ParticipantResponseProperties
| CopilotIntroductionProperties;

export enum TelemetryEventTypes {
PLAYGROUND_CODE_EXECUTED = 'Playground Code Executed',
Expand All @@ -192,6 +197,8 @@ export enum TelemetryEventTypes {
PARTICIPANT_RESPONSE_FAILED = 'Participant Response Failed',
PARTICIPANT_PROMPT_SUBMITTED = 'Participant Prompt Submitted',
PARTICIPANT_RESPONSE_GENERATED = 'Participant Response Generated',
COPILOT_INTRODUCTION_CLICKED = 'Copilot Introduction Clicked',
COPILOT_INTRODUCTION_DISMISSED = 'Copilot Introduction Dismissed',
}

/**
Expand Down Expand Up @@ -489,4 +496,14 @@ export default class TelemetryService {
trackCopilotParticipantResponse(props: ParticipantResponseProperties): void {
this.track(TelemetryEventTypes.PARTICIPANT_RESPONSE_GENERATED, props);
}

trackCopilotIntroductionClicked(props: CopilotIntroductionProperties): void {
this.track(TelemetryEventTypes.COPILOT_INTRODUCTION_CLICKED, props);
}

trackCopilotIntroductionDismissed(
props: CopilotIntroductionProperties
): void {
this.track(TelemetryEventTypes.COPILOT_INTRODUCTION_DISMISSED, props);
}
}
137 changes: 137 additions & 0 deletions src/test/suite/mdbExtensionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,143 @@ suite('MDBExtensionController Test Suite', function () {
});
});
});

suite('copilot introduction prompt', function () {
suite(
"when a user hasn't been shown the copilot introduction prompt yet, and they have connections saved",
() => {
[
{
description: 'clicked the button',
value: { title: 'Chat with @MongoDB' },
},
{ description: 'dismissed', value: undefined },
].forEach((reaction) => {
suite(`user ${reaction.description}`, () => {
let connectionsUpdateStub: SinonStub;
let executeCommandStub: SinonStub;
beforeEach(async () => {
showInformationMessageStub.resolves(reaction.value);
executeCommandStub = sandbox.stub(
vscode.commands,
'executeCommand'
);
sandbox.replace(
mdbTestExtension.testExtensionController._storageController,
'get',
sandbox.fake.returns(undefined)
);
sandbox.replace(
mdbTestExtension.testExtensionController._connectionStorage,
'hasSavedConnections',
sandbox.fake.returns(true)
);
connectionsUpdateStub = sandbox.stub(
mdbTestExtension.testExtensionController._storageController,
'update'
);
connectionsUpdateStub.resolves(undefined);
await mdbTestExtension.testExtensionController.showCopilotIntroductionForEstablishedUsers();
});

afterEach(() => {
sandbox.restore();
});

test('they are shown the copilot introduction prompt', () => {
assert(showInformationMessageStub.called);
assert.strictEqual(
showInformationMessageStub.firstCall.args[0],
'Generate queries, interact with documentation, and explore your database schema using the MongoDB Copilot extension. Give it a try!'
);
});

test('the link was open if and only if they click the button', () => {
if (reaction.value === undefined) {
assert(executeCommandStub.notCalled);
}
if (reaction.value) {
assert(executeCommandStub.called);
assert.strictEqual(
executeCommandStub.firstCall.args[0],
'workbench.action.chat.newChat'
);
}
});

test("it sets that they've been shown the copilot introduction", () => {
assert(connectionsUpdateStub.called);
assert.strictEqual(
connectionsUpdateStub.firstCall.args[0],
StorageVariables.GLOBAL_COPILOT_INTRODUCTION_SHOWN
);
assert.strictEqual(
connectionsUpdateStub.firstCall.args[1],
true
);
});
});
});
}
);

suite(
'when a user has been shown the copilot introduction prompt already',
() => {
let connectionsUpdateStub: SinonStub;
beforeEach(() => {
sandbox.replace(
mdbTestExtension.testExtensionController._storageController,
'get',
sandbox.fake.returns(true) // copilot introduction has been shown
);
sandbox.replace(
mdbTestExtension.testExtensionController._connectionStorage,
'hasSavedConnections',
sandbox.fake.returns(true)
);
connectionsUpdateStub = sandbox.stub(
mdbTestExtension.testExtensionController._storageController,
'update'
);
connectionsUpdateStub.resolves(undefined);

void mdbTestExtension.testExtensionController.showCopilotIntroductionForEstablishedUsers();
});

test('they are not shown the copilot introduction prompt', () => {
assert(showInformationMessageStub.notCalled);
});
}
);

suite('when a has no connections saved', () => {
let connectionsUpdateStub: SinonStub;
beforeEach(() => {
sandbox.replace(
mdbTestExtension.testExtensionController._storageController,
'get',
sandbox.fake.returns(undefined)
);
sandbox.replace(
mdbTestExtension.testExtensionController._connectionStorage,
'hasSavedConnections',
sandbox.fake.returns(false) // no connections yet - this might be the first install
);
connectionsUpdateStub = sandbox.stub(
mdbTestExtension.testExtensionController._storageController,
'update'
);
connectionsUpdateStub.resolves(undefined);

void mdbTestExtension.testExtensionController.showCopilotIntroductionForEstablishedUsers();
});

test('they are not shown the copilot introduction prompt', () => {
assert(showInformationMessageStub.notCalled);
});
});
});
});

test('mdb.participantViewRawSchemaOutput command opens a json document with the output', async () => {
Expand Down
Loading