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

Remove Lightspeed Enabled setting #1797

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ any level (User, Remote, Workspace and/or Folder).
completing module options.
- `ansibleServer.trace.server`: Traces the communication between VS Code and the
ansible language server.
- `ansible.lightspeed.enabled`: Enable Ansible Lightspeed.
- `ansible.lightspeed.URL`: URL for Ansible Lightspeed.
- `ansible.lightspeed.suggestions.enabled`: Enable Ansible Lightspeed with
watsonx Code Assistant inline suggestions.
Expand Down
21 changes: 7 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"steps": [
{
"id": "enable-lightspeed-playbook",
"title": "Enable Ansible Lightspeed",
"title": "Log in to Ansible Lightspeed",
"description": "Use generative AI to assist in your automation content creation.\nAnsible Lightspeed is available to Ansible Automation Platform users.\nCheck availability by logging in with your Red Hat account.\n[Log in with Red Hat ↗](command:ansible.lightspeed.signInWithLightspeed)\n[Learn more ↗](https://www.redhat.com/en/technologies/management/ansible/ansible-lightspeed) ",
"media": {
"markdown": "media/walkthroughs/startAutomatingPlaybook/enable-lightspeed.md"
Expand Down Expand Up @@ -329,7 +329,7 @@
},
{
"command": "ansible.create-playbook-options",
"title": "Ansible: Create an empty playbook or with Lightspeed (if enabled)"
"title": "Ansible: Create a playbook with Lightspeed"
},
{
"command": "ansible.content-creator.menu",
Expand Down Expand Up @@ -656,39 +656,32 @@
{
"title": "Ansible Lightspeed",
"properties": {
"ansible.lightspeed.enabled": {
"scope": "resource",
"type": "boolean",
"default": false,
"markdownDescription": "Enable Ansible Lightspeed.",
"order": 0
},
"ansible.lightspeed.URL": {
"scope": "resource",
"type": "string",
"default": "https://c.ai.ansible.redhat.com",
"markdownDescription": "URL for Ansible Lightspeed.",
"order": 1
"order": 0
},
"ansible.lightspeed.suggestions.enabled": {
"scope": "resource",
"type": "boolean",
"default": false,
"markdownDescription": "Enable Ansible Lightspeed with watsonx Code Assistant inline suggestions.",
"order": 2
"order": 1
},
"ansible.lightspeed.suggestions.waitWindow": {
"scope": "resource",
"type": "number",
"default": 0,
"markdownDescription": "Delay (in msecs) prior to sending an inline suggestion request to Ansible Lightspeed with watsonx Code Assistant.",
"order": 3
"order": 2
},
"ansible.lightspeed.modelIdOverride": {
"scope": "resource",
"type": "string",
"markdownDescription": "Model ID to override your organization's default model. This setting is only applicable to commercial users with an Ansible Lightspeed seat assignment.",
"order": 4
"order": 3
}
}
},
Expand Down Expand Up @@ -742,7 +735,7 @@
"command": "ansible.lightspeed.inlineSuggest.trigger",
"extensionName": "Ansible",
"source": "extension",
"when": "config.ansible.lightspeed.enabled && config.ansible.lightspeed.suggestions.enabled && editorTextFocus && !editorHasSelection && !inlineSuggestionVisible && editorLangId == 'ansible'"
"when": "config.ansible.lightspeed.suggestions.enabled && editorTextFocus && !editorHasSelection && !inlineSuggestionVisible && editorLangId == 'ansible'"
}
],
"languages": [
Expand Down
25 changes: 1 addition & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,15 +794,7 @@
vscode.commands.registerCommand(
"ansible.create-playbook-options",
async () => {
if (
await workspace.getConfiguration("ansible").get("lightspeed.enabled")
) {
vscode.commands.executeCommand(
"ansible.lightspeed.playbookGeneration",
);
} else {
vscode.commands.executeCommand("ansible.create-empty-playbook");
}
vscode.commands.executeCommand("ansible.lightspeed.playbookGeneration");

Check warning on line 797 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L797

Added line #L797 was not covered by tests
},
),
);
Expand Down Expand Up @@ -949,24 +941,9 @@
}
}

