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: api is now authenticated
Louis Beaumontdb1cef576361
diff --git a/pipes/search/bun.lockb b/pipes/search/bun.lockbindex 72144bfcc..ab47763d5 100755Binary files a/pipes/search/bun.lockb and b/pipes/search/bun.lockb differdiff --git a/pipes/search/package.json b/pipes/search/package.jsonindex 36d4e8208..854e95464 100644--- a/pipes/search/package.json+++ b/pipes/search/package.json@@ -22,7 +22,7 @@"@radix-ui/react-switch": "^1.1.2","@radix-ui/react-toast": "^1.2.3","@radix-ui/react-tooltip": "^1.1.5",- "@screenpipe/js": "0.1.10-beta.18",+ "@screenpipe/js": "0.1.10-beta.20","@shadcn/ui": "^0.0.4","@tanstack/react-query": "^5.62.7","@types/js-levenshtein": "^1.1.3",diff --git a/pipes/search/src/app/api/settings/route.ts b/pipes/search/src/app/api/settings/route.tsindex 8d4a2b4fc..e26c10393 100644--- a/pipes/search/src/app/api/settings/route.ts+++ b/pipes/search/src/app/api/settings/route.ts@@ -27,6 +27,9 @@ export async function GET() {enableFrameCache: true,enableUiMonitoring: false,aiMaxContextChars: 128000,+ user: {+ token: "",+ },};try {@@ -35,6 +38,7 @@ export async function GET() {throw new Error("settingsManager not found");}const rawSettings = await settingsManager.getAll();+ console.log("rawSettings", rawSettings);return NextResponse.json(rawSettings);} catch (error) {console.error("failed to get settings:", error);diff --git a/pipes/search/src/components/search-chat.tsx b/pipes/search/src/components/search-chat.tsxindex 55bf5b7b6..eb510add1 100644--- a/pipes/search/src/components/search-chat.tsx+++ b/pipes/search/src/components/search-chat.tsx@@ -299,6 +299,7 @@ export function SearchChat() {const [speakerSearchQuery, setSpeakerSearchQuery] = useState("");+useEffect(() => {if (Object.keys(selectedSpeakers).length > 0) {setSelectedTypes({@@ -672,6 +673,9 @@ export function SearchChat() {},{signal: abortControllerRef.current.signal,+ headers: {+ Authorization: `Bearer ${settings.user?.token}`,+ },});@@ -687,6 +691,7 @@ export function SearchChat() {scrollToBottom();for await (const chunk of stream) {+ console.log("chunk", chunk);const content = chunk.choices[0]?.delta?.content || "";fullResponse += content;// @ts-ignore@@ -697,7 +702,13 @@ export function SearchChat() {scrollToBottom();}} catch (error: any) {- if (error.toString().includes("aborted")) {+ if (error.toString().includes("unauthorized")) {+ toast({+ title: "Error",+ description: "Please sign in to use AI features",+ variant: "destructive",+ });+ } else if (error.toString().includes("aborted")) {console.log("Streaming was aborted");} else {console.error("Error generating AI response:", error);@@ -1088,6 +1099,10 @@ export function SearchChat() {location.reload();// 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"><div className="fixed top-4 left-4 z-50 flex items-center gap-2">@@ -1772,7 +1787,13 @@ export function SearchChat() {type="submit"className="w-12"disabled={- calculateSelectedContentLength() > MAX_CONTENT_LENGTH+ calculateSelectedContentLength() > MAX_CONTENT_LENGTH ||+ isAiDisabled+ }+ title={+ isAiDisabled+ ? "Please sign in to use AI features"+ : undefined}>{isStreaming ? (diff --git a/pipes/search/src/lib/hooks/use-settings.tsx b/pipes/search/src/lib/hooks/use-settings.tsxindex f949d6458..7c4f3a6ea 100644--- a/pipes/search/src/lib/hooks/use-settings.tsx+++ b/pipes/search/src/lib/hooks/use-settings.tsx@@ -24,6 +24,9 @@ export function useSettings() {enableFrameCache: true,enableUiMonitoring: false,aiMaxContextChars: 128000,+ user: {+ token: "",+ },};const [settings, setSettings] = useState<Settings>(defaultSettings);diff --git a/screenpipe-actions/ai-proxy/bun.lockb b/screenpipe-actions/ai-proxy/bun.lockbindex e01c5108b..a989925c4 100755Binary files a/screenpipe-actions/ai-proxy/bun.lockb and b/screenpipe-actions/ai-proxy/bun.lockb differdiff --git a/screenpipe-actions/ai-proxy/package.json b/screenpipe-actions/ai-proxy/package.jsonindex 1c585ac13..5345ba484 100644--- a/screenpipe-actions/ai-proxy/package.json+++ b/screenpipe-actions/ai-proxy/package.json@@ -15,6 +15,8 @@"wrangler": "^3.60.3"},"dependencies": {+ "@anthropic-ai/sdk": "^0.33.1",+ "@clerk/backend": "^1.21.3","langfuse-node": "^3.27.0"}}diff --git a/screenpipe-actions/ai-proxy/src/index.ts b/screenpipe-actions/ai-proxy/src/index.tsindex 58dcf53ee..c24bc71a5 100644--- a/screenpipe-actions/ai-proxy/src/index.ts+++ b/screenpipe-actions/ai-proxy/src/index.ts@@ -1,6 +1,19 @@import { DurableObject } from 'cloudflare:workers';-import { Env } from './types';import { Langfuse } from 'langfuse-node';+import { verifyToken } from '@clerk/backend';+import { Anthropic } from '@anthropic-ai/sdk';++async function verifyClerkToken(env: Env, token: string): Promise<boolean> {+ try {+ const payload = await verifyToken(token, {+ secretKey: env.CLERK_SECRET_KEY,+ });+ return !!payload.sub;+ } catch (error) {+ console.error('clerk verification failed:', error);+ return false;+ }+}export class RateLimiter {private state: DurableObjectState;@@ -115,6 +128,27 @@ export default {const url = new URL(request.url);const path = url.pathname;+ // Add auth check for protected routes+ if (path !== '/test') {+ const authHeader = request.headers.get('Authorization');+ if (!authHeader?.startsWith('Bearer ')) {+ return new Response(JSON.stringify({ error: 'unauthorized' }), {+ status: 401,+ headers: corsHeaders,+ });+ }++ const token = authHeader.split(' ')[1];+ const isValid = await verifyClerkToken(env, token);++ if (!isValid) {+ return new Response(JSON.stringify({ error: 'invalid token' }), {+ status: 401,+ headers: corsHeaders,+ });+ }+ }+if (path === '/test') {return new Response('ai proxy is working!', {status: 200,@@ -131,26 +165,42 @@ export default {temperature?: number;};const isStreaming = body.stream === true;+ const isAnthropicModel = body.model.toLowerCase().includes('claude');const trace = langfuse.trace({id: 'ai_call_' + Date.now(),name: 'ai_call',- metadata: { expectJson: body.response_format?.type === 'json_object', streaming: isStreaming },+ metadata: {+ expectJson: body.response_format?.type === 'json_object',+ streaming: isStreaming,+ provider: isAnthropicModel ? 'anthropic' : 'openai',+ },});const generation = trace.generation({- name: 'openai_completion',- startTime: new Date(),+ name: 'completion',model: body.model,modelParameters: {temperature: body.temperature,- expectJson: body.response_format?.type === 'json_object',streaming: isStreaming,},- input: body.messages,- output: null,+ input: JSON.stringify(body.messages),});+ // Convert messages to Anthropic format if needed+ const anthropicMessages = isAnthropicModel+ ? {+ messages: body.messages.map((msg) => ({+ role: msg.role === 'user' ? 'user' : 'assistant',+ content: msg.content,+ })),+ model: body.model,+ stream: isStreaming,+ temperature: body.temperature,+ max_tokens: 8192,+ }+ : null;+if (isStreaming) {const { readable, writable } = new TransformStream();const writer = writable.getWriter();@@ -158,29 +208,66 @@ export default {ctx.waitUntil((async () => {try {- const openaiResponse = await fetch('https://api.openai.com/v1/chat/completions', {- method: 'POST',- headers: {- Authorization: `Bearer ${env.OPENAI_API_KEY}`,- 'Content-Type': 'application/json',- },- body: JSON.stringify(body),- });-- if (!openaiResponse.ok) {- const errorData = await openaiResponse.json();- throw new Error(`OpenAI API error: ${JSON.stringify(errorData)}`);- }-- const reader = openaiResponse.body?.getReader();- if (!reader) {- throw new Error('Failed to get reader from OpenAI response');- }-- while (true) {- const { done, value } = await reader.read();- if (done) break;- await writer.write(value);+ if (isAnthropicModel) {+ const anthropic = new Anthropic({+ apiKey: env.ANTHROPIC_API_KEY,+ });++ try {+ const stream = await anthropic.messages.create({+ messages: body.messages.map(msg => ({+ role: msg.role === 'user' ? 'user' : 'assistant',+ content: msg.content,+ })),+ model: body.model,+ stream: true,+ max_tokens: 4096,+ })++ for await (const chunk of stream) {+ if (chunk.type === 'content_block_delta' && chunk.delta?.type === 'text_delta') {+ const openaiChunk = {+ choices: [{+ delta: {+ content: chunk.delta.text+ }+ }]+ };+ await writer.write(new TextEncoder().encode(`data: ${JSON.stringify(openaiChunk)}\n\n`));+ }+ }++ await writer.write(new TextEncoder().encode('data: [DONE]\n\n'));+ } catch (error) {+ console.error('Error in Anthropic stream:', error);+ throw error;+ }+ } else {+ // Original OpenAI format - keep the fetch call only for OpenAI+ const apiResponse = await fetch('https://api.openai.com/v1/chat/completions', {+ method: 'POST',+ headers: {+ Authorization: `Bearer ${env.OPENAI_API_KEY}`,+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify(body),+ });++ if (!apiResponse.ok) {+ const errorData = await apiResponse.json();+ throw new Error(`API error: ${JSON.stringify(errorData)}`);+ }++ const reader = apiResponse.body?.getReader();+ if (!reader) {+ throw new Error('Failed to get reader from API response');+ }++ while (true) {+ const { done, value } = await reader.read();+ if (done) break;+ await writer.write(value);+ }}generation.end({@@ -188,7 +275,7 @@ export default {output: 'Streaming response completed',});} catch (error: any) {- console.error('Error in OpenAI stream:', error);+ console.error('Error in API stream:', error);generation.end({completionStartTime: new Date(),output: error.message,@@ -211,35 +298,58 @@ export default {} else {// Non-streaming responsetry {- const openaiResponse = await fetch('https://api.openai.com/v1/chat/completions', {- method: 'POST',- headers: {- Authorization: `Bearer ${env.OPENAI_API_KEY}`,- 'Content-Type': 'application/json',- },- body: JSON.stringify(body),- });+ const apiResponse = await fetch(+ isAnthropicModel ? 'https://api.anthropic.com/v1/messages' : 'https://api.openai.com/v1/chat/completions',+ {+ method: 'POST',+ headers: {+ ...(isAnthropicModel+ ? {+ 'x-api-key': env.ANTHROPIC_API_KEY,+ 'anthropic-version': '2023-06-01',+ }+ : {+ Authorization: `Bearer ${env.OPENAI_API_KEY}`,+ }),+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify(isAnthropicModel ? anthropicMessages : body),+ }+ );- if (!openaiResponse.ok) {- const errorData = await openaiResponse.json();- throw new Error(`OpenAI API error: ${JSON.stringify(errorData)}`);+ if (!apiResponse.ok) {+ const errorData = await apiResponse.json();+ throw new Error(`API error: ${JSON.stringify(errorData)}`);}- const data = (await openaiResponse.json()) as { choices: { message: { content: string } }[] };+ const data = (await apiResponse.json()) as { choices: { message: { content: string } }[] };++ // Normalize Anthropic response to match OpenAI format+ const normalizedResponse = isAnthropicModel+ ? {+ choices: [+ {+ message: {+ content: data.choices[0].message.content,+ },+ },+ ],+ }+ : data;generation.end({completionStartTime: new Date(),- output: data.choices[0]?.message?.content,+ output: normalizedResponse.choices[0]?.message?.content,});- return new Response(JSON.stringify(data), {+ return new Response(JSON.stringify(normalizedResponse), {headers: {...corsHeaders,'Content-Type': 'application/json',},});} catch (error: any) {- console.error('Error in OpenAI request:', error);+ console.error('Error in API request:', error);generation.end({completionStartTime: new Date(),output: error.message,@@ -328,6 +438,7 @@ interface Env {ANTHROPIC_API_KEY: string;DEEPGRAM_API_KEY: string;RATE_LIMITER: DurableObjectNamespace;+ CLERK_SECRET_KEY: string;}/*@@ -340,6 +451,7 @@ wrangler devterminal 2HOST=https://ai-proxy.i-f9f.workers.devHOST=http://localhost:8787+TOKEN=foobar (check app settings)curl $host/test@@ -347,11 +459,12 @@ curl $host/testcurl -X POST $HOST/v1/listen \-H "Content-Type: audio/wav" \-H "detect_language: en" \+ -H "Authorization: Bearer $TOKEN" \--data-binary "@./screenpipe-audio/test_data/poetic_kapil_gupta.wav"curl -X POST $HOST/v1/chat/completions \-H "Content-Type: application/json" \--H "Authorization: Bearer YOUR_API_KEY" \+-H "Authorization: Bearer $TOKEN" \-d '{"model": "gpt-4o","messages": [@@ -369,6 +482,28 @@ curl -X POST $HOST/v1/chat/completions \echo "$line" | sed 's/^data: //g' | jq -r '.choices[0].delta.content // empty' 2>/dev/nulldone | tr -d '\n'+using anthropic++curl -X POST $HOST/v1/chat/completions \+-H "Content-Type: application/json" \+-H "Authorization: Bearer $TOKEN" \+-d '{+"model": "claude-3-5-sonnet-20240620",+"messages": [+ {+ "role": "system",+ "content": "You are a helpful assistant."+ },+ {+ "role": "user",+ "content": "Tell me a short joke."+ }+],+"stream": true+}' | while read -r line; do+echo "$line" | sed 's/^data: //g' | jq -r '.choices[0].delta.content // empty' 2>/dev/null+done | tr -d '\n'+deploymentdiff --git a/screenpipe-app-tauri/components/auth.tsx b/screenpipe-app-tauri/components/auth.tsxdeleted file mode 100644index df173a086..000000000--- a/screenpipe-app-tauri/components/auth.tsx+++ /dev/null@@ -1,42 +0,0 @@-"use client";--import { invoke } from "@tauri-apps/api/core";-import { Button } from "./ui/button";-import { useEffect, useState } from "react";-import { useUser } from "@/lib/hooks/use-user";-import { Avatar, AvatarFallback } from "./ui/avatar";-import posthog from "posthog-js";-import { LogIn } from "lucide-react";--export function AuthButton() {- const { isSignedIn, user } = useUser();-- useEffect(() => {- posthog.identify(user?.id, {- email: user?.email,- });- posthog.setPersonProperties({- email: user?.email,- });- }, [isSignedIn, user]);-- const handleSignIn = async () => {- // This would typically open your auth window- await invoke("open_auth_window");- };-- return (- <div>- {isSignedIn ? (- <span className="p-2 text-sm text-muted-foreground select-none [-webkit-user-select:none]">- {user?.email}- </span>- ) : (- <div className="p-2 m-0" onClick={handleSignIn}>- <LogIn className="mr-2 h-4 w-4" />- <span>sign in</span>- </div>- )}- </div>- );-}diff --git a/screenpipe-app-tauri/components/chat-message-actions.tsx b/screenpipe-app-tauri/components/chat-message-actions.tsxdeleted file mode 100644index da312d152..000000000--- a/screenpipe-app-tauri/components/chat-message-actions.tsx+++ /dev/null@@ -1,40 +0,0 @@-"use client";--// import { type Message } from "ai";--import { Button } from "@/components/ui/button";-import { IconCheck, IconCopy } from "@/components/ui/icons";-import { useCopyToClipboard } from "@/lib/hooks/use-copy-to-clipboard";-import { cn } from "@/lib/utils";--interface ChatMessageActionsProps extends React.ComponentProps<"div"> {- message: any;-}--export function ChatMessageActions({- message,- className,- ...props-}: ChatMessageActionsProps) {- const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });-- const onCopy = () => {- if (isCopied) return;- copyToClipboard(message.content);- };-- return (- <div- className={cn(- "flex items-center justify-end transition-opacity group-hover:opacity-100 md:absolute md:-right-10 md:-top-2 md:opacity-0",- className- )}- {...props}- >- <Button variant="ghost" size="icon" onClick={onCopy}>- {isCopied ? <IconCheck /> : <IconCopy />}- <span className="sr-only">Copy message</span>- </Button>- </div>- );-}diff --git a/screenpipe-app-tauri/components/chat-message-v2.tsx b/screenpipe-app-tauri/components/chat-message-v2.tsxdeleted file mode 100644index 2dee23299..000000000--- a/screenpipe-app-tauri/components/chat-message-v2.tsx+++ /dev/null@@ -1,111 +0,0 @@-import { Message } from "ai";-import remarkGfm from "remark-gfm";-import remarkMath from "remark-math";--import { cn } from "@/lib/utils";-import { CodeBlock } from "@/components/ui/codeblock";-import { MemoizedReactMarkdown } from "@/components/markdown";-import { IconOpenAI, IconUser, IconOllama } from "@/components/ui/icons";-import { ChatMessageActions } from "@/components/chat-message-actions";-import { useSettings } from "@/lib/hooks/use-settings";-import { VideoComponent } from "./video";--export interface ChatMessageProps {- message: Message;-}--export function ChatMessage({ message, ...props }: ChatMessageProps) {- const { settings } = useSettings();-- const hasMP4File = (content: string) =>- content.trim().toLowerCase().includes(".mp4");-- if (!message?.content?.trim()) {- return null;- }-- return (- <div- className={cn("group relative mb-4 flex items-start w-full")}- {...props}- >- <div- className={cn(- "flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow",- message.role === "user"- ? "bg-background"- : "bg-primary text-primary-foreground"- )}- >- {message.role === "user" ? (- <IconUser />- ) : settings.aiUrl.includes("openai") ||- settings.aiUrl.includes("worker") ? (- <IconOpenAI />- ) : (- <>🦙</>- )}- </div>- <div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden w-[96em]">- <MemoizedReactMarkdown- className="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 w-full"- remarkPlugins={[remarkGfm, remarkMath]}- components={{- p({ children }) {- return <p className="mb-2 last:mb-0">{children}</p>;- },- a({ node, href, children, ...props }) {- const isMP4Link = href?.toLowerCase().includes(".mp4");-- if (isMP4Link && href) {- return <VideoComponent filePath={href} />;- }- return (- <a- href={href}- target="_blank"- rel="noopener noreferrer"- {...props}- >- {children}- </a>- );- },- code({ node, className, children, ...props }) {- const content = String(children).replace(/\n$/, "");- const match = /language-(\w+)/.exec(className || "");-- const isMP4File = hasMP4File(content);-- if (isMP4File || !match) {- if (isMP4File) {- return <VideoComponent filePath={content.trim()} />;- }- return (- <code- className="px-1 py-0.5 rounded-sm font-mono text-sm"- {...props}- >- {content}- </code>- );- }-- return (- <CodeBlock- key={Math.random()}- language={(match && match[1]) || ""}- value={content}- {...props}- />- );- },- }}- >- {message.content}- </MemoizedReactMarkdown>- <ChatMessageActions message={message} />- </div>- </div>- );-}diff --git a/screenpipe-app-tauri/components/example-search-cards.tsx b/screenpipe-app-tauri/components/example-search-cards.tsxdeleted file mode 100644index 588be3870..000000000--- a/screenpipe-app-tauri/components/example-search-cards.tsx+++ /dev/null@@ -1,127 +0,0 @@-import React from "react";-import { Card, CardContent } from "@/components/ui/card";-import { Search, Mail, Clock, AlertCircle } from "lucide-react";-import { Badge } from "./ui/badge";-import {- Tooltip,- TooltipContent,- TooltipProvider,- TooltipTrigger,-} from "./ui/tooltip";-import { useHealthCheck } from "@/lib/hooks/use-health-check";--export interface ExampleSearch {- title: string;- windowName?: string;- appName?: string;- limit: number;- minLength: number;- contentType: string;- startDate: Date;-}--interface ExampleSearchCardsProps {- onSelect: (example: ExampleSearch) => void;-}--const exampleSearches: ExampleSearch[] = [- {- title: "summarize last hour meeting",- contentType: "audio",- limit: 120,- minLength: 10,- startDate: new Date(Date.now() - 60 * 60 * 1000), // 1 hour ago- },- {- title: "summarize my mails",- contentType: "ocr",- windowName: "gmail",- limit: 25,- minLength: 50,- startDate: new Date(new Date().setHours(0, 0, 0, 0)), // since midnight local time- },- {- title: "time spent last hour",- contentType: "ocr",- limit: 25,- minLength: 50,- startDate: new Date(Date.now() - 60 * 60 * 1000), // 1 hour ago- },-];--export function ExampleSearchCards({ onSelect }: ExampleSearchCardsProps) {- const { health } = useHealthCheck();- const getIcon = (title: string) => {- switch (title) {- case "summarize last hour meeting":- return <Search className="mr-2 h-4 w-4" />;- case "summarize my mails":- return <Mail className="mr-2 h-4 w-4" />;- case "time spent last hour":- return <Clock className="mr-2 h-4 w-4" />;- default:- return <Search className="mr-2 h-4 w-4" />; // default icon- }- };-- const isHealthError = health?.status === "error";-- return (- <div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">- {exampleSearches.map((example, index) => (- <TooltipProvider key={index}>- <Tooltip>- <TooltipTrigger asChild>- <div- className={`relative group h-[150px] ${- isHealthError ? "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" />- <Card- className={`cursor-pointer relative bg-white dark:bg-gray-800 z-10 h-full transition-transform duration-300 ease-out ${- isHealthError ? "" : "group-hover:scale-[0.98]"- }`}- onClick={() => !isHealthError && onSelect(example)}- >- <CardContent className="p-3 flex flex-col h-full">- <div className="flex items-center mb-1">- {getIcon(example.title)}- <h3 className="text-sm font-semibold">{example.title}</h3>- </div>- <div className="flex flex-wrap gap-2 mt-2">- {example.contentType && (- <Badge>{example.contentType}</Badge>- )}- {example.windowName && (- <Badge>window: {example.windowName}</Badge>- )}- {example.appName && <Badge>app: {example.appName}</Badge>}- {example.limit && <Badge>limit: {example.limit}</Badge>}- {example.minLength && (- <Badge>min: {example.minLength}</Badge>- )}- {example.startDate && (- <Badge>- start: {example.startDate.toLocaleString()}- </Badge>- )}- </div>- </CardContent>- </Card>- </div>- </TooltipTrigger>- {isHealthError && (- <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>- </TooltipContent>- )}- </Tooltip>- </TooltipProvider>- ))}- </div>- );-}diff --git a/screenpipe-app-tauri/components/rag-example.tsx b/screenpipe-app-tauri/components/rag-example.tsxdeleted file mode 100644index 4575b88ae..000000000--- a/screenpipe-app-tauri/components/rag-example.tsx+++ /dev/null@@ -1,47 +0,0 @@-import { FC } from "react";--import { CodeBlock } from "./ui/codeblock";--const ragExample = `-const searchScreenpipe = async (query) => {- const response = await fetch(\`http://localhost:3030/search?q=\${encodeURIComponent(query)}&limit=10\`);- return response.json();-};--const generateAnswer = async (question, context) => {- const response = await fetch('https://api.openai.com/v1/chat/completions', {- method: 'POST',- headers: {- 'Content-Type': 'application/json',- 'Authorization': \`Bearer \${process.env.OPENAI_API_KEY}\`,- },- body: JSON.stringify({- model: 'gpt-4',- messages: [- { role: 'system', content: 'You are a helpful assistant.' },- { role: 'user', content: \`Question: \${question}\nContext: \${JSON.stringify(context)}\` },- ],- }),- });- const data = await response.json();- return data.choices[0].message.content;-};--const ragOverScreenpipe = async (question) => {- const searchResults = await searchScreenpipe(question);- return generateAnswer(question, searchResults);-};-`;--const RagExample: FC = () => {- return (- <div className="p-4 bg-gray-100 rounded-lg relative">- <h3 className="text-lg font-semibold mb-2">- Code to chat with your screenpipe data 👇- </h3>- <CodeBlock language="javascript" value={ragExample} />- </div>- );-};--export default RagExample;diff --git a/screenpipe-app-tauri/components/search-chat.tsx b/screenpipe-app-tauri/components/search-chat.tsxdeleted file mode 100644index 85514ac9b..000000000--- a/screenpipe-app-tauri/components/search-chat.tsx+++ /dev/null@@ -1,1887 +0,0 @@-"use client";--import React, { useEffect, useRef, useState } from "react";-import { Input } from "@/components/ui/input";-import { Button } from "@/components/ui/button";-import { Card, CardContent } from "@/components/ui/card";-import { queryScreenpipe, ContentItem } from "@/lib/screenpipe";-import { Skeleton } from "@/components/ui/skeleton";-import { Slider } from "@/components/ui/slider";-import { Switch } from "@/components/ui/switch";-import { Label } from "@/components/ui/label";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/components/ui/select";-import { Progress } from "@/components/ui/progress";-import { DateTimePicker } from "./date-time-picker";-import { Badge } from "./ui/badge";-import {- ChevronDown,- ChevronLeft,- ChevronRight,- HelpCircle,- Laptop,- Layers,- Layout,- Loader2,- Search,- Send,- Square,- Clock,- Check,- Plus,- SpeechIcon,- ChevronsUpDown,-} from "lucide-react";-import { useToast } from "./ui/use-toast";-import posthog from "posthog-js";-import { AnimatePresence, motion } from "framer-motion";-import { useSettings } from "@/lib/hooks/use-settings";-import { generateId, Message } from "ai";-import { OpenAI } from "openai";-import { ChatMessage } from "./chat-message-v2";-import { spinner } from "./spinner";-import {- Accordion,- AccordionContent,- AccordionItem,- AccordionTrigger,-} from "./ui/accordion";-import { VideoComponent } from "./video";-import {- Dialog,- DialogContent,- DialogDescription,- DialogHeader,- DialogTitle,- DialogTrigger,- DialogFooter,-} from "./ui/dialog";-import {- Tooltip,- TooltipContent,- TooltipProvider,- TooltipTrigger,-} from "./ui/tooltip";-import { Separator } from "./ui/separator";-import { ContextUsageIndicator } from "./context-usage-indicator";-import { Checkbox } from "@/components/ui/checkbox";-import { IconCode } from "@/components/ui/icons";-import { CodeBlock } from "./ui/codeblock";-import { SqlAutocompleteInput } from "./sql-autocomplete-input";-import { cn, encode, removeDuplicateSelections } from "@/lib/utils";-import { ExampleSearch, ExampleSearchCards } from "./example-search-cards";-import { useDebounce } from "@/lib/hooks/use-debounce";-import { useHealthCheck } from "@/lib/hooks/use-health-check";-import { SearchHistory } from "@/lib/types/history";-import { platform } from "@tauri-apps/plugin-os";-import {- CommandInput,- CommandList,- CommandEmpty,- CommandGroup,- CommandItem,- Command,-} from "./ui/command";-import { Speaker } from "@/lib/types";-import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";--interface SearchChatProps {- currentSearchId: string | null;- setCurrentSearchId: (searchId: string | null) => void;- onAddSearch: (searchParams: any, results: any[]) => Promise<string>;- searches: SearchHistory[];-}--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,- })),- },-];--// Add this helper function to highlight keywords in text-const highlightKeyword = (text: string, keyword: string): JSX.Element => {- if (!keyword || !text) return <>{text}</>;-- const parts = text.split(new RegExp(`(${keyword})`, "gi"));- return (- <>- {parts.map((part, i) =>- part.toLowerCase() === keyword.toLowerCase() ? (- <span- key={i}- className="bg-yellow-200 dark:bg-yellow-800 rounded px-0.5"- >- {part}- </span>- ) : (- part- )- )}- </>- );-};--// Update the getContextAroundKeyword function to return both text and positions-const getContextAroundKeyword = (- text: string,- keyword: string,- contextLength: number = 40-): string => {- if (!keyword || !text) return text;-- const index = text.toLowerCase().indexOf(keyword.toLowerCase());- if (index === -1) return text;-- const start = Math.max(0, index - contextLength);- const end = Math.min(text.length, index + keyword.length + contextLength);-- let result = text.slice(start, end);- if (start > 0) result = "..." + result;- if (end < text.length) result = result + "...";-- return result;-};--export function SearchChat({- currentSearchId,- setCurrentSearchId,- onAddSearch,- searches,-}: SearchChatProps) {- // Search state- const { health } = useHealthCheck();- const [query, setQuery] = useState("");- const [results, setResults] = useState<ContentItem[]>([]);- const [isLoading, setIsLoading] = useState(false);- const [startDate, setStartDate] = useState<Date>(- new Date(Date.now() - 24 * 3600000)- );- const [endDate, setEndDate] = useState<Date>(new Date());- const [includeFrames, setIncludeFrames] = useState(false);- const [limit, setLimit] = useState(30);- const [appName, setAppName] = useState("");- const [windowName, setWindowName] = useState("");- const [contentType, setContentType] = useState("all");- const [offset, setOffset] = useState(0);- const [totalResults, setTotalResults] = useState(0);- const { settings } = useSettings();- const [isAiLoading, setIsAiLoading] = useState(false);- const [minLength, setMinLength] = useState(50);- const [maxLength, setMaxLength] = useState(10000);- const [speakers, setSpeakers] = useState<Speaker[]>([]);- const [selectedSpeakers, setSelectedSpeakers] = useState<{- [key: number]: Speaker;- }>({});- const [openSpeakers, setOpenSpeakers] = useState(false);- // Chat state- const [chatMessages, setChatMessages] = useState<Array<Message>>([]);-- const { toast } = useToast();- const [progress, setProgress] = useState(0);-- const [floatingInput, setFloatingInput] = useState("");- const [isFloatingInputVisible, setIsFloatingInputVisible] = useState(false);-- const floatingInputRef = useRef<HTMLInputElement>(null);- const [showScrollButton, setShowScrollButton] = useState(false);-- const [isUserScrolling, setIsUserScrolling] = useState(false);- const lastScrollPosition = useRef(0);-- const MAX_CONTENT_LENGTH = settings.aiMaxContextChars;-- const [selectedResults, setSelectedResults] = useState<Set<number>>(- new Set()- );- const [similarityThreshold, setSimilarityThreshold] = useState(1);- const [hoveredResult, setHoveredResult] = useState<number | null>(null);-- const [isCurlDialogOpen, setIsCurlDialogOpen] = useState(false);-- const [isStreaming, setIsStreaming] = useState(false);- const abortControllerRef = useRef<AbortController | null>(null);-- const [selectAll, setSelectAll] = useState(true);-- const [showExamples, setShowExamples] = useState(true);-- const [hasSearched, setHasSearched] = useState(false);-- const [isFiltering, setIsFiltering] = useState(false);- const debouncedThreshold = useDebounce(similarityThreshold, 300);-- const [isQueryParamsDialogOpen, setIsQueryParamsDialogOpen] = useState(false);-- // Add state for individual content types- const [selectedTypes, setSelectedTypes] = useState({- ocr: false,- audio: false,- ui: false,- });-- // Add new state near the top with other state declarations- const [hideDeselected, setHideDeselected] = useState(false);-- const [currentPlatform, setCurrentPlatform] = useState<string | null>(null);-- const [speakerSearchQuery, setSpeakerSearchQuery] = useState("");-- useEffect(() => {- if (Object.keys(selectedSpeakers).length > 0) {- setSelectedTypes({- ocr: false,- ui: false,- audio: true,- });- }- }, [selectedSpeakers]);-- useEffect(() => {- setCurrentPlatform(platform());- }, []);-- const handleSpeakerChange = (speaker: Speaker) => {- setSelectedSpeakers((prev) => {- const newSpeakers = { ...prev, [speaker.id]: speaker };-- if (prev[speaker.id]) {- delete newSpeakers[speaker.id];- }-- return newSpeakers;- });- };-- useEffect(() => {- if (isQueryParamsDialogOpen && !speakers.length) {- loadSpeakers();- }- }, [isQueryParamsDialogOpen]);-- useEffect(() => {- loadSpeakers();- }, [speakerSearchQuery]);-- const loadSpeakers = async () => {- try {- const getSpeakers = await fetch(- `http://localhost:3030/speakers/search?name=${speakerSearchQuery}`- );- const speakers = await getSpeakers.json();- setSpeakers(speakers);- } catch (error) {- console.error("Error loading speakers:", error);- setSpeakers([]);- }- };-- // Update content type when checkboxes change- const handleContentTypeChange = (type: "ocr" | "audio" | "ui") => {- const newTypes = { ...selectedTypes, [type]: !selectedTypes[type] };- setSelectedTypes(newTypes);-- if (Object.keys(selectedSpeakers).length > 0) {- setSelectedTypes({- ocr: false,- ui: false,- audio: true,- });- }-- // Convert checkbox state to content type- if (!newTypes.ocr && !newTypes.audio && !newTypes.ui) {- setContentType("all"); // fallback to all if nothing selected- } else if (newTypes.audio && newTypes.ui && !newTypes.ocr) {- setContentType("audio+ui");- } else if (newTypes.ocr && newTypes.ui && !newTypes.audio) {- setContentType("ocr+ui");- } else if (newTypes.audio && newTypes.ocr && !newTypes.ui) {- setContentType("audio+ocr");- } else if (newTypes.audio) {- setContentType("audio");- } else if (newTypes.ocr) {- setContentType("ocr");- } else if (newTypes.ui) {- setContentType("ui"); // This was missing - single UI type- } else {- setContentType("all");- }- };-- const [selectedAgent, setSelectedAgent] = useState<Agent>(AGENTS[0]);-- useEffect(() => {- const updateDates = () => {- const now = new Date();- setEndDate(now);- // Optionally update startDate if you want to maintain a rolling time window- // setStartDate(new Date(now.getTime() - 24 * 3600000)); // 24 hours ago- };-- // Update dates immediately- updateDates();-- // Set up interval to update dates every 5 minutes- const intervalId = setInterval(updateDates, 5 * 60 * 1000);-- // Add event listener for when the page becomes visible- document.addEventListener("visibilitychange", () => {- if (!document.hidden) {- updateDates();- }- });-- // Clean up on component unmount- return () => {- clearInterval(intervalId);- document.removeEventListener("visibilitychange", updateDates);- };- }, []);-- const handleExampleSelect = async (example: ExampleSearch) => {- posthog.capture("example_search", { example: example.title });-- const newWindowName = example.windowName || "";- const newAppName = example.appName || "";- const newLimit = example.limit || limit;- const newMinLength = example.minLength || minLength;- const newContentType =- (example.contentType as "all" | "ocr" | "audio") || contentType;- const newStartDate = example.startDate;-- setWindowName(newWindowName);- setAppName(newAppName);- setLimit(newLimit);- setMinLength(newMinLength);- setContentType(newContentType);- setStartDate(newStartDate);- setShowExamples(false);-- handleSearch(0, {- windowName: newWindowName,- appName: newAppName,- limit: newLimit,- minLength: newMinLength,- contentType: newContentType,- startDate: newStartDate,- });- };-- const generateCurlCommand = () => {- const baseUrl = "http://localhost:3030";- const params = {- content_type: contentType,- limit: limit.toString(),- offset: offset.toString(),- start_time: startDate.toISOString(),- end_time: endDate.toISOString(),- min_length: minLength.toString(),- max_length: maxLength.toString(),- q: query,- app_name: appName,- window_name: windowName,- include_frames: includeFrames ? "true" : undefined,- };-- const queryParams = Object.entries(params)- .filter(([_, value]) => value !== undefined && value !== "")- .map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)- .join("&");-- return `curl "${baseUrl}/search?${queryParams}" | jq`;- };-- useEffect(() => {- if (results.length > 0) {- setSelectedResults(new Set(results.map((_, index) => index)));- setSelectAll(true);- }- }, [results]);-- useEffect(() => {- handleFilterDuplicates();- }, [debouncedThreshold, results]);-- const handleFilterDuplicates = async () => {- if (similarityThreshold === 1) {- setSelectedResults(new Set(results.map((_, index) => index)));- setSelectAll(true);- return;- }- setIsFiltering(true);- // simulate a delay to show loading state- await new Promise((resolve) => setTimeout(resolve, 100));-- const allIndices = new Set(results.map((_, index) => index));- setSelectedResults(- removeDuplicateSelections(results, allIndices, debouncedThreshold)- );- setSelectAll(false);- setIsFiltering(false);- };-- useEffect(() => {- const handleScroll = () => {- const currentScrollPosition = window.scrollY;- const scrollPercentage =- (currentScrollPosition /- (document.documentElement.scrollHeight - window.innerHeight)) *- 100;- const shouldShow = scrollPercentage < 90; // Show when scrolled up more than 10%-- setShowScrollButton(shouldShow);-- // Check if user is scrolling up while AI is loading- if (isAiLoading && currentScrollPosition < lastScrollPosition.current) {- setIsUserScrolling(true);- }-- lastScrollPosition.current = currentScrollPosition;- };-- window.addEventListener("scroll", handleScroll);-- return () => window.removeEventListener("scroll", handleScroll);- }, [isAiLoading]);-- const scrollToBottom = () => {- if (!isUserScrolling) {- window.scrollTo({- top: document.documentElement.scrollHeight,- behavior: "smooth",- });- }- };-- useEffect(() => {- const handleKeyDown = (event: KeyboardEvent) => {- if (event.key === "/") {- event.preventDefault();- setIsFloatingInputVisible(true);- } else if (event.key === "Escape") {- setIsFloatingInputVisible(false);- }- };-- window.addEventListener("keydown", handleKeyDown);- return () => window.removeEventListener("keydown", handleKeyDown);- }, []);-- useEffect(() => {- if (isFloatingInputVisible && floatingInputRef.current) {- floatingInputRef.current.focus();- }- }, [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];- if (!item || !item.type) return total; // Add this check-- 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() && !isStreaming) return;-- if (isStreaming) {- handleStopStreaming();- return;- }-- scrollToBottom();-- const selectedContentLength = calculateSelectedContentLength();- if (selectedContentLength > MAX_CONTENT_LENGTH) {- toast({- title: "Content too large",- 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;- }-- // Track AI usage metrics- posthog.capture("ai_chat_usage", {- agent: selectedAgent.name,- total_chars: floatingInput.length + selectedContentLength,- });-- const userMessage = {- id: generateId(),- role: "user" as const,- content: floatingInput,- };- setChatMessages((prevMessages) => [- ...prevMessages,- userMessage,- { id: generateId(), role: "assistant", content: "" },- ]);- setFloatingInput("");- setIsAiLoading(true);-- try {- const openai = new OpenAI({- apiKey: settings.openaiApiKey,- baseURL: settings.aiUrl,- dangerouslyAllowBrowser: true,- });- console.log("openai", settings.openaiApiKey, settings.aiUrl);-- posthog.capture("ai_search", {- ai_url: settings.aiUrl,- model: settings.aiModel,- });-- const model = settings.aiModel;- const customPrompt = settings.customPrompt || "";-- const messages = [- {- role: "system" as const,- content: `You are a helpful assistant specialized as a "${- selectedAgent.name- }". ${selectedAgent.systemPrompt}- Rules:- - Current time (JavaScript Date.prototype.toString): ${new Date().toString()}- - User timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}- - User timezone offset: ${new Date().getTimezoneOffset()}- - ${customPrompt ? `Custom prompt: ${customPrompt}` : ""}- `,- },- ...chatMessages.map((msg) => ({- role: msg.role as "user" | "assistant" | "system",- content: msg.content,- })),- {- role: "user" as const,- content: `Context data: ${JSON.stringify(- selectedAgent.dataSelector(- results.filter((_, index) => selectedResults.has(index))- )- )}-- User query: ${floatingInput}`,- },- ];-- console.log("messages", messages);-- abortControllerRef.current = new AbortController();- setIsStreaming(true);-- const stream = await openai.chat.completions.create(- {- model: model,- messages: messages,- stream: true,- },- {- signal: abortControllerRef.current.signal,- }- );-- let fullResponse = "";- // @ts-ignore- setChatMessages((prevMessages) => [- ...prevMessages.slice(0, -1),- { id: generateId(), role: "assistant", content: fullResponse },- ]);-- setIsUserScrolling(false);- lastScrollPosition.current = window.scrollY;- scrollToBottom();-- for await (const chunk of stream) {- const content = chunk.choices[0]?.delta?.content || "";- fullResponse += content;- // @ts-ignore- setChatMessages((prevMessages) => [- ...prevMessages.slice(0, -1),- { id: generateId(), role: "assistant", content: fullResponse },- ]);- scrollToBottom();- }- } catch (error: any) {- if (error.toString().includes("aborted")) {- console.log("Streaming was aborted");- } else {- console.error("Error generating AI response:", error);- toast({- title: "Error",- description: "Failed to generate AI response. Please try again.",- variant: "destructive",- });- }- } finally {- setIsAiLoading(false);- setIsFloatingInputVisible(false);- setIsStreaming(false);- if (!isUserScrolling) {- scrollToBottom();- }- }- };-- const handleStopStreaming = () => {- if (abortControllerRef.current) {- abortControllerRef.current.abort();- setIsStreaming(false);- setIsAiLoading(false);- }- };-- const handleSearch = async (newOffset = 0, overrides: any = {}) => {- setHasSearched(true);- setShowExamples(false);- setIsLoading(true);- setOffset(newOffset);- setProgress(0);- setChatMessages([]);- scrollToBottom();- setResults([]);- setSimilarityThreshold(1); // Reset similarity threshold to 1-- posthog.capture("search", {- contentType: overrides.contentType || contentType,- limit: overrides.limit || limit,- offset: newOffset,- start_time: overrides.startDate?.toISOString() || startDate.toISOString(),- end_time: endDate.toISOString(),- min_length: overrides.minLength || minLength,- max_length: maxLength,- speaker_ids:- Object.keys(selectedSpeakers).length > 0- ? Object.keys(selectedSpeakers).length- : undefined,- });-- try {- const searchParams = {- q: query || undefined,- content_type: overrides.contentType || contentType,- limit: overrides.limit || limit,- offset: newOffset,- start_time:- overrides.startDate?.toISOString() || startDate.toISOString(),- end_time: endDate.toISOString(),- app_name: overrides.appName || appName || undefined,- window_name: overrides.windowName || windowName || undefined,- include_frames: includeFrames,- min_length: overrides.minLength || minLength,- max_length: maxLength,- speaker_ids:- Object.keys(selectedSpeakers).length > 0- ? Object.keys(selectedSpeakers).join(",")- : undefined,- };-- const response = await queryScreenpipe(searchParams);-- // Add debug logging- console.log("search response:", response);-- if (!response || !Array.isArray(response.data)) {- throw new Error("invalid response data");- }-- setResults(response.data);- setTotalResults(response.pagination.total);-- // Save search to history- // await onAddSearch(searchParams, response.data);- } catch (error) {- console.error("search error:", error);- toast({- title: "error",- description: "failed to fetch search results. please try again.",- variant: "destructive",- });- setResults([]);- setTotalResults(0);- } finally {- setIsLoading(false);- }- };-- const handleNextPage = () => {- if (offset + limit < totalResults) {- handleSearch(offset + limit);- }- };-- const handlePrevPage = () => {- if (offset - limit >= 0) {- handleSearch(offset - limit);- }- };-- const handleBadgeClick = (value: string, type: "app" | "window") => {- if (type === "app") {- setAppName(value);- } else {- setWindowName(value);- }- };-- const handleSelectAll = (checked: boolean) => {- setSelectAll(checked);- if (checked) {- setSelectedResults(new Set(results.map((_, index) => index)));- } else {- setSelectedResults(new Set());- }- };-- const handleQuickTimeFilter = (minutes: number) => {- const now = new Date();- const newStartDate = new Date(now.getTime() - minutes * 60000);- setStartDate(newStartDate);- setEndDate(now);- };-- const renderSearchResults = () => {- if (isLoading) {- return Array(3)- .fill(0)- .map((_, index) => (- <Card key={index}>- <CardContent className="p-4">- <Skeleton className="h-4 w-1/4 mb-2" />- <Skeleton className="h-4 w-full mb-2" />- <Skeleton className="h-4 w-full mb-2" />- <Skeleton className="h-4 w-3/4" />- </CardContent>- </Card>- ));- }-- if (hasSearched && results.length === 0) {- return <p className="text-center">no results found</p>;- }-- if (!hasSearched || results.length === 0) {- return null;- }-- // First filter results based on hideDeselected setting- const visibleResults = results- .map((item, index) => ({ item, originalIndex: index }))- .filter(- ({ originalIndex }) =>- !hideDeselected || selectedResults.has(originalIndex)- );-- return visibleResults.map(({ item, originalIndex }) => (- <motion.div- key={originalIndex}- className="flex items-center mb-4 relative pl-8"- >- <div className="absolute left-0 top-1/2 transform -translate-y-1/2">- <Checkbox- checked={selectedResults.has(originalIndex)}- onCheckedChange={() => handleResultSelection(originalIndex)}- />- </div>- <Card className="w-full">- <CardContent className="p-4">- <Accordion type="single" collapsible className="w-full">- <AccordionItem value={`item-${originalIndex}`}>- <AccordionTrigger className="flex flex-col w-full py-2">- {/* Main content */}- <div className="flex w-full items-center gap-2">- <span className="text-left truncate">- {item.type === "OCR" &&- highlightKeyword(- getContextAroundKeyword(item.content.text, query),- query- )}- {item.type === "Audio" &&- highlightKeyword(- getContextAroundKeyword(- item.content.transcription,- query- ),- query- )}- {item.type === "FTS" &&- highlightKeyword(- getContextAroundKeyword(- item.content.matched_text,- query- ),- query- )}- {item.type === "UI" &&- highlightKeyword(- getContextAroundKeyword(item.content.text, query),- query- )}- </span>- </div>- </AccordionTrigger>- <AccordionContent>- {item.type === "UI" && (- <>- <div className="max-h-[400px] overflow-y-auto rounded border border-gray-100 dark:border-gray-800 p-4">- <p className="whitespace-pre-line">- {highlightKeyword(item.content.text, query)}- </p>- </div>- <div className="flex justify-center mt-4">- <VideoComponent filePath={item.content.file_path} />- </div>- <div className="flex flex-wrap items-center gap-2 mt-2">- {item.content.app_name && (- <Badge- className="text-xs cursor-pointer"- onClick={() =>- handleBadgeClick(item.content.app_name, "app")- }- >- {item.content.app_name}- </Badge>- )}- {item.content.window_name && (- <Badge- className="text-xs cursor-pointer"- onClick={() =>- handleBadgeClick(- item.content.window_name,- "window"- )- }- >- {item.content.window_name}- </Badge>- )}- </div>- </>- )}- {item.type === "OCR" && (- <>- <div className="max-h-[400px] overflow-y-auto rounded border border-gray-100 dark:border-gray-800 p-4">- <p className="whitespace-pre-line">- {highlightKeyword(item.content.text, query)}- </p>- </div>- <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>- </div>- )}- </>- )}- {item.type === "Audio" && (- <>- <div className="max-h-[400px] overflow-y-auto rounded border border-gray-100 dark:border-gray-800 p-4">- <p className="whitespace-pre-line">- {highlightKeyword(item.content.transcription, query)}- </p>- </div>- {item.content.file_path &&- item.content.file_path.trim() !== "" ? (- <div className="flex justify-center mt-4">- <VideoComponent filePath={item.content.file_path} />- </div>- ) : (- <p className="text-gray-500 italic mt-2">- no file path available for this audio.- </p>- )}- </>- )}- {item.type === "FTS" && (- <>- <div className="max-h-[400px] overflow-y-auto rounded border border-gray-100 dark:border-gray-800 p-4">- <p className="whitespace-pre-line">- {highlightKeyword(item.content.matched_text, query)}- </p>- {item.content.original_frame_text && (- <p className="mt-2 text-sm text-gray-600 dark:text-gray-400 whitespace-pre-line">- original: {item.content.original_frame_text}- </p>- )}- </div>- </>- )}- </AccordionContent>- </AccordionItem>- </Accordion>- <div className="flex flex-wrap items-center gap-2 mt-2">- <Badge variant="outline" className="text-xs">- {item.type}- </Badge>- <p className="text-xs text-gray-400">- {new Date(item.content.timestamp).toLocaleString()}{" "}- {/* Display local time */}- </p>- {item.type === "Audio" && item.content.speaker?.name && (- <p className="text-xs text-gray-400">- {item.content.speaker.name}- </p>- )}- {item.type === "OCR" && item.content.app_name && (- <div className="flex items-center gap-1">- <span className="text-xs text-muted-foreground">app:</span>- <Badge- className="text-xs cursor-pointer"- onClick={() =>- handleBadgeClick(item.content.app_name, "app")- }- >- {item.content.app_name}- </Badge>- </div>- )}- {item.type === "OCR" && item.content.window_name && (- <div className="flex items-center gap-1">- <span className="text-xs text-muted-foreground">window:</span>- <Badge- className="text-xs cursor-pointer"- onClick={() =>- handleBadgeClick(item.content.window_name, "window")- }- >- {item.content.window_name}- </Badge>- </div>- )}- {item.content.tags &&- item.content.tags.map((tag, index) => (- <Badge key={index} className="text-xs">- {tag}- </Badge>- ))}- </div>- </CardContent>- </Card>- </motion.div>- ));- };-- // Add effect to restore search when currentSearchId changes- useEffect(() => {- // if (currentSearchId) {- const selectedSearch = searches.find((s) => s.id === currentSearchId);- if (selectedSearch) {- // Restore search parameters- setQuery(selectedSearch.searchParams.q || "");- setContentType(selectedSearch.searchParams.content_type);- setLimit(selectedSearch.searchParams.limit);- setStartDate(new Date(selectedSearch.searchParams.start_time));- setEndDate(new Date(selectedSearch.searchParams.end_time));- setAppName(selectedSearch.searchParams.app_name || "");- setWindowName(selectedSearch.searchParams.window_name || "");- setIncludeFrames(selectedSearch.searchParams.include_frames);- setMinLength(selectedSearch.searchParams.min_length);- setMaxLength(selectedSearch.searchParams.max_length);-- // Restore results- setResults(selectedSearch.results);- setTotalResults(selectedSearch.results.length);- setHasSearched(true);- setShowExamples(false);-- // Restore messages if any- if (selectedSearch.messages) {- setChatMessages(- selectedSearch.messages.map((msg) => ({- id: msg.id,- role: msg.type === "ai" ? "assistant" : "user",- content: msg.content,- }))- );- }- }- // }- }, [currentSearchId, searches]);-- const handleNewSearch = () => {- // setCurrentSearchId(null);- location.reload();- // Add any other reset logic you need- };- return (- <div className="w-full max-w-4xl mx-auto p-4 mt-12">- <div className="fixed top-4 left-4 z-50 flex items-center gap-2">- {/* <SidebarTrigger className="h-8 w-8" /> */}- <Button- variant="ghost"- size="icon"- onClick={handleNewSearch}- className="h-8 w-8"- >- <Plus className="h-4 w-4" />- </Button>- </div>- {/* Content Type Checkboxes and Code Button */}- <div className="flex items-center justify-between mb-2">- <div className="flex items-center space-x-4">- <div className="flex items-center space-x-1">- <Checkbox- id="audio-type"- checked={selectedTypes.audio}- onCheckedChange={() => handleContentTypeChange("audio")}- className="h-4 w-4"- />- <Label htmlFor="audio-type" className="text-xs">- speech- </Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-3 w-3 text-muted-foreground ml-0.5" />- </TooltipTrigger>- <TooltipContent>- <p>audio transcripts</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- {currentPlatform === "macos" && (- <div className="flex items-center space-x-1">- <Checkbox- id="ui-type"- checked={selectedTypes.ui}- onCheckedChange={() => handleContentTypeChange("ui")}- className="h-4 w-4"- />- <Label htmlFor="ui-type" className="text-xs">- screen UI- </Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-3 w-3 text-muted-foreground ml-0.5" />- </TooltipTrigger>- <TooltipContent>- <p>- text emitted directly from the source code of the desktop- applications- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- )}- <div className="flex items-center space-x-1">- <Checkbox- id="ocr-type"- checked={selectedTypes.ocr}- onCheckedChange={() => handleContentTypeChange("ocr")}- className="h-4 w-4"- />- <Label htmlFor="ocr-type" className="text-xs">- screen capture- </Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-3 w-3 text-muted-foreground ml-0.5" />- </TooltipTrigger>- <TooltipContent>- <p>- recognized text from screenshots taken every 5s by default- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>-- <Dialog open={isCurlDialogOpen} onOpenChange={setIsCurlDialogOpen}>- <DialogTrigger asChild>- <Button variant="outline" className="text-sm">- <IconCode className="h-4 w-4 mx-2" />- </Button>- </DialogTrigger>- <DialogContent className="max-w-2xl">- <DialogHeader>- <DialogTitle>curl command</DialogTitle>- <DialogDescription>- you can use this curl command to make the same search request- from the command line.- <br />- <br />- <span className="text-xs text-gray-500">- note: you need to have `jq` installed to use the command.- </span>{" "}- </DialogDescription>- </DialogHeader>- <div className="overflow-x-auto">- <CodeBlock language="bash" value={generateCurlCommand()} />- </div>- </DialogContent>- </Dialog>- </div>-- {/* Existing search bar and other controls */}- <div className="flex items-center gap-4 mb-4">- {/* Keyword search - smaller width */}- <Input- type="text"- value={query}- onChange={(e) => setQuery(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter") {- handleSearch(0);- }- }}- placeholder="keyword search, you may leave it blank"- className="w-[350px]"- autoCorrect="off"- autoComplete="off"- />-- {/* Window name filter - increased width */}- <SqlAutocompleteInput- id="window-name"- type="window"- value={windowName}- onChange={setWindowName}- placeholder="filter by window"- className="w-[300px]"- icon={<Layout className="h-4 w-4" />}- />-- {/* Advanced button */}- <Button- variant="outline"- onClick={() => setIsQueryParamsDialogOpen(true)}- >- advanced- </Button>-- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <span>- <Button- onClick={() => handleSearch(0)}- disabled={isLoading || !health || health?.status === "error"}- >- {isLoading ? (- <>- <Loader2 className="mr-2 h-4 w-4 animate-spin" />- searching...- </>- ) : (- <>- <Search className="mr-2 h-4 w-4" />- search- </>- )}- </Button>- </span>- </TooltipTrigger>- {health?.status === "error" && (- <TooltipContent>- <p>screenpipe is not running...</p>- </TooltipContent>- )}- </Tooltip>- </TooltipProvider>- </div>-- <div className="flex flex-wrap items-center gap-4 mb-4">- <div className="flex-grow space-y-2">- <div className="flex items-center space-x-2">- <Label htmlFor="start-date">start date</Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400" />- </TooltipTrigger>- <TooltipContent>- <p>select the start date to search for content</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- <DateTimePicker- date={startDate}- setDate={setStartDate}- className="w-full"- />- </div>-- <div className="flex-grow space-y-2">- <div className="flex items-center space-x-2">- <Label htmlFor="end-date">end date</Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400" />- </TooltipTrigger>- <TooltipContent>- <p>select the end date to search for content</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- <DateTimePicker- date={endDate}- setDate={setEndDate}- className="w-full"- />- </div>- </div>-- <div className="flex mt-4 space-x-2 justify-center">- <Badge- variant="outline"- className="cursor-pointer hover:bg-secondary"- onClick={() => handleQuickTimeFilter(30)}- >- <Clock className="mr-2 h-4 w-4" />- last 30m- </Badge>- <Badge- variant="outline"- className="cursor-pointer hover:bg-secondary"- onClick={() => handleQuickTimeFilter(60)}- >- <Clock className="mr-2 h-4 w-4" />- last 60m- </Badge>- <Badge- variant="outline"- className="cursor-pointer hover:bg-secondary"- onClick={() => handleQuickTimeFilter(24 * 60)}- >- <Clock className="mr-2 h-4 w-4" />- last 24h- </Badge>- <Badge- variant="outline"- className="cursor-pointer hover:bg-secondary"- onClick={() => handleQuickTimeFilter(7 * 24 * 60)}- >- <Clock className="mr-2 h-4 w-4" />- last 7d- </Badge>- <Badge- variant="outline"- className="cursor-pointer hover:bg-secondary"- onClick={() => handleQuickTimeFilter(30 * 24 * 60)}- >- <Clock className="mr-2 h-4 w-4" />- last 30d- </Badge>- </div>-- <Dialog- open={isQueryParamsDialogOpen}- onOpenChange={setIsQueryParamsDialogOpen}- >- <DialogContent className="sm:max-w-[605px]">- <DialogHeader>- <DialogTitle>advanced search parameters</DialogTitle>- <DialogDescription>- adjust additional search parameters here.- </DialogDescription>- </DialogHeader>- <div className="grid gap-4 py-4">- {/* Remove the query section */}- {/* <div className="grid grid-cols-4 items-center gap-4">- <Label htmlFor="query" className="text-right">- query- </Label>- ... query input ...- </div> */}-- {/* Keep other advanced search options */}- <div className="grid grid-cols-4 items-center gap-4">- <Label htmlFor="app-name" className="text-right">- app name- </Label>- <div className="col-span-3 flex items-center">- <SqlAutocompleteInput- id="app-name"- type="app"- icon={<Laptop className="h-4 w-4" />}- value={appName}- onChange={setAppName}- placeholder="filter by app name"- className="flex-grow"- />- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>filter results by specific application names</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>- <div className="grid grid-cols-4 items-center gap-4">- <Label htmlFor="min-length" className="text-right">- min length- </Label>- <div className="col-span-3 flex items-center">- <Input- id="min-length"- type="number"- value={minLength}- onChange={(e) => setMinLength(Number(e.target.value))}- className="flex-grow"- />- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>- enter the minimum length of the content to search for- <br />- usually transcriptions are short while text extracted- from images can be long.- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>- <div className="grid grid-cols-4 items-center gap-4">- <Label htmlFor="max-length" className="text-right">- max length- </Label>- <div className="col-span-3 flex items-center">- <Input- id="max-length"- type="number"- value={maxLength}- onChange={(e) => setMaxLength(Number(e.target.value))}- className="flex-grow"- />- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>- enter the maximum length of the content to search for- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>-- <div className="grid grid-cols-4 items-center gap-4">- <Label htmlFor="limit-slider" className="text-right">- page size: {limit}- </Label>- <div className="col-span-3 flex items-center">- <Slider- id="limit-slider"- value={[limit]}- onValueChange={(value: number[]) => setLimit(value[0])}- min={10}- max={15000}- step={10}- className="flex-grow"- />- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 ml-2 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>- select the number of results to display. usually ai- cannot ingest more than 30 OCR results at a time and- 1000 audio results at a time.- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>- </div>- <div className="flex items-center justify-center space-x-2">- <Switch- id="include-frames"- checked={includeFrames}- onCheckedChange={setIncludeFrames}- />- <Label htmlFor="include-frames">include frames</Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>- include frames in the search results. this shows the frame- where the text appeared. only works for ocr. this may slow- down the search.- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- <div className="flex items-center justify-center space-x-2">- <Label htmlFor="speakers" className="flex items-center space-x-2">- <SpeechIcon className="h-4 w-4" />- <span>speakers</span>- </Label>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>- select the speakers to include in the search results. this- will only show results from the selected speakers. note:- only audio results can be returned- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- <Popover open={openSpeakers} onOpenChange={setOpenSpeakers}>- <PopoverTrigger asChild>- <Button- variant="outline"- role="combobox"- aria-expanded={openSpeakers}- className="w-full justify-between"- >- {Object.values(selectedSpeakers).length > 0- ? `${Object.values(selectedSpeakers)- .map((s) => s.name)- .join(", ")}`- : "select speakers"}- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />- </Button>- </PopoverTrigger>- <PopoverContent className="w-full p-0">- <Command>- <CommandInput- placeholder="search speakers..."- value={speakerSearchQuery}- onValueChange={setSpeakerSearchQuery}- />- <CommandList>- <CommandEmpty>no speakers found.</CommandEmpty>- <CommandGroup>- {speakers.map((speaker: Speaker) => (- <CommandItem- key={speaker.id}- value={speaker.name}- onSelect={() => handleSpeakerChange(speaker)}- >- <div className="flex items-center">- <Check- className={cn(- "mr-2 h-4 w-4",- selectedSpeakers[speaker.id]- ? "opacity-100"- : "opacity-0"- )}- />- <span- style={{- userSelect: "none",- WebkitUserSelect: "none",- MozUserSelect: "none",- msUserSelect: "none",- }}- >- {speaker.name}- </span>- </div>- </CommandItem>- ))}- </CommandGroup>- </CommandList>- </Command>- </PopoverContent>- </Popover>- </div>- <DialogFooter>- <Button onClick={() => setIsQueryParamsDialogOpen(false)}>- done- </Button>- </DialogFooter>- </DialogContent>- </Dialog>-- {isLoading ? (- <div className="my-8 flex justify-center">- <Loader2 className="h-8 w-8 animate-spin" />- </div>- ) : (- showExamples &&- results.length === 0 && (- <div className="my-8 flex justify-center">- <ExampleSearchCards onSelect={handleExampleSelect} />- </div>- )- )}- {isLoading && (- <div className="my-2">- <Progress value={progress} className="w-full" />- </div>- )}- {results.length > 0 && (- <div className="flex flex-col space-y-4 mb-4 my-8">- <div className="flex justify-between items-center">- <div className="flex items-center space-x-4">- <div className="flex items-center space-x-2">- <Checkbox- id="select-all"- checked={selectAll}- onCheckedChange={handleSelectAll}- />- <Label htmlFor="select-all">select all results</Label>- </div>-- <Separator orientation="vertical" className="h-4" />-- <div className="flex items-center space-x-2">- <Switch- id="hide-deselected"- checked={hideDeselected}- onCheckedChange={setHideDeselected}- />- <Label htmlFor="hide-deselected">hide unselected</Label>- </div>- </div>-- <div className="flex items-center space-x-2">- <Button- variant="outline"- size="sm"- onClick={() => {- setSimilarityThreshold(similarityThreshold === 0.5 ? 1 : 0.5);- if (similarityThreshold === 0.5) {- setSelectedResults(- new Set(results.map((_, index) => index))- );- setSelectAll(true);- }- }}- disabled={isFiltering}- className="flex items-center gap-2 disabled:opacity-100"- >- {isFiltering ? (- <Loader2 className="h-4 w-4 animate-spin" />- ) : similarityThreshold === 0.5 ? (- <Check className="h-4 w-4" />- ) : (- <Layers className="h-4 w-4" />- )}- {similarityThreshold === 0.5- ? "duplicates removed"- : "remove duplicates"}- </Button>-- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-gray-400 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p>automatically unselect similar or duplicate results</p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </div>- </div>- )}- <div className="space-y-4">- {renderSearchResults()}- {totalResults > 0 && (- <div className="flex justify-between items-center mt-4">- <Button- onClick={handlePrevPage}- disabled={offset === 0}- variant="outline"- size="sm"- >- <ChevronLeft className="mr-2 h-4 w-4" /> Previous- </Button>- <span className="text-sm text-gray-500">- Showing {offset + 1} - {Math.min(offset + limit, totalResults)} of{" "}- {totalResults}- </span>- <Button- onClick={handleNextPage}- disabled={offset + limit >= totalResults}- variant="outline"- size="sm"- >- Next <ChevronRight className="ml-2 h-4 w-4" />- </Button>- </div>- )}- </div>-- <AnimatePresence>- {results.length > 0 && (- <motion.div- initial={{ opacity: 0, y: 50 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 50 }}- className="fixed bottom-4 left-0 right-0 mx-auto w-full max-w-2xl z-50"- >- <form- onSubmit={handleFloatingInputSubmit}- className="flex flex-col space-y-2 bg-white dark:bg-gray-800 shadow-lg rounded-lg overflow-hidden p-4 border border-gray-200 dark:border-gray-700"- >- <div className="relative flex-grow flex items-center space-x-2">- <Input- ref={floatingInputRef}- type="text"- placeholder="ask a question about the results..."- value={floatingInput}- disabled={- calculateSelectedContentLength() > MAX_CONTENT_LENGTH- }- 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"- />-- <Select- value={selectedAgent.id}- onValueChange={(value) =>- setSelectedAgent(- AGENTS.find((a) => a.id === value) || AGENTS[0]- )- }- >- <SelectTrigger className="w-[170px] h-12">- <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>-- <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>- <span>- <ContextUsageIndicator- currentSize={calculateSelectedContentLength()}- maxSize={MAX_CONTENT_LENGTH}- />- </span>- </TooltipTrigger>- <TooltipContent>- <p>- {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>- </TooltipProvider>-- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <HelpCircle className="h-4 w-4 text-muted-foreground ml-1 cursor-help" />- </TooltipTrigger>- <TooltipContent>- <p className="text-sm">- ai models can only process a limited amount of text at- once.- <br />- this circle shows how much of that limit you arere- using.- <br />! the exclamation mark indicates when you exceed- the limit.- </p>- </TooltipContent>- </Tooltip>- </TooltipProvider>- </div>- </form>- </motion.div>- )}- </AnimatePresence>-- {results.length > 0 && <Separator className="my-8" />}-- {/* Display chat messages - Update this section */}- {(chatMessages.length > 0 || isAiLoading) && (- <>- <div className="flex flex-col items-start flex-1 max-w-2xl gap-8 px-4 mx-auto">- {chatMessages.map((msg, index) => (- <ChatMessage key={index} message={msg} />- ))}- {isAiLoading && spinner}- </div>- </>- )}-- {/* Scroll to Bottom Button */}- {showScrollButton && (- <Button- className="fixed bottom-4 right-4 rounded-full p-2"- onClick={scrollToBottom}- >- <ChevronDown className="h-6 w-6" />- </Button>- )}- {results.length > 0 && <div className="h-32" />}- </div>- );-}diff --git a/screenpipe-app-tauri/components/stripe-subscription-button.tsx b/screenpipe-app-tauri/components/stripe-subscription-button.tsxdeleted file mode 100644index 90ace975f..000000000--- a/screenpipe-app-tauri/components/stripe-subscription-button.tsx+++ /dev/null@@ -1,82 +0,0 @@-"use client";--import { Button } from "@/components/ui/button";-import { open } from "@tauri-apps/plugin-shell";-import { toast } from "./ui/use-toast";-import posthog from "posthog-js";-import { useEffect, useState } from "react";-import { useUser } from "@/lib/hooks/use-user";--interface StripeSubscriptionButtonProps {- onSubscriptionComplete?: () => void;-}--export function StripeSubscriptionButton({- onSubscriptionComplete,-}: StripeSubscriptionButtonProps) {- const { isSignedIn, user } = useUser();- const [isSubscribed, setIsSubscribed] = useState(false);-- useEffect(() => {- const checkSubscription = async () => {- if (user) {- const hasSubscription = false;- setIsSubscribed(hasSubscription);- if (hasSubscription && onSubscriptionComplete) {- onSubscriptionComplete();- }- }- };- checkSubscription();- }, [user]);-- const handleSubscribe = async () => {- posthog.capture("subscribe_button_clicked", {- email: user?.email,- });- if (!isSignedIn) {- toast({- title: "sign in required",- description: "please sign in to subscribe to the Loom pipe",- variant: "destructive",- });- return;- }-- try {- // Direct Stripe Checkout URL with price_id- const checkoutUrl = `https://buy.stripe.com/28o00JcCq2JsgAE9AX?prefilled_email=${user?.email}&client_reference_id=${user?.id}`;-- // Open Stripe checkout in default browser- await open(checkoutUrl);-- // Store subscription locally- setIsSubscribed(true);-- if (onSubscriptionComplete) {- onSubscriptionComplete();- }- } catch (error) {- console.error("failed to open stripe checkout:", error);- toast({- title: "error",- description: "failed to open subscription page. please try again.",- variant: "destructive",- });- }- };-- if (isSubscribed) {- return null;- }-- return (- <Button- onClick={handleSubscribe}- variant="outline"- className="h-8 min-w-[100px]"- >- subscribe - $10/month- </Button>- );-}diff --git a/screenpipe-js/node.ts b/screenpipe-js/node.tsindex 566cc8620..53c8422af 100644--- a/screenpipe-js/node.ts+++ b/screenpipe-js/node.ts@@ -52,6 +52,7 @@ const DEFAULT_SETTINGS: Settings = {enableFrameCache: true,enableUiMonitoring: false,aiMaxContextChars: 128000,+ user: {},};class SettingsManager {diff --git a/screenpipe-js/package.json b/screenpipe-js/package.jsonindex 4edc96a36..a69b790b8 100644--- a/screenpipe-js/package.json+++ b/screenpipe-js/package.json@@ -1,6 +1,6 @@{"name": "@screenpipe/js",- "version": "0.1.10-beta.19",+ "version": "0.1.10-beta.20","type": "module","main": "./dist/main.cjs","module": "./dist/main.js",diff --git a/screenpipe-js/types.ts b/screenpipe-js/types.tsindex 722b48536..256185488 100644--- a/screenpipe-js/types.ts+++ b/screenpipe-js/types.ts@@ -178,6 +178,18 @@ export interface EmbeddedLLMConfig {port: number;}+export interface User {+ id?: string;+ email?: string;+ name?: string;+ image?: string;+ token?: string;+ clerk_id?: string;+ credits?: {+ amount: number;+ };+}+export interface Settings {openaiApiKey: string;deepgramApiKey: string;@@ -194,6 +206,7 @@ export interface Settings {enableFrameCache: boolean;enableUiMonitoring: boolean;aiMaxContextChars: number;+ user: User;}/**