"use client"; import { Info } from "lucide-react"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; interface SetupPromptStepProps { searchSpaceId: number; onComplete?: () => void; } export function SetupPromptStep({ searchSpaceId, onComplete }: SetupPromptStepProps) { const [enableCitations, setEnableCitations] = useState(true); const [customInstructions, setCustomInstructions] = useState(""); const [saving, setSaving] = useState(false); const [hasChanges, setHasChanges] = useState(false); // Mark that we have changes when user modifies anything useEffect(() => { setHasChanges(true); }, [enableCitations, customInstructions]); const handleSave = async () => { try { setSaving(true); // Prepare the update payload with simplified schema const payload: any = { citations_enabled: enableCitations, qna_custom_instructions: customInstructions.trim() || "", }; // Only send update if there's something to update if (Object.keys(payload).length > 0) { const response = await fetch( `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${localStorage.getItem("surfsense_bearer_token")}`, }, body: JSON.stringify(payload), } ); if (!response.ok) { const errorData = await response.json().catch(() => ({})); throw new Error( errorData.detail || `Failed to save prompt configuration (${response.status})` ); } toast.success("Prompt configuration saved successfully"); } setHasChanges(false); onComplete?.(); } catch (error: any) { console.error("Error saving prompt configuration:", error); toast.error(error.message || "Failed to save prompt configuration"); } finally { setSaving(false); } }; const handleSkip = () => { // Skip without saving - use defaults onComplete?.(); }; return (
These settings are optional. You can skip this step and configure them later in settings. {/* Citation Toggle */}

When enabled, AI responses will include citations to source documents using [citation:id] format.

{!enableCitations && ( Disabling citations means AI responses won't include source references. You can re-enable this anytime in settings. )}
{/* SearchSpace System Instructions */}

Add system instructions to guide how the AI should respond. For example: "Always provide code examples" or "Keep responses concise and technical".