better terminal code block detection

This commit is contained in:
Nate Sesti 2024-06-07 10:29:18 -07:00
parent 463660d868
commit 6abdb3677c
6 changed files with 37 additions and 17 deletions

View file

@ -3,7 +3,7 @@ import { Command } from "commander";
import { Core } from "core/core";
import { FromCoreProtocol, ToCoreProtocol } from "core/protocol";
import { IMessenger } from "core/util/messenger";
import { getCoreLogsPath } from "core/util/paths";
import { getCoreLogsPath, getPromptLogsPath } from "core/util/paths";
import fs from "node:fs";
import { IpcIde } from "./IpcIde";
import { IpcMessenger } from "./IpcMessenger";
@ -30,7 +30,10 @@ program.action(async () => {
messenger = new IpcMessenger<ToCoreProtocol, FromCoreProtocol>();
}
const ide = new IpcIde(messenger);
const core = new Core(messenger, ide);
const promptLogsPath = getPromptLogsPath();
const core = new Core(messenger, ide, async (text) => {
fs.appendFileSync(promptLogsPath, text + "\n\n");
});
} catch (e) {
fs.writeFileSync("./error.log", `${new Date().toISOString()} ${e}\n`);
console.log("Error: ", e);

View file

@ -17,6 +17,11 @@ class TerminalContextProvider extends BaseContextProvider {
query: string,
extras: ContextProviderExtras,
): Promise<ContextItem[]> {
if ((await extras.ide.getIdeInfo()).ideType === "jetbrains") {
throw new Error(
"The terminal context provider is not currently supported in JetBrains IDEs",
);
}
const content = await extras.ide.getTerminalContents();
return [
{

View file

@ -21,14 +21,14 @@ class Ollama extends BaseLLM {
if (options.model === "AUTODETECT") {
return;
}
this.fetch(this.getEndpoint("api/show"), {
method: "POST",
headers: {
Authorization: `Bearer ${this.apiKey}`,
},
body: JSON.stringify({ name: this._getModel() }),
})
.then(async (response) => {
try {
this.fetch(this.getEndpoint("api/show"), {
method: "POST",
headers: {
Authorization: `Bearer ${this.apiKey}`,
},
body: JSON.stringify({ name: this._getModel() }),
}).then(async (response) => {
if (response.status !== 200) {
// console.warn(
// "Error calling Ollama /api/show endpoint: ",
@ -67,10 +67,8 @@ class Ollama extends BaseLLM {
}
}
}
})
.catch((e) => {
// console.warn(`Error calling Ollama /api/show endpoint: ${e}`);
});
} catch (e) {}
}
private _getModel() {

View file

@ -236,8 +236,20 @@ export function getContinueDotEnv(): { [key: string]: string } {
return {};
}
export function getLogsDirPath(): string {
const logsPath = path.join(getContinueGlobalPath(), "logs");
if (!fs.existsSync(logsPath)) {
fs.mkdirSync(logsPath);
}
return logsPath;
}
export function getCoreLogsPath(): string {
return path.join(getContinueGlobalPath(), "core.log");
return path.join(getLogsDirPath(), "core.log");
}
export function getPromptLogsPath(): string {
return path.join(getLogsDirPath(), "prompt.log");
}
export function getGlobalPromptsPath(): string {

View file

@ -71,13 +71,15 @@ function StepContainer(props: StepContainerProps) {
const [feedback, setFeedback] = useState<boolean | undefined>(undefined);
const sessionId = useSelector((store: RootState) => store.state.sessionId);
const sendFeedback = (feedback: boolean) => {
setFeedback(feedback);
if (props.item.promptLogs?.length) {
for (const promptLog of props.item.promptLogs) {
ideMessenger.post("devdata/log", {
tableName: "chat",
data: { ...promptLog, feedback },
data: { ...promptLog, feedback, sessionId },
});
}
}

View file

@ -64,7 +64,7 @@ const commonTerminalCommands = [
function isTerminalCodeBlock(language: string | undefined, text: string) {
return (
terminalLanguages.includes(language) ||
(language?.length === 0 &&
((!language || language?.length === 0) &&
(text.trim().split("\n").length === 1 ||
commonTerminalCommands.some((c) => text.trim().startsWith(c))))
);
@ -91,7 +91,7 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
disabled={applying}
style={{ backgroundColor: vscEditorBackground }}
onClick={() => {
if (terminalLanguages.includes(props.language)) {
if (isTerminalCodeBlock(props.language, props.text)) {
let text = props.text;
if (text.startsWith("$ ")) {
text = text.slice(2);