🚧 messaging
This commit is contained in:
parent
a4b8b1c4e7
commit
ce04a75274
13 changed files with 107 additions and 80 deletions
|
|
@ -2,11 +2,6 @@ import { SerializedContinueConfig } from "..";
|
|||
|
||||
const defaultConfig: SerializedContinueConfig = {
|
||||
models: [
|
||||
{
|
||||
title: "GPT-4 (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "gpt-4",
|
||||
},
|
||||
{
|
||||
title: "GPT-4 Vision (Free Trial)",
|
||||
provider: "free-trial",
|
||||
|
|
|
|||
|
|
@ -67,8 +67,9 @@ export class ConfigHandler {
|
|||
);
|
||||
|
||||
return this.savedConfig;
|
||||
} catch (e) {
|
||||
throw new Error("Failed to load config");
|
||||
} catch (e: any) {
|
||||
console.error("Failed to load config: ", e.message);
|
||||
throw new Error("Failed to load config: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ async function buildConfigTs(browser: boolean) {
|
|||
sourcemap: true,
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
console.log(
|
||||
"Build error. Please check your ~/.continue/config.ts file: " + e
|
||||
);
|
||||
return undefined;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.continuedev.continueintellijextension.activities
|
||||
|
||||
import com.github.continuedev.continueintellijextension.constants.getContinueGlobalPath
|
||||
import com.github.continuedev.continueintellijextension.`continue`.CoreMessenger
|
||||
import com.github.continuedev.continueintellijextension.`continue`.startProxyServer
|
||||
import com.github.continuedev.continueintellijextension.`continue`.DefaultTextSelectionStrategy
|
||||
import com.github.continuedev.continueintellijextension.`continue`.IdeProtocolClient
|
||||
import com.github.continuedev.continueintellijextension.`continue`.*
|
||||
import com.github.continuedev.continueintellijextension.listeners.ContinuePluginSelectionListener
|
||||
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
|
||||
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
|
||||
|
|
@ -124,6 +121,8 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware {
|
|||
ContinuePluginService::class.java
|
||||
)
|
||||
|
||||
val theme = GetTheme().getTheme()
|
||||
|
||||
val defaultStrategy = DefaultTextSelectionStrategy()
|
||||
|
||||
coroutineScope.launch {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CoreMessenger(continueCorePath: String, ideProtocolClient: IdeProtocolClie
|
|||
private val ideProtocolClient = ideProtocolClient
|
||||
|
||||
private fun write(message: String) {
|
||||
writer.write(message + "\n")
|
||||
writer.write(message + "\r\n")
|
||||
writer.flush()
|
||||
}
|
||||
|
||||
|
|
@ -101,17 +101,9 @@ class CoreMessenger(continueCorePath: String, ideProtocolClient: IdeProtocolClie
|
|||
writer = OutputStreamWriter(outputStream)
|
||||
reader = BufferedReader(InputStreamReader(inputStream))
|
||||
|
||||
var sentPing = false
|
||||
|
||||
Thread {
|
||||
try {
|
||||
while (true) {
|
||||
if (!sentPing) {
|
||||
sentPing = true
|
||||
request("ping", "ping") { response ->
|
||||
println("Response!: $response")
|
||||
}
|
||||
}
|
||||
val line = reader.readLine()
|
||||
println("Core: $line")
|
||||
if (line != null && line.isNotEmpty()) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.github.continuedev.continueintellijextension.`continue`
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
|
||||
/*
|
||||
[
|
||||
"--vscode-input-background",
|
||||
"--vscode-sideBar-background",
|
||||
"--vscode-editor-foreground",
|
||||
"--vscode-button-background",
|
||||
"--vscode-editor-background",
|
||||
"--vscode-list-activeSelectionBackground",
|
||||
"--vscode-focus-border",
|
||||
"--vscode-quickInputList-focusForeground",
|
||||
"--vscode-quickInput-background",
|
||||
"--vscode-input-border",
|
||||
"--vscode-focusBorder",
|
||||
"--vscode-badge-background",
|
||||
"--vscode-badge-foreground",
|
||||
"--vscode-sideBar-border"
|
||||
]
|
||||
|
||||
*/
|
||||
val vscToJetBrainsColorName = listOf(
|
||||
arrayOf("--vscode-input-background", "?"),
|
||||
arrayOf("--vscode-sideBar-background", "?"),
|
||||
arrayOf("--vscode-editor-foreground", "?"),
|
||||
|
||||
)
|
||||
|
||||
class GetTheme {
|
||||
fun getTheme(): EditorColorsScheme {
|
||||
val editorColorsManager: EditorColorsManager = EditorColorsManager.getInstance()
|
||||
val scheme: EditorColorsScheme = editorColorsManager.globalScheme
|
||||
return scheme
|
||||
}
|
||||
}
|
||||
|
|
@ -317,29 +317,6 @@ class IdeProtocolClient (
|
|||
|
||||
respond(output.toString());
|
||||
}
|
||||
"getSerializedConfig" -> {
|
||||
val configPath = getConfigJsonPath()
|
||||
var config = File(configPath).readText()
|
||||
|
||||
migrate("camelCaseConfig") {
|
||||
if (config.contains("_")) {
|
||||
config = config
|
||||
.replace(Regex("(_\\w)")) { it.value[1].uppercase() }
|
||||
.replace("openai-aiohttp", "openai")
|
||||
// Rewrite to config.json
|
||||
File(configPath).writeText(config)
|
||||
}
|
||||
}
|
||||
|
||||
migrate("renameFreeTrialProvider") {
|
||||
config = config.replace("openai-free-trial", "free-trial");
|
||||
File(configPath).writeText(config)
|
||||
}
|
||||
|
||||
val mapType = object : TypeToken<Map<String, Any>>() {}.type
|
||||
val parsed: Map<String, Any> = Gson().fromJson(config, mapType)
|
||||
respond(parsed)
|
||||
}
|
||||
"getConfigJsUrl" -> {
|
||||
// Calculate a data URL for the config.js file
|
||||
val configJsPath = getConfigJsPath()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.github.continuedev.continueintellijextension.toolWindow
|
||||
|
||||
import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath
|
||||
import com.github.continuedev.continueintellijextension.`continue`.Position
|
||||
import com.github.continuedev.continueintellijextension.`continue`.Range
|
||||
import com.github.continuedev.continueintellijextension.`continue`.RangeInFile
|
||||
import com.github.continuedev.continueintellijextension.`continue`.getMachineUniqueID
|
||||
import com.github.continuedev.continueintellijextension.`continue`.*
|
||||
import com.github.continuedev.continueintellijextension.factories.CustomSchemeHandlerFactory
|
||||
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
|
||||
import com.google.gson.Gson
|
||||
|
|
@ -99,7 +96,7 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
"messageType" to messageType
|
||||
)
|
||||
val jsonString = Gson().toJson(jsonData)
|
||||
browser.executeJavaScriptAsync("""window.postMessage($jsonString, "*");""")
|
||||
continuePluginService.sendToWebview(messageType, data, messageId ?: uuid())
|
||||
}
|
||||
|
||||
if (PASS_THROUGH_TO_CORE.contains(messageType)) {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,8 @@ function _postToIde(messageType: string, data: any, messageId?: string) {
|
|||
);
|
||||
throw new Error("postIntellijMessage is undefined");
|
||||
}
|
||||
(window as any).postIntellijMessage?.(
|
||||
messageType,
|
||||
data,
|
||||
messageId ?? uuidv4()
|
||||
);
|
||||
messageId = messageId ?? uuidv4();
|
||||
(window as any).postIntellijMessage?.(messageType, data, messageId);
|
||||
return;
|
||||
} else {
|
||||
console.log(
|
||||
|
|
|
|||
|
|
@ -119,6 +119,11 @@ export class Core {
|
|||
});
|
||||
return items;
|
||||
});
|
||||
|
||||
// Pass-through
|
||||
on("getSerializedConfig", (msg) => {
|
||||
return this.configHandler.getSerializedConfig();
|
||||
});
|
||||
}
|
||||
|
||||
public invoke<T extends keyof Protocol>(
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
import { Command } from "commander";
|
||||
import { IpcIde } from "./IpcIde";
|
||||
import FileSystemIde from "core/util/filesystem";
|
||||
import fs from "fs";
|
||||
import { Core } from "./core";
|
||||
import { IpcMessenger } from "./messenger";
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program.action(() => {
|
||||
const messenger = new IpcMessenger();
|
||||
const ide = new IpcIde(messenger);
|
||||
const core = new Core(messenger, ide);
|
||||
try {
|
||||
const messenger = new IpcMessenger();
|
||||
// const ide = new IpcIde(messenger);
|
||||
const ide = new FileSystemIde();
|
||||
const core = new Core(messenger, ide);
|
||||
} catch (e) {
|
||||
fs.writeFileSync("./error.log", `${new Date().toISOString()} ${e}\n`);
|
||||
console.log("Error: ", e);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
|
|
|||
|
|
@ -21,29 +21,43 @@ export class IpcMessenger {
|
|||
console.log("[info] Starting Continue core...");
|
||||
|
||||
process.stdin.on("data", (data) => {
|
||||
console.log("Receieved data: ", data);
|
||||
try {
|
||||
const d = data.toString();
|
||||
const msg: Message = JSON.parse(d);
|
||||
if (msg.messageType === undefined || msg.messageId === undefined) {
|
||||
throw new Error("Invalid message sent: " + JSON.stringify(msg));
|
||||
}
|
||||
|
||||
// Call handler and respond with return value
|
||||
this.typeListeners
|
||||
.get(msg.messageType as any)
|
||||
?.forEach(async (handler) => {
|
||||
const response = await handler(msg);
|
||||
this.send(msg.messageType, response, msg.messageId);
|
||||
});
|
||||
|
||||
// Call handler which is waiting for the response, nothing to return
|
||||
this.idListeners.get(msg.messageId)?.(msg);
|
||||
} catch (e) {
|
||||
console.error("Invalid JSON:", data);
|
||||
return;
|
||||
}
|
||||
this._handleData(data);
|
||||
});
|
||||
process.stdout.on("close", () => {
|
||||
fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`);
|
||||
console.log("[info] Exiting Continue core...");
|
||||
process.exit(1);
|
||||
});
|
||||
process.stdin.on("close", () => {
|
||||
fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`);
|
||||
console.log("[info] Exiting Continue core...");
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
private _handleData(data: Buffer) {
|
||||
console.log("Receieved data: ", data);
|
||||
try {
|
||||
const d = data.toString();
|
||||
const msg: Message = JSON.parse(d);
|
||||
if (msg.messageType === undefined || msg.messageId === undefined) {
|
||||
throw new Error("Invalid message sent: " + JSON.stringify(msg));
|
||||
}
|
||||
|
||||
// Call handler and respond with return value
|
||||
this.typeListeners
|
||||
.get(msg.messageType as any)
|
||||
?.forEach(async (handler) => {
|
||||
const response = await handler(msg);
|
||||
this.send(msg.messageType, response, msg.messageId);
|
||||
});
|
||||
|
||||
// Call handler which is waiting for the response, nothing to return
|
||||
this.idListeners.get(msg.messageId)?.(msg);
|
||||
} catch (e) {
|
||||
console.error("Invalid JSON:", data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
send(messageType: string, message: any, messageId?: string): string {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { BrowserSerializedContinueConfig } from "core/config/load";
|
||||
import {
|
||||
ChatMessage,
|
||||
CompletionOptions,
|
||||
|
|
@ -83,4 +84,7 @@ export type Protocol = {
|
|||
},
|
||||
AsyncGenerator<string>,
|
||||
];
|
||||
|
||||
// Pass-through from webview
|
||||
getSerializedConfig: [undefined, Promise<BrowserSerializedContinueConfig>];
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue