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
feat: add custom agents drop down
Louis Beaumont4393ce576ed5
diff --git a/screenpipe-app-tauri/app/timeline/page.tsx b/screenpipe-app-tauri/app/timeline/page.tsxindex 9202983bd..121599f19 100644--- a/screenpipe-app-tauri/app/timeline/page.tsx+++ b/screenpipe-app-tauri/app/timeline/page.tsx@@ -52,8 +52,69 @@ interface TimeRange {end: Date;}+interface Agent {+ id: string;+ name: string;+ description: string;+ dataSelector: (frames: StreamTimeSeriesResponse[]) => any;+}++const AGENTS: Agent[] = [+ {+ id: "context-master",+ name: "context master",+ description: "analyzes everything: apps, windows, text & audio",+ dataSelector: (frames) =>+ frames.map((frame) => ({+ timestamp: frame.timestamp,+ devices: frame.devices.map((device) => ({+ device_id: device.device_id,+ metadata: device.metadata,+ audio: device.audio,+ })),+ })),+ },+ {+ id: "window-tracker",+ name: "window tracker",+ description: "focuses on app switching patterns",+ dataSelector: (frames) =>+ frames.map((frame) => ({+ timestamp: frame.timestamp,+ windows: frame.devices.map((device) => ({+ app: device.metadata.app_name,+ window: device.metadata.window_name,+ })),+ })),+ },+ {+ id: "text-scanner",+ name: "text scanner",+ description: "analyzes visible text (OCR)",+ dataSelector: (frames) =>+ frames.map((frame) => ({+ timestamp: frame.timestamp,+ text: frame.devices+ .map((device) => device.metadata.ocr_text)+ .filter(Boolean),+ })),+ },+ {+ id: "voice-analyzer",+ name: "voice analyzer",+ description: "focuses on audio transcriptions",+ dataSelector: (frames) =>+ frames.map((frame) => ({+ timestamp: frame.timestamp,+ audio: frame.devices.flatMap((device) => device.audio),+ })),+ },+];+export default function Timeline() {- const [currentFrame, setCurrentFrame] = useState<DeviceFrameResponse | null>(null);+ const [currentFrame, setCurrentFrame] = useState<DeviceFrameResponse | null>(+ null+ );const [frames, setFrames] = useState<StreamTimeSeriesResponse[]>([]);const [currentIndex, setCurrentIndex] = useState(0);const [isLoading, setIsLoading] = useState(true);@@ -83,6 +144,7 @@ export default function Timeline() {const [isDraggingPanel, setIsDraggingPanel] = useState(false);const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });const [osType, setOsType] = useState<string>("");+ const [selectedAgent, setSelectedAgent] = useState<Agent>(AGENTS[0]);useEffect(() => {setPosition({@@ -121,12 +183,15 @@ export default function Timeline() {setFrames((prev) => {const exists = prev.some((f) => f.timestamp === data.timestamp);if (exists) return prev;-+// ! HACK: Add new frame and sort in descending orderconst newFrames = [...prev, data].sort((a, b) => {- return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();+ return (+ new Date(b.timestamp).getTime() -+ new Date(a.timestamp).getTime()+ );});-+return newFrames;});@@ -159,18 +224,20 @@ export default function Timeline() {};const getLoadedTimeRangeStyles = () => {- if (!loadedTimeRange || frames.length === 0) return { left: "0%", right: "100%" };+ if (!loadedTimeRange || frames.length === 0)+ return { left: "0%", right: "100%" };// Find the earliest frame timestamp- const firstFrame = [...frames].sort((a, b) =>- new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()+ const firstFrame = [...frames].sort(+ (a, b) =>+ new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime())[0];const earliestTime = new Date(firstFrame.timestamp);// Create local date objects for todayconst startOfDay = new Date();startOfDay.setHours(0, 0, 0, 0);-+const endOfDay = new Date();endOfDay.setHours(23, 59, 59, 999);@@ -179,8 +246,10 @@ export default function Timeline() {const localEnd = new Date(loadedTimeRange.end);const totalMs = endOfDay.getTime() - startOfDay.getTime();- const startPercent = ((localStart.getTime() - startOfDay.getTime()) / totalMs) * 100;- const endPercent = ((localEnd.getTime() - startOfDay.getTime()) / totalMs) * 100;+ const startPercent =+ ((localStart.getTime() - startOfDay.getTime()) / totalMs) * 100;+ const endPercent =+ ((localEnd.getTime() - startOfDay.getTime()) / totalMs) * 100;// Temporarily return empty values to disable grey areasreturn {@@ -261,8 +330,10 @@ export default function Timeline() {const getCurrentTimePercentage = () => {if (!currentFrame) return 0;-- const frameTime = new Date(currentFrame.metadata.timestamp || frames[currentIndex].timestamp);++ const frameTime = new Date(+ currentFrame.metadata.timestamp || frames[currentIndex].timestamp+ );const startOfDay = new Date(frameTime);startOfDay.setHours(0, 0, 0, 0);const endOfDay = new Date(frameTime);@@ -278,10 +349,10 @@ export default function Timeline() {const rect = e.currentTarget.getBoundingClientRect();const clickX = e.clientX - rect.left;const percentage = (clickX / rect.width) * 100;-+// Clamp percentage between 0 and 100const clampedPercentage = Math.max(0, Math.min(100, percentage));-+setIsDragging(true);setDragStart(clampedPercentage);@@ -317,13 +388,15 @@ export default function Timeline() {const rect = e.currentTarget.getBoundingClientRect();const moveX = e.clientX - rect.left;const percentage = (moveX / rect.width) * 100;-+// Clamp percentage between 0 and 100const clampedPercentage = Math.max(0, Math.min(100, percentage));const totalMinutesInDay = 24 * 60;- const startMinutes = (Math.min(dragStart, clampedPercentage) / 100) * totalMinutesInDay;- const endMinutes = (Math.max(dragStart, clampedPercentage) / 100) * totalMinutesInDay;+ const startMinutes =+ (Math.min(dragStart, clampedPercentage) / 100) * totalMinutesInDay;+ const endMinutes =+ (Math.max(dragStart, clampedPercentage) / 100) * totalMinutesInDay;const startLocal = new Date();startLocal.setHours(@@ -393,16 +466,14 @@ export default function Timeline() {e.preventDefault();if (!aiInput.trim() || !selectionRange) return;- console.log("selectionRange", selectionRange);- console.log("frames", frames);const relevantFrames = frames.filter((frame) => {const frameTime = new Date(frame.timestamp);- console.log("frameTime", frameTime);return (frameTime >= selectionRange.start && frameTime <= selectionRange.end);});- console.log("relevantFrames", relevantFrames);++ const contextData = selectedAgent.dataSelector(relevantFrames);const userMessage = {id: generateId(),@@ -423,7 +494,9 @@ export default function Timeline() {const messages = [{role: "system" as const,- content: `You are a helpful assistant analyzing screen & mic 24/7 recordings including OCR, transcription, and more.+ content: `You are a helpful assistant specialized as a "${+ selectedAgent.name+ }" analyzing screen & mic recordings.Rules:- Current time (JavaScript Date.prototype.toString): ${new Date().toString()}- User timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}@@ -431,22 +504,13 @@ export default function Timeline() {- All timestamps in the context data are in UTC- Convert timestamps to local time for human-readable responses- Never output UTC time unless explicitly asked- - Focus on app usage patterns and context switches+ - Focus on ${selectedAgent.description}`,},...chatMessages,{role: "user" as const,- content: `Context data: ${JSON.stringify(- relevantFrames.map((frame) => ({- timestamp: frame.timestamp,- devices: frame.devices.map(device => ({- device_id: device.device_id,- metadata: device.metadata,- audio: device.audio,- }))- }))- )}+ content: `Context data: ${JSON.stringify(contextData)}${aiInput}`,},@@ -620,7 +684,9 @@ export default function Timeline() {<div className="flex items-center gap-4"><div>device: {currentFrame.device_id}</div><div>app: {currentFrame.metadata.app_name || "n/a"}</div>- <div>window: {currentFrame.metadata.window_name || "n/a"}</div>+ <div>+ window: {currentFrame.metadata.window_name || "n/a"}+ </div></div></div></div>@@ -784,32 +850,45 @@ export default function Timeline() {msUserSelect: "text",}}>- <div className="flex gap-2">- <Input- ref={inputRef}- type="text"- value={aiInput}- onChange={(e) => setAiInput(e.target.value)}- placeholder="ask about this time range..."- className="flex-1 bg-black/50 border-[#0f0] text-[#0f0] placeholder-[#0f0]/50"- disabled={isAiLoading}- />- <Button- type="submit"- disabled={isAiLoading}- className="bg-[#0f0]/20 hover:bg-[#0f0]/30 border border-[#0f0] text-[#0f0] group relative"+ <div className="flex flex-col gap-2">+ <select+ value={selectedAgent.id}+ onChange={(e) => setSelectedAgent(AGENTS.find(a => a.id === e.target.value) || AGENTS[0])}+ className="w-full bg-black/50 border border-[#0f0] text-[#0f0] rounded px-2 py-1 text-xs">- {isStreaming ? (- <Square className="h-4 w-4" />- ) : (- <>- <Send className="h-4 w-4" />- <span className="absolute -top-8 right-0 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity bg-black/90 px-2 py-1 rounded whitespace-nowrap">- {osType === "macos" ? "⌘↵" : "Ctrl+↵"}- </span>- </>- )}- </Button>+ {AGENTS.map((agent) => (+ <option key={agent.id} value={agent.id} className="bg-black">+ {agent.name} - {agent.description}+ </option>+ ))}+ </select>+ <div className="flex gap-2">+ <Input+ ref={inputRef}+ type="text"+ value={aiInput}+ onChange={(e) => setAiInput(e.target.value)}+ placeholder="ask about this time range..."+ className="flex-1 bg-black/50 border-[#0f0] text-[#0f0] placeholder-[#0f0]/50"+ disabled={isAiLoading}+ />+ <Button+ type="submit"+ disabled={isAiLoading}+ className="bg-[#0f0]/20 hover:bg-[#0f0]/30 border border-[#0f0] text-[#0f0] group relative"+ >+ {isStreaming ? (+ <Square className="h-4 w-4" />+ ) : (+ <>+ <Send className="h-4 w-4" />+ <span className="absolute -top-8 right-0 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity bg-black/90 px-2 py-1 rounded whitespace-nowrap">+ {osType === "macos" ? "⌘↵" : "Ctrl+↵"}+ </span>+ </>+ )}+ </Button>+ </div></div></form></div>diff --git a/screenpipe-app-tauri/components/search-chat.tsx b/screenpipe-app-tauri/components/search-chat.tsxindex abb58ee14..496faa33b 100644--- a/screenpipe-app-tauri/components/search-chat.tsx+++ b/screenpipe-app-tauri/components/search-chat.tsx@@ -80,6 +80,75 @@ import { useDebounce } from "@/lib/hooks/use-debounce";import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";import { useHealthCheck } from "@/lib/hooks/use-health-check";+interface Agent {+ id: string;+ name: string;+ description: string;+ dataSelector: (results: ContentItem[]) => any;+ systemPrompt: string;+}++const AGENTS: Agent[] = [+ {+ id: "context-master",+ name: "context master",+ description: "analyzes everything: apps, windows, text & audio",+ systemPrompt:+ "you analyze all types of data from screen recordings and audio transcriptions. provide comprehensive insights.",+ dataSelector: (results) => results,+ },+ {+ id: "window-detective",+ name: "window detective",+ description: "focuses on app usage patterns",+ systemPrompt:+ "you specialize in analyzing app usage patterns and window switching behavior. help users understand their app usage.",+ dataSelector: (results) =>+ results+ .filter(+ (item) =>+ item.type === "OCR" &&+ (item.content.app_name || item.content.window_name)+ )+ .map((item) => ({+ timestamp: item.content.timestamp,+ // @ts-ignore+ app_name: item.content.app_name,+ // @ts-ignore+ window_name: item.content.window_name,+ })),+ },+ {+ id: "text-oracle",+ name: "text oracle",+ description: "analyzes screen text (OCR)",+ systemPrompt:+ "you focus on text extracted from screen recordings. help users find and understand text content.",+ dataSelector: (results) =>+ results+ .filter((item) => item.type === "OCR")+ .map((item) => ({+ timestamp: item.content.timestamp,+ text: item.content.text,+ app_name: item.content.app_name,+ })),+ },+ {+ id: "voice-sage",+ name: "voice sage",+ description: "focuses on audio transcriptions",+ systemPrompt:+ "you analyze audio transcriptions from recordings. help users understand spoken content.",+ dataSelector: (results) =>+ results+ .filter((item) => item.type === "Audio")+ .map((item) => ({+ timestamp: item.content.timestamp,+ transcription: item.content.transcription,+ })),+ },+];+export function SearchChat() {// Search stateconst { health } = useHealthCheck();@@ -141,6 +210,8 @@ export function SearchChat() {const [isQueryParamsDialogOpen, setIsQueryParamsDialogOpen] = useState(false);+ const [selectedAgent, setSelectedAgent] = useState<Agent>(AGENTS[0]);+useEffect(() => {const updateDates = () => {const now = new Date();@@ -382,23 +453,14 @@ export function SearchChat() {const messages = [{role: "system" as const,- content: `You are a helpful assistant.- The user is using a product called "screenpipe" which records- his screen and mics 24/7. The user ask you questions- and you use his screenpipe recordings to answer him.- The user will provide you with a list of search results- and you will use them to answer his questions.-+ content: `You are a helpful assistant specialized as a "${+ selectedAgent.name+ }". ${selectedAgent.systemPrompt}Rules:- - Current time (JavaScript Date.prototype.toString): ${new Date().toString()}. Adjust start/end times to match user intent.+ - Current time (JavaScript Date.prototype.toString): ${new Date().toString()}- User timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}- - User timezone offset (JavaScript Date.prototype.getTimezoneOffset): ${new Date().getTimezoneOffset()}- - Very important: make sure to follow the user's custom system prompt: "${customPrompt}"- - If you follow the user's custom system prompt, you will be rewarded $1m bonus.- - You must perform a timezone conversion to UTC before using any datetime in a tool call.- - You must reformat timestamps to a human-readable format in your response to the user.- - Never output UTC time unless explicitly asked by the user.- - Do not try to embed videos in table (would crash the app)+ - User timezone offset: ${new Date().getTimezoneOffset()}+ - ${customPrompt ? `Custom prompt: ${customPrompt}` : ""}`,},...chatMessages.map((msg) => ({@@ -408,7 +470,9 @@ export function SearchChat() {{role: "user" as const,content: `Context data: ${JSON.stringify(- results.filter((_, index) => selectedResults.has(index))+ selectedAgent.dataSelector(+ results.filter((_, index) => selectedResults.has(index))+ ))}User query: ${floatingInput}`,@@ -683,7 +747,8 @@ export function SearchChat() {{item.type === "Audio" && (<><p className="mt-2">{item.content.transcription}</p>- {item.content.file_path && item.content.file_path.trim() !== "" ? (+ {item.content.file_path &&+ item.content.file_path.trim() !== "" ? (<div className="flex justify-center mt-4"><VideoComponent filePath={item.content.file_path} /></div>@@ -1215,9 +1280,41 @@ export function SearchChat() {><formonSubmit={handleFloatingInputSubmit}- className="flex space-x-2 bg-white shadow-lg rounded-lg overflow-hidden p-4 items-center"+ className="flex flex-col space-y-2 bg-white shadow-lg rounded-lg overflow-hidden p-4">- <div className="relative flex-grow">+ <div className="flex items-center space-x-2">+ <Select+ value={selectedAgent.id}+ onValueChange={(value) =>+ setSelectedAgent(+ AGENTS.find((a) => a.id === value) || AGENTS[0]+ )+ }+ >+ <SelectTrigger className="w-full">+ <SelectValue placeholder="select agent" />+ </SelectTrigger>+ <SelectContent>+ {AGENTS.map((agent) => (+ <SelectItem key={agent.id} value={agent.id}>+ <span className="font-mono text-sm">{agent.name}</span>+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <HelpCircle className="h-4 w-4 text-gray-400" />+ </TooltipTrigger>+ <TooltipContent>+ <p>{selectedAgent.description}</p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </div>++ <div className="relative flex-grow flex items-center space-x-2"><Inputref={floatingInputRef}type="text"@@ -1229,15 +1326,26 @@ export function SearchChat() {onChange={(e) => setFloatingInput(e.target.value)}className="w-full h-12 focus:outline-none focus:ring-0 border-0 focus:border-black focus:border-b transition-all duration-200 pr-10"/>+ <Button+ type="submit"+ className="w-12"+ disabled={+ calculateSelectedContentLength() > MAX_CONTENT_LENGTH+ }+ >+ {isStreaming ? (+ <Square className="h-4 w-4" />+ ) : (+ <Send className="h-4 w-4" />+ )}+ </Button><TooltipProvider><Tooltip><TooltipTrigger asChild>- <div className="absolute right-3 top-1/2 -translate-y-1/2">- <ContextUsageIndicator- currentSize={calculateSelectedContentLength()}- maxSize={MAX_CONTENT_LENGTH}- />- </div>+ <ContextUsageIndicator+ currentSize={calculateSelectedContentLength()}+ maxSize={MAX_CONTENT_LENGTH}+ /></TooltipTrigger><TooltipContent><p>@@ -1249,17 +1357,6 @@ export function SearchChat() {</Tooltip></TooltipProvider></div>- <Button- type="submit"- className={`w-12 `}- disabled={calculateSelectedContentLength() > MAX_CONTENT_LENGTH}- >- {isStreaming ? (- <Square className="h-4 w-4" />- ) : (- <Send className="h-4 w-4" />- )}- </Button></form></motion.div>)}@@ -1284,7 +1381,7 @@ export function SearchChat() {<ChevronDown className="h-6 w-6" /></Button>)}- {results.length > 0 && <div className="h-24" />}+ {results.length > 0 && <div className="h-32" />}</div>);-}\ No newline at end of file+}diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lockindex 6ba600966..6b7b9c1e5 100755--- a/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -3777,7 +3777,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"[[package]]name = "screenpipe-app"-version = "0.8.6"+version = "0.8.7"dependencies = ["anyhow","axum",diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex e09b5113d..529df57e4 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.8.6"+version = "0.8.7"description = ""authors = ["you"]license = ""