2024-03-09 02:42:30 -05:00
|
|
|
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
|
|
|
|
const fs = require('fs');
|
2024-03-09 02:15:01 -05:00
|
|
|
const path = require('path');
|
2024-03-09 02:42:30 -05:00
|
|
|
const os = require('os');
|
2024-03-09 16:19:47 -05:00
|
|
|
const KuzcoCore = require('./js/kuzcoCore');
|
2024-03-09 02:15:01 -05:00
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
const mainWindow = new BrowserWindow({
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
webPreferences: {
|
2024-03-09 16:19:47 -05:00
|
|
|
preload: path.join(__dirname, 'js/preload.js'),
|
2024-03-09 02:15:01 -05:00
|
|
|
nodeIntegration: false,
|
|
|
|
contextIsolation: true,
|
|
|
|
enableRemoteModule: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-03-09 16:19:47 -05:00
|
|
|
mainWindow.loadFile('html/index.html');
|
2024-03-09 02:42:30 -05:00
|
|
|
|
|
|
|
if (!kuzcoCore.apiKeyExists()) {
|
|
|
|
promptForApiKey(mainWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcMain.on('submit-api-key', (event, apiKey) => {
|
|
|
|
const configDir = path.join(os.homedir(), '.kuzco-cli');
|
|
|
|
const configPath = path.join(configDir, 'config.json');
|
|
|
|
|
|
|
|
if (!fs.existsSync(configDir)){
|
|
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(configPath, JSON.stringify({ API_KEY: apiKey }, null, 2), 'utf8');
|
2024-03-09 02:52:10 -05:00
|
|
|
event.reply('api-key-saved');
|
|
|
|
|
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
2024-03-09 02:42:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let inputWindow;
|
|
|
|
|
|
|
|
function promptForApiKey() {
|
|
|
|
inputWindow = new BrowserWindow({
|
|
|
|
width: 300,
|
2024-03-09 16:19:47 -05:00
|
|
|
height: 300,
|
2024-03-09 02:42:30 -05:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
contextIsolation: false,
|
|
|
|
enableRemoteModule: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-03-09 16:19:47 -05:00
|
|
|
inputWindow.loadFile('html/prompt.html');
|
2024-03-09 02:42:30 -05:00
|
|
|
inputWindow.on('closed', () => {
|
|
|
|
inputWindow = null;
|
|
|
|
});
|
2024-03-09 02:15:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') app.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
const kuzcoCore = new KuzcoCore();
|
|
|
|
|
2024-03-09 05:43:40 -05:00
|
|
|
ipcMain.handle('send-prompt', async (event, { prompt, model }) => {
|
|
|
|
console.log("Received model in main process:", model);
|
|
|
|
return await kuzcoCore.sendPrompt(prompt, model);
|
2024-03-09 15:22:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('abort-prompt', () => {
|
|
|
|
kuzcoCore.abortFetch();
|
2024-03-09 05:43:40 -05:00
|
|
|
});
|