Skip to content

Commit

Permalink
feat(participant): Add telemetry for user feedback VSCODE-601 (#812)
Browse files Browse the repository at this point in the history
* Wire up telemetry to user feedback VSCODE-575

* Improve tests

* Remove incorrect sandbox usage

* Clean up some changes

* Ignore external type definitions from eslint

* Rename

* Fix participant tests
  • Loading branch information
nirinchev authored Sep 18, 2024
1 parent 764b8d1 commit 01486e4
Show file tree
Hide file tree
Showing 12 changed files with 706 additions and 215 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
out
dist
scripts
src/vscode-dts
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ npm run watch

2. Inside of [VS Code Insiders](https://code.visualstudio.com/insiders/) open this directory and press `F5` to begin debugging the extension. This should launch a new VSCode window which is running the extension.

### Using Proposed API

The vscode extension will occasionally need to use [proposed API](https://code.visualstudio.com/api/advanced-topics/using-proposed-api) that haven't been promoted to stable yet. To enable an API proposal, add it to the `enabledApiProposals` section in `package.json`, then run `cd src/vscode-dts && npx @vscode/dts dev` to install the type definitions for the API you want to enable.

**Note**: Using proposed API is only possible during local development and will prevent publishing the extension.

#### Code Tour

- `out` Compiled extension code
Expand Down
125 changes: 0 additions & 125 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"theme": "dark"
},
"enabledApiProposals": [
"chatVariableResolver"
"chatParticipantAdditions"
],
"license": "SEE LICENSE IN LICENSE.txt",
"main": "./dist/extension.js",
Expand Down Expand Up @@ -1211,7 +1211,6 @@
"@types/chai": "^4.3.17",
"@types/debug": "^4.1.12",
"@types/glob": "^7.2.0",
"@types/jest": "^26.0.24",
"@types/micromatch": "^4.0.9",
"@types/mkdirp": "^2.0.0",
"@types/mocha": "^8.2.3",
Expand Down
1 change: 1 addition & 0 deletions src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default class MDBExtensionController implements vscode.Disposable {
this._participantController = new ParticipantController({
connectionController: this._connectionController,
storageController: this._storageController,
telemetryService: this._telemetryService,
});
this._editorsController = new EditorsController({
context,
Expand Down
110 changes: 66 additions & 44 deletions src/participant/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,82 @@ import { ChatMetadataStore } from './chatMetadata';
export const CHAT_PARTICIPANT_ID = 'mongodb.participant';
export const CHAT_PARTICIPANT_MODEL = 'gpt-4o';

export class NamespaceRequestChatResult implements vscode.ChatResult {
readonly metadata: {
chatId: string;
intent: 'askForNamespace';
databaseName?: string | undefined;
collectionName?: string | undefined;
};
export type ParticipantResponseType =
| 'query'
| 'schema'
| 'docs'
| 'generic'
| 'emptyRequest'
| 'askToConnect'
| 'askForNamespace';

interface Metadata {
intent: Exclude<ParticipantResponseType, 'askForNamespace'>;
chatId: string;
}

interface AskForNamespaceMetadata {
intent: 'askForNamespace';
chatId: string;
databaseName?: string | undefined;
collectionName?: string | undefined;
}

export interface ChatResult extends vscode.ChatResult {
readonly metadata: Metadata | AskForNamespaceMetadata;
}

constructor({
databaseName,
collectionName,
history,
}: {
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>;
databaseName: string | undefined;
collectionName: string | undefined;
}) {
this.metadata = {
export function namespaceRequestChatResult({
databaseName,
collectionName,
history,
}: {
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>;
databaseName: string | undefined;
collectionName: string | undefined;
}): ChatResult {
return {
metadata: {
chatId: ChatMetadataStore.getChatIdFromHistoryOrNewChatId(history),
intent: 'askForNamespace',
databaseName,
collectionName,
};
}
},
};
}

export class EmptyRequestChatResult implements vscode.ChatResult {
readonly metadata: {
chatId: string;
intent: 'emptyRequest';
function createChatResult(
intent: ParticipantResponseType,
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
): ChatResult {
return {
metadata: {
intent,
chatId: ChatMetadataStore.getChatIdFromHistoryOrNewChatId(history),
},
};
}

constructor(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
) {
this.metadata = {
chatId: ChatMetadataStore.getChatIdFromHistoryOrNewChatId(history),
intent: 'emptyRequest',
};
}
export function emptyRequestChatResult(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
): ChatResult {
return createChatResult('emptyRequest', history);
}

export class AskToConnectChatResult implements vscode.ChatResult {
readonly metadata: {
chatId: string;
intent: 'askToConnect';
};
export function askToConnectChatResult(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
): ChatResult {
return createChatResult('askToConnect', history);
}

constructor(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
) {
this.metadata = {
chatId: ChatMetadataStore.getChatIdFromHistoryOrNewChatId(history),
intent: 'askToConnect',
};
}
export function genericRequestChatResult(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
): ChatResult {
return createChatResult('generic', history);
}

export function queryRequestChatResult(
history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>
): ChatResult {
return createChatResult('query', history);
}
Loading

0 comments on commit 01486e4

Please sign in to comment.