export async function isLightspeedEnabled(): Promise<boolean> {
if (
!(await workspace.getConfiguration("ansible").get("lightspeed.enabled"))
) {
await window.showErrorMessage(
"Enable lightspeed services from settings to use the feature.",
);
return false;
}
return true;
}

async function lightspeedLogin(
providerType: AuthProviderType | undefined,
): Promise<void> {
if (!(await isLightspeedEnabled())) {
return;
}
lightSpeedManager.currentModelValue = undefined;
const authenticatedUser =
await lightSpeedManager.lightspeedAuthenticatedUser.getLightspeedUserDetails(
Expand Down
3 changes: 0 additions & 3 deletions src/features/ansibleMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface ansibleMetadataEvent {
pythonVersion?: string;
ansibleLintVersion?: string;
eeEnabled: boolean;
lightSpeedEnabled: boolean;
lightSpeedCodeAssistEnabled: boolean;
}

Expand Down Expand Up @@ -156,8 +155,6 @@ export class MetadataManager {
ansibleVersion,
pythonVersion,
eeEnabled: this.extensionSettings.settings.executionEnvironment.enabled,
lightSpeedEnabled:
this.extensionSettings.settings.lightSpeedService.enabled,
lightSpeedCodeAssistEnabled:
this.extensionSettings.settings.lightSpeedService.suggestions.enabled,
};
Expand Down
44 changes: 17 additions & 27 deletions src/features/lightspeed/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
ANSIBLE_LIGHTSPEED_AUTH_ID,
ANSIBLE_LIGHTSPEED_AUTH_NAME,
);
if (this.settingsManager.settings.lightSpeedService.enabled) {
this.lightSpeedAuthenticationProvider.initialize();
}
this.lightSpeedAuthenticationProvider.initialize();

this.lightspeedAuthenticatedUser = new LightspeedUser(
this.context,
this.settingsManager,
Expand Down Expand Up @@ -109,29 +108,21 @@
const lightspeedSettings = <LightSpeedServiceSettings>(
vscode.workspace.getConfiguration("ansible").get("lightspeed")
);
const lightspeedEnabled = lightspeedSettings.enabled;

if (!lightspeedEnabled) {
this.resetContext();
await this.lightSpeedAuthenticationProvider.dispose();
this.statusBarProvider.statusBar.hide();
return;
} else {
this.lightSpeedAuthenticationProvider.initialize();
this.statusBarProvider.setLightSpeedStatusBarTooltip();
this.setContext();
if (lightspeedSettings.suggestions.enabled) {
const githubConfig = (<unknown>(
vscode.workspace.getConfiguration("github")
)) as {
copilot: { enable?: { ansible?: boolean } };
};
const copilotEnableForAnsible = githubConfig?.copilot?.enable?.ansible;
if (copilotEnableForAnsible) {
vscode.window.showInformationMessage(
"Please disable GitHub Copilot for Ansible Lightspeed file types to use Ansible Lightspeed.",
);
}
this.lightSpeedAuthenticationProvider.initialize();
this.statusBarProvider.setLightSpeedStatusBarTooltip();
this.setContext();
if (lightspeedSettings.suggestions.enabled) {
const githubConfig = (<unknown>(
vscode.workspace.getConfiguration("github")
)) as {
copilot: { enable?: { ansible?: boolean } };
};
const copilotEnableForAnsible = githubConfig?.copilot?.enable?.ansible;

Check warning on line 121 in src/features/lightspeed/base.ts

View check run for this annotation

Codecov / codecov/patch

src/features/lightspeed/base.ts#L116-L121

Added lines #L116 - L121 were not covered by tests
if (copilotEnableForAnsible) {
vscode.window.showInformationMessage(
"Please disable GitHub Copilot for Ansible Lightspeed file types to use Ansible Lightspeed.",
);

Check warning on line 125 in src/features/lightspeed/base.ts

View check run for this annotation

Codecov / codecov/patch

src/features/lightspeed/base.ts#L123-L125

Added lines #L123 - L125 were not covered by tests
}
}

Expand Down Expand Up @@ -165,10 +156,9 @@
const lightspeedSettings = <LightSpeedServiceSettings>(
vscode.workspace.getConfiguration("ansible").get("lightspeed")
);
const lightspeedEnabled = lightspeedSettings?.enabled;
const lightspeedSuggestionsEnabled =
lightspeedSettings?.suggestions.enabled;
return lightspeedEnabled && lightspeedSuggestionsEnabled;
return lightspeedSuggestionsEnabled;
}

private setCustomWhenClauseContext(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/features/lightspeed/inlineSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function getCompletionState(
if (isCancellationRequested) {
return CompletionState.CancellationRequested;
}
if (!lightSpeedSetting.enabled || !lightSpeedSetting.suggestions.enabled) {
if (!lightSpeedSetting.suggestions.enabled) {
return CompletionState.LightspeedIsDisabled;
}

Expand Down
13 changes: 0 additions & 13 deletions src/features/lightspeed/lightspeedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ export class LightspeedUser {
createIfNone: boolean,
useProviderType: AuthProviderType | undefined = undefined,
) {
// Ensure we don't try to get a lightspeed auth session when the provider is not initialized
if (!this._settingsManager.settings.lightSpeedService.enabled) {
return undefined;
}
if (
this._userDetails &&
(!useProviderType || useProviderType === this._userType)
Expand All @@ -388,10 +384,6 @@ export class LightspeedUser {
createIfNone: boolean,
useProviderType: AuthProviderType | undefined = undefined,
) {
// Ensure we don't try to get a lightspeed auth session when the provider is not initialized
if (!this._settingsManager.settings.lightSpeedService.enabled) {
return undefined;
}
if (
this._markdownUserDetails &&
(!useProviderType || useProviderType === this._userType)
Expand All @@ -405,11 +397,6 @@ export class LightspeedUser {
}

public async getLightspeedUserContent() {
// Ensure we don't try to get a lightspeed auth session when the provider is not initialized
if (!this._settingsManager.settings.lightSpeedService.enabled) {
return undefined;
}

const markdownUserDetails =
await this.getMarkdownLightspeedUserDetails(false);
const userDetails = await this.getLightspeedUserDetails(false);
Expand Down
11 changes: 8 additions & 3 deletions src/features/lightspeed/playbookGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from "uuid";
import { Webview, Uri } from "vscode";
import { getNonce } from "../utils/getNonce";
import { getUri } from "../utils/getUri";
import { isLightspeedEnabled, lightSpeedManager } from "../../extension";
import { lightSpeedManager } from "../../extension";
import { IError } from "./utils/errors";
import { PlaybookGenerationResponseParams } from "../../interfaces/lightspeed";
import {
Expand Down Expand Up @@ -93,8 +93,13 @@ async function generatePlaybook(
}

export async function showPlaybookGenerationPage(extensionUri: vscode.Uri) {
// Check if Lightspeed is enabled or not. If it is not, return without opening the panel.
if (!(await isLightspeedEnabled())) {
const isAuthenticated =
await lightSpeedManager.lightspeedAuthenticatedUser.isAuthenticated();
if (!isAuthenticated) {
await vscode.window.showErrorMessage(
"Log in to lightspeed services to use the feature.",
);

return;
}

Expand Down
8 changes: 1 addition & 7 deletions src/features/lightspeed/roleGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from "uuid";
import { Webview, Uri, workspace } from "vscode";
import { getNonce } from "../utils/getNonce";
import { getUri } from "../utils/getUri";
import { isLightspeedEnabled, lightSpeedManager } from "../../extension";
import { lightSpeedManager } from "../../extension";
import { IError } from "./utils/errors";
import {
RoleGenerationResponseParams,
Expand Down Expand Up @@ -101,12 +101,6 @@ async function fileExists(uri: Uri): Promise<boolean> {
}

export async function showRoleGenerationPage(extensionUri: vscode.Uri) {
// Check if Lightspeed is enabled or not. If it is not, return without opening the panel.
if (!(await isLightspeedEnabled())) {
vscode.window.showErrorMessage("Lightspeed is not enabled.");
return;
}

function addLog(message: string) {
panel.webview.postMessage({
command: "addGenerateRoleLogEntry",
Expand Down
10 changes: 2 additions & 8 deletions src/features/lightspeed/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ export class LightspeedStatusBar {
);
}

if (
this.settingsManager.settings.lightSpeedService.enabled &&
this.settingsManager.settings.lightSpeedService.suggestions.enabled
) {
if (this.settingsManager.settings.lightSpeedService.suggestions.enabled) {
this.statusBar.backgroundColor = new vscode.ThemeColor(
"statusBarItem.prominentForeground",
);
Expand All @@ -97,10 +94,7 @@ export class LightspeedStatusBar {
}

public async updateLightSpeedStatusbar(): Promise<void> {
if (
vscode.window.activeTextEditor?.document.languageId !== "ansible" ||
!this.settingsManager.settings.lightSpeedService.enabled
) {
if (vscode.window.activeTextEditor?.document.languageId !== "ansible") {
this.statusBar.hide();
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/extensionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface UserResponse {

// Settings appear on VS Code Settings UI
export interface LightSpeedServiceSettings {
enabled: boolean;
URL: string;
suggestions: { enabled: boolean; waitWindow: number };
model: string | undefined;
Expand Down
1 change: 0 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class SettingsManager {
volumeMounts: eeSettings.get("volumeMounts", []),
},
lightSpeedService: {
enabled: lightSpeedSettings.get("enabled", false),
URL: lightSpeedSettings.get("URL", "https://c.ai.ansible.redhat.com"),
suggestions: {
enabled: lightSpeedSettings.get("suggestions.enabled", false),
Expand Down
2 changes: 0 additions & 2 deletions test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export async function disableExecutionEnvironmentSettings(): Promise<void> {
}

export async function enableLightspeedSettings(): Promise<void> {
await updateSettings("lightspeed.enabled", true);
await updateSettings("lightspeed.suggestions.enabled", true);
await updateSettings("lightspeed.URL", process.env.TEST_LIGHTSPEED_URL);

Expand All @@ -152,7 +151,6 @@ export async function enableLightspeedSettings(): Promise<void> {
}

export async function disableLightspeedSettings(): Promise<void> {
await updateSettings("lightspeed.enabled", false);
await updateSettings("lightspeed.suggestions.enabled", false);
await updateSettings("lightspeed.URL", "");
}
Expand Down
1 change: 0 additions & 1 deletion test/testFixtures/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"ansible.python.activationScript": "",
"ansible.python.interpreterPath": "python3",
"ansibleServer.trace.server": "verbose",
"ansible.lightspeed.enabled": false,
"ansible.lightspeed.suggestions.enabled": false,
"ansible.lightspeed.URL": "https://c.ai.ansible.redhat.com",

Expand Down
1 change: 0 additions & 1 deletion test/ui-test/lightspeedAuthUiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe("Login to Lightspeed", () => {
// Enable Lightspeed and open Ansible Light view on sidebar
workbench = new Workbench();
const settingsEditor = await workbench.openSettings();
await updateSettings(settingsEditor, "ansible.lightspeed.enabled", true);
await updateSettings(
settingsEditor,
"ansible.lightspeed.URL",
Expand Down
2 changes: 1 addition & 1 deletion test/ui-test/lightspeedOneClickTrialUITest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// BEFORE: ansible.lightspeed.enabled: true
// BEFORE: ansible.lightspeed.suggestions.enabled: true
import {
ActionsControl,
ActivityBar,
Expand Down
2 changes: 1 addition & 1 deletion test/ui-test/lightspeedRoleGenTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// BEFORE: ansible.lightspeed.enabled: true
// BEFORE: ansible.lightspeed.suggestions.enabled: true

import { expect, config } from "chai";
import fs from "fs";
Expand Down
Loading
Loading