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

refactor(timeline): unify AI chat experience

Louis Beaumont6dcc332b3439
diff --git a/screenpipe-app-tauri/components/global-chat.tsx b/screenpipe-app-tauri/components/global-chat.tsx
index 0ef82afa2..b09f05930 100644
--- a/screenpipe-app-tauri/components/global-chat.tsx
+++ b/screenpipe-app-tauri/components/global-chat.tsx
@@ -20,9 +20,17 @@ import OpenAI from "openai";
import { ChatCompletionTool } from "openai/resources/chat/completions";
import { open as openUrl } from "@tauri-apps/plugin-shell";
import { usePlatform } from "@/lib/hooks/use-platform";
+import { useTimelineSelection } from "@/lib/hooks/use-timeline-selection";
const SCREENPIPE_API = "http://localhost:3030";
+// Suggestion badges for timeline selection
+const TIMELINE_SUGGESTIONS = [
+ "what did i work on?",
+ "summarize this period",
+ "what apps did i use?",
+];
+
// Tool definitions for OpenAI format
const TOOLS: ChatCompletionTool[] = [
{
@@ -134,11 +142,19 @@ export function GlobalChat() {
const { settings } = useSettings();
const pathname = usePathname();
const { isMac } = usePlatform();
+ const { selectionRange, setSelectionRange } = useTimelineSelection();
// Only show floating button on timeline page, but keep dialog available everywhere
// pathname can be null during initial hydration
const isOnTimeline = !pathname || pathname === "/" || pathname === "/timeline";
+ // Auto-open chat when user makes a selection on timeline
+ useEffect(() => {
+ if (selectionRange && isOnTimeline) {
+ setOpen(true);
+ }
+ }, [selectionRange, isOnTimeline]);
+
const [input, setInput] = useState("");
const [messages, setMessages] = useState<Message[]>([]);
const [isLoading, setIsLoading] = useState(false);
@@ -216,8 +232,10 @@ export function GlobalChat() {
// Reset chat state when dialog closes
setMessages([]);
setInput("");
+ // Clear timeline selection when closing
+ setSelectionRange(null);
}
- }, [open]);
+ }, [open, setSelectionRange]);
// Close chat when leaving timeline
useEffect(() => {
@@ -368,9 +386,21 @@ export function GlobalChat() {
abortControllerRef.current = new AbortController();
try {
+ // Build system prompt with selection context if available
+ let systemPrompt = SYSTEM_PROMPT;
+ if (selectionRange) {
+ const startTime = selectionRange.start.toISOString();
+ const endTime = selectionRange.end.toISOString();
+ systemPrompt += `\n\nIMPORTANT: The user has selected a specific time range on their timeline. Focus your searches on this period:
+- Start time: ${startTime}
+- End time: ${endTime}
+
+Always use these exact start_time and end_time values when searching, unless the user explicitly asks about a different time period.`;
+ }
+
// Build conversation history for OpenAI format
const conversationMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
- { role: "system", content: SYSTEM_PROMPT },
+ { role: "system", content: systemPrompt },
...messages.map((m) => ({
role: m.role as "user" | "assistant",
content: m.content,
@@ -643,10 +673,40 @@ export function GlobalChat() {
{messages.length === 0 && canChat && (
<div className="text-center text-muted-foreground py-12">
<Sparkles className="h-8 w-8 mx-auto mb-3 opacity-50" />
- <p className="text-sm">Ask me anything about your screen activity!</p>
- <p className="text-xs mt-2 opacity-70">
- Try: &quot;What did I do in the last hour?&quot; or &quot;Find my Slack messages&quot;
- </p>
+ {selectionRange ? (
+ <>
+ <p className="text-sm mb-1">
+ Selected: {selectionRange.start.toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })}
+ {" - "}
+ {selectionRange.end.toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })}
+ </p>
+ <p className="text-xs opacity-70 mb-4">Ask about this time period</p>
+ <div className="flex flex-wrap gap-2 justify-center">
+ {TIMELINE_SUGGESTIONS.map((suggestion) => (
+ <button
+ key={suggestion}
+ onClick={() => {
+ setInput(suggestion);
+ setTimeout(() => {
+ const form = document.querySelector('form') as HTMLFormElement;
+ if (form) form.requestSubmit();
+ }, 50);
+ }}
+ className="px-3 py-1.5 text-xs font-mono bg-muted/50 hover:bg-muted border border-border rounded-full text-muted-foreground hover:text-foreground transition-colors"
+ >
+ {suggestion}
+ </button>
+ ))}
+ </div>
+ </>
+ ) : (
+ <>
+ <p className="text-sm">Ask me anything about your screen activity!</p>
+ <p className="text-xs mt-2 opacity-70">
+ Try: &quot;What did I do in the last hour?&quot; or &quot;Find my Slack messages&quot;
+ </p>
+ </>
+ )}
</div>
)}
{messages.map((message) => (
diff --git a/screenpipe-app-tauri/components/rewind/timeline.tsx b/screenpipe-app-tauri/components/rewind/timeline.tsx
index c6d23b162..2f3d39e57 100644
--- a/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -2,10 +2,8 @@
import { useEffect, useState, useRef, useMemo, useCallback } from "react";
import { Loader2, RotateCcw, AlertCircle } from "lucide-react";
import { AudioTranscript } from "@/components/rewind/timeline/audio-transcript";
-import { AIPanel } from "@/components/rewind/timeline/ai-panel";
import { TimelineProvider } from "@/lib/hooks/use-timeline-selection";
import { throttle } from "lodash";
-import { AGENTS } from "@/components/rewind/timeline/agents";
import { TimelineControls } from "@/components/rewind/timeline/timeline-controls";
import { addDays, isAfter, isSameDay, subDays } from "date-fns";
import { getStartDate } from "@/lib/actions/get-start-date";
@@ -61,10 +59,8 @@ const easeOutCubic = (x: number): number => {
export default function Timeline() {
const [currentIndex, setCurrentIndex] = useState(0);
- const [isAiPanelExpanded, setIsAiPanelExpanded] = useState(false);
const [showAudioTranscript, setShowAudioTranscript] = useState(true);
const containerRef = useRef<HTMLDivElement | null>(null);
- const [aiPanelPosition, setAiPanelPosition] = useState({ x: 0, y: 0 });
// const [searchResults, setSearchResults] = useState<number[]>([]);
const [startAndEndDates, setStartAndEndDates] = useState<TimeRange>({
// Default to 1 year ago so navigation works even if getStartDate fails
@@ -120,13 +116,6 @@ export default function Timeline() {
getStartDateAndSet();
}, []);
- useEffect(() => {
- setAiPanelPosition({
- x: window.innerWidth - 400,
- y: window.innerHeight / 4,
- });
- }, []);
-
useEffect(() => {
let currentDateEffect = new Date(currentDate);
const checkIfThereAreFrames = async () => {
@@ -527,18 +516,6 @@ export default function Timeline() {
)}
</div>
- <AIPanel
- position={aiPanelPosition}
- onPositionChange={setAiPanelPosition}
- onClose={() => {
- setIsAiPanelExpanded(false);
- }}
- frames={frames}
- agents={AGENTS}
- isExpanded={isAiPanelExpanded}
- onExpandedChange={setIsAiPanelExpanded}
- />
-
{/* Scroll Indicator */}
<div className="fixed left-6 top-1/2 -translate-y-1/2 text-xs text-foreground z-40">
<div className="flex flex-col items-center gap-1 bg-card rounded-full p-2 border border-border">
diff --git a/screenpipe-app-tauri/lib/hooks/use-timeline-selection.tsx b/screenpipe-app-tauri/lib/hooks/use-timeline-selection.tsx
index 3ada436d1..5387e333e 100644
--- a/screenpipe-app-tauri/lib/hooks/use-timeline-selection.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-timeline-selection.tsx
@@ -1,36 +1,22 @@
-import { createContext, useContext, useState, ReactNode } from "react";
+import { create } from "zustand";
+import { ReactNode } from "react";
interface TimelineSelection {
start: Date;
end: Date;
- frameIds: string[];
}
-interface TimelineContextType {
+interface TimelineSelectionStore {
selectionRange: TimelineSelection | null;
setSelectionRange: (range: TimelineSelection | null) => void;
}
-const TimelineContext = createContext<TimelineContextType | null>(null);
+export const useTimelineSelection = create<TimelineSelectionStore>((set) => ({
+ selectionRange: null,
+ setSelectionRange: (range) => set({ selectionRange: range }),
+}));
+// Keep the provider for backwards compatibility, but it's now a no-op wrapper
export function TimelineProvider({ children }: { children: ReactNode }) {
- const [selectionRange, setSelectionRange] =
- useState<TimelineSelection | null>(null);
-
- return (
- <TimelineContext.Provider value={{ selectionRange, setSelectionRange }}>
- {children}
- </TimelineContext.Provider>
- );
-}
-
-export function useTimelineSelection() {
- const context = useContext(TimelineContext);
- if (!context) {
- throw new Error(
- "useTimelineSelection must be used within a TimelineProvider",
- );
- }
- return context;
+ return <>{children}</>;
}
-