first commit

This commit is contained in:
Mario Gil 2025-02-23 07:40:22 -05:00
commit 01d4fab793
5 changed files with 216 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.vscode
/.vscode-test.mjs
/node_modules

10
.vscodeignore Normal file
View File

@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
test/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map
**/eslint.config.mjs
**/.vscode-test.*

128
extension.js Normal file
View File

@ -0,0 +1,128 @@
const vscode = require('vscode');
class ApiResponseViewProvider {
constructor() {
this._view = undefined;
this._response = '';
}
resolveWebviewView(webviewView) {
this._view = webviewView;
webviewView.webview.options = {
enableScripts: true
};
this.updateContent();
}
updateResponse(response) {
this._response = response;
this.updateContent();
}
getResponse() {
return this._response;
}
updateContent() {
if (this._view) {
this._view.webview.html = `
<!DOCTYPE html>
<html>
<body>
<pre>${this._response}</pre>
</body>
</html>
`;
}
}
}
function activate(context) {
const apiResponseProvider = new ApiResponseViewProvider();
context.subscriptions.push(
vscode.window.registerWebviewViewProvider('apiResponseView', apiResponseProvider)
);
// Comando para enviar código a la API
let sendToApiCommand = vscode.commands.registerCommand('code-api-integration.sendToApi', async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No hay editor activo');
return;
}
const selection = editor.selection;
const selectedText = editor.document.getText(selection);
if (!selectedText) {
vscode.window.showErrorMessage('No hay texto seleccionado');
return;
}
try {
// Mostrar indicador de progreso
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: "Enviando código a la API...",
cancellable: false
}, async (progress) => {
const response = await fetch('http://127.0.0.1:7869/api/v2/text/text', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(
{"server":"groq",
"model":"deepseek-r1-distill-llama-70B",
"system":"Te dare un codigo de python quiero que generes el docstring tomando el cuenta el codigo",
"content":selectedText,
"password": "1223Aer*",
"userid": "Anon"}
)
});
if (!response.ok) {
throw new Error(`Error en la API: ${response.statusText}`);
}
const data = await response.json();
apiResponseProvider.updateResponse(JSON.stringify(data, null, 2));
// Notificar que la respuesta está lista para usar
vscode.window.showInformationMessage('Respuesta de API guardada - usa el botón derecho para pegarla');
});
} catch (error) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
}
});
// Comando para pegar la última respuesta
let pasteResponseCommand = vscode.commands.registerCommand('code-api-integration.pasteLastResponse', async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No hay editor activo');
return;
}
const response = apiResponseProvider.getResponse();
if (!response) {
vscode.window.showWarningMessage('No hay respuesta guardada de la API');
return;
}
editor.edit(editBuilder => {
editBuilder.insert(editor.selection.active, response);
});
});
context.subscriptions.push(sendToApiCommand, pasteResponseCommand);
}
function deactivate() {}
module.exports = {
activate,
deactivate
}

35
package-lock.json generated Normal file
View File

@ -0,0 +1,35 @@
{
"name": "basic-ai",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "basic-ai",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@types/node": "^22.13.5",
"@types/vscode": "^1.97.0"
}
},
"node_modules/@types/node": {
"version": "22.13.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.5.tgz",
"integrity": "sha512-+lTU0PxZXn0Dr1NBtC7Y8cR21AJr87dLLU953CWA6pMxxv/UDc7jYAY90upcrie1nRcD6XNG5HOYEDtgW5TxAg==",
"dependencies": {
"undici-types": "~6.20.0"
}
},
"node_modules/@types/vscode": {
"version": "1.97.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.97.0.tgz",
"integrity": "sha512-ueE73loeOTe7olaVyqP9mrRI54kVPJifUPjblZo9fYcv1CuVLPOEKEkqW0GkqPC454+nCEoigLWnC2Pp7prZ9w=="
},
"node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="
}
}
}

40
package.json Normal file
View File

@ -0,0 +1,40 @@
{
"name": "code-api-integration",
"displayName": "Code API Integration",
"description": "Send selected code to API and display response",
"version": "0.0.1",
"engines": {
"vscode": "^1.80.0"
},
"categories": ["Other"],
"activationEvents": [],
"main": "./extension.js",
"contributes": {
"commands": [
{
"command": "code-api-integration.sendToApi",
"title": "Send Code to API"
},
{
"command": "code-api-integration.pasteLastResponse",
"title": "Paste API Response"
}
],
"views": {
"explorer": [
{
"id": "apiResponseView",
"name": "API Response"
}
]
},
"menus": {
"editor/context": [
{
"command": "code-api-integration.pasteLastResponse",
"group": "navigation"
}
]
}
}
}