Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: better context indicator

Louis Beaumont33604941b571
diff --git a/screenpipe-app-tauri/components/context-usage-indicator.tsx b/screenpipe-app-tauri/components/context-usage-indicator.tsx
new file mode 100644
index 000000000..6db1e7622
--- /dev/null
+++ b/screenpipe-app-tauri/components/context-usage-indicator.tsx
@@ -0,0 +1,39 @@
+import React from "react";
+import { Progress } from "@/components/ui/progress";
+import { AlertTriangle } from "lucide-react";
+
+interface ContextUsageIndicatorProps {
+ currentSize: number;
+ maxSize: number;
+}
+
+export function ContextUsageIndicator({
+ currentSize,
+ maxSize,
+}: ContextUsageIndicatorProps) {
+ const percentage = Math.min((currentSize / maxSize) * 100, 100);
+
+ return (
+ <div className="w-5 h-5 relative">
+ {/* <svg className="w-full h-full" viewBox="0 0 36 36">
+ <path
+ className="text-gray-300"
+ d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="3"
+ />
+ <path
+ d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="3"
+ strokeDasharray="100"
+ strokeDashoffset={100 - percentage}
+ />
+
+ </svg> */}
+ {percentage > 90 && <AlertTriangle className="w-6 h-6 " />}
+ </div>
+ );
+}
diff --git a/screenpipe-app-tauri/components/search-chat.tsx b/screenpipe-app-tauri/components/search-chat.tsx
index a7e7dfa3b..fe5375eb6 100644
--- a/screenpipe-app-tauri/components/search-chat.tsx
+++ b/screenpipe-app-tauri/components/search-chat.tsx
@@ -56,6 +56,8 @@ import {
} from "./ui/tooltip";
import { Separator } from "./ui/separator";
import { useInputHistory } from "@/lib/hooks/use-input-history";
+import { ContextUsageIndicator } from "./context-usage-indicator";
+
// Add this constant at the top of the file
const MAX_CONTENT_LENGTH = 30000; // Adjust as needed
@@ -733,20 +735,22 @@ export function SearchChat() {
</div>
</div>
</div>
- <Button
- onClick={() => handleSearch(0)}
- disabled={isLoading}
- className="w-full mb-4"
- >
- {isLoading ? (
- <>
- <Loader2 className="mr-2 h-4 w-4 animate-spin" />
- searching... {progress.toFixed(0)}%
- </>
- ) : (
- "search"
- )}
- </Button>
+ <div className="flex justify-between items-center mb-4">
+ <Button
+ onClick={() => handleSearch(0)}
+ disabled={isLoading}
+ className="w-full mr-4"
+ >
+ {isLoading ? (
+ <>
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
+ searching... {progress.toFixed(0)}%
+ </>
+ ) : (
+ "search"
+ )}
+ </Button>
+ </div>
{isLoading && (
<div className="mt-2">
<Progress value={progress} className="w-full" />
@@ -798,27 +802,37 @@ export function SearchChat() {
type="text"
placeholder="ask a question about the results..."
value={floatingInput}
- disabled={isAiLoading}
+ disabled={
+ isAiLoading ||
+ calculateTotalContentLength(results) > MAX_CONTENT_LENGTH
+ }
onChange={(e) => setFloatingInput(e.target.value)}
className="w-full h-12 focus:outline-none focus:ring-0 border-0 focus:border-black focus:border transition-all duration-200 pr-10"
/>
- {calculateTotalContentLength(results) > MAX_CONTENT_LENGTH && (
- <TooltipProvider>
- <Tooltip>
- <TooltipTrigger asChild>
- <div className="absolute right-3 top-1/2 -translate-y-1/2">
- <AlertCircle className="h-5 w-5 text-yellow-500" />
- </div>
- </TooltipTrigger>
- <TooltipContent>
- <p>
- content exceeds 30k tokens. refine your search for
- better results.
- </p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- )}
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <div className="absolute right-3 top-1/2 -translate-y-1/2">
+ <ContextUsageIndicator
+ currentSize={calculateTotalContentLength(results)}
+ maxSize={MAX_CONTENT_LENGTH}
+ />
+ </div>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>
+ {calculateTotalContentLength(results) >
+ MAX_CONTENT_LENGTH
+ ? `content exceeds maximum allowed: ${calculateTotalContentLength(
+ results
+ )} / ${MAX_CONTENT_LENGTH} characters. refine your search to use AI.`
+ : `${calculateTotalContentLength(
+ results
+ )} / ${MAX_CONTENT_LENGTH} characters used`}
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
</div>
<Button
type="submit"