From e6c779d91a2c4be6488e66c9fc3ad542a66d788c Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Sun, 24 Nov 2024 23:43:10 -0800 Subject: [PATCH] progress --- src/vs/code/electron-main/app.ts | 20 +++++++++++++++++-- .../inlineDiffService/inlineDiffService.ts | 2 +- .../void/browser/sendLLMMessage.ts | 8 ++++---- .../void/common/sendLLMMessage.ts | 4 ++-- .../void/electron-main/sendLLMMessage.ts | 20 +++++++++++++++++++ .../contrib/void/browser/react/README.md | 2 +- .../react/src/sidebar-tsx/SidebarChat.tsx | 1 - .../browser/react/src/util/sendLLMMessage.tsx | 4 ++-- .../void/browser/registerInlineDiffs.ts | 5 +++-- .../contrib/void/browser/registerSidebar.ts | 2 +- .../electron-sandbox/desktop.main.ts | 5 +++++ .../void/electron-sandbox/sendLLMMessage.ts | 17 ---------------- src/vs/workbench/workbench.common.main.ts | 1 + src/vs/workbench/workbench.desktop.main.ts | 11 ++++------ .../workbench/workbench.web.main.internal.ts | 5 ----- test/unit/electron/preload.js | 12 +++++++++++ 16 files changed, 74 insertions(+), 45 deletions(-) rename src/vs/{workbench/services => platform}/void/browser/sendLLMMessage.ts (76%) rename src/vs/{workbench/services => platform}/void/common/sendLLMMessage.ts (84%) create mode 100644 src/vs/platform/void/electron-main/sendLLMMessage.ts delete mode 100644 src/vs/workbench/services/void/electron-sandbox/sendLLMMessage.ts diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 6d19d2809..8f4a62ad1 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -121,6 +121,9 @@ import { normalizeNFC } from '../../base/common/normalization.js'; import { ICSSDevelopmentService, CSSDevelopmentService } from '../../platform/cssDev/node/cssDevService.js'; import { ExtensionSignatureVerificationService, IExtensionSignatureVerificationService } from '../../platform/extensionManagement/node/extensionSignatureVerificationService.js'; +import { ISendLLMMessageService } from '../../platform/void/common/sendLLMMessage.js'; +import { SendLLMMessageService } from '../../platform/void/electron-main/sendLLMMessage.js'; + /** * The main VS Code application. There will only ever be one instance, * even if the user starts many instances (e.g. from the command line). @@ -508,6 +511,16 @@ export class CodeApplication extends Disposable { }); //#endregion + + // //#region Void IPC + // validatedIpcMain.handle('vscode:sendLLMMessage', async (event, data) => { + // try { + // await this.sendLLMMessage(data); + // } catch (error) { + // console.error('Error sending LLM message:', error); + // } + // }); + // //#endregion } private onUnexpectedError(error: Error): void { @@ -998,6 +1011,9 @@ export class CodeApplication extends Disposable { break; } + // Void + services.set(ISendLLMMessageService, new SyncDescriptor(SendLLMMessageService)); + // Windows services.set(IWindowsMainService, new SyncDescriptor(WindowsMainService, [machineId, sqmId, devDeviceId, this.userEnv], false)); services.set(IAuxiliaryWindowsMainService, new SyncDescriptor(AuxiliaryWindowsMainService, undefined, false)); @@ -1182,8 +1198,8 @@ export class CodeApplication extends Disposable { mainProcessElectronServer.registerChannel('keyboardLayout', keyboardLayoutChannel); // Void - const sendLLMMessageChannel = ProxyChannel.fromService(accessor.get(IEncryptionMainService), disposables); - mainProcessElectronServer.registerChannel('sendLLMMessage', sendLLMMessageChannel); + const sendLLMMessageChannel = ProxyChannel.fromService(accessor.get(ISendLLMMessageService), disposables); + mainProcessElectronServer.registerChannel('void-channel-sendLLMMessage', sendLLMMessageChannel); // Native host (main & shared process) this.nativeHostMainService = accessor.get(INativeHostMainService); diff --git a/src/vs/editor/browser/services/inlineDiffService/inlineDiffService.ts b/src/vs/editor/browser/services/inlineDiffService/inlineDiffService.ts index 0303e43f3..7c2d1324c 100644 --- a/src/vs/editor/browser/services/inlineDiffService/inlineDiffService.ts +++ b/src/vs/editor/browser/services/inlineDiffService/inlineDiffService.ts @@ -12,7 +12,7 @@ export interface IInlineDiffService { removeDiffs(editor: ICodeEditor): void; } -export const IInlineDiffService = createDecorator('inlineDiffService'); +export const IInlineDiffService = createDecorator('inlineDiffServiceOld'); class InlineDiffService extends Disposable implements IInlineDiffService { private readonly _diffDecorations = new Map(); diff --git a/src/vs/workbench/services/void/browser/sendLLMMessage.ts b/src/vs/platform/void/browser/sendLLMMessage.ts similarity index 76% rename from src/vs/workbench/services/void/browser/sendLLMMessage.ts rename to src/vs/platform/void/browser/sendLLMMessage.ts index 6b7cf2f97..14824b36c 100644 --- a/src/vs/workbench/services/void/browser/sendLLMMessage.ts +++ b/src/vs/platform/void/browser/sendLLMMessage.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { ISendLLMMessageService, SendLLMMessageParams } from '../common/sendLLMMessage.js'; -import { ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js'; -import { IMainProcessService } from '../../../../platform/ipc/common/mainProcessService.js'; -import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; +import { ProxyChannel } from '../../../base/parts/ipc/common/ipc.js'; +import { IMainProcessService } from '../../ipc/common/mainProcessService.js'; +import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js'; // BROWSER IMPLEMENTATION OF SENDLLMMESSAGE @@ -22,7 +22,7 @@ export class SendLLMMessageService implements ISendLLMMessageService { constructor( @IMainProcessService mainProcessService: IMainProcessService ) { - this._proxySendLLMService = ProxyChannel.toService(mainProcessService.getChannel('sendLLMMessage')); + this._proxySendLLMService = ProxyChannel.toService(mainProcessService.getChannel('void-channel-sendLLMMessage')); } sendLLMMessage(params: SendLLMMessageParams) { diff --git a/src/vs/workbench/services/void/common/sendLLMMessage.ts b/src/vs/platform/void/common/sendLLMMessage.ts similarity index 84% rename from src/vs/workbench/services/void/common/sendLLMMessage.ts rename to src/vs/platform/void/common/sendLLMMessage.ts index f50f46114..3e1547900 100644 --- a/src/vs/workbench/services/void/common/sendLLMMessage.ts +++ b/src/vs/platform/void/common/sendLLMMessage.ts @@ -1,7 +1,7 @@ // void/common/sendLLMMessage.ts -import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js'; -import { VoidConfig } from '../../../contrib/void/browser/registerConfig.js'; +import { createDecorator } from '../../instantiation/common/instantiation.js'; +import { VoidConfig } from '../../../workbench/contrib/void/browser/registerConfig.js'; diff --git a/src/vs/platform/void/electron-main/sendLLMMessage.ts b/src/vs/platform/void/electron-main/sendLLMMessage.ts new file mode 100644 index 000000000..de2c67fb3 --- /dev/null +++ b/src/vs/platform/void/electron-main/sendLLMMessage.ts @@ -0,0 +1,20 @@ +// import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; +import { ISendLLMMessageService } from '../common/sendLLMMessage.js'; +import { sendLLMMessage } from '../../../workbench/contrib/void/browser/react/out/util/sendLLMMessage.js'; +// import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js'; +// import { ipcMain } from 'electron'; + +// NODE IMPLEMENTATION OF SENDLLMMESSAGE +export class SendLLMMessageService implements ISendLLMMessageService { + readonly _serviceBrand: undefined; + + async sendLLMMessage(data: any) { + console.log('NODE sendLLMMessage', data); + // ipcMain.emit('vscode:sendLLMMessage', data) + + return sendLLMMessage(data) + } +} + +// we don't need to register this, it's registered in app.ts: +// registerSingleton(ISendLLMMessageService, SendLLMMessageService, InstantiationType.Delayed); diff --git a/src/vs/workbench/contrib/void/browser/react/README.md b/src/vs/workbench/contrib/void/browser/react/README.md index e6bfee13a..9f998f8de 100644 --- a/src/vs/workbench/contrib/void/browser/react/README.md +++ b/src/vs/workbench/contrib/void/browser/react/README.md @@ -5,6 +5,6 @@ A couple things to remember: - Make sure to add .js at the end of any external imports used in here, e.g. ../../../../../my_file.js. If you don't do this, you will get untraceable errors. -- src/ needs to be shallow so the detection of externals works properly (see tsup.config.js). +- src/ needs to be shallow (1 folder deep) so the detection of externals works properly (see tsup.config.js). diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index a3b8d35a7..1b18f93c3 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -6,7 +6,6 @@ import React, { FormEvent, Fragment, useCallback, useEffect, useRef, useState } import { useConfigState, useService, useThreadsState } from '../util/services.js'; -import { sendLLMMessage } from '../util/sendLLMMessage.js'; import { generateDiffInstructions } from '../../../prompt/systemPrompts.js'; import { userInstructionsStr } from '../../../prompt/stringifyFiles.js'; import { CodeSelection, CodeStagingSelection } from '../../../registerThreads.js'; diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx index 3f37ca947..eb9a9cefe 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx @@ -4,8 +4,8 @@ import { Ollama } from 'ollama/browser' import { Content, GoogleGenerativeAI, GoogleGenerativeAIFetchError } from '@google/generative-ai'; import { posthog } from 'posthog-js' import type { VoidConfig } from '../../../registerConfig.js'; -import type { LLMMessage, LLMMessageOnText, OnFinalMessage, } from '../../../../../../services/void/common/sendLLMMessage.js'; -import { SendLLMMessageParams } from '../../../../../../services/void/common/sendLLMMessage.js'; +import type { LLMMessage, LLMMessageOnText, OnFinalMessage, } from '../../../../../../../platform/void/common/sendLLMMessage.js'; +import { SendLLMMessageParams } from '../../../../../../../platform/void/common/sendLLMMessage.js'; type SendLLMMessageFnTypeInternal = (params: { messages: LLMMessage[]; diff --git a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts index 4dafd4d44..b3885525f 100644 --- a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts +++ b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts @@ -28,7 +28,8 @@ import { ILanguageService } from '../../../../editor/common/languages/language.j import * as dom from '../../../../base/browser/dom.js'; import { Widget } from '../../../../base/browser/ui/widget.js'; import { URI } from '../../../../base/common/uri.js'; -import { ISendLLMMessageService } from '../../../services/void/common/sendLLMMessage.js'; +import { ISendLLMMessageService } from '../../../../platform/void/common/sendLLMMessage.js'; +// import { ISendLLMMessageService } from '../../../../platform/void/common/sendLLMMessage.js'; // import { sendLLMMessage } from './react/out/util/sendLLMMessage.js'; @@ -116,7 +117,7 @@ export interface IInlineDiffsService { } -export const IInlineDiffsService = createDecorator('inlineDiffsService'); +export const IInlineDiffsService = createDecorator('inlineDiffAreasService'); class InlineDiffsService extends Disposable implements IInlineDiffsService { _serviceBrand: undefined; diff --git a/src/vs/workbench/contrib/void/browser/registerSidebar.ts b/src/vs/workbench/contrib/void/browser/registerSidebar.ts index f5447ba22..104a2354d 100644 --- a/src/vs/workbench/contrib/void/browser/registerSidebar.ts +++ b/src/vs/workbench/contrib/void/browser/registerSidebar.ts @@ -47,7 +47,7 @@ import { IVoidConfigStateService } from './registerConfig.js'; import { IFileService } from '../../../../platform/files/common/files.js'; import { IInlineDiffsService } from './registerInlineDiffs.js'; import { IModelService } from '../../../../editor/common/services/model.js'; -import { ISendLLMMessageService } from '../../../services/void/common/sendLLMMessage.js'; +import { ISendLLMMessageService } from '../../../../platform/void/common/sendLLMMessage.js'; // import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js'; diff --git a/src/vs/workbench/electron-sandbox/desktop.main.ts b/src/vs/workbench/electron-sandbox/desktop.main.ts index 24d89f630..da3a7ede4 100644 --- a/src/vs/workbench/electron-sandbox/desktop.main.ts +++ b/src/vs/workbench/electron-sandbox/desktop.main.ts @@ -328,6 +328,11 @@ export class DesktopMain extends Disposable { // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // // Void + // const sendLLMMessageService = new SendLLMMessageService(); + // serviceCollection.set(ISendLLMMessageService, sendLLMMessageService); + + return { serviceCollection, logService, storageService, configurationService }; } diff --git a/src/vs/workbench/services/void/electron-sandbox/sendLLMMessage.ts b/src/vs/workbench/services/void/electron-sandbox/sendLLMMessage.ts deleted file mode 100644 index 906cf84ef..000000000 --- a/src/vs/workbench/services/void/electron-sandbox/sendLLMMessage.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; -import { ISendLLMMessageService } from '../common/sendLLMMessage.js'; - - -// NODE IMPLEMENTATION OF SENDLLMMESSAGE - -export class SendLLMMessageService implements ISendLLMMessageService { - readonly _serviceBrand: undefined; - - async sendLLMMessage(data: any): Promise { - console.log('NODE sendLLMMessage', data); - // Your existing logic to send a message to the server - // For example: - // return fetch('https://your-server.com/api', { method: 'POST', body: JSON.stringify(data) }); - } -} -registerSingleton(ISendLLMMessageService, SendLLMMessageService, InstantiationType.Delayed); diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index 655ec116e..0c3b9dd31 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -17,6 +17,7 @@ import './browser/workbench.contribution.js'; //#region --- Void // Void added this: import './contrib/void/browser/void.contribution.js'; +import '../platform/void/browser/sendLLMMessage.js'; //#endregion diff --git a/src/vs/workbench/workbench.desktop.main.ts b/src/vs/workbench/workbench.desktop.main.ts index f8a16b858..5b0a42b69 100644 --- a/src/vs/workbench/workbench.desktop.main.ts +++ b/src/vs/workbench/workbench.desktop.main.ts @@ -31,13 +31,10 @@ import './electron-sandbox/parts/dialogs/dialog.contribution.js'; //#endregion - - - -//#region --- Void -// Void added this (modeling off of import '.*clipboardservice.js'): -import './services/void/electron-sandbox/sendLLMMessage.js'; -//#endregion +// //#region --- Void +// // Void added this (modeling off of import '.*clipboardservice.js'): +// import './services/void/electron-main/sendLLMMessage.js'; +// //#endregion diff --git a/src/vs/workbench/workbench.web.main.internal.ts b/src/vs/workbench/workbench.web.main.internal.ts index 27cbc8c45..f8cfa0e0d 100644 --- a/src/vs/workbench/workbench.web.main.internal.ts +++ b/src/vs/workbench/workbench.web.main.internal.ts @@ -33,11 +33,6 @@ import './browser/web.main.js'; -//#region --- Void -// Void added this (modeling off of import '.*clipboardservice.js'): -import './services/void/browser/sendLLMMessage.js'; -//#endregion - //#region --- workbench services diff --git a/test/unit/electron/preload.js b/test/unit/electron/preload.js index 04439d66e..4c878e1c8 100644 --- a/test/unit/electron/preload.js +++ b/test/unit/electron/preload.js @@ -77,6 +77,18 @@ process.on(type, callback); } }, + + // Void : { + // /** + // * Send a message to the LLM. + // * @param {any} data The data to send to the LLM. + // * @returns {Promise} The response from the LLM. + // */ + // sendLLMMessage: async (data) => { + // // Use ipcRenderer.invoke to send the message to the main process (see app.ts) + // return await ipcRenderer.invoke('vscode:sendLLMMessage', data); + // } + // }, }; if (process.contextIsolated) {