diff --git a/index.js b/index.js index d63be01..f6fdce4 100644 --- a/index.js +++ b/index.js @@ -78,13 +78,15 @@ const messageLogAndSend = (message) => { } let errorlogFile = fs.createWriteStream(path.join(LOG_PATH, 'error_log.txt'), { flags: 'w' }) +console.error = (...message) => { + errorlogFile.write(format(...message) + '\n') + process.stderr.write(format(...message) + '\n') +} process .on('unhandledRejection', (reason, promise) => { - errorlogFile.write(format('Unhandled Rejection at:', promise, 'reason:', reason) + '\n') console.error('Unhandled Rejection at:', promise, 'reason:', reason) }) .on('uncaughtException', err => { - errorlogFile.write(format(err, 'Uncaught Exception thrown') + '\n') console.error(err, 'Uncaught Exception thrown') process.exit(1) }) @@ -240,7 +242,7 @@ const speakPrompt = async ({ text, preAudioPath }) => { resolveSpeakTextList() } } catch (e) { - console.log(e) + console.error(e) resolveSpeakTextList() } } @@ -332,12 +334,11 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f break } } catch (e) { - console.log(e) + console.error(e) functionCallResult = e.message } messages.push({ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' }) // addHistory([{ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' }]) - console.log({ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' }) messageLogAndSend({ id: nanoid(), from: 'Function Calling', @@ -495,7 +496,7 @@ const resloveAdminPrompt = async ({ prompt, promptType = 'string', triggerRecord }) } } catch (e) { - console.log(e) + console.error(e) if (triggerRecord && STATUS.isSpeechTalk) triggerSpeech() } return resText @@ -567,18 +568,11 @@ const triggerSpeech = async () => { } ipcMain.handle('send-prompt', async (event, prompt) => { - console.log('prompt', prompt) resloveAdminPrompt({ prompt: prompt.content, promptType: prompt.type }) }) -ipcMain.handle('get-admin-name', async () => { - return ADMIN_NAME -}) -ipcMain.handle('open-config', async () => { - shell.openExternal(path.join(STORE_PATH, 'config.json')) -}) ipcMain.handle('switch-speech-talk', async () => { STATUS.isSpeechTalk = !STATUS.isSpeechTalk STATUS.isAudioPlay = STATUS.isSpeechTalk diff --git a/modules/functions.js b/modules/functions.js index 14e82df..ea5e364 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -246,7 +246,8 @@ const readFileFromDisk = async ({ filePath }) => { return await fs.promises.readFile(filePath, { encoding: 'utf-8' }) } -const javaScriptInterpreter = async ({ code }) => {uickjs = await getQuickJS() +const javaScriptInterpreter = async ({ code }) => { + const quickjs = await getQuickJS() let result = quickjs.evalCode(code, { shouldInterrupt: shouldInterruptAfterDeadline(Date.now() + 10000), memoryLimitBytes: 100 * 1024 * 1024, diff --git a/src/App.vue b/src/App.vue index 9e0bbcb..e559603 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,9 +23,6 @@ const printMessage = (type, msg, option) => { const messageHistory = ref([]) -let ADMIN_NAME -onMounted(() => ipcRenderer.invoke('get-admin-name').then(name => ADMIN_NAME = name)) - const renderCodeBlocks = (text) => { return text.replace(/```(\w+)\n((?:(?!```)[\s\S])*)(?:```)?/g, (match, language, code) => { return `
${code.trim()}
` @@ -111,7 +108,7 @@ const sendText = (event) => { }) messageHistory.value.push({ id: nanoid(), - from: ADMIN_NAME, + from: config.value.ADMIN_NAME, text: inputText.value, images: imageBlobUrlList.value }) @@ -124,7 +121,7 @@ const sendText = (event) => { }) messageHistory.value.push({ id: nanoid(), - from: ADMIN_NAME, + from: config.value.ADMIN_NAME, text: inputText.value }) } @@ -135,7 +132,8 @@ const scrollToBottom = (id) => { const element = document.getElementById(id) element.scrollTop = element.scrollHeight } -// API Key Check + +// config const setting = ref(null) const config = ref({}) onMounted(async () => { @@ -227,7 +225,7 @@ const removeImage = (index) => {