From cdc9600e689161877ff7416f63baa9dcbfa6c18a Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 26 Nov 2024 14:26:15 -0800 Subject: [PATCH] fix: type errors --- core/autocomplete/snippets/getAllSnippets.ts | 2 +- core/commands/slash/commit.ts | 9 +++++---- core/config/promptFile.ts | 7 +++++-- core/context/providers/DiffContextProvider.ts | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index 274ff5657..30d89e7b9 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -87,7 +87,7 @@ const getDiffSnippets = async ( ): Promise => { const diff = await ide.getDiff(true); - return [diff].map((item) => { + return diff.map((item) => { return { content: item, type: AutocompleteSnippetType.Diff, diff --git a/core/commands/slash/commit.ts b/core/commands/slash/commit.ts index 7d5f22a90..fc6e81531 100644 --- a/core/commands/slash/commit.ts +++ b/core/commands/slash/commit.ts @@ -8,15 +8,16 @@ const CommitMessageCommand: SlashCommand = { const includeUnstaged = params?.includeUnstaged ?? false; const diff = await ide.getDiff(includeUnstaged); - if (!diff || diff.trim() === "") { + if (diff.length === 0) { yield "No changes detected. Make sure you are in a git repository with current changes."; return; } const prompt = `${diff}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`; - for await (const chunk of llm.streamChat([ - { role: "user", content: prompt }, - ], new AbortController().signal)) { + for await (const chunk of llm.streamChat( + [{ role: "user", content: prompt }], + new AbortController().signal, + )) { yield stripImages(chunk.content); } }, diff --git a/core/config/promptFile.ts b/core/config/promptFile.ts index 1ec963513..a630e41d6 100644 --- a/core/config/promptFile.ts +++ b/core/config/promptFile.ts @@ -125,7 +125,10 @@ export function slashCommandFromPromptFile( systemMessage, ); - for await (const chunk of context.llm.streamChat(messages, new AbortController().signal)) { + for await (const chunk of context.llm.streamChat( + messages, + new AbortController().signal, + )) { yield stripImages(chunk.content); } @@ -173,7 +176,7 @@ async function renderPrompt( const diff = await context.ide.getDiff(false); const currentFile = await context.ide.getCurrentFile(); const inputData: Record = { - diff, + diff: diff.join("\n"), input: userInput, }; if (currentFile) { diff --git a/core/context/providers/DiffContextProvider.ts b/core/context/providers/DiffContextProvider.ts index f2c95083f..a0fc7524d 100644 --- a/core/context/providers/DiffContextProvider.ts +++ b/core/context/providers/DiffContextProvider.ts @@ -22,7 +22,7 @@ class DiffContextProvider extends BaseContextProvider { { description: "The current git diff", content: - diff.trim() === "" + diff.length === 0 ? "Git shows no current changes." : `\`\`\`git diff\n${diff}\n\`\`\``, name: "Git Diff",