mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
proxy works!
This commit is contained in:
parent
790a2b6a4f
commit
bdc3c9cb7e
9 changed files with 37 additions and 43 deletions
|
|
@ -121,7 +121,7 @@ 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 { LLMMessageChannel } from '../../platform/void/electron-main/LLMMessageChannel.js';
|
||||
import { LLMMessageChannel } from '../../platform/void/electron-main/llmMessageChannel.js';
|
||||
|
||||
/**
|
||||
* The main VS Code application. There will only ever be one instance,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* Void Editor additions licensed under the AGPLv3 License.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { LLMMessageOnTextEvent, OnErrorEvent, OnFinalMessageEvent, SendLLMMessageParams, SendLLMMessageProxyParams } from '../common/sendLLMTypes.js';
|
||||
import { ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, LLMMessageServiceParams, ProxyLLMMessageParams } 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';
|
||||
|
|
@ -18,7 +18,7 @@ export const ISendLLMMessageService = createDecorator<ISendLLMMessageService>('s
|
|||
// defines an interface that node/ creates and browser/ uses
|
||||
export interface ISendLLMMessageService {
|
||||
readonly _serviceBrand: undefined;
|
||||
sendLLMMessage: (params: SendLLMMessageParams) => void;
|
||||
sendLLMMessage: (params: LLMMessageServiceParams) => void;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -36,35 +36,32 @@ export class SendLLMMessageService implements ISendLLMMessageService {
|
|||
// const service = ProxyChannel.toService<LLMMessageChannel>(mainProcessService.getChannel('void-channel-sendLLMMessage')); // lets you call it like a service, not needed here
|
||||
}
|
||||
|
||||
sendLLMMessage(params: SendLLMMessageParams) {
|
||||
sendLLMMessage(params: LLMMessageServiceParams) {
|
||||
const requestId_ = generateUuid();
|
||||
const { onText, onFinalMessage, onError, ...proxyParams } = params;
|
||||
|
||||
// listen for listenerName='onText' | 'onFinalMessage' | 'onError', and call the original function on it
|
||||
|
||||
const onTextEvent: Event<LLMMessageOnTextEvent> = this.channel.listen('onText')
|
||||
const onTextEvent: Event<ProxyOnTextPayload> = this.channel.listen('onText')
|
||||
onTextEvent(e => {
|
||||
console.log('event TEXT EVENT!!!:', JSON.stringify(e, null, 5))
|
||||
if (requestId_ !== e.requestId) return;
|
||||
onText(e)
|
||||
})
|
||||
|
||||
const onFinalMessageEvent: Event<OnFinalMessageEvent> = this.channel.listen('onFinalMessage')
|
||||
const onFinalMessageEvent: Event<ProxyOnFinalMessagePayload> = this.channel.listen('onFinalMessage')
|
||||
onFinalMessageEvent(e => {
|
||||
console.log('FINAL MESSAGE EVENT!!!:', JSON.stringify(e, null, 5))
|
||||
if (requestId_ !== e.requestId) return;
|
||||
onFinalMessage(e)
|
||||
})
|
||||
|
||||
const onErrorEvent: Event<OnErrorEvent> = this.channel.listen('onError')
|
||||
const onErrorEvent: Event<ProxyOnErrorPayload> = this.channel.listen('onError')
|
||||
onErrorEvent(e => {
|
||||
console.log('ERROR EVENT!!!:', JSON.stringify(e, null, 5))
|
||||
if (requestId_ !== e.requestId) return;
|
||||
onError(e)
|
||||
})
|
||||
|
||||
// params will be stripped of all its functions
|
||||
this.channel.call('sendLLMMessage', { ...proxyParams, requestId: requestId_ } satisfies SendLLMMessageProxyParams);
|
||||
this.channel.call('sendLLMMessage', { ...proxyParams, requestId: requestId_ } satisfies ProxyLLMMessageParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5,29 +5,29 @@
|
|||
|
||||
import { VoidConfig } from '../../../workbench/contrib/void/browser/registerConfig.js';
|
||||
|
||||
// ---------- definitions ----------
|
||||
// ---------- type definitions ----------
|
||||
|
||||
export type LLMMessageOnText = (p: { newText: string, fullText: string }) => void
|
||||
export type OnText = (p: { newText: string, fullText: string }) => void
|
||||
|
||||
export type OnFinalMessage = (p: { fullText: string }) => void
|
||||
|
||||
export type OnError = (p: { error: Error | string }) => void
|
||||
|
||||
export type LLMMessageAbortRef = { current: (() => void) | null }
|
||||
export type AbortRef = { current: (() => void) | null }
|
||||
|
||||
export type LLMMessage = {
|
||||
role: 'system' | 'user' | 'assistant';
|
||||
content: string;
|
||||
}
|
||||
|
||||
export type SendLLMMessageParams = {
|
||||
onText: LLMMessageOnText;
|
||||
export type LLMMessageServiceParams = {
|
||||
onText: OnText;
|
||||
onFinalMessage: OnFinalMessage;
|
||||
onError: OnError;
|
||||
|
||||
messages: LLMMessage[];
|
||||
voidConfig: VoidConfig | null;
|
||||
abortRef: LLMMessageAbortRef;
|
||||
abortRef: AbortRef;
|
||||
|
||||
logging: {
|
||||
loggingName: string,
|
||||
|
|
@ -36,8 +36,8 @@ export type SendLLMMessageParams = {
|
|||
|
||||
// can't send functions across a proxy, use listeners instead
|
||||
export const listenerNames = ['onText', 'onFinalMessage', 'onError'] as const
|
||||
export type SendLLMMessageProxyParams = Omit<SendLLMMessageParams, typeof listenerNames[number]> & { requestId: string }
|
||||
export type ProxyLLMMessageParams = Omit<LLMMessageServiceParams, typeof listenerNames[number]> & { requestId: string }
|
||||
|
||||
export type LLMMessageOnTextEvent = Parameters<LLMMessageOnText>[0] & { requestId: string }
|
||||
export type OnFinalMessageEvent = Parameters<OnFinalMessage>[0] & { requestId: string }
|
||||
export type OnErrorEvent = Parameters<OnError>[0] & { requestId: string }
|
||||
export type ProxyOnTextPayload = Parameters<OnText>[0] & { requestId: string }
|
||||
export type ProxyOnFinalMessagePayload = Parameters<OnFinalMessage>[0] & { requestId: string }
|
||||
export type ProxyOnErrorPayload = Parameters<OnError>[0] & { requestId: string }
|
||||
|
|
@ -11,18 +11,18 @@
|
|||
import { IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
|
||||
import { Emitter, Event } from '../../../base/common/event.js';
|
||||
import { sendLLMMessage } from '../../../workbench/contrib/void/browser/react/out/util/sendLLMMessage.js';
|
||||
import { listenerNames, LLMMessageOnTextEvent, OnErrorEvent, OnFinalMessageEvent, SendLLMMessageParams, SendLLMMessageProxyParams } from '../common/sendLLMTypes.js';
|
||||
import { listenerNames, ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, LLMMessageServiceParams, ProxyLLMMessageParams } from '../common/llmMessageTypes.js';
|
||||
|
||||
// NODE IMPLEMENTATION OF SENDLLMMESSAGE
|
||||
// NODE IMPLEMENTATION OF SENDLLMMESSAGE - calls sendLLMMessage() and returns listeners
|
||||
|
||||
export class LLMMessageChannel implements IServerChannel {
|
||||
private readonly _onText = new Emitter<LLMMessageOnTextEvent>();
|
||||
private readonly _onText = new Emitter<ProxyOnTextPayload>();
|
||||
readonly onText = this._onText.event;
|
||||
|
||||
private readonly _onFinalMessage = new Emitter<OnFinalMessageEvent>();
|
||||
private readonly _onFinalMessage = new Emitter<ProxyOnFinalMessagePayload>();
|
||||
readonly onFinalMessage = this._onFinalMessage.event;
|
||||
|
||||
private readonly _onError = new Emitter<OnErrorEvent>();
|
||||
private readonly _onError = new Emitter<ProxyOnErrorPayload>();
|
||||
readonly onError = this._onError.event;
|
||||
|
||||
constructor() { }
|
||||
|
|
@ -45,13 +45,13 @@ export class LLMMessageChannel implements IServerChannel {
|
|||
}
|
||||
|
||||
// both use this
|
||||
async call(_: unknown, command: string, params: SendLLMMessageProxyParams): Promise<any> {
|
||||
async call(_: unknown, command: string, params: ProxyLLMMessageParams): Promise<any> {
|
||||
|
||||
if (command !== 'sendLLMMessage') throw new Error(`Invalid call in sendLLMMessage channel: ${command}.\nArgs:\n${JSON.stringify(params, null, 5)}`);
|
||||
|
||||
try {
|
||||
const { requestId } = params;
|
||||
const mainThreadParams: SendLLMMessageParams = {
|
||||
const mainThreadParams: LLMMessageServiceParams = {
|
||||
...params,
|
||||
onText: ({ newText, fullText }) => { this._onText.fire({ requestId, newText, fullText }); },
|
||||
onFinalMessage: ({ fullText }) => { this._onFinalMessage.fire({ requestId, fullText }); },
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { URI } from '../../../../../../../base/common/uri.js';
|
|||
import { EndOfLinePreference } from '../../../../../../../editor/common/model.js';
|
||||
import { IDisposable } from '../../../../../../../base/common/lifecycle.js';
|
||||
import { ErrorDisplay } from '../util/ErrorDisplay.js';
|
||||
import { SendLLMMessageParams } from '../../../../../../../platform/void/common/sendLLMTypes.js';
|
||||
import { LLMMessageServiceParams } from '../../../../../../../platform/void/common/llmMessageTypes.js';
|
||||
|
||||
// import { } from '@vscode/webview-ui-toolkit/react';
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ export const SidebarChat = () => {
|
|||
|
||||
// send message to LLM
|
||||
|
||||
const object: SendLLMMessageParams = {
|
||||
const object: LLMMessageServiceParams = {
|
||||
logging: { loggingName: 'Chat' },
|
||||
messages: [...(currentThread?.messages ?? []).map(m => ({ role: m.role, content: m.content })),],
|
||||
onText: ({ newText, fullText }) => setMessageStream(fullText),
|
||||
|
|
@ -241,8 +241,6 @@ export const SidebarChat = () => {
|
|||
abortRef: abortFnRef,
|
||||
}
|
||||
|
||||
console.log('object!!!!!2', Object.keys(object))
|
||||
|
||||
sendLLMMessageService.sendLLMMessage(object)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ 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, OnError, OnFinalMessage, } from '../../../../../../../platform/void/common/sendLLMTypes.js';
|
||||
import { SendLLMMessageParams } from '../../../../../../../platform/void/common/sendLLMTypes.js';
|
||||
import type { LLMMessage, OnText, OnError, OnFinalMessage, } from '../../../../../../../platform/void/common/llmMessageTypes.js';
|
||||
import { LLMMessageServiceParams } from '../../../../../../../platform/void/common/llmMessageTypes.js';
|
||||
|
||||
type SendLLMMessageFnTypeInternal = (params: {
|
||||
messages: LLMMessage[];
|
||||
onText: LLMMessageOnText;
|
||||
onText: OnText;
|
||||
onFinalMessage: OnFinalMessage;
|
||||
onError: OnError;
|
||||
voidConfig: VoidConfig;
|
||||
|
|
@ -284,7 +284,7 @@ export const sendLLMMessage = ({
|
|||
abortRef: abortRef_,
|
||||
voidConfig,
|
||||
logging: { loggingName }
|
||||
}: SendLLMMessageParams) => {
|
||||
}: LLMMessageServiceParams) => {
|
||||
if (!voidConfig) return;
|
||||
|
||||
// trim message content (Anthropic and other providers give an error if there is trailing whitespace)
|
||||
|
|
@ -307,7 +307,7 @@ export const sendLLMMessage = ({
|
|||
let _setAborter = (fn: () => void) => { _aborter = fn }
|
||||
let _didAbort = false
|
||||
|
||||
const onText: LLMMessageOnText = ({ newText, fullText }) => {
|
||||
const onText: OnText = ({ newText, fullText }) => {
|
||||
if (_didAbort) return
|
||||
onText_({ newText, fullText })
|
||||
_fullTextSoFar = fullText
|
||||
|
|
|
|||
|
|
@ -28,8 +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 { SendLLMMessageParams } from '../../../../platform/void/common/sendLLMTypes.js';
|
||||
import { ISendLLMMessageService } from '../../../../platform/void/browser/sendLLMMessage.js';
|
||||
import { LLMMessageServiceParams } from '../../../../platform/void/common/llmMessageTypes.js';
|
||||
import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMessageService.js';
|
||||
// import { ISendLLMMessageService } from '../../../../platform/void/common/sendLLMMessage.js';
|
||||
// import { sendLLMMessage } from './react/out/util/sendLLMMessage.js';
|
||||
|
||||
|
|
@ -734,7 +734,7 @@ Please finish writing the new file by applying the diff to the original file. Re
|
|||
const abortRef = { current: null } as { current: null | (() => void) }
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
|
||||
const object: SendLLMMessageParams = {
|
||||
const object: LLMMessageServiceParams = {
|
||||
logging: { loggingName: 'streamChunk' },
|
||||
messages: [
|
||||
{ role: 'system', content: writeFileWithDiffInstructions, },
|
||||
|
|
@ -764,7 +764,6 @@ Please finish writing the new file by applying the diff to the original file. Re
|
|||
abortRef,
|
||||
}
|
||||
|
||||
console.log('object!!!!!', Object.keys(object))
|
||||
this._sendLLMMessageService.sendLLMMessage(object)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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 '../../../../platform/void/browser/sendLLMMessage.js';
|
||||
import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMessageService.js';
|
||||
|
||||
|
||||
// import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
|
||||
|
|
|
|||
|
|
@ -17,7 +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';
|
||||
import '../platform/void/browser/llmMessageService.js';
|
||||
//#endregion
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue