From 95796a84f2f095d3ada4d59abdb0584457329173 Mon Sep 17 00:00:00 2001 From: Benjamin Shafii Date: Wed, 1 Jan 2025 16:09:49 +0100 Subject: [PATCH] fix: a lot of stuff --- .../plugin/views/assistant/ai-chat/chat.tsx | 131 +++++++++++++++--- .../ai-chat/context-limit-indicator.tsx | 75 ++++++---- .../views/assistant/ai-chat/submit-button.tsx | 2 +- .../ai-chat/tool-handlers/screenpipe-utils.ts | 1 + .../assistant/ai-chat/types/annotations.ts | 32 ++++- 5 files changed, 184 insertions(+), 57 deletions(-) diff --git a/packages/plugin/views/assistant/ai-chat/chat.tsx b/packages/plugin/views/assistant/ai-chat/chat.tsx index 57271d0b..30bdabba 100644 --- a/packages/plugin/views/assistant/ai-chat/chat.tsx +++ b/packages/plugin/views/assistant/ai-chat/chat.tsx @@ -24,7 +24,10 @@ import { ContextItems } from "./components/context-items"; import { ClearAllButton } from "./components/clear-all-button"; import { useCurrentFile } from "./hooks/use-current-file"; import { SearchAnnotationHandler } from "./tool-handlers/search-annotation-handler"; -import { isSearchResultsAnnotation, SearchResultsAnnotation } from "./types/annotations"; +import { + isSearchResultsAnnotation, + SearchResultsAnnotation, +} from "./types/annotations"; import { ExamplePrompts } from "./components/example-prompts"; interface ChatComponentProps { @@ -79,29 +82,35 @@ export const ChatComponent: React.FC = ({ files: Object.fromEntries( Object.entries(files).map(([id, file]) => [ id, - { ...file, content: '' } + { ...file, content: "" }, ]) ), folders: Object.fromEntries( Object.entries(folders).map(([id, folder]) => [ id, - { ...folder, files: folder.files.map(f => ({ ...f, content: '' })) } + { + ...folder, + files: folder.files.map(f => ({ ...f, content: "" })), + }, ]) ), tags: Object.fromEntries( Object.entries(tags).map(([id, tag]) => [ id, - { ...tag, files: tag.files.map(f => ({ ...f, content: '' })) } + { ...tag, files: tag.files.map(f => ({ ...f, content: "" })) }, ]) ), searchResults: Object.fromEntries( Object.entries(searchResults).map(([id, search]) => [ id, - { ...search, results: search.results.map(r => ({ ...r, content: '' })) } + { + ...search, + results: search.results.map(r => ({ ...r, content: "" })), + }, ]) ), // Keep these as is - currentFile: currentFile ? { ...currentFile, content: '' } : null, + currentFile: currentFile ? { ...currentFile, content: "" } : null, screenpipe, textSelections, }; @@ -129,6 +138,8 @@ export const ChatComponent: React.FC = ({ handleSubmit, stop, addToolResult, + error, + reload, } = useChat({ onDataChunk: (chunk: DataChunk) => { if (chunk.type === "metadata" && chunk.data?.groundingMetadata) { @@ -183,7 +194,8 @@ export const ChatComponent: React.FC = ({ onError: error => { logger.error(error.message); setErrorMessage( - "Connection failed. If the problem persists, please check your internet connection or VPN." + error.message || + "Connection failed. If the problem persists, please check your internet connection or VPN." ); }, onFinish: () => { @@ -253,10 +265,55 @@ export const ChatComponent: React.FC = ({ } as React.ChangeEvent); }; + const handleRetry = () => { + setErrorMessage(null); + reload(); + }; + return (
+ {errorMessage && ( +
+ + + + + {errorMessage} + + +
+ )} + {messages.length === 0 ? (

Try these examples

@@ -271,7 +328,7 @@ export const ChatComponent: React.FC = ({ return ( ); } @@ -292,6 +349,33 @@ export const ChatComponent: React.FC = ({ )) )} + + {isGenerating && ( +
+ + + + + Generating response... +
+ )} +
{groundingMetadata && ( @@ -302,25 +386,30 @@ export const ChatComponent: React.FC = ({
-
-
-
- - -
- +
+
+ + +
+ +
+
-
diff --git a/packages/plugin/views/assistant/ai-chat/context-limit-indicator.tsx b/packages/plugin/views/assistant/ai-chat/context-limit-indicator.tsx index 11e71deb..cff91f63 100644 --- a/packages/plugin/views/assistant/ai-chat/context-limit-indicator.tsx +++ b/packages/plugin/views/assistant/ai-chat/context-limit-indicator.tsx @@ -70,36 +70,55 @@ export function ContextLimitIndicator({ const shouldWarn = stats.percentUsed > 80; return ( -
-
- - {isOverLimit - ? "Context size exceeds maximum" +
+
+
- {stats.percentUsed.toFixed(0)}% -
- - +
); } \ No newline at end of file diff --git a/packages/plugin/views/assistant/ai-chat/submit-button.tsx b/packages/plugin/views/assistant/ai-chat/submit-button.tsx index 518d977a..19ead3f7 100644 --- a/packages/plugin/views/assistant/ai-chat/submit-button.tsx +++ b/packages/plugin/views/assistant/ai-chat/submit-button.tsx @@ -13,7 +13,7 @@ export const SubmitButton: React.FC = ({ return (