Skip to content

Commit

Permalink
build: Made web sockets work for both http and https.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiscool committed Dec 15, 2024
1 parent 60f9625 commit 0149c63
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
32 changes: 16 additions & 16 deletions public/ChatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ChatManager {
//make it so that on change it saves the title
this.conversationTitleInput.addEventListener('change', async () => {
const conversationId = this.conversationPicker.value;
await doAjax('/setConversationTitle', { id: conversationId, title: this.conversationTitleInput.value });
await doAjax('./setConversationTitle', { id: conversationId, title: this.conversationTitleInput.value });
await this.loadConversationsList();
});

Expand Down Expand Up @@ -278,7 +278,7 @@ export class ChatManager {
}

async loadConversationsList() {
const conversations = await doAjax('/getConversationsList', {});
const conversations = await doAjax('./getConversationsList', {});
//console.log('conversations', conversations);
// format the conversations list
// [
Expand Down Expand Up @@ -311,7 +311,7 @@ export class ChatManager {

async loadConversation(conversationId) {
console.log('conversationId', conversationId);
const response = await doAjax('/pullMessages', { id: conversationId });
const response = await doAjax('./pullMessages', { id: conversationId });
ctx.targetFile = response.targetFile;
await this.setTargetFile(response.targetFile);
this.conversationTitleInput.value = response.title;
Expand Down Expand Up @@ -356,7 +356,7 @@ export class ChatManager {
savePlanButton.style.padding = '2px 5px';
savePlanButton.style.borderRadius = '3px';
savePlanButton.addEventListener('click', async () => {
await doAjax('/savePlan', { plan: message.content });
await doAjax('./savePlan', { plan: message.content });

});
individualMessageDiv.appendChild(savePlanButton);
Expand All @@ -372,7 +372,7 @@ export class ChatManager {
appendPlanButton.style.padding = '2px 5px';
appendPlanButton.style.borderRadius = '3px';
appendPlanButton.addEventListener('click', async () => {
await doAjax('/savePlan', { plan: message.content, append: true });
await doAjax('./savePlan', { plan: message.content, append: true });

});
individualMessageDiv.appendChild(appendPlanButton);
Expand All @@ -392,17 +392,17 @@ export class ChatManager {

addPromptButton.style.borderRadius = '3px';
addPromptButton.addEventListener('click', async () => {
//await doAjax('/storeCustomPrompts', { prompt: message.content });
//await doAjax('./storeCustomPrompts', { prompt: message.content });
const prompt = message.content;
// get the current list of prompts
const customPromptsJSON = await doAjax('/readFile', { targetFile: './.aiCoder/prompts/customPrompts.json' });
const customPromptsJSON = await doAjax('./readFile', { targetFile: './.aiCoder/prompts/customPrompts.json' });
let customPrompts = JSON.parse(customPromptsJSON.fileContent);
if (!customPrompts) customPrompts = [];
//console.log('prompts', customPrompts);
// check if the prompt is already in the list
if (!customPrompts.includes(prompt)) {
customPrompts.push(prompt);
await doAjax('/writeFile', {
await doAjax('./writeFile', {
targetFile: './.aiCoder/prompts/customPrompts.json',
fileContent: JSON.stringify(customPrompts, null, 2),
});
Expand Down Expand Up @@ -434,7 +434,7 @@ export class ChatManager {
for (const codeBlock of markdown.codeBlocks) {
const applyCodeBlock = await ConfirmDialog.confirm("Apply code block?", ctx.autoApplyTimeout, true);
if (applyCodeBlock) {
//const mergeWorked = await doAjax('/applySnippet', { snippet: codeBlock, targetFile: this.targetFileInput.value });
//const mergeWorked = await doAjax('./applySnippet', { snippet: codeBlock, targetFile: this.targetFileInput.value });

await this.applySnippet(codeBlock);

Expand All @@ -456,7 +456,7 @@ export class ChatManager {


async displayPremadePromptsList() {
const customPromptsJSON = await doAjax('/readFile', { targetFile: '.aiCoder/prompts/customPrompts.json' });
const customPromptsJSON = await doAjax('./readFile', { targetFile: '.aiCoder/prompts/customPrompts.json' });
let customPrompts = JSON.parse(customPromptsJSON.fileContent);
if (!customPrompts) customPrompts = [];
//console.log('prompts', customPrompts);
Expand Down Expand Up @@ -507,7 +507,7 @@ export class ChatManager {
const confirmDelete = await ConfirmDialog.confirm(`Delete prompt: \n "${prompt}"?`, 0, false);
if (confirmDelete) {
customPrompts = customPrompts.filter((p) => p !== prompt);
await doAjax('/writeFile', {
await doAjax('./writeFile', {
targetFile: './.aiCoder/prompts/customPrompts.json',
fileContent: JSON.stringify(customPrompts, null, 2),
});
Expand All @@ -530,7 +530,7 @@ export class ChatManager {

async addMessage(message) {
const conversationId = this.conversationPicker.value;
await doAjax('/addMessage', { id: conversationId, message });
await doAjax('./addMessage', { id: conversationId, message });
await this.loadConversation(conversationId); // Fix method call
}

Expand All @@ -539,15 +539,15 @@ export class ChatManager {
if (!targetFile || targetFile === '') {
targetFile = await choseFile();
}
const response = await doAjax('/newChat', { targetFile, title });
const response = await doAjax('./newChat', { targetFile, title });
this.chatMode = 'chat';
await this.loadConversationsList();
this.conversationPicker.value = response.id;
await this.loadConversation(response.id); // Fix method call
}

async newPlanChat(title = false) {
const response = await doAjax('/newPlanChat', { title });
const response = await doAjax('./newPlanChat', { title });
await this.loadConversationsList();
this.chatMode = 'plan';
this.conversationPicker.value = response.id;
Expand All @@ -556,7 +556,7 @@ export class ChatManager {

async callLLM() {
const conversationId = this.conversationPicker.value;
await doAjax('/callLLM', { id: conversationId });
await doAjax('./callLLM', { id: conversationId });
await this.loadConversation(conversationId); // Fix method call
}

Expand Down Expand Up @@ -641,7 +641,7 @@ export class ChatManager {

async applySnippet(codeString) {
const conversationId = this.conversationPicker.value;
const isCodeGood = await doAjax('/applySnippet', { snippet: codeString, targetFile: this.targetFileInput.value });
const isCodeGood = await doAjax('./applySnippet', { snippet: codeString, targetFile: this.targetFileInput.value });

if (!isCodeGood.success) {
alert('Merge failed. Please resolve the conflict manually.');
Expand Down
4 changes: 2 additions & 2 deletions public/LLMSettingsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class LLMSettingsManager {
}

async fetchSettings() {
return await doAjax('/llmSettings', {});
return await doAjax('./llmSettings', {});
}

createSettingsDiv() {
Expand Down Expand Up @@ -178,7 +178,7 @@ export class LLMSettingsManager {
}

console.log(newSettings);
await doAjax('/llmSettingsUpdate', newSettings);
await doAjax('./llmSettingsUpdate', newSettings);

await this.init();
}
Expand Down
4 changes: 2 additions & 2 deletions public/ProjectSettingsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ProjectSettingsManager {
}

async fetchPrompts() {
return await doAjax('/getSystemPrompts', {});
return await doAjax('./getSystemPrompts', {});
}

createPromptsDiv() {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class ProjectSettingsManager {
}

console.log(updatedPrompts); // Log the updated data for debugging
await doAjax('/updateSystemPrompts', updatedPrompts); // Send updated prompts back to the server
await doAjax('./updateSystemPrompts', updatedPrompts); // Send updated prompts back to the server

await this.init(); // Reinitialize the settings manager
}
Expand Down
2 changes: 1 addition & 1 deletion public/doAjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function doAjax(urlToCall, body) {

class WebSocketClient {
constructor() {
this.url = `ws://${window.location.host}`;
this.url = window.location.protocol === "http:"? `ws://${window.location.host}` : `wss://${window.location.host}`;
this.socket = null;
}

Expand Down
2 changes: 1 addition & 1 deletion public/fileDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export async function fileDialog(fileListArray) {
}

export async function choseFile() {
const response = await doAjax('/getFilesList', {});
const response = await doAjax('./getFilesList', {});
const fileList = response.files || [];

const selectedFile = await fileDialog(fileList);
Expand Down
18 changes: 9 additions & 9 deletions public/toolsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class toolsManager {
if (!await this.verifyTargetFileSpecified())
return;
this.showToolBar();
await doAjax('/implementAllStubs', { targetFile: ctx.targetFile });
await doAjax('./implementAllStubs', { targetFile: ctx.targetFile });
}
async mergeAndFormat() {
if (!await this.verifyTargetFileSpecified())
Expand All @@ -103,7 +103,7 @@ export class toolsManager {
snippet = this.snippetTextArea.value;
this.snippetTextArea = null;
}
await doAjax('/applySnippet', {
await doAjax('./applySnippet', {
targetFile: ctx.targetFile,
snippet: snippet
});
Expand All @@ -119,10 +119,10 @@ export class toolsManager {
async prependClassStructure() {
if (!await this.verifyTargetFileSpecified())
return;
await doAjax('/prependClassStructure', { targetFile: ctx.targetFile });
await doAjax('./prependClassStructure', { targetFile: ctx.targetFile });
}
async pullMethodsList() {
const listOfMethods = await doAjax('/getMethodsList', { targetFile: ctx.targetFile });
const listOfMethods = await doAjax('./getMethodsList', { targetFile: ctx.targetFile });
console.log(listOfMethods);
// the response contains
for (const className in listOfMethods) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class toolsManager {
}
}
async pullFunctionList() {
const listOfFunctions = await doAjax('/getFunctionList', { targetFile: ctx.targetFile });
const listOfFunctions = await doAjax('./getFunctionList', { targetFile: ctx.targetFile });

for (const key in listOfFunctions) {
// console.log(key);
Expand Down Expand Up @@ -193,7 +193,7 @@ export class toolsManager {
}
async implementSpecificClassMethod(className, methodName, lineNumber) {
ctx.tabs.switchToTab('Chat');
await doAjax('/gotoLineNumber', {
await doAjax('./gotoLineNumber', {
lineNumber,
targetFile: ctx.targetFile
});
Expand All @@ -203,7 +203,7 @@ export class toolsManager {
}
async addToChatPrompt(className, methodName, lineNumber) {
ctx.tabs.switchToTab('Chat');
await doAjax('/gotoLineNumber', {
await doAjax('./gotoLineNumber', {
lineNumber,
targetFile: ctx.targetFile
});
Expand All @@ -212,7 +212,7 @@ export class toolsManager {
}
async implementSpecificFunction(functionName, lineNumber) {
ctx.tabs.switchToTab('Chat');
await doAjax('/gotoLineNumber', {
await doAjax('./gotoLineNumber', {
lineNumber,
targetFile: ctx.targetFile
});
Expand All @@ -222,7 +222,7 @@ export class toolsManager {
}
async addFunctionToChatPrompt(functionName, lineNumber) {
ctx.tabs.switchToTab('Chat');
await doAjax('/gotoLineNumber', {
await doAjax('./gotoLineNumber', {
lineNumber,
targetFile: ctx.targetFile
});
Expand Down

0 comments on commit 0149c63

Please sign in to comment.