🩹 fix cancellation and other bugs for /edit
This commit is contained in:
parent
d50264b281
commit
ac1ebcd382
5 changed files with 33 additions and 15 deletions
|
|
@ -248,7 +248,7 @@ const EditSlashCommand: SlashCommand = {
|
|||
|
||||
let fullPrefixLines = fullFileContentsLines.slice(
|
||||
0,
|
||||
rif.range.start.line
|
||||
rif.range.start.line - 1
|
||||
);
|
||||
let fullSuffixLines = fullFileContentsLines.slice(rif.range.end.line);
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ export async function* ideStreamRequest(
|
|||
done = true;
|
||||
returnVal = event.data.message.data;
|
||||
} else {
|
||||
buffer += event.data.message.content;
|
||||
buffer += event.data.message.content || "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -100,6 +100,8 @@ export async function* ideStreamRequest(
|
|||
const chunk = buffer.slice(index);
|
||||
index = buffer.length;
|
||||
yield chunk;
|
||||
} else {
|
||||
yield undefined;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
|
|
@ -131,7 +133,9 @@ export async function* llmStreamChat(
|
|||
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
yield { role: "user", content: next.value };
|
||||
if (next.value) {
|
||||
yield { role: "user", content: next.value };
|
||||
}
|
||||
next = await gen.next();
|
||||
}
|
||||
return { prompt: next.value?.prompt, completion: next.value?.completion };
|
||||
|
|
|
|||
|
|
@ -525,9 +525,11 @@ export function getSidebarContent(
|
|||
});
|
||||
},
|
||||
})) {
|
||||
if (update) {
|
||||
respond({ content: update });
|
||||
if (abortedMessageIds.has(data.messageId)) {
|
||||
abortedMessageIds.delete(data.messageId);
|
||||
break;
|
||||
}
|
||||
respond({ content: update });
|
||||
}
|
||||
respond({ done: true });
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -696,7 +696,12 @@
|
|||
resolved "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz"
|
||||
integrity sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==
|
||||
|
||||
"@lancedb/vectordb-darwin-arm64@*", "@lancedb/vectordb-darwin-arm64@0.4.8":
|
||||
"@lancedb/vectordb-darwin-arm64@*":
|
||||
version "0.4.9"
|
||||
resolved "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.9.tgz"
|
||||
integrity sha512-u56TXU0hvdLbknGwC7Ebza3/CUFeCTkoCy/sC6h0FtOGya+NV7jraAeXEwDzoZbfW08VYYxnp3TsCcpNU9lpTA==
|
||||
|
||||
"@lancedb/vectordb-darwin-arm64@0.4.8":
|
||||
version "0.4.8"
|
||||
resolved "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.8.tgz"
|
||||
integrity sha512-FpnJaw7KmNdD/FtOw9AcmPL5P+L04AcnfPj9ZyEjN8iCwB/qaOGYgdfBv+EbEtfHIsqA12q/1BRduu9KdB6BIA==
|
||||
|
|
|
|||
|
|
@ -100,18 +100,25 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
input: string,
|
||||
historyIndex: number
|
||||
) {
|
||||
const abortController = new AbortController();
|
||||
const cancelToken = abortController.signal;
|
||||
const modelTitle = defaultModel.title;
|
||||
|
||||
for await (const update of ideStreamRequest("runNodeJsSlashCommand", {
|
||||
input,
|
||||
history: messages,
|
||||
modelTitle,
|
||||
slashCommandName: slashCommand.name,
|
||||
contextItems,
|
||||
params: slashCommand.params,
|
||||
historyIndex,
|
||||
})) {
|
||||
for await (const update of ideStreamRequest(
|
||||
"runNodeJsSlashCommand",
|
||||
{
|
||||
input,
|
||||
history: messages,
|
||||
modelTitle,
|
||||
slashCommandName: slashCommand.name,
|
||||
contextItems,
|
||||
params: slashCommand.params,
|
||||
historyIndex,
|
||||
},
|
||||
cancelToken
|
||||
)) {
|
||||
if (!activeRef.current) {
|
||||
abortController.abort();
|
||||
break;
|
||||
}
|
||||
if (typeof update === "string") {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue