Skip to content

Commit

Permalink
Adding the chatbot screen. (#64)
Browse files Browse the repository at this point in the history
* chore: adding a chatbot screen

Signed-off-by: Aditya-eddy <aditya282003@gmail.com>

* chore:adding example prompts

Signed-off-by: Aditya-eddy <aditya282003@gmail.com>

---------

Signed-off-by: Aditya-eddy <aditya282003@gmail.com>
  • Loading branch information
Aditya-eddy authored Oct 7, 2024
1 parent cb8ee11 commit 30c04a5
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 30 deletions.
49 changes: 27 additions & 22 deletions scripts/utg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

export API_KEY="1234"


sourceFilePath=$1
testFilePath=$2
coverageReportPath=$3
command=$4

additional_prompts=$5

# Get the file extension
extension="${sourceFilePath##*.}"
Expand Down Expand Up @@ -40,26 +39,32 @@ if [ "$extension" = "go" ]; then
export PATH=$PATH:$(go env GOPATH)/bin
fi

# Add env variables to the npm test command
# utgEnv=" -- --coverage --coverageReporters=text --coverageReporters=cobertura --coverageDirectory=./coverage"

# Construct the keploy gen command
if [ "$extension" = "java" ]; then
keploy gen --source-file-path="$sourceFilePath" \
--test-file-path="$testFilePath" \
--test-command="$command" \
--coverage-report-path="$coverageReportPath" \
--llmApiVersion "2024-02-01" \
--llmBaseUrl "https://api.keploy.io" \
--max-iterations "5" \
--coverageFormat jacoco
keployCommand="keploy gen --source-file-path=\"$sourceFilePath\" \
--test-file-path=\"$testFilePath\" \
--test-command=\"$command\" \
--coverage-report-path=\"$coverageReportPath\" \
--llmApiVersion \"2024-02-01\" \
--llmBaseUrl \"https://api.keploy.io\" \
--max-iterations \"5\" \
--coverageFormat jacoco"
else
keploy gen --source-file-path="$sourceFilePath" \
--test-file-path="$testFilePath" \
--test-command="$command" \
--coverage-report-path="$coverageReportPath" \
--llmApiVersion "2024-02-01" \
--llmBaseUrl "https://api.keploy.io" \
--max-iterations "5" \
--coverageFormat cobertura
fi
keployCommand="keploy gen --source-file-path=\"$sourceFilePath\" \
--test-file-path=\"$testFilePath\" \
--test-command=\"$command\" \
--coverage-report-path=\"$coverageReportPath\" \
--llmApiVersion \"2024-02-01\" \
--llmBaseUrl \"https://api.keploy.io\" \
--max-iterations \"5\" \
--coverageFormat cobertura"
fi

# Add the additional prompt if it's provided and not an empty string
if [ -n "$additional_prompts" ] && [ "$additional_prompts" != " " ]; then
keployCommand="$keployCommand --additional-prompt \"$additional_prompts\""
fi

# Run the keploy command
# echo "Running: $keployCommand"
eval $keployCommand
66 changes: 62 additions & 4 deletions src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,40 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
constructor(private readonly _extensionUri: vscode.Uri, private readonly _context: vscode.ExtensionContext) {
}

public postMessage(type: any, value: any) {
console.log('postMessage');
this._view?.webview.postMessage({ type: type, value: value });
public postMessage(value: any) {
if (!this._view) {
vscode.window.showErrorMessage('Webview is not available');
return;
}

let webviewView = this._view;

try {
console.log('Navigate to ' + value);
let sveltePageJs: vscode.Uri;
let sveltePageCss: vscode.Uri;
if(value = "KeployChatBot"){
sveltePageJs = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.js")
);
sveltePageCss = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.css")
);

}
else {
throw new Error("Unsupported navigation value");
}

// Save the language state
// vscode.getState().then(() => {
// vscode.setState({ language: data.language });
// });

webviewView.webview.html = this._getHtmlForWebview(webviewView.webview, sveltePageCss, sveltePageJs);
} catch (error) {
this._view?.webview.postMessage({ type: 'error', value: `Failed to open page ${error}` });
}
}

public resolveWebviewView(webviewView: vscode.WebviewView) {
Expand Down Expand Up @@ -321,7 +352,16 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
sveltePageCss = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployHome.css")
);
} else {
}else if(data.value = "KeployChatBot"){
sveltePageJs = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.js")
);
sveltePageCss = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.css")
);

}
else {
throw new Error("Unsupported navigation value");
}

