From 94f4d2caaf96468f680b0a2728826594c11bedeb Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Thu, 12 Dec 2024 19:01:01 -0800 Subject: [PATCH] add ollamaList to llmMessageService --- src/vs/code/electron-main/app.ts | 11 +- .../void/browser/llmMessageService.ts | 71 ++++++++---- .../void/browser/ollamaListService.ts | 30 ----- .../platform/void/common/llmMessageTypes.ts | 108 +++++++++++++----- .../platform/void/common/ollamaListService.ts | 48 -------- .../electron-main/llmMessage/anthropic.ts | 4 +- .../void/electron-main/llmMessage/gemini.ts | 4 +- .../void/electron-main/llmMessage/groq.ts | 4 +- .../void/electron-main/llmMessage/ollama.ts | 7 +- .../void/electron-main/llmMessage/openai.ts | 4 +- .../llmMessage/sendLLMMessage.ts | 4 +- .../void/electron-main/llmMessageChannel.ts | 82 ++++++++----- .../electron-main/ollamaListMainService.ts | 24 ---- .../void/browser/registerInlineDiffs.ts | 4 +- .../contrib/void/browser/registerSidebar.ts | 12 -- 15 files changed, 202 insertions(+), 215 deletions(-) delete mode 100644 src/vs/platform/void/browser/ollamaListService.ts delete mode 100644 src/vs/platform/void/common/ollamaListService.ts delete mode 100644 src/vs/platform/void/electron-main/ollamaListMainService.ts diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 2e348c96..1a027000 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -124,8 +124,6 @@ import { ExtensionSignatureVerificationService, IExtensionSignatureVerificationS import { LLMMessageChannel } from '../../platform/void/electron-main/llmMessageChannel.js'; import { IMetricsService } from '../../platform/void/common/metricsService.js'; import { MetricsMainService } from '../../platform/void/electron-main/metricsMainService.js'; -import { OllamaListMainService } from '../../platform/void/electron-main/ollamaListMainService.js'; -import { IOllamaListService } from '../../platform/void/common/ollamaListService.js'; /** * The main VS Code application. There will only ever be one instance, @@ -1109,7 +1107,6 @@ export class CodeApplication extends Disposable { // Void main process services (required for services with a channel for comm between browser and electron-main (node)) services.set(IMetricsService, new SyncDescriptor(MetricsMainService, undefined, false)); - services.set(IOllamaListService, new SyncDescriptor(OllamaListMainService, undefined, false)); // Default Extensions Profile Init services.set(IExtensionsProfileScannerService, new SyncDescriptor(ExtensionsProfileScannerService, undefined, true)); @@ -1245,13 +1242,11 @@ export class CodeApplication extends Disposable { mainProcessElectronServer.registerChannel('logger', loggerChannel); sharedProcessClient.then(client => client.registerChannel('logger', loggerChannel)); - // Void + // Void - use loggerChannel as reference const metricsChannel = ProxyChannel.fromService(accessor.get(IMetricsService), disposables); mainProcessElectronServer.registerChannel('void-channel-metrics', metricsChannel); - const ollamaListChannel = ProxyChannel.fromService(accessor.get(IOllamaListService), disposables); - mainProcessElectronServer.registerChannel('void-channel-ollama-list', ollamaListChannel); - const sendLLMMessageChannel = new LLMMessageChannel(accessor.get(IMetricsService)); - mainProcessElectronServer.registerChannel('void-channel-sendLLMMessage', sendLLMMessageChannel); + const llmMessageChannel = new LLMMessageChannel(accessor.get(IMetricsService)); + mainProcessElectronServer.registerChannel('void-channel-llmMessageService', llmMessageChannel); // Extension Host Debug Broadcasting const electronExtensionHostDebugBroadcastChannel = new ElectronExtensionHostDebugBroadcastChannel(accessor.get(IWindowsMainService)); diff --git a/src/vs/platform/void/browser/llmMessageService.ts b/src/vs/platform/void/browser/llmMessageService.ts index 52115567..f0fb6a97 100644 --- a/src/vs/platform/void/browser/llmMessageService.ts +++ b/src/vs/platform/void/browser/llmMessageService.ts @@ -3,7 +3,7 @@ * Void Editor additions licensed under the AGPL 3.0 License. *--------------------------------------------------------------------------------------------*/ -import { ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, LLMMessageServiceParams, ProxyLLMMessageParams, ProxyLLMMessageAbortParams } from '../common/llmMessageTypes.js'; +import { EventLLMMessageOnTextParams, EventLLMMessageOnErrorParams, EventLLMMessageOnFinalMessageParams, ServiceSendLLMMessageParams, MainLLMMessageParams, MainLLMMessageAbortParams, ServiceOllamaListParams, EventOllamaListOnSuccessParams, EventOllamaListOnErrorParams, MainOllamaListParams } from '../common/llmMessageTypes.js'; import { IChannel } from '../../../base/parts/ipc/common/ipc.js'; import { IMainProcessService } from '../../ipc/common/mainProcessService.js'; import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js'; @@ -21,7 +21,7 @@ export const ISendLLMMessageService = createDecorator('s // defines an interface that node/ creates and browser/ uses export interface ISendLLMMessageService { readonly _serviceBrand: undefined; - sendLLMMessage: (params: LLMMessageServiceParams) => string | null; + sendLLMMessage: (params: ServiceSendLLMMessageParams) => string | null; abort: (requestId: string) => void; } @@ -31,9 +31,16 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage readonly _serviceBrand: undefined; private readonly channel: IChannel // LLMMessageChannel - private readonly onTextHooks: { [eventId: string]: ((params: ProxyOnTextPayload) => void) } = {} - private readonly onFinalMessageHooks: { [eventId: string]: ((params: ProxyOnFinalMessagePayload) => void) } = {} - private readonly onErrorHooks: { [eventId: string]: ((params: ProxyOnErrorPayload) => void) } = {} + // llmMessage + private readonly onTextHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnTextParams) => void) } = {} + private readonly onFinalMessageHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnFinalMessageParams) => void) } = {} + private readonly onErrorHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnErrorParams) => void) } = {} + + + // ollamaList + private readonly onSuccess_ollama: { [eventId: string]: ((params: EventOllamaListOnSuccessParams) => void) } = {} + private readonly onError_ollama: { [eventId: string]: ((params: EventOllamaListOnErrorParams) => void) } = {} + constructor( @IMainProcessService private readonly mainProcessService: IMainProcessService, // used as a renderer (only usable on client side) @@ -43,22 +50,22 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage super() // const service = ProxyChannel.toService(mainProcessService.getChannel('void-channel-sendLLMMessage')); // lets you call it like a service - this.channel = this.mainProcessService.getChannel('void-channel-sendLLMMessage') + this.channel = this.mainProcessService.getChannel('void-channel-llmMessageService') // this sets up an IPC channel and takes a few ms, so we set up listeners immediately and add hooks to them instead - const onTextEvent: Event = this.channel.listen('onText') - const onFinalMessageEvent: Event = this.channel.listen('onFinalMessage') - const onErrorEvent: Event = this.channel.listen('onError') + const onTextEvent: Event = this.channel.listen('onText') + const onFinalMessageEvent: Event = this.channel.listen('onFinalMessage') + const onErrorEvent: Event = this.channel.listen('onError') this._register( onTextEvent(e => { - this.onTextHooks[e.requestId]?.(e) + this.onTextHooks_llm[e.requestId]?.(e) }) ) this._register( onFinalMessageEvent(e => { - this.onFinalMessageHooks[e.requestId]?.(e) + this.onFinalMessageHooks_llm[e.requestId]?.(e) this._onRequestIdDone(e.requestId) }) ) @@ -66,14 +73,13 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage this._register( onErrorEvent(e => { console.log('Error in SendLLMMessageService:', JSON.stringify(e)) - this.onErrorHooks[e.requestId]?.(e) + this.onErrorHooks_llm[e.requestId]?.(e) this._onRequestIdDone(e.requestId) }) ) } - - sendLLMMessage(params: LLMMessageServiceParams) { + sendLLMMessage(params: ServiceSendLLMMessageParams) { const { onText, onFinalMessage, onError, ...proxyParams } = params; const { featureName } = proxyParams @@ -87,9 +93,9 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage // add state for request id const requestId_ = generateUuid(); - this.onTextHooks[requestId_] = onText - this.onFinalMessageHooks[requestId_] = onFinalMessage - this.onErrorHooks[requestId_] = onError + this.onTextHooks_llm[requestId_] = onText + this.onFinalMessageHooks_llm[requestId_] = onFinalMessage + this.onErrorHooks_llm[requestId_] = onError const { settingsOfProvider } = this.voidConfigStateService.state @@ -100,21 +106,42 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage providerName, modelName, settingsOfProvider, - } satisfies ProxyLLMMessageParams); + } satisfies MainLLMMessageParams); return requestId_ } abort(requestId: string) { - this.channel.call('abort', { requestId } satisfies ProxyLLMMessageAbortParams); + this.channel.call('abort', { requestId } satisfies MainLLMMessageAbortParams); this._onRequestIdDone(requestId) } + ollamaList = (params: ServiceOllamaListParams) => { + const { onSuccess, onError, ...proxyParams } = params + + const { settingsOfProvider } = this.voidConfigStateService.state + + // add state for request id + const requestId_ = generateUuid(); + this.onSuccess_ollama[requestId_] = onSuccess + this.onError_ollama[requestId_] = onError + + this.channel.call('ollamaList', { + ...proxyParams, + settingsOfProvider, + requestId: requestId_, + } satisfies MainOllamaListParams) + } + + _onRequestIdDone(requestId: string) { - delete this.onTextHooks[requestId] - delete this.onFinalMessageHooks[requestId] - delete this.onErrorHooks[requestId] + delete this.onTextHooks_llm[requestId] + delete this.onFinalMessageHooks_llm[requestId] + delete this.onErrorHooks_llm[requestId] + + delete this.onSuccess_ollama[requestId] + delete this.onError_ollama[requestId] } } diff --git a/src/vs/platform/void/browser/ollamaListService.ts b/src/vs/platform/void/browser/ollamaListService.ts deleted file mode 100644 index 0b0d05f6..00000000 --- a/src/vs/platform/void/browser/ollamaListService.ts +++ /dev/null @@ -1,30 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Glass Devtools, Inc. All rights reserved. - * Void Editor additions licensed under the AGPL 3.0 License. - *--------------------------------------------------------------------------------------------*/ - -import { ProxyChannel } from '../../../base/parts/ipc/common/ipc.js'; -import { IMainProcessService } from '../../ipc/common/mainProcessService.js'; -import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js'; -import { IOllamaListService } from '../common/ollamaListService.js'; - -// BROWSER IMPLEMENTATION, calls channel - -export class OllamaListService implements IOllamaListService { - - readonly _serviceBrand: undefined; - private readonly ollamaListService: IOllamaListService; - - constructor( - @IMainProcessService mainProcessService: IMainProcessService // (only usable on client side) - ) { - this.ollamaListService = ProxyChannel.toService(mainProcessService.getChannel('void-channel-ollama-list')); - } - - list: IOllamaListService['list'] = (...params) => { - this.ollamaListService.list(...params); - } -} - -registerSingleton(IOllamaListService, OllamaListService, InstantiationType.Eager); - diff --git a/src/vs/platform/void/common/llmMessageTypes.ts b/src/vs/platform/void/common/llmMessageTypes.ts index a9bbb592..95d613bd 100644 --- a/src/vs/platform/void/common/llmMessageTypes.ts +++ b/src/vs/platform/void/common/llmMessageTypes.ts @@ -8,11 +8,8 @@ import { ProviderName, SettingsOfProvider } from './voidConfigTypes' export type OnText = (p: { newText: string, fullText: string }) => void - export type OnFinalMessage = (p: { fullText: string }) => void - export type OnError = (p: { message: string, fullError: Error | null }) => void - export type AbortRef = { current: (() => void) | null } export type LLMMessage = { @@ -30,20 +27,8 @@ export type LLMFeatureSelection = { range: IRange } -export type LLMMessageServiceParams = { - onText: OnText; - onFinalMessage: OnFinalMessage; - onError: OnError; - - messages: LLMMessage[]; - - logging: { - loggingName: string, - }; -} & LLMFeatureSelection - // params to the true sendLLMMessage function -export type SendLLMMMessageParams = { +export type LLMMMessageParams = { onText: OnText; onFinalMessage: OnFinalMessage; onError: OnError; @@ -59,21 +44,29 @@ export type SendLLMMMessageParams = { settingsOfProvider: SettingsOfProvider; } +export type ServiceSendLLMMessageParams = { + onText: OnText; + onFinalMessage: OnFinalMessage; + onError: OnError; + + messages: LLMMessage[]; + + logging: { + loggingName: string, + }; +} & LLMFeatureSelection + // can't send functions across a proxy, use listeners instead -export type BlockedProxyParams = 'onText' | 'onFinalMessage' | 'onError' | 'abortRef' -export type ProxyLLMMessageParams = Omit & { requestId: string } +export type BlockedMainLLMMessageParams = 'onText' | 'onFinalMessage' | 'onError' | 'abortRef' -export type ProxyOnTextPayload = Parameters[0] & { requestId: string } -export type ProxyOnFinalMessagePayload = Parameters[0] & { requestId: string } -export type ProxyOnErrorPayload = Parameters[0] & { requestId: string } +export type MainLLMMessageParams = Omit & { requestId: string } +export type MainLLMMessageAbortParams = { requestId: string } -export type ProxyLLMMessageAbortParams = { requestId: string } +export type EventLLMMessageOnTextParams = Parameters[0] & { requestId: string } +export type EventLLMMessageOnFinalMessageParams = Parameters[0] & { requestId: string } +export type EventLLMMessageOnErrorParams = Parameters[0] & { requestId: string } - - - - -export type SendLLMMessageFnTypeInternal = (params: { +export type _InternalSendLLMMessageFnType = (params: { messages: LLMMessage[]; onText: OnText; onFinalMessage: OnFinalMessage; @@ -84,3 +77,64 @@ export type SendLLMMessageFnTypeInternal = (params: { _setAborter: (aborter: () => void) => void; }) => void + +// service -> main -> internal -> event (back to main) +// (browser) + + + + + + + + + + + + + + + + +// These are from 'ollama' SDK +interface ModelDetails { + parent_model: string; + format: string; + family: string; + families: string[]; + parameter_size: string; + quantization_level: string; +} + +type ModelResponse = { + name: string; + modified_at: Date; + size: number; + digest: string; + details: ModelDetails; + expires_at: Date; + size_vram: number; +} + + +// params to the true list fn +export type OllamaListParams = { + settingsOfProvider: SettingsOfProvider; + onSuccess: (param: { models: ModelResponse[] }) => void; + onError: (param: { error: any }) => void; +} + +export type ServiceOllamaListParams = { + onSuccess: (param: { models: ModelResponse[] }) => void; + onError: (param: { error: any }) => void; +} + +type BlockedMainOllamaListParams = 'onSuccess' | 'onError' +export type MainOllamaListParams = Omit & { requestId: string } + +export type EventOllamaListOnSuccessParams = Parameters[0] & { requestId: string } +export type EventOllamaListOnErrorParams = Parameters[0] & { requestId: string } + + + +export type _InternalOllamaListFnType = (params: OllamaListParams) => void diff --git a/src/vs/platform/void/common/ollamaListService.ts b/src/vs/platform/void/common/ollamaListService.ts deleted file mode 100644 index 3a9513de..00000000 --- a/src/vs/platform/void/common/ollamaListService.ts +++ /dev/null @@ -1,48 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Glass Devtools, Inc. All rights reserved. - * Void Editor additions licensed under the AGPL 3.0 License. - *--------------------------------------------------------------------------------------------*/ - -import { createDecorator } from '../../instantiation/common/instantiation.js'; -import { SettingsOfProvider } from './voidConfigTypes.js'; - - -export type OllamaListFnParams = { - settingsOfProvider: SettingsOfProvider; - onSuccess: (param: { models: ModelResponse[] }) => void; - onError: (param: { error: any }) => void; -} - - -export interface IOllamaListService { - readonly _serviceBrand: undefined; - list(params: OllamaListFnParams): void; -} - -export const IOllamaListService = createDecorator('ollamaListService'); - - - - - - -// These are from 'ollama' SDK -interface ModelDetails { - parent_model: string; - format: string; - family: string; - families: string[]; - parameter_size: string; - quantization_level: string; -} - -type ModelResponse = { - name: string; - modified_at: Date; - size: number; - digest: string; - details: ModelDetails; - expires_at: Date; - size_vram: number; -} - diff --git a/src/vs/platform/void/electron-main/llmMessage/anthropic.ts b/src/vs/platform/void/electron-main/llmMessage/anthropic.ts index b3610efb..86282282 100644 --- a/src/vs/platform/void/electron-main/llmMessage/anthropic.ts +++ b/src/vs/platform/void/electron-main/llmMessage/anthropic.ts @@ -5,7 +5,7 @@ import Anthropic from '@anthropic-ai/sdk'; import { parseMaxTokensStr } from './util.js'; -import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js'; +import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js'; import { displayInfoOfSettingName } from '../../common/voidConfigTypes.js'; // Anthropic @@ -13,7 +13,7 @@ type LLMMessageAnthropic = { role: 'user' | 'assistant'; content: string; } -export const sendAnthropicMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { +export const sendAnthropicMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { const thisConfig = settingsOfProvider.anthropic diff --git a/src/vs/platform/void/electron-main/llmMessage/gemini.ts b/src/vs/platform/void/electron-main/llmMessage/gemini.ts index d68879cb..59e0c1c3 100644 --- a/src/vs/platform/void/electron-main/llmMessage/gemini.ts +++ b/src/vs/platform/void/electron-main/llmMessage/gemini.ts @@ -4,10 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import { Content, GoogleGenerativeAI, GoogleGenerativeAIFetchError } from '@google/generative-ai'; -import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js'; +import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js'; // Gemini -export const sendGeminiMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { +export const sendGeminiMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { let fullText = '' diff --git a/src/vs/platform/void/electron-main/llmMessage/groq.ts b/src/vs/platform/void/electron-main/llmMessage/groq.ts index cbeb8669..5ab59211 100644 --- a/src/vs/platform/void/electron-main/llmMessage/groq.ts +++ b/src/vs/platform/void/electron-main/llmMessage/groq.ts @@ -4,11 +4,11 @@ *--------------------------------------------------------------------------------------------*/ import Groq from 'groq-sdk'; -import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js'; +import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js'; import { parseMaxTokensStr } from './util.js'; // Groq -export const sendGroqMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { +export const sendGroqMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { let fullText = ''; const thisConfig = settingsOfProvider.groq diff --git a/src/vs/platform/void/electron-main/llmMessage/ollama.ts b/src/vs/platform/void/electron-main/llmMessage/ollama.ts index 415adb19..98713670 100644 --- a/src/vs/platform/void/electron-main/llmMessage/ollama.ts +++ b/src/vs/platform/void/electron-main/llmMessage/ollama.ts @@ -4,11 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import { Ollama } from 'ollama'; -import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js'; +import { _InternalOllamaListFnType, _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js'; import { parseMaxTokensStr } from './util.js'; -import { OllamaListFnParams } from '../../common/ollamaListService.js'; -export const getDefaultOllamaModels = async ({ onSuccess, onError, settingsOfProvider }: OllamaListFnParams) => { +export const ollamaList: _InternalOllamaListFnType = async ({ onSuccess, onError, settingsOfProvider }) => { const thisConfig = settingsOfProvider.ollama const ollama = new Ollama({ host: thisConfig.endpoint }) ollama.list() @@ -24,7 +23,7 @@ export const getDefaultOllamaModels = async ({ onSuccess, onError, settingsOfPro // Ollama -export const sendOllamaMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { +export const sendOllamaMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => { const thisConfig = settingsOfProvider.ollama diff --git a/src/vs/platform/void/electron-main/llmMessage/openai.ts b/src/vs/platform/void/electron-main/llmMessage/openai.ts index 0e7e21b0..3b8c3645 100644 --- a/src/vs/platform/void/electron-main/llmMessage/openai.ts +++ b/src/vs/platform/void/electron-main/llmMessage/openai.ts @@ -4,12 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import OpenAI from 'openai'; -import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js'; +import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js'; import { parseMaxTokensStr } from './util.js'; // OpenAI, OpenRouter, OpenAICompatible -export const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter, providerName }) => { +export const sendOpenAIMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter, providerName }) => { let fullText = '' diff --git a/src/vs/platform/void/electron-main/llmMessage/sendLLMMessage.ts b/src/vs/platform/void/electron-main/llmMessage/sendLLMMessage.ts index b0823547..9e106f97 100644 --- a/src/vs/platform/void/electron-main/llmMessage/sendLLMMessage.ts +++ b/src/vs/platform/void/electron-main/llmMessage/sendLLMMessage.ts @@ -3,7 +3,7 @@ * Void Editor additions licensed under the AGPL 3.0 License. *--------------------------------------------------------------------------------------------*/ -import { SendLLMMMessageParams, OnText, OnFinalMessage, OnError } from '../../common/llmMessageTypes.js'; +import { LLMMMessageParams, OnText, OnFinalMessage, OnError } from '../../common/llmMessageTypes.js'; import { IMetricsService } from '../../common/metricsService.js'; import { sendAnthropicMsg } from './anthropic.js'; @@ -22,7 +22,7 @@ export const sendLLMMessage = ({ settingsOfProvider, providerName, modelName, -}: SendLLMMMessageParams, +}: LLMMMessageParams, metricsService: IMetricsService ) => { diff --git a/src/vs/platform/void/electron-main/llmMessageChannel.ts b/src/vs/platform/void/electron-main/llmMessageChannel.ts index 203eebd6..67cbee5d 100644 --- a/src/vs/platform/void/electron-main/llmMessageChannel.ts +++ b/src/vs/platform/void/electron-main/llmMessageChannel.ts @@ -8,43 +8,55 @@ import { IServerChannel } from '../../../base/parts/ipc/common/ipc.js'; import { Emitter, Event } from '../../../base/common/event.js'; -import { BlockedProxyParams, ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, ProxyLLMMessageParams, AbortRef, SendLLMMMessageParams, ProxyLLMMessageAbortParams } from '../common/llmMessageTypes.js'; +import { EventLLMMessageOnTextParams, EventLLMMessageOnErrorParams, EventLLMMessageOnFinalMessageParams, MainLLMMessageParams, AbortRef, LLMMMessageParams, MainLLMMessageAbortParams, MainOllamaListParams, OllamaListParams, EventOllamaListOnSuccessParams, EventOllamaListOnErrorParams } from '../common/llmMessageTypes.js'; import { sendLLMMessage } from './llmMessage/sendLLMMessage.js' import { IMetricsService } from '../common/metricsService.js'; +import { ollamaList } from './llmMessage/ollama.js'; // NODE IMPLEMENTATION - calls actual sendLLMMessage() and returns listeners to it export class LLMMessageChannel implements IServerChannel { - private readonly _onText = new Emitter(); - readonly onText = this._onText.event; + // sendLLMMessage + private readonly _onText_llm = new Emitter(); + private readonly onText_llm = this._onText_llm.event; - private readonly _onFinalMessage = new Emitter(); - readonly onFinalMessage = this._onFinalMessage.event; + private readonly _onFinalMessage_llm = new Emitter(); + private readonly onFinalMessage_llm = this._onFinalMessage_llm.event; - private readonly _onError = new Emitter(); - readonly onError = this._onError.event; + private readonly _onError_llm = new Emitter(); + private readonly onError_llm = this._onError_llm.event; + private readonly _abortRefOfRequestId_llm: Record = {} - private readonly _abortRefOfRequestId: Record = {} + // ollamaList + private readonly _onSuccess_ollama = new Emitter(); + private readonly onSuccess_ollama = this._onSuccess_ollama.event; + private readonly _onError_ollama = new Emitter(); + private readonly onError_ollama = this._onError_ollama.event; // stupidly, channels can't take in @IService constructor( private readonly metricsService: IMetricsService, ) { - } // browser uses this to listen for changes - listen(_: unknown, event: BlockedProxyParams): Event { - if (event === 'onText') { - return this.onText; + listen(_: unknown, event: string): Event { + if (event === 'onText_llm') { + return this.onText_llm; } - else if (event === 'onFinalMessage') { - return this.onFinalMessage; + else if (event === 'onFinalMessage_llm') { + return this.onFinalMessage_llm; } - else if (event === 'onError') { - return this.onError; + else if (event === 'onError_llm') { + return this.onError_llm; + } + else if (event === 'onSuccess_ollama') { + return this.onSuccess_ollama; + } + else if (event === 'onError_ollama') { + return this.onError_ollama; } else { throw new Error(`Event not found: ${event}`); @@ -61,6 +73,9 @@ export class LLMMessageChannel implements IServerChannel { else if (command === 'abort') { this._callAbort(params) } + else if (command === 'ollamaList') { + this._callOllamaList(params) + } else { throw new Error(`Void sendLLM: command "${command}" not recognized.`) } @@ -71,27 +86,38 @@ export class LLMMessageChannel implements IServerChannel { } // the only place sendLLMMessage is actually called - private async _callSendLLMMessage(params: ProxyLLMMessageParams) { + private async _callSendLLMMessage(params: MainLLMMessageParams) { const { requestId } = params; - if (!(requestId in this._abortRefOfRequestId)) - this._abortRefOfRequestId[requestId] = { current: null } + if (!(requestId in this._abortRefOfRequestId_llm)) + this._abortRefOfRequestId_llm[requestId] = { current: null } - const mainThreadParams: SendLLMMMessageParams = { + const mainThreadParams: LLMMMessageParams = { ...params, - onText: ({ newText, fullText }) => { this._onText.fire({ requestId, newText, fullText }); }, - onFinalMessage: ({ fullText }) => { this._onFinalMessage.fire({ requestId, fullText }); }, - onError: ({ message: error, fullError }) => { console.log('sendLLM: firing err'); this._onError.fire({ requestId, message: error, fullError }); }, - abortRef: this._abortRefOfRequestId[requestId], + onText: ({ newText, fullText }) => { this._onText_llm.fire({ requestId, newText, fullText }); }, + onFinalMessage: ({ fullText }) => { this._onFinalMessage_llm.fire({ requestId, fullText }); }, + onError: ({ message: error, fullError }) => { console.log('sendLLM: firing err'); this._onError_llm.fire({ requestId, message: error, fullError }); }, + abortRef: this._abortRefOfRequestId_llm[requestId], } sendLLMMessage(mainThreadParams, this.metricsService); } - private _callAbort(params: ProxyLLMMessageAbortParams) { + private _callAbort(params: MainLLMMessageAbortParams) { const { requestId } = params; - if (!(requestId in this._abortRefOfRequestId)) return - this._abortRefOfRequestId[requestId].current?.() - delete this._abortRefOfRequestId[requestId] + if (!(requestId in this._abortRefOfRequestId_llm)) return + this._abortRefOfRequestId_llm[requestId].current?.() + delete this._abortRefOfRequestId_llm[requestId] + } + + private _callOllamaList(params: MainOllamaListParams) { + const { requestId } = params; + + const mainThreadParams: OllamaListParams = { + ...params, + onSuccess: ({ models }) => { this._onSuccess_ollama.fire({ requestId, models }); }, + onError: ({ error }) => { this._onError_ollama.fire({ requestId, error }); }, + } + ollamaList(mainThreadParams) } diff --git a/src/vs/platform/void/electron-main/ollamaListMainService.ts b/src/vs/platform/void/electron-main/ollamaListMainService.ts deleted file mode 100644 index cb09fd6d..00000000 --- a/src/vs/platform/void/electron-main/ollamaListMainService.ts +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Glass Devtools, Inc. All rights reserved. - * Void Editor additions licensed under the AGPL 3.0 License. - *--------------------------------------------------------------------------------------------*/ - -import { Disposable } from '../../../base/common/lifecycle.js'; - -import { IOllamaListService } from '../common/ollamaListService.js'; -import { getDefaultOllamaModels } from './llmMessage/ollama.js'; - - -export class OllamaListMainService extends Disposable implements IOllamaListService { - _serviceBrand: undefined; - - constructor() { - super() - } - - list: IOllamaListService['list'] = (...params) => { - return getDefaultOllamaModels(...params) - } -} - - diff --git a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts index accfe6fe..e66ec9c8 100644 --- a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts +++ b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts @@ -28,7 +28,7 @@ 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 { LLMFeatureSelection, LLMMessageServiceParams } from '../../../../platform/void/common/llmMessageTypes.js'; +import { LLMFeatureSelection, ServiceSendLLMMessageParams } from '../../../../platform/void/common/llmMessageTypes.js'; import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMessageService.js'; @@ -709,7 +709,7 @@ Please finish writing the new file by applying the diff to the original file. Re let streamRequestId: string | null = null - const object: LLMMessageServiceParams = { + const object: ServiceSendLLMMessageParams = { logging: { loggingName: 'streamChunk' }, messages: [ { role: 'system', content: writeFileWithDiffInstructions, }, diff --git a/src/vs/workbench/contrib/void/browser/registerSidebar.ts b/src/vs/workbench/contrib/void/browser/registerSidebar.ts index 15dd232d..3fd8ecc9 100644 --- a/src/vs/workbench/contrib/void/browser/registerSidebar.ts +++ b/src/vs/workbench/contrib/void/browser/registerSidebar.ts @@ -46,7 +46,6 @@ import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMes import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js'; import { IViewsService } from '../../../services/views/common/viewsService.js'; import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; -import { IOllamaListService } from '../../../../platform/void/common/ollamaListService.js'; // compare against search.contribution.ts and debug.contribution.ts, scm.contribution.ts (source control) @@ -89,20 +88,9 @@ class VoidSidebarViewPane extends ViewPane { @IOpenerService openerService: IOpenerService, @ITelemetryService telemetryService: ITelemetryService, @IHoverService hoverService: IHoverService, - @IVoidConfigStateService configStateService: IVoidConfigStateService, - @IOllamaListService ollamaListService: IOllamaListService, ) { super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService) - console.log('calling Ollama list!!!') - ollamaListService.list({ - onSuccess: ({ models }) => { - console.log('ollama models:', models) - }, onError: ({ error }) => { - console.error('ollama error:', error) - }, - settingsOfProvider: configStateService.state.settingsOfProvider, - }) }