From 17e1a8a6113e7cba03b9630a654650090c965a2b Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sun, 16 Jun 2024 15:26:12 -0700 Subject: [PATCH 1/4] Minor UI improvements --- sweep_chat/components/App.tsx | 9 ++++++++- sweep_chat/components/shared/SnippetBadge.tsx | 16 +++++++++++++++- sweep_chat/tailwind.config.ts | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 5e45e0881e..864a986045 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -285,7 +285,11 @@ const MessageDisplay = ({ ${message.role === "assistant" ? "py-1" : ""} ${className || roleToColor[message.role]}`} > {message.role === "function" ? ( - 0)) ? "function" : undefined}> + 0)) ? "function" : undefined} + >
@@ -1237,6 +1241,9 @@ function App({ window.history.pushState({}, '', '/'); setSuggestedChanges([]) setPullRequest(null) + setFeatureBranch(null) + setPullRequestTitle(null) + setPullRequestBody(null) }} disabled={isLoading} > diff --git a/sweep_chat/components/shared/SnippetBadge.tsx b/sweep_chat/components/shared/SnippetBadge.tsx index d84f39d5c3..609fa9bcef 100644 --- a/sweep_chat/components/shared/SnippetBadge.tsx +++ b/sweep_chat/components/shared/SnippetBadge.tsx @@ -5,6 +5,15 @@ import { HoverCard, HoverCardTrigger, HoverCardContent } from "@/components/ui/h import SyntaxHighlighter from "react-syntax-highlighter"; import { Button } from "../ui/button"; +const MutePath = ({ path }: { path: string }) => { + return ( + + {path.substring(0, path.lastIndexOf('/') + 1)} + {path.substring(path.lastIndexOf('/') + 1)} + + ); +} + const SnippetBadge = ({ snippet, className, @@ -27,7 +36,12 @@ const SnippetBadge = ({ }}> {snippet.end > snippet.content.split('\n').length - 3 && snippet.start == 0 ? - snippet.file_path : `${snippet.file_path}:${snippet.start}-${snippet.end}` + : ( + <> + + :{snippet.start}-{snippet.end} + + ) } { diff --git a/sweep_chat/tailwind.config.ts b/sweep_chat/tailwind.config.ts index 84287e82fb..e823067450 100644 --- a/sweep_chat/tailwind.config.ts +++ b/sweep_chat/tailwind.config.ts @@ -7,6 +7,7 @@ const config = { './components/**/*.{ts,tsx}', './app/**/*.{ts,tsx}', './src/**/*.{ts,tsx}', + './lib/**/*.{ts,tsx}', ], prefix: "", theme: { From bcd7c50d45f05095339c6d5cd919a8c42c04faed Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sun, 16 Jun 2024 15:39:00 -0700 Subject: [PATCH 2/4] CSS Fixes --- sweep_chat/app/globals.css | 22 +++++++++++++--------- sweep_chat/components/App.tsx | 12 ++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/sweep_chat/app/globals.css b/sweep_chat/app/globals.css index a21d17b67d..bf43053d70 100644 --- a/sweep_chat/app/globals.css +++ b/sweep_chat/app/globals.css @@ -79,8 +79,8 @@ pre { padding-top: 0.5rem; padding-bottom: 0.5rem; - margin-top: 0.5rem; - margin-bottom: 0.5rem; + /* margin-top: 0.5rem; */ + /* margin-bottom: 0.5rem; */ color: salmon; > code { padding: 1rem @@ -90,13 +90,13 @@ h2 { font-size: 1.5rem; margin-top: 1rem; - margin-bottom: 1.5rem; + /* margin-bottom: 1.5rem; */ } h3 { font-size: 1.25rem; margin-top: 1rem; - margin-bottom: 0.75rem; + /* margin-bottom: 0.75rem; */ } code { @@ -116,12 +116,16 @@ ol,ul { margin-top: 1rem; - margin-bottom: 1rem; + /* margin-bottom: 1rem; */ margin-left: 1.5rem; ol,ul { margin-top: 0.5rem; - margin-bottom: 0.5rem; + /* margin-bottom: 0.5rem; */ + } + + li { + margin-top: 0.25rem; } } @@ -129,14 +133,14 @@ color: lightblue; text-decoration: underline; } - + p:not(:first-child) { margin-top: 0.75rem; } - p:not(:last-child) { + /* p:not(:last-child) { margin-bottom: 0.75rem; - } + } */ } .hljs-addition { diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 864a986045..392e2bd5e1 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -798,10 +798,15 @@ function App({ var streamedMessages: Message[] = [] var respondedMessages: Message[] = [...newMessages, { content: "", role: "assistant" } as Message] setMessages(respondedMessages); + let messageLength = newMessages.length; try { for await (const patch of streamMessages(reader, isStream)) { streamedMessages = jsonpatch.applyPatch(streamedMessages, patch).newDocument setMessages([...newMessages, ...streamedMessages]) + if (streamedMessages.length > messageLength) { + save(repoName, newMessages, currentSnippets, suggestedChanges, pullRequest) + messageLength = streamedMessages.length; + } } if (!isStream.current) { reader!.cancel() @@ -1099,6 +1104,13 @@ function App({ setFeatureBranch(featureBranch || "sweep-chat-suggested-changes-" + new Date().toISOString().slice(0, 19).replace('T', '_').replace(':', '_')) setPullRequestTitle(title || "Sweep Chat Suggested Changes") setPullRequestBody(description || "Suggested changes by Sweep Chat.") + } else { + toast({ + title: "Failed to auto-fix changes!", + description: "This feature is still under development, so it's not completely reliable yet. We'll fix this for you shortly.", + variant: "destructive", + duration: Infinity, + }) } })(); setTimeout(() => { From 951d1049b1502c230d0cd1344027e873a92d0511 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sun, 16 Jun 2024 15:49:35 -0700 Subject: [PATCH 3/4] Fixed coloring issues --- sweep_chat/components/shared/SnippetBadge.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sweep_chat/components/shared/SnippetBadge.tsx b/sweep_chat/components/shared/SnippetBadge.tsx index 609fa9bcef..0244a8592c 100644 --- a/sweep_chat/components/shared/SnippetBadge.tsx +++ b/sweep_chat/components/shared/SnippetBadge.tsx @@ -2,7 +2,7 @@ import { typeNameToColor, codeStyle } from "@/lib/constants"; import { sliceLines } from "@/lib/str_utils"; import { Snippet } from "@/lib/types"; import { HoverCard, HoverCardTrigger, HoverCardContent } from "@/components/ui/hover-card"; -import SyntaxHighlighter from "react-syntax-highlighter"; +import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { Button } from "../ui/button"; const MutePath = ({ path }: { path: string }) => { @@ -14,6 +14,10 @@ const MutePath = ({ path }: { path: string }) => { ); } +const getLanguage = (filePath: string) => { + return filePath.split('.').pop(); +} + const SnippetBadge = ({ snippet, className, @@ -55,7 +59,7 @@ const SnippetBadge = ({ Date: Sun, 16 Jun 2024 15:52:47 -0700 Subject: [PATCH 4/4] Fixed error message --- sweep_chat/components/App.tsx | 50 ++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 392e2bd5e1..7d18c7a086 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -1080,31 +1080,33 @@ function App({ })) }), // TODO: casing should be automatically handled }); - const data = await response.json(); - console.log(data) - if (data.modify_files_dict) { - setSuggestedChanges(Object.entries(data.modify_files_dict).map(([filePath, { original_contents, contents }]: any) => ({ - filePath, - originalCode: original_contents, - newCode: contents, - }))) - save(repoName, messages, snippets, suggestedChanges, pullRequest) - setIsProcessingSuggestedChanges(false); + try { + const data = await response.json(); + console.log(data) + if (data.modify_files_dict) { + setSuggestedChanges(Object.entries(data.modify_files_dict).map(([filePath, { original_contents, contents }]: any) => ({ + filePath, + originalCode: original_contents, + newCode: contents, + }))) + save(repoName, messages, snippets, suggestedChanges, pullRequest) + setIsProcessingSuggestedChanges(false); - const prMetadata = await authorizedFetch("/backend/create_pull_metadata", { - body: JSON.stringify({ - repo_name: repoName, - modify_files_dict: data.modify_files_dict, - messages: messages, - }), - }) - - const prData = await prMetadata.json() - const { title, description, branch: featureBranch } = prData - setFeatureBranch(featureBranch || "sweep-chat-suggested-changes-" + new Date().toISOString().slice(0, 19).replace('T', '_').replace(':', '_')) - setPullRequestTitle(title || "Sweep Chat Suggested Changes") - setPullRequestBody(description || "Suggested changes by Sweep Chat.") - } else { + const prMetadata = await authorizedFetch("/backend/create_pull_metadata", { + body: JSON.stringify({ + repo_name: repoName, + modify_files_dict: data.modify_files_dict, + messages: messages, + }), + }) + + const prData = await prMetadata.json() + const { title, description, branch: featureBranch } = prData + setFeatureBranch(featureBranch || "sweep-chat-suggested-changes-" + new Date().toISOString().slice(0, 19).replace('T', '_').replace(':', '_')) + setPullRequestTitle(title || "Sweep Chat Suggested Changes") + setPullRequestBody(description || "Suggested changes by Sweep Chat.") + } + } catch { toast({ title: "Failed to auto-fix changes!", description: "This feature is still under development, so it's not completely reliable yet. We'll fix this for you shortly.",