Expand All @@ -345,6 +385,24 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
vscode.window.showErrorMessage('Failed to sign in. Please try again.');
}
break;
}
//cannot make it a case of generate unit test as we will taking the input from the user and keploy gen with additional prompts will from a cta hence making a new case for it.
case "keployGenWithAdditionalPrompts":{
try{
const additional_prompts = data.prompt;
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage("No file is currently open.");
return;
}

const fileUri = editor.document.uri;
console.log("additional prompts and uri: ", additional_prompts , fileUri);
await vscode.commands.executeCommand('keploy.utg' , fileUri , additional_prompts );
}catch(error){
console.error("Error executing keploy.utg command:", error);
}
break;
}

case "openLink": {
Expand Down
9 changes: 7 additions & 2 deletions src/Utg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import axios, { AxiosResponse } from 'axios';


async function Utg(context: vscode.ExtensionContext) {
async function Utg(context: vscode.ExtensionContext , additional_prompts?:string) {

try {
return new Promise<void>(async (resolve, reject) => {
Expand Down Expand Up @@ -106,7 +106,12 @@ async function Utg(context: vscode.ExtensionContext) {
return;
}

terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePath}" "${coverageReportPath}" "${command}";`);
if(!additional_prompts){
additional_prompts = "";
}


terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePath}" "${coverageReportPath}" "${command}" "${additional_prompts}";`);

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

Expand Down
40 changes: 38 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
command: 'keploy.utg',
arguments: [document.uri.fsPath]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
arguments: [document.uri.fsPath]
}));
} else if (fileName.endsWith('.js') || fileName.endsWith('.ts')) {
if (node.type === 'arrow_function') {
const parent = ancestors[ancestors.length - 1];
Expand All @@ -78,6 +83,12 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
command: 'keploy.utg',
arguments: [document.uri.fsPath]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
arguments: [document.uri.fsPath]
}));
}
}
} else if (fileName.endsWith('.py') && node.type === 'function_definition') {
Expand All @@ -88,6 +99,11 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
command: 'keploy.utg',
arguments: [document.uri.fsPath]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
arguments: [document.uri.fsPath]
}));
} else if (fileName.endsWith('.java') && (node.type === 'method_declaration' || node.type === 'constructor_declaration')) {
const line = document.positionAt(node.startIndex).line;
const range = new vscode.Range(line, 0, line, 0);
Expand All @@ -96,6 +112,11 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
command: 'keploy.utg',
arguments: [document.uri.fsPath]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
arguments: [document.uri.fsPath]
}));
} else if (fileName.endsWith('.go') && (node.type === 'function_declaration' || node.type === 'method_declaration')) {
const line = document.positionAt(node.startIndex).line;
const range = new vscode.Range(line, 0, line, 0);
Expand All @@ -104,6 +125,11 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
command: 'keploy.utg',
arguments: [document.uri.fsPath]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
arguments: [document.uri.fsPath]
}));
}

// Traverse to the first child node
Expand Down Expand Up @@ -357,8 +383,18 @@ export function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(updateKeployDisposable);

let showSidebarDisposable = vscode.commands.registerCommand('keploy.showSidebar', async () => {
// Show the sidebar when this command is executed
vscode.commands.executeCommand('workbench.view.extension.Keploy-Sidebar');
sidebarProvider.postMessage("KeployChatBot")

Check warning on line 389 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 389 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 389 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
vscode.window.showInformationMessage('Sidebar opened for additional prompts.');
});

context.subscriptions.push(showSidebarDisposable);


// Register the command
let disposable = vscode.commands.registerCommand('keploy.utg', async (uri: vscode.Uri) => {
let disposable = vscode.commands.registerCommand('keploy.utg', async (uri: vscode.Uri , additional_prompts?:string) => {
// Check if the user is already signed in
const signedIn = await context.globalState.get('accessToken');
const signedInOthers = await context.globalState.get('SignedOthers');
Expand Down Expand Up @@ -400,7 +436,7 @@ export function activate(context: vscode.ExtensionContext) {
if (updatedSubscriptionEnded === false) {
// If SubscriptionEnded is false or undefined, continue running Utg
vscode.window.showInformationMessage('Welcome to Keploy!');
await Utg(context);
await Utg(context , additional_prompts);
}
}
});
Expand Down
Loading

0 comments on commit 30c04a5

Please sign in to comment.