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

lightspeed/explanation: send the feedback events #1313

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
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
26 changes: 16 additions & 10 deletions src/features/lightspeed/playbookExplanation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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";

export const playbookExplanation = async (
extensionUri: vscode.Uri,
Expand All @@ -21,7 +22,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 +49,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 +77,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 +98,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 +126,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 +178,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,
});
}
Loading