Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

refactor

matthew-heartfulee03dbc866ac
diff --git a/pipes/example-pipe/components/health-status.tsx b/pipes/example-pipe/components/health-status.tsx
deleted file mode 100644
index 5796a38d2..000000000
--- a/pipes/example-pipe/components/health-status.tsx
+++ /dev/null
@@ -1,209 +0,0 @@
-"use client";
-
-import { useState, useEffect, useCallback } from "react";
-import { Button } from "@/components/ui/button";
-import { RefreshCw, CheckCircle, AlertTriangle, XCircle } from "lucide-react";
-import { motion } from "framer-motion";
-import { Badge } from "@/components/ui/badge";
-
-export function HealthStatus({ onHealthDataChange }: { onHealthDataChange?: (data: any, error: string | null) => void }) {
- const [health, setHealth] = useState<any>(null);
- const [loading, setLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
-
- // Wrap fetchHealth in useCallback to prevent unnecessary re-renders
- const fetchHealth = useCallback(async () => {
- try {
- setLoading(true);
- setError(null);
- console.log("fetching health data...");
-
- // Capture the start time for logging
- const startTime = performance.now();
- const response = await fetch("http://localhost:3030/health");
- const endTime = performance.now();
- console.log(`health request completed in ${(endTime - startTime).toFixed(2)}ms`);
-
- if (!response.ok) {
- throw new Error(`health api returned ${response.status}`);
- }
-
- const data = await response.json();
- console.log("health data received:", data);
- setHealth(data);
-
- // Notify parent component about the new health data
- if (onHealthDataChange) {
- onHealthDataChange(data, null);
- }
- } catch (err) {
- console.error("error fetching health data:", err);
- const errorMsg = err instanceof Error ? err.message : "unknown error occurred";
- setError(errorMsg);
-
- // Notify parent component about the error
- if (onHealthDataChange) {
- onHealthDataChange(null, errorMsg);
- }
- } finally {
- setLoading(false);
- }
- }, [onHealthDataChange]);
-
- // Fetch health data when component mounts
- useEffect(() => {
- console.log("component mounted, fetching initial health data");
- fetchHealth();
- // Remove fetchHealth from the dependency array to prevent re-fetching on every render
- }, []); // Empty dependency array - only run on mount
-
- // Add a separate effect to handle changes to onHealthDataChange if needed
- useEffect(() => {
- console.log("health data callback changed");
- // Only re-fetch if the callback changes and we already have data
- if (health) {
- onHealthDataChange?.(health, null);
- }
- }, [onHealthDataChange, health]);
-
- // Helper function to determine status icon and color
- const getStatusInfo = (status: string) => {
- switch(status?.toLowerCase()) {
- case "healthy":
- case "ok":
- case "up":
- case "running":
- return { icon: <CheckCircle className="h-5 w-5" />, color: "text-green-500", bg: "bg-green-50" };
- case "warning":
- case "degraded":
- return { icon: <AlertTriangle className="h-5 w-5" />, color: "text-amber-500", bg: "bg-amber-50" };
- case "error":
- case "down":
- case "critical":
- return { icon: <XCircle className="h-5 w-5" />, color: "text-red-500", bg: "bg-red-50" };
- default:
- return { icon: <AlertTriangle className="h-5 w-5" />, color: "text-slate-500", bg: "bg-slate-50" };
- }
- };
-
- return (
- <div className="w-full max-w-2xl">
- <div className="flex items-center justify-between mb-4">
- <h2 className="text-lg font-medium">system health</h2>
- <Button
- variant="outline"
- size="sm"
- onClick={fetchHealth}
- disabled={loading}
- >
- <RefreshCw className={`h-4 w-4 mr-2 ${loading ? "animate-spin" : ""}`} />
- {health ? "refresh" : "fetch health data"}
- </Button>
- </div>
-
- {error && (
- <motion.div
- initial={{ opacity: 0, y: -10 }}
- animate={{ opacity: 1, y: 0 }}
- className="p-4 mb-4 border border-red-300 bg-red-50 text-red-700 rounded-md"
- >
- {error}
- </motion.div>
- )}
-
- {loading && (
- <motion.div
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- className="p-4 border rounded-md animate-pulse bg-slate-100"
- >
- loading health data...
- </motion.div>
- )}
-
- {health && !loading && (
- <motion.div
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.3 }}
- className="space-y-4"
- >
- {/* Overall status */}
- {health.status && (
- <motion.div
- className={`p-4 rounded-md flex items-center ${getStatusInfo(health.status).bg}`}
- initial={{ scale: 0.95 }}
- animate={{ scale: 1 }}
- transition={{ type: "spring", stiffness: 200 }}
- >
- <div className={`mr-3 ${getStatusInfo(health.status).color}`}>
- {getStatusInfo(health.status).icon}
- </div>
- <div>
- <div className="font-medium">overall status</div>
- <div className={`${getStatusInfo(health.status).color}`}>{health.status}</div>
- </div>
- </motion.div>
- )}
-
- {/* Services/Components */}
- {health.services && (
- <motion.div
- className="bg-white rounded-md border overflow-hidden"
- initial={{ y: 20, opacity: 0 }}
- animate={{ y: 0, opacity: 1 }}
- transition={{ delay: 0.1 }}
- >
- <div className="p-3 border-b bg-slate-50">
- <h3 className="font-medium">services</h3>
- </div>
- <div className="divide-y">
- {Object.entries(health.services).map(([name, info]: [string, any], index) => (
- <motion.div
- key={name}
- className="p-3 flex items-center justify-between"
- initial={{ opacity: 0, x: -10 }}
- animate={{ opacity: 1, x: 0 }}
- transition={{ delay: 0.1 + (index * 0.05) }}
- >
- <div className="flex items-center">
- <div className={`mr-3 ${getStatusInfo(info.status).color}`}>
- {getStatusInfo(info.status).icon}
- </div>
- <div>{name}</div>
- </div>
- <Badge variant={info.status === "healthy" ? "outline" : "destructive"}>
- {info.status}
- </Badge>
- </motion.div>
- ))}
- </div>
- </motion.div>
- )}
-
- {/* System Info */}
- {health.system && (
- <motion.div
- className="bg-white rounded-md border overflow-hidden"
- initial={{ y: 20, opacity: 0 }}
- animate={{ y: 0, opacity: 1 }}
- transition={{ delay: 0.2 }}
- >
- <div className="p-3 border-b bg-slate-50">
- <h3 className="font-medium">system info</h3>
- </div>
- <div className="p-3 grid grid-cols-2 gap-2 text-sm">
- {Object.entries(health.system).map(([key, value]: [string, any]) => (
- <div key={key} className="flex justify-between">
- <span className="text-slate-500">{key}:</span>
- <span className="font-mono">{value?.toString()}</span>
- </div>
- ))}
- </div>
- </motion.div>
- )}
- </motion.div>
- )}
- </div>
- );
-}
\ No newline at end of file
diff --git a/pipes/example-pipe/components/last-ocr-image.tsx b/pipes/example-pipe/components/last-ocr-image.tsx
deleted file mode 100644
index 69384d5df..000000000
--- a/pipes/example-pipe/components/last-ocr-image.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-"use client";
-
-import { useState } from "react";
-import { pipe, type OCRContent, type ContentItem } from "@screenpipe/browser";
-import { Button } from "@/components/ui/button";
-import { Loader2 } from "lucide-react";
-
-export function LastOcrImage() {
- const [ocrData, setOcrData] = useState<OCRContent | null>(null);
- const [isLoading, setIsLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
-
- const fetchLatestOCR = async () => {
- setIsLoading(true);
- setError(null);
- try {
- console.log("fetching latest ocr...");
- const result = await pipe.queryScreenpipe({
- contentType: "ocr",
- limit: 1,
- });
-
- if (!result || !result.data || result.data.length === 0) {
- console.log("no ocr data found");
- setError("No OCR data available");
- return;
- }
-
- const item = result.data[0] as ContentItem & { type: "OCR" };
- console.log("got ocr data:", item.content);
- setOcrData(item.content);
- } catch (error) {
- console.error("error fetching ocr:", error);
- setError("Failed to fetch OCR data");
- } finally {
- setIsLoading(false);
- }
- };
-
- return (
- <div className="space-y-4">
- <Button
- onClick={fetchLatestOCR}
- disabled={isLoading}
- >
- {isLoading ? (
- <>
- <Loader2 className="mr-2 h-4 w-4 animate-spin" />
- Fetching...
- </>
- ) : (
- 'Fetch Latest OCR'
- )}
- </Button>
-
- {error && (
- <p className="text-sm text-red-500">{error}</p>
- )}
-
- {ocrData && (
- <pre className="p-4 bg-slate-100 rounded-lg overflow-auto max-h-[400px]">
- {JSON.stringify(ocrData, null, 2)}
- </pre>
- )}
- </div>
- );
-}
diff --git a/pipes/example-pipe/components/last-ui-record.tsx b/pipes/example-pipe/components/last-ui-record.tsx
deleted file mode 100644
index d6052900c..000000000
--- a/pipes/example-pipe/components/last-ui-record.tsx
+++ /dev/null
@@ -1,95 +0,0 @@
-"use client";
-
-import { useEffect, useState } from "react";
-import { pipe } from "@screenpipe/browser";
-import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
-import { UiContent } from "@screenpipe/browser";
-import { Skeleton } from "@/components/ui/skeleton";
-
-export function LastUiRecord() {
- const [loading, setLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
- const [uiRecord, setUiRecord] = useState<UiContent | null>(null);
-
- async function fetchLatestUiRecord() {
- try {
- console.log("fetching latest ui record...");
- setLoading(true);
- setError(null);
-
- const response = await pipe.queryScreenpipe({
- contentType: "ui",
- limit: 1,
- // Sort by most recent
- offset: 0,
- });
-
- console.log("ui record response:", response);
-
- if (response && response.data.length > 0 && response.data[0].type === "UI") {
- setUiRecord(response.data[0].content);
- } else {
- console.log("no ui records found");
- setError("No UI records found");
- }
- } catch (err) {
- console.error("error fetching ui record:", err);
- setError(`Failed to fetch UI record: ${err instanceof Error ? err.message : String(err)}`);
- } finally {
- setLoading(false);
- }
- }
-
- return (
- <Card className="w-full max-w-md">
- <CardHeader>
- <CardTitle className="text-lg">latest ui record</CardTitle>
- </CardHeader>
- <CardContent>
- <div className="mb-4">
- <button
- onClick={fetchLatestUiRecord}
- className="w-full py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors"
- disabled={loading}
- >
- {loading ? "fetching..." : "fetch latest ui record"}
- </button>
- </div>
-
- {loading ? (
- <div className="space-y-2">
- <Skeleton className="h-4 w-full" />
- <Skeleton className="h-4 w-3/4" />
- <Skeleton className="h-4 w-1/2" />
- </div>
- ) : error ? (
- <div className="text-red-500">{error}</div>
- ) : uiRecord ? (
- <div className="space-y-2">
- <div className="grid grid-cols-3 gap-1">
- <span className="text-muted-foreground">app:</span>
- <span className="col-span-2 font-mono text-sm">{uiRecord.appName}</span>
-
- <span className="text-muted-foreground">window:</span>
- <span className="col-span-2 font-mono text-sm">{uiRecord.windowName}</span>
-
- <span className="text-muted-foreground">time:</span>
- <span className="col-span-2 font-mono text-sm">
- {new Date(uiRecord.timestamp).toLocaleTimeString()}
- </span>
- </div>
-
- <div className="mt-2">
- <span className="text-muted-foreground">text:</span>
- <div className="mt-1 p-2 bg-muted rounded-md font-mono text-xs overflow-auto max-h-24">
- {uiRecord.text}
- </div>
- </div>
- </div>
- ) : (
- <div className="text-muted-foreground">press the button to fetch ui records</div>
- )}
- </CardContent>
- </Card>
- );
-}
\ No newline at end of file
diff --git a/pipes/example-pipe/components/playground-card.tsx b/pipes/example-pipe/components/playground-card.tsx
index 45854cba0..92c6b752e 100644
--- a/pipes/example-pipe/components/playground-card.tsx
+++ b/pipes/example-pipe/components/playground-card.tsx
@@ -4,14 +4,30 @@ import { useState, useEffect } from "react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { CodeBlock } from "./ui/codeblock";
-import { HealthStatus } from "./health-status";
-import { parseHtmlContent } from './html-content-parser';
-import { Copy } from "lucide-react";
+import { parseHtmlContent } from '../lib/html-content-parser';
+import { Copy, ChevronDown, ChevronUp } from "lucide-react";
import { Button } from "@/components/ui/button";
-export function PlaygroundCard() {
+// Import the JSON data
+import healthStatusCardData from '../content/health-status-card.json';
+
+// Create a component registry that will be populated dynamically
+const COMPONENT_REGISTRY = {};
+
+// Define the content interface
+interface PlaygroundCardContent {
+ componentPath: string;
+ endpoint_optional: string;
+ llmModel: string;
+ llmUserPrompt: string;
+ llmContextUrl: string;
+ title?: string; // Optional title for the card
+}
+
+// Update component to accept content as props
+export function PlaygroundCard({ content }: { content: PlaygroundCardContent }) {
const [health, setHealth] = useState<any>(null);
- const [loading, setLoading] = useState(false);
+ const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [rawOutput, setRawOutput] = useState<string | null>(null);
const [componentCode, setComponentCode] = useState<string>("");
@@ -20,55 +36,52 @@ export function PlaygroundCard() {
const [responseStatus, setResponseStatus] = useState<string | null>(null);
const [contentType, setContentType] = useState<string | null>(null);
const [copiedButton, setCopiedButton] = useState<string | null>(null);
+ const [isCollapsed, setIsCollapsed] = useState(true);
+ const [componentModule, setComponentModule] = useState<any>(null);
- // Add LLM model information
- const llmModel = "claude-3.7-sonnet";
-
- // API docs URL for reference
- const llmContextUrl = "https://docs.screenpi.pe/docs/api-reference";
+ // Destructure content props
+ const {
+ componentPath,
+ endpoint_optional,
+ llmModel,
+ llmUserPrompt,
+ llmContextUrl,
+ title
+ } = content;
- // Fetch the component source code
+ // Dynamically load the component based on the path
useEffect(() => {
- const fetchComponentSource = async () => {
+ const loadComponent = async () => {
try {
- console.log("fetching component source code...");
+ setLoading(true);
- // Use the correct path relative to the project structure
- // The path should be relative to where the API route is looking for files
- const componentPath = "/pipes/example-pipe/components/health-status.tsx";
- console.log("attempting to fetch component source with path:", componentPath);
+ // Extract the component name from the path
+ // For example, from "/pipes/example-pipe/components/ready-to-use-examples/health-status.tsx"
+ // we extract "health-status"
+ const pathParts = componentPath.split('/');
+ const fileName = pathParts[pathParts.length - 1].replace('.tsx', '');
- const response = await fetch(
- `/api/component-source?path=${encodeURIComponent(componentPath)}`
- );
+ // Dynamically import the component
+ const module = await import(`./ready-to-use-examples/${fileName}`);
- console.log("fetch response status:", response.status);
-
- if (!response.ok) {
- throw new Error(`failed to fetch source: ${response.status}`);
- }
- const source = await response.text();
- console.log(
- "component source loaded, length:",
- source.length,
- "first 50 chars:",
- source.substring(0, 50)
- );
- setComponentCode(source);
+ // Store the module in state
+ setComponentModule(module);
+ setLoading(false);
} catch (err) {
- console.error("error fetching component source:", err);
- setError(err instanceof Error ? err.message : "unknown error occurred");
-
- // Set a fallback component code so the UI doesn't break completely
- setComponentCode(
- "// Component source could not be loaded\n// Error: " +
- (err instanceof Error ? err.message : "unknown error")
- );
+ console.error("Error loading component:", err);
+ setError(err instanceof Error ? err.message : "Unknown error loading component");
+ setLoading(false);
}
};
- fetchComponentSource();
- }, []);
+ // If the component is already in the registry, use it
+ if (COMPONENT_REGISTRY[componentPath]) {
+ setComponentModule(COMPONENT_REGISTRY[componentPath]);
+ setLoading(false);
+ } else {
+ loadComponent();
+ }
+ }, [componentPath]);
// Fetch API reference documentation
useEffect(() => {
@@ -104,38 +117,133 @@ export function PlaygroundCard() {
};
fetchApiDocs();
- }, []);
+ }, [llmContextUrl]);
+
+ // Fetch the component source code
+ useEffect(() => {
+ const fetchComponentSource = async () => {
+ try {
+ console.log("fetching component source code...");
+
+ console.log("attempting to fetch component source with path:", componentPath);
+
+ const response = await fetch(
+ `/api/component-source?path=${encodeURIComponent(componentPath)}`
+ );
+
+ console.log("fetch response status:", response.status);
+
+ if (!response.ok) {
+ throw new Error(`failed to fetch source: ${response.status}`);
+ }
+ const source = await response.text();
+ console.log(
+ "component source loaded, length:",
+ source.length,
+ "first 50 chars:",
+ source.substring(0, 50)
+ );
+ setComponentCode(source);
+ } catch (err) {
+ console.error("error fetching component source:", err);
+ setError(err instanceof Error ? err.message : "unknown error occurred");
+
+ // Set a fallback component code so the UI doesn't break completely
+ setComponentCode(
+ "// Component source could not be loaded\n// Error: " +
+ (err instanceof Error ? err.message : "unknown error")
+ );
+ }
+ };
+
+ fetchComponentSource();
+ }, [componentPath]);
- // Handle health data changes from the HealthStatus component
- const handleHealthDataChange = (data: any, errorMsg: string | null) => {
- console.log("health data changed:", data ? "data received" : "no data", "error:", errorMsg);
+ // Utility function to format API call results into raw output
+ const formatRawOutput = (
+ endpoint: string,
+ data: any | null,
+ error: string | null,
+ metadata: {
+ requestTime?: number,
+ status?: number | string,
+ contentType?: string,
+ method?: string
+ } = {}
+ ) => {
+ const { requestTime, status, contentType, method = "GET" } = metadata;
- if (data) {
- setHealth(data);
-
- // Create raw CLI-like output
- const timeInfo = requestTime ? `> Request completed in ${requestTime.toFixed(2)}ms` : "";
- const statusInfo = responseStatus ? `> Status: ${responseStatus}` : "";
- const contentTypeInfo = contentType ? `> Content-Type: ${contentType}` : "";
-
- setRawOutput(`> fetch http://localhost:3030/health
+ // Create header information
+ const timeInfo = requestTime ? `> Request completed in ${requestTime.toFixed(2)}ms` : "";
+ const statusInfo = status ? `> Status: ${status}` : "";
+ const contentTypeInfo = contentType ? `> Content-Type: ${contentType}` : "";
+
+ if (error) {
+ return `> ${method} ${endpoint}
+> Error: ${error}`;
+ }
+
+ return `> ${method} ${endpoint}
${timeInfo}
${statusInfo}
${contentTypeInfo}
-${JSON.stringify(data, null, 2)}`);
- } else if (errorMsg) {
+${data ? JSON.stringify(data, null, 2) : "No data returned"}`;
+ };
+
+ // Handle data changes
+ const handleDataChange = (data: any, errorMsg: string | null) => {
+ console.log("data changed:", data ? "data received" : "no data", "error:", errorMsg);
+
+ // Only update state if the data is different to prevent infinite loops
+ if (data && JSON.stringify(data) !== JSON.stringify(health)) {
+ setHealth(data);
+
+ // Use the generalized formatter
+ setRawOutput(formatRawOutput(
+ endpoint_optional,
+ data,
+ null,
+ {
+ requestTime,
+ status: responseStatus,
+ contentType
+ }
+ ));
+ } else if (errorMsg && errorMsg !== error) {
setError(errorMsg);
- setRawOutput(`> fetch http://localhost:3030/health
-> Error: ${errorMsg}`);
+ setRawOutput(formatRawOutput(endpoint_optional, null, errorMsg));
}
};
- // Split the prompt into user prompt and context
- const llmUserPrompt =
- "Can we have another component to call screenpipe health endpoint and render raw json output? " +
- "can we display the output more user friendly, with some animation (framer motion), etc., keep code short";
- const llmContext = apiDocs || `Loading API reference documentation... See docs at ${llmContextUrl}`;
+ // For other API calls, you can use the same formatter
+ const handleOtherApiCall = (endpoint: string, method = "GET") => {
+ // Example of using the formatter with another API call
+ fetch(endpoint)
+ .then(async (response) => {
+ const data = await response.json();
+ const requestTime = performance.now() - startTime;
+ setRawOutput(formatRawOutput(
+ endpoint,
+ data,
+ null,
+ {
+ requestTime,
+ status: response.status,
+ contentType: response.headers.get("content-type") || undefined,
+ method
+ }
+ ));
+ // Process data...
+ })
+ .catch(err => {
+ setRawOutput(formatRawOutput(endpoint, null, err.message, { method }));
+ // Handle error...
+ });
+ };
+
+ // Use the llmContext from API docs or fallback
+ const llmContext = apiDocs || `Loading reference documentation... See docs at ${llmContextUrl}`;
// Add these new functions to handle copying text
const copyToClipboard = (text: string, buttonId: string) => {
@@ -159,125 +267,182 @@ ${JSON.stringify(data, null, 2)}`);
copyToClipboard(fullPrompt, "entire-prompt");
};
+ // Get the component from the module
+ const DynamicComponent = componentModule ?
+ // Try different naming conventions to find the component
+ componentModule.default ||
+ getComponentFromModule(componentModule, componentPath) :
+ null;
+
+ // Helper function to extract component from module based on naming conventions
+ function getComponentFromModule(module: any, path: string) {
+ const pathParts = path.split('/');
+ const fileName = pathParts[pathParts.length - 1].replace('.tsx', '');
+
+ // Try camelCase (first letter lowercase)
+ const camelCaseName = fileName.split('-').map((part, i) =>
+ i === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)
+ ).join('');
+
+ // Try PascalCase (all first letters uppercase)
+ const pascalCaseName = fileName.split('-').map(part =>
+ part.charAt(0).toUpperCase() + part.slice(1)
+ ).join('');
+
+ return module[camelCaseName] || module[pascalCaseName];
+ }
+
return (
- <div className="w-full max-w-4xl space-y-6">
+ <div className="w-full max-w-4xl space-y-4">
{/* Component Showcase */}
- <Card>
- <CardHeader>
- <CardTitle className="text-lg font-medium">health status </CardTitle>
+ <Card className="border-2 border-slate-300 bg-slate-50 shadow-md dark:bg-slate-900 dark:border-slate-700">
+ <CardHeader
+ className="flex flex-row items-center justify-between border-b border-slate-200 dark:border-slate-700 bg-slate-100 dark:bg-slate-800 cursor-pointer py-2"
+ onClick={() => {
+ console.log("toggling component collapse state:", !isCollapsed);
+ setIsCollapsed(!isCollapsed);
+ }}
+ >
+ <CardTitle className="text-lg font-mono font-medium">{title}</CardTitle>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 w-6 p-0"
+ aria-label={isCollapsed ? "expand component" : "collapse component"}
+ tabIndex={-1} // Prevents independent focus from the header
+ onClick={(e) => e.stopPropagation()} // Prevents double-triggering
+ >
+ {isCollapsed ? (
+ <ChevronDown className="h-4 w-4" />
+ ) : (
+ <ChevronUp className="h-4 w-4" />
+ )}
+ </Button>
</CardHeader>
- <CardContent>
- <Tabs defaultValue="prompt">
- <TabsList className="mb-4">
- <TabsTrigger value="prompt">llm prompt</TabsTrigger>
- <TabsTrigger value="code">code</TabsTrigger>
- <TabsTrigger value="raw">raw output</TabsTrigger>
- <TabsTrigger value="rendered">rendered</TabsTrigger>
- </TabsList>
-
- <TabsContent value="prompt" className="p-4 bg-slate-50 rounded-md">
- <div className="space-y-4">
- <div className="flex justify-between items-center mb-2">
- <div>
- <div className="text-xs text-gray-500 mb-1">model: {llmModel}</div>
- <h3 className="text-sm font-semibold">user prompt:</h3>
+ {!isCollapsed && (
+ <CardContent className="p-2">
+ <Tabs defaultValue="rendered" orientation="vertical" className="flex">
+ <TabsList className="mr-4 h-auto flex-col space-y-1 bg-slate-200 dark:bg-slate-800 p-2 rounded-md self-start w-40">
+ <TabsTrigger value="rendered" className="justify-start font-mono text-xs w-full text-left">rendered output</TabsTrigger>
+ <TabsTrigger value="raw" className="justify-start font-mono text-xs w-full text-left">raw output</TabsTrigger>
+ <TabsTrigger value="code" className="justify-start font-mono text-xs w-full text-left">full code</TabsTrigger>
+ <TabsTrigger value="prompt" className="justify-start font-mono text-xs w-full text-left">llm prompt</TabsTrigger>
+ </TabsList>
+
+ <div className="flex-1 relative">
+ <TabsContent value="prompt" className="p-3 bg-slate-100 dark:bg-slate-800 border border-slate-300 dark:border-slate-700 rounded-md mt-0 absolute inset-0 overflow-auto h-[350px]">
+ <div className="space-y-3">
+ <div className="flex justify-between items-center mb-1">
+ <div>
+ <div className="text-xs text-gray-500 mb-1">model: {llmModel}</div>
+ <h3 className="text-sm font-semibold">user prompt:</h3>
+ </div>
+ <Button
+ variant="outline"
+ size="sm"
+ className="text-xs h-6 py-0 px-2"
+ onClick={copyEntirePrompt}
+ >
+ {copiedButton === "entire-prompt" ? (
+ <span className="text-green-500">copied!</span>
+ ) : (
+ <>
+ <Copy className="h-3.5 w-3.5 mr-1" /> copy entire prompt
+ </>
+ )}
+ </Button>
+ </div>
+ <div className="relative">
+ <div className="flex items-start gap-2">
+ <div className="flex-1 bg-slate-50 p-2 rounded-md">
+ <p className="text-sm">{llmUserPrompt}</p>
+ </div>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs h-8 py-0 px-2 whitespace-nowrap"
+ onClick={() => copyToClipboard(llmUserPrompt, "user-prompt")}
+ >
+ {copiedButton === "user-prompt" ? (
+ <span className="text-green-500">copied!</span>
+ ) : (
+ <Copy className="h-3.5 w-3.5" />
+ )}
+ </Button>
+ </div>
+ </div>
+ <div className="relative">
+ <div className="flex justify-between items-center mb-1">
+ <h3 className="text-sm font-semibold">
+ context:
+ <span className="text-xs text-gray-500 block mt-1">{llmContextUrl}</span>
+ </h3>
+ </div>
+ <div className="text-xs max-h-40 overflow-y-auto p-2 bg-slate-50 rounded break-words whitespace-pre-wrap relative">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 w-6 p-0 absolute top-1 right-1 bg-slate-100/80 hover:bg-slate-200/90 z-10"
+ onClick={() => copyToClipboard(llmContext, "context")}
+ >
+ {copiedButton === "context" ? (
+ <span className="text-green-500">copied!</span>
+ ) : (
+ <Copy className="h-3.5 w-3.5" />
+ )}
+ </Button>
+ {llmContext}
+ </div>
+ </div>
</div>
- <Button
- variant="outline"
- size="sm"
- className="text-xs h-6 py-0 px-2"
- onClick={copyEntirePrompt}
- >
- {copiedButton === "entire-prompt" ? (
- <span className="text-green-500">copied!</span>
+ </TabsContent>
+
+ <TabsContent value="code" className="mt-0 absolute inset-0 overflow-auto h-[350px]">
+ <div className="p-3 bg-slate-100 dark:bg-slate-800 border border-slate-300 dark:border-slate-700 rounded-md h-full">
+ {componentCode ? (
+ <div className="text-[12px] [&_*]:text-[12px]">
+ <CodeBlock language="tsx" value={componentCode} />
+ </div>
) : (
- <>
- <Copy className="h-3.5 w-3.5 mr-1" /> copy entire prompt
- </>
+ <div className="animate-pulse text-sm text-slate-500">loading component code...</div>
)}
- </Button>
- </div>
- <div className="relative">
- <div className="flex items-start gap-2">
- <div className="flex-1 bg-slate-100 p-3 rounded-md">
- <p className="text-sm">{llmUserPrompt}</p>
- </div>
- <Button
- variant="ghost"
- size="sm"
- className="text-xs h-8 py-0 px-2 whitespace-nowrap"
- onClick={() => copyToClipboard(llmUserPrompt, "user-prompt")}
- >
- {copiedButton === "user-prompt" ? (
- <span className="text-green-500">copied!</span>
- ) : (
- <Copy className="h-3.5 w-3.5" />
- )}
- </Button>
- </div>
- </div>
- <div className="relative">
- <div className="flex justify-between items-center mb-2">
- <h3 className="text-sm font-semibold">
- context from <a
- href={llmContextUrl}
- target="_blank"
- rel="noopener noreferrer"
- className="text-blue-500 hover:underline"
- >
- api reference
- </a>:
- <span className="text-xs text-gray-500 block mt-1">{llmContextUrl}</span>
- </h3>
- <Button
- variant="ghost"
- size="sm"
- className="h-6 w-6 p-0"
- onClick={() => copyToClipboard(llmContext, "context")}
- >
- {copiedButton === "context" ? (
- <span className="text-green-500">copied!</span>
- ) : (
- <Copy className="h-3.5 w-3.5" />
- )}
- </Button>
</div>
- <div className="text-xs max-h-60 overflow-y-auto p-2 bg-slate-100 rounded break-words whitespace-pre-wrap">
- {llmContext}
+ </TabsContent>
+
+ <TabsContent value="raw" className="mt-0 absolute inset-0 overflow-auto h-[350px]">
+ {rawOutput ? (
+ <div className="p-3 bg-black text-green-400 font-mono rounded-md h-full border border-green-700">
+ <pre className="text-sm font-mono">{rawOutput}</pre>
+ </div>
+ ) : (
+ <div className="p-3 bg-slate-100 dark:bg-slate-800 border border-slate-300 dark:border-slate-700 rounded-md h-full">
+ <p className="text-sm text-slate-500 font-mono">click to see raw output</p>
+ </div>
+ )}
+ </TabsContent>
+
+ <TabsContent value="rendered" className="mt-0 absolute inset-0 overflow-auto h-[350px]">
+ <div className="border border-slate-300 dark:border-slate-700 rounded-md p-3 h-full bg-white dark:bg-slate-950">
+ {loading ? (
+ <div className="flex items-center justify-center h-full">
+ <div className="animate-pulse text-sm text-slate-500">Loading component...</div>
+ </div>
+ ) : DynamicComponent ? (
+ <DynamicComponent onDataChange={handleDataChange} />
+ ) : (
+ <div className="text-sm text-slate-500">
+ No component found for path: {componentPath}
+ </div>
+ )}
</div>
- </div>
- </div>
- </TabsContent>
-
- <TabsContent value="code">
- <div className="p-4 bg-slate-100 rounded-md overflow-auto">
- {componentCode ? (
- <CodeBlock language="tsx" value={componentCode} />
- ) : (
- <div className="animate-pulse text-sm text-slate-500">loading component code...</div>
- )}
- </div>
- </TabsContent>
-
- <TabsContent value="raw">
- {rawOutput ? (
- <div className="p-4 bg-black text-green-400 rounded-md overflow-auto">
- <pre className="text-sm font-mono">{rawOutput}</pre>
- </div>
- ) : (
- <div className="p-4 bg-slate-100 rounded-md">
- <p className="text-sm text-slate-500">click &quot;fetch health data&quot; to see raw output</p>
- </div>
- )}
- </TabsContent>
-
- <TabsContent value="rendered">
- <div className="border rounded-md p-4">
- <HealthStatus onHealthDataChange={handleHealthDataChange} />
+ </TabsContent>
+
+ {/* Add an invisible spacer div to maintain consistent height */}
+ <div className="invisible h-[350px]"></div>
</div>
- </TabsContent>
- </Tabs>
- </CardContent>
+ </Tabs>
+ </CardContent>
+ )}
</Card>
</div>
);
diff --git a/pipes/example-pipe/components/client-only.tsx b/pipes/example-pipe/lib/client-only.tsx
similarity index 100%
rename from pipes/example-pipe/components/client-only.tsx
rename to pipes/example-pipe/lib/client-only.tsx
diff --git a/pipes/example-pipe/components/generic-settings.tsx b/pipes/example-pipe/lib/hooks/generic-settings.tsx
similarity index 96%
rename from pipes/example-pipe/components/generic-settings.tsx
rename to pipes/example-pipe/lib/hooks/generic-settings.tsx
index af87a1106..5e56abd00 100644
--- a/pipes/example-pipe/components/generic-settings.tsx
+++ b/pipes/example-pipe/lib/hooks/generic-settings.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useSettings } from "./settings-provider";
+import { useSettings } from "../settings-provider";
import { useState } from "react";
export function GenericSettings() {
diff --git a/pipes/example-pipe/components/html-content-parser.ts b/pipes/example-pipe/lib/html-content-parser.ts
similarity index 100%
rename from pipes/example-pipe/components/html-content-parser.ts
rename to pipes/example-pipe/lib/html-content-parser.ts
diff --git a/pipes/example-pipe/components/ollama-models-list.tsx b/pipes/example-pipe/lib/ollama-models-list.tsx
similarity index 100%
rename from pipes/example-pipe/components/ollama-models-list.tsx
rename to pipes/example-pipe/lib/ollama-models-list.tsx
diff --git a/pipes/example-pipe/components/settings-provider.tsx b/pipes/example-pipe/lib/settings-provider.tsx
similarity index 100%
rename from pipes/example-pipe/components/settings-provider.tsx
rename to pipes/example-pipe/lib/settings-provider.tsx