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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: make AI context more friendly
Louis Beaumontda479b07f2e8
diff --git a/screenpipe-app-tauri/components/context-usage-indicator.tsx b/screenpipe-app-tauri/components/context-usage-indicator.tsxindex 6db1e7622..9f11412d4 100644--- a/screenpipe-app-tauri/components/context-usage-indicator.tsx+++ b/screenpipe-app-tauri/components/context-usage-indicator.tsx@@ -1,5 +1,5 @@import React from "react";-import { Progress } from "@/components/ui/progress";+import { motion } from "framer-motion";import { AlertTriangle } from "lucide-react";interface ContextUsageIndicatorProps {@@ -12,28 +12,35 @@ export function ContextUsageIndicator({maxSize,}: ContextUsageIndicatorProps) {const percentage = Math.min((currentSize / maxSize) * 100, 100);+ const circumference = 2 * Math.PI * 14;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"+ <div className="w-8 h-8 relative">+ <svg width="32" height="32" viewBox="0 0 32 32">+ <circle+ cx="16"+ cy="16"+ r="14"fill="none"- stroke="currentColor"- strokeWidth="3"+ stroke="#e2e8f0"+ strokeWidth="2"/>- <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"+ <motion.circle+ cx="16"+ cy="16"+ r="14"fill="none"- stroke="currentColor"- strokeWidth="3"- strokeDasharray="100"- strokeDashoffset={100 - percentage}+ stroke="black"+ strokeWidth="2"+ strokeDasharray={circumference}+ initial={{ strokeDashoffset: circumference }}+ animate={{ strokeDashoffset: circumference - (percentage / 100) * circumference }}+ transition={{ duration: 0.5 }}/>-- </svg> */}- {percentage > 90 && <AlertTriangle className="w-6 h-6 " />}+ </svg>+ {percentage > 90 && (+ <AlertTriangle className="w-5 h-5 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-black" />+ )}</div>);}diff --git a/screenpipe-app-tauri/components/recording-settings.tsx b/screenpipe-app-tauri/components/recording-settings.tsxindex 762720407..c6722ec68 100644--- a/screenpipe-app-tauri/components/recording-settings.tsx+++ b/screenpipe-app-tauri/components/recording-settings.tsx@@ -264,14 +264,14 @@ export function RecordingSettings({return (<><div className="relative">- {!isUpdating && isDisabled && (+ {settings.devMode || (!isUpdating && isDisabled) ? (<Card className="p-16 shadow-lg w-fit absolute bottom-1/4 left-1/2 -translate-x-1/2 -translate-y-1/2 z-10 text-center font-bold text-xl mb-4 "><CardTitle>make sure to turn off dev mode and start screenpipe recorder first(go to status)</CardTitle></Card>- )}+ ) : <></>}<Card className={cn(isDisabled && "opacity-50 pointer-events-none")}><CardHeader><CardTitle className="text-center">recording settings</CardTitle>diff --git a/screenpipe-app-tauri/components/search-chat.tsx b/screenpipe-app-tauri/components/search-chat.tsxindex 69c764cc7..24405e727 100644--- a/screenpipe-app-tauri/components/search-chat.tsx+++ b/screenpipe-app-tauri/components/search-chat.tsx@@ -57,9 +57,7 @@ import {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+import { Checkbox } from "@/components/ui/checkbox";export function SearchChat() {// Search state@@ -100,6 +98,19 @@ export function SearchChat() {const [isUserScrolling, setIsUserScrolling] = useState(false);const lastScrollPosition = useRef(0);+ const MAX_CONTENT_LENGTH = settings.aiMaxContextChars;++ const [selectedResults, setSelectedResults] = useState<Set<number>>(+ new Set()+ );+ const [hoveredResult, setHoveredResult] = useState<number | null>(null);++ useEffect(() => {+ if (results.length > 0) {+ setSelectedResults(new Set(results.map((_, index) => index)));+ }+ }, [results]);+useEffect(() => {const handleScroll = () => {const currentScrollPosition = window.scrollY;@@ -168,17 +179,44 @@ export function SearchChat() {}}, [isFloatingInputVisible]);+ const handleResultSelection = (index: number) => {+ setSelectedResults((prev) => {+ const newSet = new Set(prev);+ if (newSet.has(index)) {+ newSet.delete(index);+ } else {+ newSet.add(index);+ }+ return newSet;+ });+ };++ const calculateSelectedContentLength = () => {+ return Array.from(selectedResults).reduce((total, index) => {+ const item = results[index];+ const contentLength =+ item.type === "OCR"+ ? item.content.text.length+ : item.type === "Audio"+ ? item.content.transcription.length+ : item.type === "FTS"+ ? item.content.matched_text.length+ : 0;+ return total + contentLength;+ }, 0);+ };+const handleFloatingInputSubmit = async (e: React.FormEvent) => {e.preventDefault();if (!floatingInput.trim()) return;scrollToBottom();- const totalContentLength = calculateTotalContentLength(results);- if (totalContentLength > MAX_CONTENT_LENGTH) {+ const selectedContentLength = calculateSelectedContentLength();+ if (selectedContentLength > MAX_CONTENT_LENGTH) {toast({title: "Content too large",- description: `The total content length (${totalContentLength} characters) exceeds the maximum allowed (${MAX_CONTENT_LENGTH} characters). Please refine your search to reduce the amount of content.`,+ description: `The selected content length (${selectedContentLength} characters) exceeds the maximum allowed (${MAX_CONTENT_LENGTH} characters). Please unselect some items to reduce the amount of content.`,variant: "destructive",});return;@@ -223,8 +261,10 @@ export function SearchChat() {- Never output UTC time unless explicitly asked by the user.- Do not try to embed videos in table (would crash the app)- Based on the following search results:- ${JSON.stringify(results)}+ Based on the following selected search results:+ ${JSON.stringify(+ results.filter((_, index) => selectedResults.has(index))+ )}`,},...chatMessages.map((msg) => ({@@ -354,112 +394,135 @@ export function SearchChat() {}return results.map((item, index) => (- <Card key={index}>- <CardContent className="p-4">- <Accordion type="single" collapsible className="w-full">- <AccordionItem value={`item-${index}`}>- <AccordionTrigger className="flex items-center">- <div className="flex items-center w-full">- <Badge className="mr-2">{item.type}</Badge>- </div>- <span className="flex-grow text-center truncate">- {item.type === "OCR" && item.content.text.substring(0, 50)}- {item.type === "Audio" &&- item.content.transcription.substring(0, 50)}- {item.type === "FTS" &&- item.content.matched_text.substring(0, 50)}- ...- </span>- </AccordionTrigger>- <AccordionContent>- {item.type === "OCR" && (- <>- <p className="mt-2">{item.content.text}</p>- <div className="flex justify-center mt-4">- <VideoComponent filePath={item.content.file_path} />- </div>- {includeFrames && item.content.frame && (- <div className="mt-2 flex items-center">- <Dialog>- <DialogTrigger asChild>- <img- src={`data:image/jpeg;base64,${item.content.frame}`}- alt="Frame"- className="w-24 h-auto cursor-pointer"- />- </DialogTrigger>- <DialogContent className="sm:max-w-[80vw]">- <img- src={`data:image/jpeg;base64,${item.content.frame}`}- alt="Frame"- className="w-full h-auto"- />- </DialogContent>- </Dialog>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>this is the frame where the text appeared</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>+ <motion.div+ key={index}+ className="flex items-center mb-4 relative pl-8"+ onHoverStart={() => setHoveredResult(index)}+ onHoverEnd={() => setHoveredResult(null)}+ >+ <AnimatePresence>+ {hoveredResult === index && (+ <motion.div+ initial={{ opacity: 0 }}+ animate={{ opacity: 1 }}+ exit={{ opacity: 0 }}+ transition={{ duration: 0.2 }}+ className="absolute left-0 top-1/2 transform -translate-y-1/2"+ >+ <Checkbox+ checked={selectedResults.has(index)}+ onCheckedChange={() => handleResultSelection(index)}+ />+ </motion.div>+ )}+ </AnimatePresence>+ <Card className="w-full">+ <CardContent className="p-4">+ <Accordion type="single" collapsible className="w-full">+ <AccordionItem value={`item-${index}`}>+ <AccordionTrigger className="flex items-center">+ <div className="flex items-center w-full">+ <Badge className="mr-2">{item.type}</Badge>+ </div>+ <span className="flex-grow text-center truncate">+ {item.type === "OCR" && item.content.text.substring(0, 50)}+ {item.type === "Audio" &&+ item.content.transcription.substring(0, 50)}+ {item.type === "FTS" &&+ item.content.matched_text.substring(0, 50)}+ ...+ </span>+ </AccordionTrigger>+ <AccordionContent>+ {item.type === "OCR" && (+ <>+ <p className="mt-2">{item.content.text}</p>+ <div className="flex justify-center mt-4">+ <VideoComponent filePath={item.content.file_path} /></div>- )}- </>- )}- {item.type === "Audio" && (- <>- <p className="mt-2">{item.content.transcription}</p>- <div className="flex justify-center mt-4">- <VideoComponent filePath={item.content.file_path} />- </div>- </>- )}- {item.type === "FTS" && (- <>- <p className="mt-2">{item.content.matched_text}</p>- {item.content.original_frame_text && (- <p className="mt-2 text-sm text-gray-600">- Original: {item.content.original_frame_text}- </p>- )}- </>- )}- </AccordionContent>- </AccordionItem>- </Accordion>- <div className="flex flex-wrap items-center gap-2 mt-2">- <p className="text-xs text-gray-400">- {new Date(item.content.timestamp).toLocaleString()}- </p>- {item.type === "OCR" && item.content.app_name && (- <Badge- className="text-xs cursor-pointer"- onClick={() => setAppName(item.content.app_name)}- >- {item.content.app_name}- </Badge>- )}- {item.type === "OCR" && item.content.window_name && (- <Badge- className="text-xs cursor-pointer"- onClick={() => setWindowName(item.content.window_name)}- >- {item.content.window_name}- </Badge>- )}- {item.content.tags &&- item.content.tags.map((tag, index) => (- <Badge key={index} className="text-xs">- {tag}+ {includeFrames && item.content.frame && (+ <div className="mt-2 flex items-center">+ <Dialog>+ <DialogTrigger asChild>+ <img+ src={`data:image/jpeg;base64,${item.content.frame}`}+ alt="Frame"+ className="w-24 h-auto cursor-pointer"+ />+ </DialogTrigger>+ <DialogContent className="sm:max-w-[80vw]">+ <img+ src={`data:image/jpeg;base64,${item.content.frame}`}+ alt="Frame"+ className="w-full h-auto"+ />+ </DialogContent>+ </Dialog>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />+ </TooltipTrigger>+ <TooltipContent>+ <p>this is the frame where the text appeared</p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </div>+ )}+ </>+ )}+ {item.type === "Audio" && (+ <>+ <p className="mt-2">{item.content.transcription}</p>+ <div className="flex justify-center mt-4">+ <VideoComponent filePath={item.content.file_path} />+ </div>+ </>+ )}+ {item.type === "FTS" && (+ <>+ <p className="mt-2">{item.content.matched_text}</p>+ {item.content.original_frame_text && (+ <p className="mt-2 text-sm text-gray-600">+ Original: {item.content.original_frame_text}+ </p>+ )}+ </>+ )}+ </AccordionContent>+ </AccordionItem>+ </Accordion>+ <div className="flex flex-wrap items-center gap-2 mt-2">+ <p className="text-xs text-gray-400">+ {new Date(item.content.timestamp).toLocaleString()}+ </p>+ {item.type === "OCR" && item.content.app_name && (+ <Badge+ className="text-xs cursor-pointer"+ onClick={() => setAppName(item.content.app_name)}+ >+ {item.content.app_name}</Badge>- ))}- </div>- </CardContent>- </Card>+ )}+ {item.type === "OCR" && item.content.window_name && (+ <Badge+ className="text-xs cursor-pointer"+ onClick={() => setWindowName(item.content.window_name)}+ >+ {item.content.window_name}+ </Badge>+ )}+ {item.content.tags &&+ item.content.tags.map((tag, index) => (+ <Badge key={index} className="text-xs">+ {tag}+ </Badge>+ ))}+ </div>+ </CardContent>+ </Card>+ </motion.div>));};@@ -824,7 +887,7 @@ export function SearchChat() {value={floatingInput}disabled={isAiLoading ||- calculateTotalContentLength(results) > MAX_CONTENT_LENGTH+ calculateSelectedContentLength() > 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"@@ -834,21 +897,16 @@ export function SearchChat() {<TooltipTrigger asChild><div className="absolute right-3 top-1/2 -translate-y-1/2"><ContextUsageIndicator- currentSize={calculateTotalContentLength(results)}+ currentSize={calculateSelectedContentLength()}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`}+ {calculateSelectedContentLength() > MAX_CONTENT_LENGTH+ ? `selected content exceeds maximum allowed: ${calculateSelectedContentLength()} / ${MAX_CONTENT_LENGTH} characters. unselect some items to use AI.`+ : `${calculateSelectedContentLength()} / ${MAX_CONTENT_LENGTH} characters used for AI message`}</p></TooltipContent></Tooltip>@@ -859,7 +917,7 @@ export function SearchChat() {className="w-12"disabled={isAiLoading ||- calculateTotalContentLength(results) > MAX_CONTENT_LENGTH+ calculateSelectedContentLength() > MAX_CONTENT_LENGTH}><Send className="h-4 w-4" />diff --git a/screenpipe-app-tauri/components/settings.tsx b/screenpipe-app-tauri/components/settings.tsxindex 4d9a357fc..42becb251 100644--- a/screenpipe-app-tauri/components/settings.tsx+++ b/screenpipe-app-tauri/components/settings.tsx@@ -24,6 +24,7 @@ import { MemoizedReactMarkdown } from "./markdown";import { Separator } from "@/components/ui/separator";import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";import { Textarea } from "./ui/textarea";+import { Slider } from "@/components/ui/slider"; // Add this importimport { platform } from "@tauri-apps/plugin-os";import { Eye, EyeOff, HelpCircle, RefreshCw } from "lucide-react";@@ -73,6 +74,12 @@ export function Settings({ className }: { className?: string }) {resetSetting("customPrompt");};+ const handleMaxContextCharsChange = (value: number[]) => {+ const newValue = value[0];+ setLocalSettings((prev) => ({ ...prev, aiMaxContextChars: newValue }));+ updateSettings({ aiMaxContextChars: newValue });+ };+React.useEffect(() => {setLocalSettings(settings);setCurrentPlatform(platform());@@ -136,10 +143,15 @@ export function Settings({ className }: { className?: string }) {<TooltipContent side="left"><p>the url of your ai provider's api endpoint. for- openai: <pre className="bg-gray-100 p-1 rounded-md">https://api.openai.com/v1</pre>+ openai:{" "}+ <pre className="bg-gray-100 p-1 rounded-md">+ https://api.openai.com/v1+ </pre><br />for local providers like ollama usually it's- <pre className="bg-gray-100 p-1 rounded-md">http://localhost:11434/v1</pre>+ <pre className="bg-gray-100 p-1 rounded-md">+ http://localhost:11434/v1+ </pre></p></TooltipContent></Tooltip>@@ -222,6 +234,50 @@ export function Settings({ className }: { className?: string }) {</div></div>+ <div className="w-full">+ <div className="flex items-center gap-4 mb-4">+ <Label+ htmlFor="aiMaxContextChars"+ className="min-w-[80px] text-right"+ >+ max context+ </Label>+ <div className="flex-grow flex items-center">+ <Slider+ id="aiMaxContextChars"+ min={1000}+ max={128000}+ step={1000}+ value={[localSettings.aiMaxContextChars]}+ onValueChange={handleMaxContextCharsChange}+ className="flex-grow"+ />+ <span className="ml-2 min-w-[60px] text-right">+ {localSettings.aiMaxContextChars.toLocaleString()}+ </span>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button variant="ghost" size="icon" className="ml-2">+ <HelpCircle className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent side="left">+ <p>+ maximum number of characters (think 3 characters per+ token) to send to the ai model. <br />+ usually, openai models support up to 128k tokens,+ which is roughly 30k-40k characters. <br />+ we'll use this for UI purposes to show you how+ much you can send.+ </p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </div>+ </div>+ </div>+<Separator /><p className="mt-2 text-sm text-muted-foreground text-center">@@ -292,8 +348,8 @@ export function Settings({ className }: { className?: string }) {className="text-primary hover:underline">deepgram's website- </a>- {" "} or DM us on discord, it's on us!+ </a>{" "}+ or DM us on discord, it's on us!</p></CardContent></Card>diff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex a534048b4..6cc81efc7 100644--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -35,6 +35,7 @@ const defaultSettings: Settings = {ignoredWindows: [],includedWindows: [],aiUrl: "https://api.openai.com/v1",+ aiMaxContextChars: 30000,};export interface Settings {@@ -60,6 +61,7 @@ export interface Settings {ignoredWindows: string[];includedWindows: string[];aiUrl: string;+ aiMaxContextChars: number;}let store: Store | null = null;@@ -147,6 +149,8 @@ export function useSettings() {const savedAiUrl =((await store!.get("aiUrl")) as string) ||"https://api.openai.com/v1";+ const savedAiMaxContextChars =+ ((await store!.get("aiMaxContextChars")) as number) || 30000;setSettings({openaiApiKey: savedKey,deepgramApiKey: savedDeepgramKey,@@ -170,6 +174,7 @@ export function useSettings() {ignoredWindows: savedIgnoredWindows,includedWindows: savedIncludedWindows,aiUrl: savedAiUrl,+ aiMaxContextChars: savedAiMaxContextChars,});} catch (error) {console.error("Failed to load settings:", error);diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 8d31bf9f9..2e32974a1 100644--- a/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "0.2.41"+version = "0.2.42"description = ""authors = ["you"]license = ""