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: search pipe (#1168)
tribhuwan389a703c6f54
diff --git a/pipes/search/bun.lockb b/pipes/search/bun.lockbindex b98b19251..9c5adeea8 100755Binary files a/pipes/search/bun.lockb and b/pipes/search/bun.lockb differdiff --git a/pipes/search/src/app/layout.tsx b/pipes/search/src/app/layout.tsxindex 7fef7d66a..917144a62 100644--- a/pipes/search/src/app/layout.tsx+++ b/pipes/search/src/app/layout.tsx@@ -1,6 +1,7 @@import type { Metadata } from "next";import { Geist, Geist_Mono } from "next/font/google";import "./globals.css";+import { Toaster } from "@/components/ui/toaster";const geistSans = Geist({variable: "--font-geist-sans",@@ -29,6 +30,8 @@ export default function RootLayout({className={`${geistSans.variable} ${geistMono.variable} antialiased`}>{children}++ <Toaster /></body></html>);diff --git a/pipes/search/src/app/page.tsx b/pipes/search/src/app/page.tsxindex 74a6049d1..a3c457cd0 100644--- a/pipes/search/src/app/page.tsx+++ b/pipes/search/src/app/page.tsx@@ -1,12 +1,28 @@-// "use client";-+"use client";+import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"+import { useSettings } from "@/lib/hooks/use-settings";+import { Terminal } from "lucide-react";import { SearchChat } from "@/components/search-chat";+export default function SearchPage() {+ const { settings } = useSettings();+ const aiDisabled = settings.aiProviderType === "screenpipe-cloud" && !settings.user.token;+return (- <div className="flex flex-col gap-4 items-center justify-center h-full mt-12">- <p className="text-xl font-bold">where pixels become magic</p>+ <div className={`flex flex-col gap-4 items-center justify-center h-full ${aiDisabled ? "mt-2" : "mt-12"}`}>+ {aiDisabled &&(+ <Alert className="w-[70%] shadow-sm">+ <Terminal className="h-4 w-4" />+ <AlertTitle>heads up!</AlertTitle>+ <AlertDescription className="text-muted-foreground">+ your ai provider is set to 'screenpipe-cloud' and you don't have logged in <br/>+ please login to use this pipe, go to app > settings > login+ </AlertDescription>+ </Alert>+ )}+ <p className="text-2xl font-bold">where pixels become magic</p><SearchChat /></div>);diff --git a/pipes/search/src/components/example-search-cards.tsx b/pipes/search/src/components/example-search-cards.tsxindex c8ff98209..275a2a32f 100644--- a/pipes/search/src/components/example-search-cards.tsx+++ b/pipes/search/src/components/example-search-cards.tsx@@ -9,6 +9,7 @@ import {TooltipTrigger,} from "./ui/tooltip";import { useHealthCheck } from "@/lib/hooks/use-health-check";+import { useSettings } from "@/lib/hooks/use-settings";export interface ExampleSearch {title: string;@@ -27,6 +28,7 @@ interface ExampleSearchCardsProps {export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {const [exampleSearches, setExampleSearches] = useState<ExampleSearch[]>([]);const { health } = useHealthCheck();+ const { settings } = useSettings();useEffect(() => {setExampleSearches([@@ -68,7 +70,9 @@ export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {}};- const isHealthError = health?.status === "error";+ const isHealthError = !health || health?.status === "error";+ const isAiDisabled =+ !settings.user?.token && settings.aiProviderType === "screenpipe-cloud";return (<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">@@ -78,7 +82,7 @@ export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {<TooltipTrigger asChild><divclassName={`relative group h-[150px] ${- isHealthError ? "opacity-50 cursor-not-allowed" : ""+ (isHealthError || isAiDisabled) ? "opacity-50 cursor-not-allowed" : ""}`}><div className="absolute inset-0 rounded-lg transition-all duration-300 ease-out group-hover:before:opacity-100 group-hover:before:scale-100 before:absolute before:inset-0 before:rounded-lg before:border-2 before:border-black dark:before:border-white before:opacity-0 before:scale-95 group-hover:before:opacity-100 group-hover:before:scale-100 before:transition-all before:duration-300 before:ease-out" />@@ -115,12 +119,28 @@ export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {</Card></div></TooltipTrigger>- {isHealthError && (+ {(isHealthError || isAiDisabled) && (<TooltipContent>- <div className="flex items-center">- <AlertCircle className="mr-2 h-4 w-4 text-red-500" />- <p>screenpipe is not running. examples are disabled.</p>- </div>+ <p>+ {(isAiDisabled && isHealthError) ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ you don't have access to screenpipe-cloud, <br /> and screenpipe backend is not running!+ </>+ ) : isHealthError ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ screenpipe is not running. examples are disabled!+ </>+ ) : isAiDisabled ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ you don't have access to screenpipe-cloud :( <br/> please consider login!+ </>+ ) : (+ ""+ )}+ </p></TooltipContent>)}</Tooltip>diff --git a/pipes/search/src/components/search-chat.tsx b/pipes/search/src/components/search-chat.tsxindex 3c9de2a6c..0515ad9fa 100644--- a/pipes/search/src/components/search-chat.tsx+++ b/pipes/search/src/components/search-chat.tsx@@ -34,10 +34,11 @@ import {Clock,Check,Plus,+ AlertCircle,SpeechIcon,ChevronsUpDown,} from "lucide-react";-import { useToast } from "@/components/ui/use-toast";+import { useToast } from "@/lib/use-toast";import { AnimatePresence, motion } from "framer-motion";import { generateId, Message } from "ai";import { OpenAI } from "openai";@@ -222,7 +223,7 @@ export function SearchChat() {toggleCollapse,} = useSearchHistory();// Search state- const { health } = useHealthCheck();+ const { health, isServerDown } = useHealthCheck();const [query, setQuery] = useState("");const [results, setResults] = useState<ContentItem[]>([]);const [isLoading, setIsLoading] = useState(false);@@ -425,7 +426,18 @@ export function SearchChat() {};}, []);+ const isAiDisabled =+ !settings.user?.token && settings.aiProviderType === "screenpipe-cloud";+const handleExampleSelect = async (example: ExampleSearch) => {+ if (isAiDisabled){+ toast({+ title: "error",+ description: "your selected ai provider is screenpipe-cloud. consider login in app to use screenpipe-cloud",+ variant: "destructive",+ });+ return;+ }const newWindowName = example.windowName || "";const newAppName = example.appName || "";const newLimit = example.limit || limit;@@ -738,6 +750,15 @@ export function SearchChat() {};const handleSearch = async (newOffset = 0, overrides: any = {}) => {+ if (isAiDisabled){+ toast({+ title: "error",+ description: "your ai provider is screenpipe-cloud. consider login in app to use screenpipe-cloud",+ duration: 3000,+ variant: "destructive",+ });+ return;+ }await pipe.captureMainFeatureEvent("search", {contentType: overrides.contentType || contentType,limit: overrides.limit || limit,@@ -1113,8 +1134,6 @@ export function SearchChat() {// Add any other reset logic you need};- const isAiDisabled =- !settings.user?.token && settings.aiProviderType === "screenpipe-cloud";return (<div className="w-full max-w-4xl mx-auto p-4 mt-12">@@ -1273,7 +1292,9 @@ export function SearchChat() {<span><ButtononClick={() => handleSearch(0)}- disabled={isLoading || !health || health?.status === "error"}+ disabled={(isLoading || isAiDisabled || !health+ || health?.status === "error")}+ className="disabled:cursor-not-allowed">{isLoading ? (<>@@ -1289,9 +1310,28 @@ export function SearchChat() {</Button></span></TooltipTrigger>- {health?.status === "error" && (+ {(!health || health?.status === "error" || isAiDisabled) && (<TooltipContent>- <p>screenpipe is not running...</p>+ <p>+ {(isAiDisabled && isServerDown) ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ you don't have access to screenpipe-cloud <br /> and screenpipe server is down!+ </>+ ) : isServerDown ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ screenpipe is not running...+ </>+ ) : isAiDisabled ? (+ <>+ <AlertCircle className="mr-1 h-4 w-4 text-red-500 inline" />+ you don't have access to screenpipe-cloud :( <br/> please consider login!+ </>+ ) : (+ ""+ )}+ </p></TooltipContent>)}</Tooltip>@@ -1768,7 +1808,7 @@ export function SearchChat() {placeholder="ask a question about the results..."value={floatingInput}disabled={- calculateSelectedContentLength() > MAX_CONTENT_LENGTH+ calculateSelectedContentLength() > MAX_CONTENT_LENGTH || isAiDisabled}onChange={(e) => setFloatingInput(e.target.value)}className="flex-1 h-12 focus:outline-none focus:ring-0 border-0 focus:border-black dark:focus:border-white focus:border-b transition-all duration-200"diff --git a/pipes/search/src/components/ui/alert.tsx b/pipes/search/src/components/ui/alert.tsxnew file mode 100644index 000000000..41fa7e056--- /dev/null+++ b/pipes/search/src/components/ui/alert.tsx@@ -0,0 +1,59 @@+import * as React from "react"+import { cva, type VariantProps } from "class-variance-authority"++import { cn } from "@/lib/utils"++const alertVariants = cva(+ "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",+ {+ variants: {+ variant: {+ default: "bg-background text-foreground",+ destructive:+ "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",+ },+ },+ defaultVariants: {+ variant: "default",+ },+ }+)++const Alert = React.forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>+>(({ className, variant, ...props }, ref) => (+ <div+ ref={ref}+ role="alert"+ className={cn(alertVariants({ variant }), className)}+ {...props}+ />+))+Alert.displayName = "Alert"++const AlertTitle = React.forwardRef<+ HTMLParagraphElement,+ React.HTMLAttributes<HTMLHeadingElement>+>(({ className, ...props }, ref) => (+ <h5+ ref={ref}+ className={cn("mb-1 font-medium leading-none tracking-tight", className)}+ {...props}+ />+))+AlertTitle.displayName = "AlertTitle"++const AlertDescription = React.forwardRef<+ HTMLParagraphElement,+ React.HTMLAttributes<HTMLParagraphElement>+>(({ className, ...props }, ref) => (+ <div+ ref={ref}+ className={cn("text-sm [&_p]:leading-relaxed", className)}+ {...props}+ />+))+AlertDescription.displayName = "AlertDescription"++export { Alert, AlertTitle, AlertDescription }diff --git a/pipes/search/src/components/ui/toaster.tsx b/pipes/search/src/components/ui/toaster.tsxindex fe7103d70..813223577 100644--- a/pipes/search/src/components/ui/toaster.tsx+++ b/pipes/search/src/components/ui/toaster.tsx@@ -1,6 +1,6 @@"use client"-import { useToast } from "@/components/ui/use-toast"+import { useToast } from "@/lib/use-toast"import {Toast,ToastClose,diff --git a/pipes/search/src/lib/hooks/use-health-check.tsx b/pipes/search/src/lib/hooks/use-health-check.tsxindex 8d32570d0..e076837b9 100644--- a/pipes/search/src/lib/hooks/use-health-check.tsx+++ b/pipes/search/src/lib/hooks/use-health-check.tsx@@ -1,8 +1,6 @@import { useState, useEffect, useCallback, useRef } from "react";-import { debounce } from "lodash";-interface HealthCheckResponse {status: string;status_code: number;@@ -45,21 +43,13 @@ export function useHealthCheck() {const [health, setHealth] = useState<HealthCheckResponse | null>(null);const [isServerDown, setIsServerDown] = useState(false);const [isLoading, setIsLoading] = useState(false);- const abortControllerRef = useRef<AbortController | null>(null);const healthRef = useRef(health);const fetchHealth = useCallback(async () => {- if (abortControllerRef.current) {- abortControllerRef.current.abort();- }-- abortControllerRef.current = new AbortController();-try {setIsLoading(true);const response = await fetch("http://localhost:3030/health", {cache: "no-store",- signal: abortControllerRef.current.signal,headers: {"Cache-Control": "no-cache",Pragma: "no-cache",@@ -67,6 +57,7 @@ export function useHealthCheck() {});if (!response.ok) {+ setIsServerDown(true);throw new Error(`HTTP error! status: ${response.status}`);}@@ -79,31 +70,24 @@ export function useHealthCheck() {setIsServerDown(false);} catch (error) {- if (error instanceof Error && error.name === "AbortError") {- return;- }-- // console.error("Health check error:", error);- if (!isServerDown) {- setIsServerDown(true);- const errorHealth: HealthCheckResponse = {- last_frame_timestamp: null,- last_audio_timestamp: null,- last_ui_timestamp: null,- frame_status: "error",- audio_status: "error",- ui_status: "error",- status: "error",- status_code: 500,- message: "Failed to fetch health status. Server might be down.",- };- setHealth(errorHealth);- healthRef.current = errorHealth;- }+ setIsServerDown(true);+ const errorHealth: HealthCheckResponse = {+ last_frame_timestamp: null,+ last_audio_timestamp: null,+ last_ui_timestamp: null,+ frame_status: "error",+ audio_status: "error",+ ui_status: "error",+ status: "error",+ status_code: 500,+ message: "Failed to fetch health status. Server might be down.",+ };+ setHealth(errorHealth);+ healthRef.current = errorHealth;} finally {setIsLoading(false);}- }, [isServerDown, setIsLoading]);+ }, []);const debouncedFetchHealth = useCallback(debounce(fetchHealth, 200), [fetchHealth,@@ -111,13 +95,10 @@ export function useHealthCheck() {useEffect(() => {fetchHealth();- const interval = setInterval(fetchHealth, 1000);+ const interval = setInterval(fetchHealth, 2000);return () => {clearInterval(interval);- if (abortControllerRef.current) {- abortControllerRef.current.abort();- }};}, [fetchHealth]);@@ -129,3 +110,4 @@ export function useHealthCheck() {debouncedFetchHealth,} as HealthCheckHook;}+diff --git a/pipes/search/src/components/ui/use-toast.ts b/pipes/search/src/lib/use-toast.tssimilarity index 100%rename from pipes/search/src/components/ui/use-toast.tsrename to pipes/search/src/lib/use-toast.ts