Skip to content

Commit

Permalink
lightspeed/explanation: send the feedback events
Browse files Browse the repository at this point in the history
Send the feedback events to the server.
  • Loading branch information
goneri committed May 13, 2024
1 parent df8a75e commit 59bcbfc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export class AnsibleLanguageService {
const accessToken: string = params["accessToken"];
const URL: string = params["URL"];
const content: string = params["content"];
const explanationId: string = params["explanationId"];

const headers = {
"Content-Type": "application/json",
Expand All @@ -380,7 +381,7 @@ export class AnsibleLanguageService {
const result: ExplanationResponse = await axiosInstance
.post("/ai/explanations/", {
content: content,
explanationId: uuidv4(),
explanationId: explanationId,
})
.then((response) => {
return response.data;
Expand Down
26 changes: 19 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ import {
LightspeedUser,
AuthProviderType,
} from "./features/lightspeed/lightspeedUser";
import { PlaybookOutlineEvent } from "./interfaces/lightspeed";
import {
PlaybookOutlineEvent,
PlaybookExplanationEvent,
} from "./interfaces/lightspeed";

export let client: LanguageClient;
export let lightSpeedManager: LightSpeedManager;
Expand Down Expand Up @@ -558,12 +561,21 @@ export async function activate(context: ExtensionContext): Promise<void> {
context.subscriptions.push(
vscode.commands.registerCommand(
"ansible.lightspeed.thumbsUpDown",
async (param: PlaybookOutlineEvent) => {
lightSpeedManager.apiInstance.feedbackRequest(
{ playbookOutlineFeedback: param },
true,
true,
);
async (param: PlaybookOutlineEvent | PlaybookExplanationEvent) => {
if ("outlineId" in param) {
lightSpeedManager.apiInstance.feedbackRequest(
{ playbookOutlineFeedback: param },
true,
true,
);
}
if ("explanationId" in param) {
lightSpeedManager.apiInstance.feedbackRequest(
{ playbookExplanationFeedback: param },
true,
true,
);
}
window.showInformationMessage("Thank you for your feedback!");
},
),
Expand Down
27 changes: 17 additions & 10 deletions src/features/lightspeed/playbookExplanation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { SettingsManager } from "../../settings";
import { lightSpeedManager } from "../../extension";
import { LightspeedUser } from "./lightspeedUser";
import { ExplanationResponse } from "@ansible/ansible-language-server/src/interfaces/lightspeedApi";
import { v4 as uuidv4 } from "uuid";
import { explanations } from "../../../test/mockLightspeedServer/explanations";

export const playbookExplanation = async (
extensionUri: vscode.Uri,
Expand All @@ -21,7 +23,11 @@ export const playbookExplanation = async (
if (document?.languageId !== "ansible") {
return;
}
const currentPanel = PlaybookExplanationPanel.createOrShow(extensionUri);
const explanationId = uuidv4();
const currentPanel = PlaybookExplanationPanel.createOrShow(
extensionUri,
explanationId,
);
currentPanel.setContent(
`<div id="icons">
<span class="codicon codicon-loading codicon-modifier-spin"></span>
Expand All @@ -44,6 +50,7 @@ export const playbookExplanation = async (
accessToken: accessToken,
URL: settingsManager.settings.lightSpeedService.URL,
content: content,
explanationId: explanationId,
},
);
markdown = response.content;
Expand Down Expand Up @@ -71,7 +78,7 @@ export class PlaybookExplanationPanel {
private readonly _extensionUri: vscode.Uri;
private _disposables: vscode.Disposable[] = [];

public static createOrShow(extensionUri: vscode.Uri) {
public static createOrShow(extensionUri: vscode.Uri, explanationId: string) {
const panel = vscode.window.createWebviewPanel(
PlaybookExplanationPanel.viewType,
"Explanation",
Expand All @@ -92,7 +99,10 @@ export class PlaybookExplanationPanel {
switch (command) {
case "thumbsUp":
case "thumbsDown":
vscode.commands.executeCommand("ansible.lightspeed.thumbsUpDown");
vscode.commands.executeCommand("ansible.lightspeed.thumbsUpDown", {
action: message.action,
explanationId: explanationId,
});
break;
}
});
Expand All @@ -117,14 +127,11 @@ export class PlaybookExplanationPanel {
);
}

public setContent(html_snippet: string, showFeedbackBox = false) {
this._panel.webview.html = this.buildFullHtml(
html_snippet,
showFeedbackBox,
);
public setContent(htmlSnippet: string, showFeedbackBox = false) {
this._panel.webview.html = this.buildFullHtml(htmlSnippet, showFeedbackBox);
}

private buildFullHtml(html_snippet: string, showFeedbackBox = false) {
private buildFullHtml(htmlSnippet: string, showFeedbackBox = false) {
const webview = this._panel.webview;
const webviewUri = getUri(webview, this._extensionUri, [
"out",
Expand Down Expand Up @@ -172,7 +179,7 @@ export class PlaybookExplanationPanel {
</head>
<body>
<div class="playbookGeneration">
${html_snippet}
${htmlSnippet}
</div>
${showFeedbackBox ? feedbackBoxSnippet : ""}
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/lightspeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ export interface PlaybookOutlineEvent {
outlineId: string;
}

export interface PlaybookExplanationEvent {
action: ThumbsUpDownAction;
outlineId: string;
}

export interface FeedbackRequestParams {
inlineSuggestion?: InlineSuggestionEvent;
sentimentFeedback?: SentimentEvent;
suggestionQualityFeedback?: SuggestionQualityEvent;
issueFeedback?: IssueFeedbackEvent;
playbookExplanationFeedback?: PlaybookExplanationEvent;
playbookOutlineFeedback?: PlaybookOutlineEvent;
model?: string;
}
Expand Down
24 changes: 21 additions & 3 deletions src/webview/apps/lightspeed/playbookExplanation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Button,
vsCodeButton,
} from "@vscode/webview-ui-toolkit";
import { ThumbsUpDownAction } from "../../../../definitions/lightspeed";

provideVSCodeDesignSystem().register(vsCodeButton());

Expand Down Expand Up @@ -31,11 +32,28 @@ function changeDisplay(className: string, displayState: string) {
element.style.display = displayState;
}
}

function sendThumbsup() {
vscode.postMessage({ command: "thumbsUp" });
const thumbsUpButton = document.getElementById("thumbsup-button") as Button;
const thumbsDownButton = document.getElementById(
"thumbsdown-button",
) as Button;
thumbsUpButton.setAttribute("class", "iconButtonSelected");
thumbsDownButton.setAttribute("class", "iconButton");
vscode.postMessage({
command: "thumbsUp",
action: ThumbsUpDownAction.UP,
});
}

function sendThumbsdown() {
vscode.postMessage({ command: "thumbsDown" });
const thumbsUpButton = document.getElementById("thumbsup-button") as Button;
const thumbsDownButton = document.getElementById(
"thumbsdown-button",
) as Button;
thumbsUpButton.setAttribute("class", "iconButton");
thumbsDownButton.setAttribute("class", "iconButtonSelected");
vscode.postMessage({
command: "thumbsDown",
action: ThumbsUpDownAction.DOWN,
});
}

0 comments on commit 59bcbfc

Please sign in to comment.