🚧 messaging
This commit is contained in:
parent
5ff47248eb
commit
998ceec5df
9 changed files with 132 additions and 127 deletions
|
|
@ -26,40 +26,44 @@ class Ollama extends BaseLLM {
|
|||
method: "POST",
|
||||
headers: {},
|
||||
body: JSON.stringify({ name: this._getModel() }),
|
||||
}).then(async (response) => {
|
||||
if (response.status !== 200) {
|
||||
console.warn(
|
||||
"Error calling Ollama /api/show endpoint: ",
|
||||
await response.text()
|
||||
);
|
||||
return;
|
||||
}
|
||||
const body = await response.json();
|
||||
if (body.parameters) {
|
||||
const params = [];
|
||||
for (let line of body.parameters.split("\n")) {
|
||||
let parts = line.split(" ");
|
||||
if (parts.length < 2) {
|
||||
continue;
|
||||
}
|
||||
let key = parts[0];
|
||||
let value = parts[parts.length - 1];
|
||||
switch (key) {
|
||||
case "num_ctx":
|
||||
this.contextLength = parseInt(value);
|
||||
break;
|
||||
case "stop":
|
||||
if (!this.completionOptions.stop) {
|
||||
this.completionOptions.stop = [];
|
||||
}
|
||||
this.completionOptions.stop.push(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (response.status !== 200) {
|
||||
console.warn(
|
||||
"Error calling Ollama /api/show endpoint: ",
|
||||
await response.text()
|
||||
);
|
||||
return;
|
||||
}
|
||||
const body = await response.json();
|
||||
if (body.parameters) {
|
||||
const params = [];
|
||||
for (let line of body.parameters.split("\n")) {
|
||||
let parts = line.split(" ");
|
||||
if (parts.length < 2) {
|
||||
continue;
|
||||
}
|
||||
let key = parts[0];
|
||||
let value = parts[parts.length - 1];
|
||||
switch (key) {
|
||||
case "num_ctx":
|
||||
this.contextLength = parseInt(value);
|
||||
break;
|
||||
case "stop":
|
||||
if (!this.completionOptions.stop) {
|
||||
this.completionOptions.stop = [];
|
||||
}
|
||||
this.completionOptions.stop.push(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
console.warn(`Error calling Ollama /api/show endpoint: ${e}`);
|
||||
});
|
||||
}
|
||||
|
||||
private _getModel() {
|
||||
|
|
@ -178,16 +182,16 @@ class Ollama extends BaseLLM {
|
|||
): AsyncGenerator<ChatMessage> {
|
||||
const client = new ollama.Ollama({
|
||||
host: this.apiBase,
|
||||
|
||||
|
||||
fetch: (input, config) => {
|
||||
return fetch(input, {
|
||||
...config,
|
||||
headers: {
|
||||
...(config?.headers || {}),
|
||||
...(this.requestOptions?.headers || {})
|
||||
}
|
||||
...(this.requestOptions?.headers || {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
const response = await client.chat({
|
||||
...this._convertArgs(options, messages),
|
||||
|
|
|
|||
|
|
@ -157,4 +157,5 @@ export type ReverseWebviewProtocol = {
|
|||
newSession: [undefined, void];
|
||||
refreshSubmenuItems: [undefined, void];
|
||||
setTheme: [{ theme: any }, void];
|
||||
setColors: [{ [key: string]: string }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -105,9 +105,10 @@ class CoreMessenger(continueCorePath: String, ideProtocolClient: IdeProtocolClie
|
|||
try {
|
||||
while (true) {
|
||||
val line = reader.readLine()
|
||||
println("Core: $line")
|
||||
if (line != null && line.isNotEmpty()) {
|
||||
handleMessage(line)
|
||||
} else {
|
||||
Thread.sleep(100)
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
|
|
|
|||
|
|
@ -1,38 +1,58 @@
|
|||
package com.github.continuedev.continueintellijextension.`continue`
|
||||
import com.intellij.codeInsight.template.impl.TemplateColors
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
|
||||
import com.intellij.openapi.editor.colors.EditorColors
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/*
|
||||
[
|
||||
"--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
|
||||
fun getTheme(): Map<String, String> {
|
||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||
val defaultBackground = globalScheme.defaultBackground
|
||||
val defaultForeground = globalScheme.defaultForeground
|
||||
val highlight = globalScheme.getColor(EditorColors.MODIFIED_TAB_ICON_COLOR) ?: defaultForeground
|
||||
val defaultBackgroundHex = String.format("#%02x%02x%02x", defaultBackground.red, defaultBackground.green, defaultBackground.blue)
|
||||
val defaultForegroundHex = String.format("#%02x%02x%02x", defaultForeground.red, defaultForeground.green, defaultForeground.blue)
|
||||
val highlightHex = String.format("#%02x%02x%02x", highlight.red, highlight.green, highlight.blue)
|
||||
|
||||
val grayscale = (defaultBackground.red * 0.3 + defaultBackground.green * 0.59 + defaultBackground.blue * 0.11).toInt()
|
||||
|
||||
val adjustedRed: Int
|
||||
val adjustedGreen: Int
|
||||
val adjustedBlue: Int
|
||||
|
||||
val tint: Int = 20
|
||||
if (grayscale > 128) { // if closer to white
|
||||
adjustedRed = max(0, defaultBackground.red - tint)
|
||||
adjustedGreen = max(0, defaultBackground.green - tint)
|
||||
adjustedBlue = max(0, defaultBackground.blue - tint)
|
||||
} else { // if closer to black
|
||||
adjustedRed = min(255, defaultBackground.red + tint)
|
||||
adjustedGreen = min(255, defaultBackground.green + tint)
|
||||
adjustedBlue = min(255, defaultBackground.blue + tint)
|
||||
}
|
||||
|
||||
val secondaryDarkHex = String.format("#%02x%02x%02x", adjustedRed, adjustedGreen, adjustedBlue)
|
||||
|
||||
return mapOf(
|
||||
"--vscode-editor-foreground" to defaultForegroundHex,
|
||||
"--vscode-sideBar-background" to defaultBackgroundHex,
|
||||
"--vscode-input-background" to secondaryDarkHex,
|
||||
"--vscode-editor-background" to defaultBackgroundHex,
|
||||
"--vscode-button-background" to defaultBackgroundHex,
|
||||
"--vscode-list-activeSelectionBackground" to secondaryDarkHex,
|
||||
"--vscode-focusBorder" to highlightHex,
|
||||
"--vscode-quickInputList-focusForeground" to defaultForegroundHex,
|
||||
"--vscode-quickInput-background" to defaultBackgroundHex,
|
||||
"--vscode-input-border" to "#80808080",
|
||||
"--vscode-badge-background" to highlightHex,
|
||||
"--vscode-badge-foreground" to defaultForegroundHex,
|
||||
"--vscode-sideBar-border" to "#80808080"
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -53,7 +53,24 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
class ContinuePluginWindow(toolWindow: ToolWindow, project: Project) {
|
||||
|
||||
val PASS_THROUGH_TO_CORE = listOf(
|
||||
"getSerializedConfig"
|
||||
"abort",
|
||||
"getContinueDir",
|
||||
"history",
|
||||
"saveSession",
|
||||
"deleteSession",
|
||||
"loadSession",
|
||||
"logDevData",
|
||||
"addModel",
|
||||
"deleteModel",
|
||||
"addOpenAIKey",
|
||||
"llmStreamComplete",
|
||||
"llmStreamChat",
|
||||
"llmComplete",
|
||||
"runNodeJsSlashCommand",
|
||||
"loadSubmenuItems",
|
||||
"getContextItems",
|
||||
"addDocs",
|
||||
"getSerializedConfig",
|
||||
)
|
||||
|
||||
init {
|
||||
|
|
@ -108,35 +125,8 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
"onLoad" -> {
|
||||
GlobalScope.launch {
|
||||
// Set the colors to match Intellij theme
|
||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||
val defaultBackground = globalScheme.defaultBackground
|
||||
val defaultForeground = globalScheme.defaultForeground
|
||||
val defaultBackgroundHex = String.format("#%02x%02x%02x", defaultBackground.red, defaultBackground.green, defaultBackground.blue)
|
||||
val defaultForegroundHex = String.format("#%02x%02x%02x", defaultForeground.red, defaultForeground.green, defaultForeground.blue)
|
||||
|
||||
val grayscale = (defaultBackground.red * 0.3 + defaultBackground.green * 0.59 + defaultBackground.blue * 0.11).toInt()
|
||||
|
||||
val adjustedRed: Int
|
||||
val adjustedGreen: Int
|
||||
val adjustedBlue: Int
|
||||
|
||||
val tint: Int = 20
|
||||
if (grayscale > 128) { // if closer to white
|
||||
adjustedRed = max(0, defaultBackground.red - tint)
|
||||
adjustedGreen = max(0, defaultBackground.green - tint)
|
||||
adjustedBlue = max(0, defaultBackground.blue - tint)
|
||||
} else { // if closer to black
|
||||
adjustedRed = min(255, defaultBackground.red + tint)
|
||||
adjustedGreen = min(255, defaultBackground.green + tint)
|
||||
adjustedBlue = min(255, defaultBackground.blue + tint)
|
||||
}
|
||||
|
||||
val secondaryDarkHex = String.format("#%02x%02x%02x", adjustedRed, adjustedGreen, adjustedBlue)
|
||||
|
||||
browser.executeJavaScriptAsync("document.body.style.setProperty(\"--vscode-editor-foreground\", \"$defaultForegroundHex\");")
|
||||
browser.executeJavaScriptAsync("document.body.style.setProperty(\"--vscode-sideBar-background\", \"$defaultBackgroundHex\");")
|
||||
browser.executeJavaScriptAsync("document.body.style.setProperty(\"--vscode-input-background\", \"$secondaryDarkHex\");")
|
||||
browser.executeJavaScriptAsync("document.body.style.setProperty(\"--vscode-editor-background\", \"$defaultBackgroundHex\");")
|
||||
val colors = GetTheme().getTheme();
|
||||
continuePluginService.sendToWebview("setColors", colors)
|
||||
|
||||
val jsonData = mutableMapOf(
|
||||
"windowId" to continuePluginService.windowId,
|
||||
|
|
|
|||
|
|
@ -34,24 +34,6 @@ const GridDiv = styled.div`
|
|||
overflow: hidden;
|
||||
`;
|
||||
|
||||
const Select = styled.select`
|
||||
border: none;
|
||||
max-width: 50vw;
|
||||
background-color: ${vscBackground};
|
||||
color: ${vscForeground};
|
||||
padding: 6px;
|
||||
max-height: 35vh;
|
||||
overflow: scroll;
|
||||
cursor: pointer;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
&:hover {
|
||||
background-color: ${vscInputBackground};
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledPlusIcon = styled(PlusIcon)`
|
||||
background-color: ${vscBackground};
|
||||
cursor: pointer;
|
||||
|
|
@ -66,18 +48,6 @@ const StyledPlusIcon = styled(PlusIcon)`
|
|||
border-left: 0.5px solid ${lightGray};
|
||||
`;
|
||||
|
||||
const NewProviderDiv = styled.div`
|
||||
cursor: pointer;
|
||||
padding: 8px;
|
||||
padding-left: 16px;
|
||||
padding-right: 16px;
|
||||
border-top: 0.5px solid ${lightGray};
|
||||
|
||||
&:hover {
|
||||
background-color: ${vscInputBackground};
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledListbox = styled(Listbox)`
|
||||
background-color: ${vscBackground};
|
||||
padding: 0;
|
||||
|
|
@ -124,7 +94,7 @@ const StyledListboxOptions = styled(Listbox.Options)`
|
|||
max-height: 80vh;
|
||||
|
||||
border-radius: ${defaultBorderRadius};
|
||||
overflow: scroll;
|
||||
overflow-y: scroll;
|
||||
`;
|
||||
|
||||
const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>`
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ function useSetup(dispatch: Dispatch<any>) {
|
|||
dispatch(setInactive());
|
||||
});
|
||||
|
||||
useWebviewListener("setColors", async (colors) => {
|
||||
Object.keys(colors).forEach((key) => {
|
||||
document.body.style.setProperty(key, colors[key]);
|
||||
});
|
||||
});
|
||||
|
||||
useWebviewListener("configUpdate", async () => {
|
||||
loadConfig();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ program.action(() => {
|
|||
// const ide = new IpcIde(messenger);
|
||||
const ide = new FileSystemIde();
|
||||
const core = new Core(messenger, ide);
|
||||
|
||||
// setTimeout(() => {
|
||||
// messenger.mock({
|
||||
// messageId: "2fe7823c-10bd-4771-abb5-781f520039ec",
|
||||
// messageType: "loadSubmenuItems",
|
||||
// data: { title: "issue" },
|
||||
// });
|
||||
// }, 1000);
|
||||
} catch (e) {
|
||||
fs.writeFileSync("./error.log", `${new Date().toISOString()} ${e}\n`);
|
||||
console.log("Error: ", e);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ export class IpcMessenger {
|
|||
});
|
||||
}
|
||||
|
||||
mock(data: any) {
|
||||
const d = JSON.stringify(data);
|
||||
this._handleData(Buffer.from(d));
|
||||
}
|
||||
|
||||
private _handleData(data: Buffer) {
|
||||
console.log("Receieved data: ", data);
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue