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

fix: ai & settings related update in search and reddit pipe (#1199)

tribhuwand0e10080a449
diff --git a/pipes/reddit-auto-posts/bun.lockb b/pipes/reddit-auto-posts/bun.lockb
index 88dba8326..fa1015e41 100755
Binary files a/pipes/reddit-auto-posts/bun.lockb and b/pipes/reddit-auto-posts/bun.lockb differ
diff --git a/pipes/reddit-auto-posts/components/pipe.tsx b/pipes/reddit-auto-posts/components/pipe.tsx
index 6404956a5..3a5a196df 100644
--- a/pipes/reddit-auto-posts/components/pipe.tsx
+++ b/pipes/reddit-auto-posts/components/pipe.tsx
@@ -11,6 +11,7 @@ import { useHealthCheck } from "@/lib/hooks/use-health";
import { MemoizedReactMarkdown } from "./markdown";
import { SqlAutocompleteInput } from "./sql-autocomplete-input";
import { Eye, EyeOff } from "lucide-react";
+import { useAiProvider } from "@/lib/hooks/use-ai-provider";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import {
@@ -30,6 +31,7 @@ import {
const Pipe: React.FC = () => {
const { settings, updateSettings } = useSettings();
+ const { isAvailable, error } = useAiProvider(settings);
const { isServerDown } = useHealthCheck();
const { toast } = useToast();
const [showKey, setShowKey] = useState(false);
@@ -329,18 +331,19 @@ const Pipe: React.FC = () => {
onClick={testPipe}
className="w-full border-[1.4px] shadow-sm"
variant={"outline"}
- disabled={loading || aiDisabled || isServerDown}
+ disabled={loading || aiDisabled || isServerDown || !isAvailable}
>
{loading ? "generating..." : "generate reddit questions"}
</Button>
</span>
</TooltipTrigger>
- {(aiDisabled || isServerDown) && (
+ {(aiDisabled || isServerDown || !isAvailable) && (
<TooltipContent>
- <p>{`${(aiDisabled && isServerDown) ?
+ <p>{`${(aiDisabled && isServerDown || !isAvailable) ?
"you don't have access of screenpipe-cloud and screenpipe is down!"
: isServerDown ? "screenpipe is not running..."
: aiDisabled ? "you don't have access to screenpipe-cloud :( please consider login"
+ : !isAvailable ? {error}
: ""
}
`}</p>
diff --git a/pipes/reddit-auto-posts/lib/hooks/use-ai-provider.tsx b/pipes/reddit-auto-posts/lib/hooks/use-ai-provider.tsx
new file mode 100644
index 000000000..d784a47be
--- /dev/null
+++ b/pipes/reddit-auto-posts/lib/hooks/use-ai-provider.tsx
@@ -0,0 +1,85 @@
+import { useState, useEffect } from "react";
+import type { Settings } from "@screenpipe/browser";
+
+interface AIProviderStatus {
+ isAvailable: boolean;
+ error: string;
+}
+
+export function useAiProvider(settings: Settings): AIProviderStatus {
+ const [status, setStatus] = useState<AIProviderStatus>({
+ isAvailable: true,
+ error: "",
+ });
+
+ useEffect(() => {
+ const checkAiProvider = async () => {
+ try {
+ if (!settings.aiProviderType) {
+ setStatus({ isAvailable: false, error: "no ai-provider is set" });
+ return;
+ }
+ switch (settings.aiProviderType) {
+ case "openai":
+ if (!settings.openaiApiKey) {
+ setStatus({
+ isAvailable: false,
+ error: "openai api key not configured",
+ });
+ return;
+ }
+ break;
+
+ case "native-ollama":
+ try {
+ const response = await fetch("http://localhost:11434/api/tags");
+ if (!response.ok) throw new Error();
+ } catch {
+ setStatus({
+ isAvailable: false,
+ error: "ollama not running on port 11434",
+ });
+ return;
+ }
+ break;
+
+ case "screenpipe-cloud":
+ if (!settings.user?.token) {
+ setStatus({
+ isAvailable: false,
+ error: "login required for screenpipe cloud",
+ });
+ return;
+ }
+ break;
+
+ case "custom":
+ if (!settings.aiUrl) {
+ setStatus({
+ isAvailable: false,
+ error: "custom ai url not configured",
+ });
+ return;
+ }
+ break;
+ }
+
+ setStatus({ isAvailable: true, error: "" });
+ } catch (error) {
+ setStatus({
+ isAvailable: false,
+ error: "failed to check ai provider",
+ });
+ }
+ };
+
+ checkAiProvider();
+ }, [
+ settings.aiProviderType,
+ settings.openaiApiKey,
+ settings.aiUrl,
+ settings.user?.token,
+ ]);
+
+ return status;
+}
diff --git a/pipes/reddit-auto-posts/lib/hooks/use-health.tsx b/pipes/reddit-auto-posts/lib/hooks/use-health.tsx
index d22796faf..91414255f 100644
--- a/pipes/reddit-auto-posts/lib/hooks/use-health.tsx
+++ b/pipes/reddit-auto-posts/lib/hooks/use-health.tsx
@@ -1,8 +1,6 @@
import { useState, useEffect, useCallback, useRef } from "react";
-
import { debounce } from "lodash";
-
interface HealthCheckResponse {
status: string;
status_code: number;
@@ -48,7 +46,6 @@ export function useHealthCheck() {
const healthRef = useRef(health);
const fetchHealth = useCallback(async () => {
-
try {
setIsLoading(true);
const response = await fetch("http://localhost:3030/health", {
@@ -73,31 +70,24 @@ export function useHealthCheck() {
setIsServerDown(false);
} catch (error) {
- if (error instanceof Error) {
- setIsServerDown(true);
- return;
- }
-
- 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,
diff --git a/pipes/rewind/src/lib/hooks/use-ai-provider.tsx b/pipes/rewind/src/lib/hooks/use-ai-provider.tsx
index 827efdb05..d784a47be 100644
--- a/pipes/rewind/src/lib/hooks/use-ai-provider.tsx
+++ b/pipes/rewind/src/lib/hooks/use-ai-provider.tsx
@@ -15,6 +15,10 @@ export function useAiProvider(settings: Settings): AIProviderStatus {
useEffect(() => {
const checkAiProvider = async () => {
try {
+ if (!settings.aiProviderType) {
+ setStatus({ isAvailable: false, error: "no ai-provider is set" });
+ return;
+ }
switch (settings.aiProviderType) {
case "openai":
if (!settings.openaiApiKey) {
diff --git a/pipes/search/src/components/search-chat.tsx b/pipes/search/src/components/search-chat.tsx
index 9595ac2a7..ae5d6dca2 100644
--- a/pipes/search/src/components/search-chat.tsx
+++ b/pipes/search/src/components/search-chat.tsx
@@ -9,6 +9,7 @@ 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 { useAiProvider } from "@/lib/hooks/use-ai-provider";
import {
Select,
SelectContent,
@@ -240,6 +241,7 @@ export function SearchChat() {
const [offset, setOffset] = useState(0);
const [totalResults, setTotalResults] = useState(0);
const { settings } = useSettings();
+ const { isAvailable, error } = useAiProvider(settings);
const [isAiLoading, setIsAiLoading] = useState(false);
const [minLength, setMinLength] = useState(50);
const [maxLength, setMaxLength] = useState(10000);
@@ -1137,6 +1139,7 @@ export function SearchChat() {
// 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">
@@ -1822,20 +1825,28 @@ export function SearchChat() {
</TooltipContent>
</Tooltip>
</TooltipProvider>
-
- <Input
- ref={floatingInputRef}
- type="text"
- placeholder="ask a question about the results..."
- value={floatingInput}
- disabled={
- 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"
- />
-
+ <TooltipProvider>
+ <Tooltip open={!isAvailable}>
+ <TooltipTrigger asChild>
+ <div className="flex-1">
+ <Input
+ ref={floatingInputRef}
+ type="text"
+ placeholder="ask a question about the results..."
+ value={floatingInput}
+ disabled={
+ calculateSelectedContentLength() > MAX_CONTENT_LENGTH || isAiDisabled || !isAvailable
+ }
+ 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"
+ />
+ </div>
+ </TooltipTrigger>
+ <TooltipContent side="top">
+ <p className="text-sm text-destructive">{error}</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
<Select
value={selectedAgent.id}
onValueChange={(value) =>
diff --git a/pipes/search/src/lib/hooks/use-ai-provider.tsx b/pipes/search/src/lib/hooks/use-ai-provider.tsx
new file mode 100644
index 000000000..97ead8f20
--- /dev/null
+++ b/pipes/search/src/lib/hooks/use-ai-provider.tsx
@@ -0,0 +1,85 @@
+import { useState, useEffect } from "react";
+import type { Settings } from "@screenpipe/browser";
+
+interface AIProviderStatus {
+ isAvailable: boolean;
+ error: string;
+}
+
+export function useAiProvider(settings: Settings): AIProviderStatus {
+ const [status, setStatus] = useState<AIProviderStatus>({
+ isAvailable: true,
+ error: "",
+ });
+
+ useEffect(() => {
+ const checkAiProvider = async () => {
+ try {
+ if (!settings.aiProviderType) {
+ setStatus({ isAvailable: false, error: "no ai-provider is set" });
+ return;
+ }
+ switch (settings.aiProviderType) {
+ case "openai":
+ if (!settings.openaiApiKey) {
+ setStatus({
+ isAvailable: false,
+ error: "openai api key not configured",
+ });
+ return;
+ }
+ break;
+
+ case "native-ollama":
+ try {
+ const response = await fetch("http://localhost:11434/api/tags");
+ if (!response.ok) throw new Error();
+ } catch {
+ setStatus({
+ isAvailable: false,
+ error: "ollama not running on port 11434",
+ });
+ return;
+ }
+ break;
+
+ case "screenpipe-cloud":
+ if (!settings.user?.token) {
+ setStatus({
+ isAvailable: false,
+ error: "login required for screenpipe cloud",
+ });
+ return;
+ }
+ break;
+
+ case "custom":
+ if (!settings.aiUrl || !settings.openaiApiKey) {
+ setStatus({
+ isAvailable: false,
+ error: "custom ai url not configured",
+ });
+ return;
+ }
+ break;
+ }
+
+ setStatus({ isAvailable: true, error: "" });
+ } catch (error) {
+ setStatus({
+ isAvailable: false,
+ error: "failed to check ai provider",
+ });
+ }
+ };
+
+ checkAiProvider();
+ }, [
+ settings.aiProviderType,
+ settings.openaiApiKey,
+ settings.aiUrl,
+ settings.user?.token,
+ ]);
+
+ return status;
+}