From 60d6d603ba2c10c8afb691b2f86f1885a14cf76a Mon Sep 17 00:00:00 2001 From: Robert Gruen Date: Tue, 4 Feb 2025 13:37:48 -0800 Subject: [PATCH] ran prettier --- ts/packages/shell/src/main/index.ts | 34 ++++++----- .../shell/src/main/shellSettingsType.ts | 2 +- .../shell/src/preload/electronTypes.ts | 4 +- .../shell/src/renderer/assets/styles.less | 2 +- ts/packages/shell/src/renderer/src/main.ts | 58 ++++++++++++------- .../shell/src/renderer/src/settingsView.ts | 10 +++- 6 files changed, 69 insertions(+), 41 deletions(-) diff --git a/ts/packages/shell/src/main/index.ts b/ts/packages/shell/src/main/index.ts index 1eb0bd41a..4cc2db736 100644 --- a/ts/packages/shell/src/main/index.ts +++ b/ts/packages/shell/src/main/index.ts @@ -60,7 +60,10 @@ process.argv.forEach((arg) => { }); export function runningTests(): boolean { - return process.env["INSTANCE_NAME"] !== undefined && process.env["INSTANCE_NAME"].startsWith("test_") === true; + return ( + process.env["INSTANCE_NAME"] !== undefined && + process.env["INSTANCE_NAME"].startsWith("test_") === true + ); } let mainWindow: BrowserWindow | null = null; @@ -619,11 +622,20 @@ async function initialize() { ShellSettings.getinstance().onSettingsChanged!(); // Load chat history if enabled - const chatHistory: string = path.join(getInstanceDir(), "chat_history.html") - if (ShellSettings.getinstance().chatHistory && existsSync(chatHistory)) { + const chatHistory: string = path.join( + getInstanceDir(), + "chat_history.html", + ); + if ( + ShellSettings.getinstance().chatHistory && + existsSync(chatHistory) + ) { chatView?.webContents.send( "chat-history", - readFileSync(path.join(getInstanceDir(), "chat_history.html"), "utf-8"), + readFileSync( + path.join(getInstanceDir(), "chat_history.html"), + "utf-8", + ), ); } @@ -640,19 +652,16 @@ async function initialize() { // send the agent greeting if it's turned on if (ShellSettings.getinstance().agentGreeting) { dispatcher.processCommand("@greeting", "agent-0", []); - } + } }); // Store the chat history whenever the DOM changes // this let's us rehydrate the chat when reopening the shell - ipcMain.on("dom changed", async(_event, html) => { + ipcMain.on("dom changed", async (_event, html) => { // store the modified DOM contents const file: string = path.join(getInstanceDir(), "chat_history.html"); - debugShell( - `Saving chat history to '${file}'.`, - performance.now(), - ); + debugShell(`Saving chat history to '${file}'.`, performance.now()); try { writeFileSync(file, html); @@ -660,7 +669,7 @@ async function initialize() { debugShell( `Unable to save history to '${file}'. Error: ${e}`, performance.now(), - ); + ); } }); @@ -710,8 +719,7 @@ async function initialize() { // On windows, we will spin up a local end point that listens // for pen events which will trigger speech reco // Don't spin this up during testing - if ( - process.platform == "win32" && !runningTests()) { + if (process.platform == "win32" && !runningTests()) { const pipePath = path.join("\\\\.\\pipe\\TypeAgent", "speech"); const server = net.createServer((stream) => { stream.on("data", (c) => { diff --git a/ts/packages/shell/src/main/shellSettingsType.ts b/ts/packages/shell/src/main/shellSettingsType.ts index 43bdd93e7..4b48c9a8d 100644 --- a/ts/packages/shell/src/main/shellSettingsType.ts +++ b/ts/packages/shell/src/main/shellSettingsType.ts @@ -39,5 +39,5 @@ export const defaultSettings: ShellSettingsType = { partialCompletion: true, disallowedDisplayType: [], darkMode: false, - chatHistory: true + chatHistory: true, }; diff --git a/ts/packages/shell/src/preload/electronTypes.ts b/ts/packages/shell/src/preload/electronTypes.ts index 45fdffc57..a3c731714 100644 --- a/ts/packages/shell/src/preload/electronTypes.ts +++ b/ts/packages/shell/src/preload/electronTypes.ts @@ -72,7 +72,9 @@ export interface ClientAPI { settings: ShellSettings, ) => void, ): void; - onChatHistory(callback: (e: Electron.IpcRendererEvent, chatHistory: string) => void): void; + onChatHistory( + callback: (e: Electron.IpcRendererEvent, chatHistory: string) => void, + ): void; registerClientIO(clientIO: ClientIO); } diff --git a/ts/packages/shell/src/renderer/assets/styles.less b/ts/packages/shell/src/renderer/assets/styles.less index 6c5277423..bbd6ef395 100644 --- a/ts/packages/shell/src/renderer/assets/styles.less +++ b/ts/packages/shell/src/renderer/assets/styles.less @@ -88,7 +88,7 @@ body { } .chat-separator-text { - margin: 0px 10px; + margin: 0px 10px; color: darkgray; height: 20px; } diff --git a/ts/packages/shell/src/renderer/src/main.ts b/ts/packages/shell/src/renderer/src/main.ts index 05f634c81..46780370b 100644 --- a/ts/packages/shell/src/renderer/src/main.ts +++ b/ts/packages/shell/src/renderer/src/main.ts @@ -276,20 +276,28 @@ function addEvents( // add the separator if (history.length > 0) { - // don't add a separator if there's already one there - if (!chatView.getScollContainer().children[0].classList.contains("chat-separator")) { - let separator: HTMLDivElement = document.createElement("div"); + if ( + !chatView + .getScollContainer() + .children[0].classList.contains("chat-separator") + ) { + let separator: HTMLDivElement = + document.createElement("div"); separator.classList.add("chat-separator"); - separator.innerHTML = "
previously
" - + separator.innerHTML = + '
previously
'; + chatView.getScollContainer().prepend(separator); } // make all old messages "inactive" and set the context for each separator let lastSeparatorText: HTMLDivElement | null; - for(let i = 0; i < chatView.getScollContainer().children.length; i++) { - + for ( + let i = 0; + i < chatView.getScollContainer().children.length; + i++ + ) { // gray out this item const div = chatView.getScollContainer().children[i]; div.classList.add("history"); @@ -297,17 +305,22 @@ function addEvents( // is this a separator? const separator = div.querySelector(".chat-separator-text"); if (separator != null) { - lastSeparatorText = div.querySelector(".chat-separator-text"); + lastSeparatorText = div.querySelector( + ".chat-separator-text", + ); } // get the timestamp for this chat bubble (if applicable) - const span: HTMLSpanElement | null = div.querySelector(".timestring"); + const span: HTMLSpanElement | null = + div.querySelector(".timestring"); if (span !== null) { - const timeStamp: Date = new Date(span.attributes["data"].value); - lastSeparatorText!.innerText = getDateDifferenceDescription(new Date(), timeStamp); + const timeStamp: Date = new Date( + span.attributes["data"].value, + ); + lastSeparatorText!.innerText = + getDateDifferenceDescription(new Date(), timeStamp); } - } } } @@ -476,8 +489,7 @@ document.addEventListener("DOMContentLoaded", async function () { }); function watchForDOMChanges(element: HTMLDivElement) { - - // ignore attribute changes but wach for + // ignore attribute changes but wach for const config = { attributes: false, childList: true, subtree: true }; // timeout @@ -485,16 +497,18 @@ function watchForDOMChanges(element: HTMLDivElement) { // observer callback const observer = new MutationObserver(() => { - // increment the idle counter idleCounter++; // decrement the idle counter setTimeout(() => { if (--idleCounter == 0) { - // last one notifies main process + // last one notifies main process if ((window as any).electron) { - (window as any).electron.ipcRenderer.send("dom changed", element.innerHTML); + (window as any).electron.ipcRenderer.send( + "dom changed", + element.innerHTML, + ); } } }, 3000); @@ -503,7 +517,7 @@ function watchForDOMChanges(element: HTMLDivElement) { // start observing observer.observe(element!, config); - // observer.disconnect(); + // observer.disconnect(); } function getDateDifferenceDescription(date1: Date, date2: Date): string { @@ -516,11 +530,11 @@ function getDateDifferenceDescription(date1: Date, date2: Date): string { const diffYears = Math.floor(diff / (1000 * 60 * 60 * 24 * 365)); if (diffMinutes < 1) { - return "just now" + return "just now"; } else if (diffMinutes < 15) { return "a few minutes ago"; } else if (diffMinutes < 60) { - return "under an hour ago" + return "under an hour ago"; } else if (diffHours < 2) { return "an hour ago"; } else if (diffDays < 1) { @@ -528,7 +542,7 @@ function getDateDifferenceDescription(date1: Date, date2: Date): string { } else if (diffDays < 2) { return "yesterday"; } else if (diffDays < 7) { - return date1.toLocaleDateString('en-US', { weekday: 'long' }); + return date1.toLocaleDateString("en-US", { weekday: "long" }); } else if (diffWeeks < 2) { return "last week"; } else if (diffMonths < 2) { @@ -536,6 +550,6 @@ function getDateDifferenceDescription(date1: Date, date2: Date): string { } else if (diffYears < 2) { return "last year"; } else { - return date1.toLocaleDateString('en-US', { weekday: 'long' }); + return date1.toLocaleDateString("en-US", { weekday: "long" }); } } diff --git a/ts/packages/shell/src/renderer/src/settingsView.ts b/ts/packages/shell/src/renderer/src/settingsView.ts index 094fa5854..094e1999c 100644 --- a/ts/packages/shell/src/renderer/src/settingsView.ts +++ b/ts/packages/shell/src/renderer/src/settingsView.ts @@ -302,9 +302,13 @@ export class SettingsView { this._shellSettings.darkMode ? "Light mode" : "Dark mode", ); - this.saveChatHistoryCheckBox = this.addCheckbox("Save Chat History", () => { - this._shellSettings.chatHistory = this.saveChatHistoryCheckBox.checked; - }); + this.saveChatHistoryCheckBox = this.addCheckbox( + "Save Chat History", + () => { + this._shellSettings.chatHistory = + this.saveChatHistoryCheckBox.checked; + }, + ); } getContainer() {