Skip to content

Commit

Permalink
Extension API history and dark mode friendly logo
Browse files Browse the repository at this point in the history
  • Loading branch information
SwapnilChand committed Oct 16, 2024
1 parent 0e73a01 commit 51c8fa0
Show file tree
Hide file tree
Showing 12 changed files with 876 additions and 697 deletions.
Binary file modified assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions extensions/vscode/api_history/history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"method": "GET",
"name": "https://jsonplaceholder.typicode.com/posts",
"lastUsed": "2024-10-16T16:18:51.817Z"
},
{
"method": "GET",
"name": "http://localhost:8000/github-webhook",
"lastUsed": "2024-10-16T12:08:14.848Z"
},
{
"method": "PATCH",
"name": "http://localhost:8000/github-webhook",
"lastUsed": "2024-10-16T12:03:42.401Z"
},
{
"method": "POST",
"name": "http://localhost:8000/github-webhook",
"lastUsed": "2024-10-16T12:01:18.314Z"
},
{
"name": "GET https://jsonplaceholder.typicode.com/posts",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts",
"headers": {},
"body": ""
},
{
"name": "GET https://jsonplaceholder.typicode.com/posts",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts",
"headers": {},
"body": ""
},
{
"name": "GET https://jsonplaceholder.typicode.com/posts",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts",
"headers": {},
"body": ""
},
{
"name": "GET https://jsonplaceholder.typicode.com/posts",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts",
"headers": {},
"body": ""
},
{
"name": "GET https://jsonplaceholder.typicode.com/posts",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts",
"headers": {},
"body": ""
}
]
1 change: 1 addition & 0 deletions extensions/vscode/api_history/history.msgpack
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���method�GET�name�*https://jsonplaceholder.typicode.com/posts�lastUsed�2024-10-16T16:18:51.817Z��method�GET�name�$http://localhost:8000/github-webhook�lastUsed�2024-10-16T12:08:14.848Z��method�PATCH�name�$http://localhost:8000/github-webhook�lastUsed�2024-10-16T12:03:42.401Z��method�POST�name�$http://localhost:8000/github-webhook�lastUsed�2024-10-16T12:01:18.314Z��name�.GET https://jsonplaceholder.typicode.com/posts�method�GET�url�*https://jsonplaceholder.typicode.com/posts�headers��body���name�.GET https://jsonplaceholder.typicode.com/posts�method�GET�url�*https://jsonplaceholder.typicode.com/posts�headers��body���name�.GET https://jsonplaceholder.typicode.com/posts�method�GET�url�*https://jsonplaceholder.typicode.com/posts�headers��body���name�.GET https://jsonplaceholder.typicode.com/posts�method�GET�url�*https://jsonplaceholder.typicode.com/posts�headers��body���name�.GET https://jsonplaceholder.typicode.com/posts�method�GET�url�*https://jsonplaceholder.typicode.com/posts�headers��body�
28 changes: 28 additions & 0 deletions extensions/vscode/api_history/viewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as fs from 'fs';
import * as msgpack from 'msgpack-lite';

// Function to read and decode a MessagePack file
const readMessagePackFile = (filePath: string) => {
try {
// Read the packed data from the file
const packedData = fs.readFileSync(filePath);

// Decode the packed data to a JavaScript object
const decodedData = msgpack.decode(packedData);

// Convert the object to a human-readable JSON format
const jsonString = JSON.stringify(decodedData, null, 2);

// Save the JSON string to a file in the same directory
const outputFilePath = './history.json';
fs.writeFileSync(outputFilePath, jsonString, { encoding: 'utf8' });

console.log(`Decoded data saved to ${outputFilePath}`);
} catch (error) {
console.error(`Error reading or decoding the file: ${error.message}`);
}
};

// Specify the path to your MessagePack file
const filePath = './history.msgpack';
readMessagePackFile(filePath);
31 changes: 28 additions & 3 deletions extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "CloudCodeAI",
"repository": {
"type": "git",
"url": "https://github.com/Clouod-Code-AI/kaizen.git"
"url": "https://github.com/Cloud-Code-AI/kaizen.git"
},
"engines": {
"vscode": "^1.93.0"
Expand Down Expand Up @@ -93,5 +93,8 @@
"eslint": "^9.9.1",
"npm-run-all": "^4.1.5",
"typescript": "^5.5.4"
},
"dependencies": {
"msgpack-lite": "^0.1.26"
}
}
62 changes: 48 additions & 14 deletions extensions/vscode/src/apiRequest/apiRequestProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as vscode from 'vscode';
import { ApiRequestView } from './apiRequestView';
import { HttpClient } from '../utils/httpClient';
import * as fs from 'fs';
import * as path from 'path';
import * as msgpack from 'msgpack-lite';

interface Collection {
name: string;
Expand All @@ -21,13 +24,15 @@ export class ApiRequestProvider {
private httpClient: HttpClient;
private collections: Collection[] = [];
private environment: Record<string, string> = {};
private apiHistory: ApiRequest[] = [];

constructor(context: vscode.ExtensionContext) {
this.context = context;
this.httpClient = new HttpClient();
this.handleApiRequest = this.handleApiRequest.bind(this);
this.loadCollections();
this.loadEnvironment();
this.loadApiHistory(); // Load existing API history
}

public openApiRequestView() {
Expand Down Expand Up @@ -76,9 +81,22 @@ export class ApiRequestProvider {
const responseTime = endTime - startTime;
const responseSize = JSON.stringify(response).length;

// Create an API request object
const apiRequest: ApiRequest = {
name: `${method} ${url}`,
method,
url,
headers,
body,
};

// Add to API history and save it
this.apiHistory.push(apiRequest);
await this.saveApiHistory(); // Save in MessagePack format

this.view?.postMessage({
command: 'receiveResponse',
response: response,
response,
time: responseTime,
size: responseSize
});
Expand All @@ -87,22 +105,38 @@ export class ApiRequestProvider {
}
}

private replaceEnvironmentVariables(str: string): string {
return str.replace(/\{\{(\w+)\}\}/g, (_, key) => this.environment[key] || '');
private loadApiHistory() {
// Load existing API history from global state if needed
this.apiHistory = this.context.globalState.get('apiHistory', []);
}

public addCollection(name: string) {
this.collections.push({ name, requests: [] });
this.saveCollections();
this.updateCollectionsView();
}
private async saveApiHistory() {
try {
console.log("Saving API History...");

// Update global state with current API history
await this.context.globalState.update('apiHistory', this.apiHistory);

// Define file path for saving the API history
const folderPath = path.join(this.context.extensionPath, 'api_history');

// Create directory if it doesn't exist
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
console.log(`Created folder at ${folderPath}`);
}

public addRequestToCollection(collectionName: string, request: ApiRequest) {
const collection = this.collections.find(c => c.name === collectionName);
if (collection) {
collection.requests.push(request);
this.saveCollections();
this.updateCollectionsView();
// Define file path for the MessagePack file
const filePath = path.join(folderPath, 'history.msgpack');

// Write API history to MessagePack file
const packedData = msgpack.encode(this.apiHistory); // Encode data using MessagePack
fs.writeFileSync(filePath, packedData); // Write packed data to file

vscode.window.showInformationMessage('API history saved successfully in MessagePack format!');
} catch (error) {
console.error('Error saving API history:', error); // Log any errors encountered
vscode.window.showErrorMessage(`Failed to save API history: ${error.message}`);
}
}

Expand Down
Loading

0 comments on commit 51c8fa0

Please sign in to comment.