Skip to content

Commit

Permalink
AAP-35216: integrate the roleGen with its new API endpoint
Browse files Browse the repository at this point in the history
- Interact with the LIGHTSPEED_ROLE_GENERATION_URL end-point
- Use the Dummy Lightspeed server to do the e2e test coverage
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
goneri committed Dec 4, 2024
1 parent 6e4d070 commit 907e667
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 163 deletions.
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
!media/welcomePage/quickLinksStyle.css
!media/playbookGeneration/playbookGeneration.css
!media/playbookGeneration/style.css
!media/roleGeneration/style.css
!out/client/src/extension.js
!out/syntaxHighlighter/src/syntaxHighlighter.js
!out/client/webview/apps/lightspeed/main.js
!out/client/webview/apps/lightspeed/explorer/main.js
!out/client/webview/apps/lightspeed/playbookExplanation/main.js
!out/client/webview/apps/lightspeed/playbookGeneration/main.js
!out/client/webview/apps/lightspeed/roleGeneration/main.js
!out/client/webview/apps/contentCreator/welcomePageApp.js
!out/client/webview/apps/contentCreator/createAnsibleCollectionPageApp.js
!out/client/webview/apps/contentCreator/createAnsibleProjectPageApp.js
Expand Down
1 change: 0 additions & 1 deletion media/roleGeneration/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ a:active {

.formattedPlaybook {
width: 100%;
height: 25em;
border-style: solid;
border-width: thin;
border-color: var(--vscode-widget-border);
Expand Down
46 changes: 42 additions & 4 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
FeedbackRequestParams,
FeedbackResponseParams,
GenerationRequestParams,
GenerationResponseParams,
PlaybookGenerationResponseParams,
RoleGenerationResponseParams,
} from "../../interfaces/lightspeed";
import {
LIGHTSPEED_PLAYBOOK_EXPLANATION_URL,
LIGHTSPEED_PLAYBOOK_GENERATION_URL,
LIGHTSPEED_ROLE_GENERATION_URL,
LIGHTSPEED_SUGGESTION_COMPLETION_URL,
LIGHTSPEED_SUGGESTION_CONTENT_MATCHES_URL,
LIGHTSPEED_SUGGESTION_FEEDBACK_URL,
Expand Down Expand Up @@ -325,13 +327,13 @@ export class LightSpeedAPI {
}
}

public async generationRequest(
public async playbookGenerationRequest(
inputData: GenerationRequestParams,
): Promise<GenerationResponseParams | IError> {
): Promise<PlaybookGenerationResponseParams | IError> {
const axiosInstance = await this.getApiInstance();
if (axiosInstance === undefined) {
console.error("Ansible Lightspeed instance is not initialized.");
return {} as GenerationResponseParams;
return {} as PlaybookGenerationResponseParams;
}
try {
const requestData = {
Expand Down Expand Up @@ -361,4 +363,40 @@ export class LightSpeedAPI {
return mappedError;
}
}

public async roleGenerationRequest(
inputData: GenerationRequestParams,
): Promise<RoleGenerationResponseParams | IError> {
const axiosInstance = await this.getApiInstance();
if (axiosInstance === undefined) {
console.error("Ansible Lightspeed instance is not initialized.");
return {} as RoleGenerationResponseParams;
}
try {
const requestData = {
...inputData,
metadata: { ansibleExtensionVersion: this._extensionVersion },
};
console.log(
`[ansible-lightspeed] Role Generation request sent to lightspeed: ${JSON.stringify(
requestData,
)}`,
);
const response = await axiosInstance.post(
LIGHTSPEED_ROLE_GENERATION_URL,
requestData,
{
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
signal: AbortSignal.timeout(ANSIBLE_LIGHTSPEED_API_TIMEOUT),
},
);
return response.data;
} catch (error) {
const err = error as AxiosError;
const mappedError: IError = await mapError(err);
// Do not show trial popup for errors on content matches because either
// completions or generations API should have been called already.
return mappedError;
}
}
}
36 changes: 19 additions & 17 deletions src/features/lightspeed/playbookGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getNonce } from "../utils/getNonce";
import { getUri } from "../utils/getUri";
import { isLightspeedEnabled, lightSpeedManager } from "../../extension";
import { IError } from "./utils/errors";
import { GenerationResponseParams } from "../../interfaces/lightspeed";
import { PlaybookGenerationResponseParams } from "../../interfaces/lightspeed";
import {
LightSpeedCommands,
WizardGenerationActionType,
Expand Down Expand Up @@ -73,13 +73,13 @@ async function generatePlaybook(
outline: string | undefined,
generationId: string,
panel: vscode.WebviewPanel,
): Promise<GenerationResponseParams | IError> {
): Promise<PlaybookGenerationResponseParams | IError> {
try {
panel.webview.postMessage({ command: "startSpinner" });
const createOutline = outline === undefined;

const response: GenerationResponseParams | IError =
await apiInstance.generationRequest({
const response: PlaybookGenerationResponseParams | IError =
await apiInstance.playbookGenerationRequest({
text,
outline,
createOutline,
Expand Down Expand Up @@ -134,20 +134,22 @@ export async function showPlaybookGenerationPage(extensionUri: vscode.Uri) {
undefined,
message.generationId,
panel,
).then(async (response: GenerationResponseParams | IError) => {
if (isError(response)) {
const oneClickTrialProvider = getOneClickTrialProvider();
if (!(await oneClickTrialProvider.showPopup(response))) {
const errorMessage: string = `${response.message ?? UNKNOWN_ERROR} ${response.detail ?? ""}`;
vscode.window.showErrorMessage(errorMessage);
).then(
async (response: PlaybookGenerationResponseParams | IError) => {
if (isError(response)) {
const oneClickTrialProvider = getOneClickTrialProvider();
if (!(await oneClickTrialProvider.showPopup(response))) {
const errorMessage: string = `${response.message ?? UNKNOWN_ERROR} ${response.detail ?? ""}`;
vscode.window.showErrorMessage(errorMessage);
}
} else {
panel.webview.postMessage({
command: "outline",
outline: response,
});
}
} else {
panel.webview.postMessage({
command: "outline",
outline: response,
});
}
});
},
);
} else {
panel.webview.postMessage({
command: "outline",
Expand Down
Loading

0 comments on commit 907e667

Please sign in to comment.