🚧 working on core protocol
This commit is contained in:
parent
4c7c3ab567
commit
70bf23c3fa
6 changed files with 52 additions and 22 deletions
|
|
@ -5,8 +5,8 @@ import { IpcMessenger } from "./messenger";
|
|||
export class IpcIde implements IDE {
|
||||
private messenger: IpcMessenger;
|
||||
|
||||
constructor() {
|
||||
this.messenger = new IpcMessenger();
|
||||
constructor(messenger: IpcMessenger) {
|
||||
this.messenger = messenger;
|
||||
}
|
||||
|
||||
getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import { Command } from "commander";
|
||||
import { Core } from "./core";
|
||||
import { IpcMessenger } from "./messenger";
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program.argument("<name>", "input name").action((name) => {
|
||||
console.log(`Hello, ${name}`);
|
||||
program.action(() => {
|
||||
const messenger = new IpcMessenger();
|
||||
const core = new Core(messenger);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
|
|
|||
19
core/ipc/core.ts
Normal file
19
core/ipc/core.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import historyManager from "../util/history";
|
||||
import { IpcIde } from "./IpcIde";
|
||||
import { IpcMessenger } from "./messenger";
|
||||
|
||||
export class Core {
|
||||
private messenger: IpcMessenger;
|
||||
private ide: IpcIde;
|
||||
constructor(messenger: IpcMessenger) {
|
||||
this.messenger = messenger;
|
||||
this.ide = new IpcIde(messenger);
|
||||
|
||||
this.messenger.on("history/list", (msg) => {
|
||||
return historyManager.list();
|
||||
});
|
||||
this.messenger.on("history/delete", (msg) => {
|
||||
historyManager.delete(msg.data.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +1,32 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { PersistedSessionInfo } from "..";
|
||||
|
||||
export abstract class Messenger {
|
||||
abstract send(messageType: string, message: any, messageId?: string): string;
|
||||
abstract onMessage(
|
||||
messageType: string,
|
||||
handler: (message: any) => Promise<any> | undefined
|
||||
): void;
|
||||
abstract on(messageType: string, handler: (message: any) => any): void;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
export interface Message<T = any> {
|
||||
messageType: string;
|
||||
messageId: string;
|
||||
message: any;
|
||||
data: T;
|
||||
}
|
||||
|
||||
type Protocol = {
|
||||
"history/list": [undefined, PersistedSessionInfo[]];
|
||||
"history/delete": [{ id: string }, void];
|
||||
"history/load": [{ id: string }, PersistedSessionInfo];
|
||||
"history/save": [PersistedSessionInfo, void];
|
||||
"devdata/log": [{ tableName: string; data: any }, void];
|
||||
};
|
||||
type ProtocolKeys = keyof Protocol;
|
||||
|
||||
type ProtocolCallbacks = {
|
||||
[K in ProtocolKeys]: (msg: Protocol[K][0]) => Protocol[K][1];
|
||||
};
|
||||
|
||||
export class IpcMessenger extends Messenger {
|
||||
listeners = new Map<
|
||||
string,
|
||||
((message: Message) => Promise<any> | undefined)[]
|
||||
>();
|
||||
listeners = new Map<string, ((message: Message) => any)[]>();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
|
@ -30,7 +38,7 @@ export class IpcMessenger extends Messenger {
|
|||
try {
|
||||
const msg: Message = JSON.parse(d);
|
||||
if (
|
||||
msg.message !== undefined ||
|
||||
msg.data !== undefined ||
|
||||
msg.messageType !== undefined ||
|
||||
msg.messageId !== undefined
|
||||
) {
|
||||
|
|
@ -52,7 +60,7 @@ export class IpcMessenger extends Messenger {
|
|||
messageId = messageId ?? uuidv4();
|
||||
const data: Message = {
|
||||
messageType,
|
||||
message,
|
||||
data: message,
|
||||
messageId,
|
||||
};
|
||||
// process.send?.(data);
|
||||
|
|
@ -60,9 +68,9 @@ export class IpcMessenger extends Messenger {
|
|||
return messageId;
|
||||
}
|
||||
|
||||
onMessage(
|
||||
messageType: string,
|
||||
handler: (message: Message) => Promise<any> | undefined
|
||||
on<T extends keyof Protocol>(
|
||||
messageType: T,
|
||||
handler: (message: Message<Protocol[T][0]>) => Protocol[T][1]
|
||||
): void {
|
||||
if (!this.listeners.has(messageType)) {
|
||||
this.listeners.set(messageType, []);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { PersistedSessionInfo, SessionInfo } from "core";
|
||||
import { getSessionFilePath, getSessionsListPath } from "core/util/paths";
|
||||
import * as fs from "fs";
|
||||
import { PersistedSessionInfo, SessionInfo } from "..";
|
||||
import { getSessionFilePath, getSessionsListPath } from "./paths";
|
||||
|
||||
class HistoryManager {
|
||||
list(): PersistedSessionInfo[] {
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { ContextItemId, DiffLine, FileEdit, ModelDescription } from "core";
|
||||
import { indexDocs } from "core/indexing/docs";
|
||||
import TransformersJsEmbeddingsProvider from "core/indexing/embeddings/TransformersJsEmbeddingsProvider";
|
||||
import historyManager from "core/util/history";
|
||||
import { editConfigJson, getConfigJsonPath } from "core/util/paths";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
|
@ -12,7 +13,6 @@ import {
|
|||
windowId,
|
||||
} from "./activation/activate";
|
||||
import { streamEdit } from "./diff/verticalPerLine/manager";
|
||||
import historyManager from "./history";
|
||||
import { VsCodeIde } from "./ideProtocol";
|
||||
import { configHandler, llmFromTitle } from "./loadConfig";
|
||||
import { getTheme } from "./util/getTheme";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue