fix empty uuid

This commit is contained in:
LE Quoc Dat 2025-04-24 13:36:56 +01:00
parent 034ea37745
commit d7b95b24a7
1 changed files with 45 additions and 31 deletions

View File

@ -5,7 +5,8 @@ import { Skeleton } from "@/components/ui/skeleton";
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { Menu } from "lucide-react"; import { Menu } from "lucide-react";
import { ChatInput, ChatInputHandles } from '@/components/thread/chat-input'; import { ChatInput, ChatInputHandles } from '@/components/thread/chat-input';
import { initiateAgent, createThread, addUserMessage, startAgent } from "@/lib/api"; import { initiateAgent, createThread, addUserMessage, startAgent, createProject } from "@/lib/api";
import { generateThreadName } from "@/lib/actions/threads";
import { useIsMobile } from "@/hooks/use-mobile"; import { useIsMobile } from "@/hooks/use-mobile";
import { useSidebar } from "@/components/ui/sidebar"; import { useSidebar } from "@/components/ui/sidebar";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@ -32,7 +33,7 @@ function DashboardContent() {
const chatInputRef = useRef<ChatInputHandles>(null); const chatInputRef = useRef<ChatInputHandles>(null);
const handleSubmit = async (message: string, options?: { model_name?: string; enable_thinking?: boolean }) => { const handleSubmit = async (message: string, options?: { model_name?: string; enable_thinking?: boolean }) => {
if (!message.trim() && !chatInputRef.current?.getPendingFiles().length || isSubmitting) return; if ((!message.trim() && !(chatInputRef.current?.getPendingFiles().length)) || isSubmitting) return;
setIsSubmitting(true); setIsSubmitting(true);
@ -62,26 +63,38 @@ function DashboardContent() {
// Call initiateAgent API // Call initiateAgent API
const result = await initiateAgent(formData); const result = await initiateAgent(formData);
console.log('Agent initiated:', result); console.log('Agent initiated with files:', result);
// Navigate to the thread // Navigate to the thread
if (result.thread_id) { if (result.thread_id) {
router.push(`/agents/${result.thread_id}`); router.push(`/agents/${result.thread_id}`);
} }
} else { } else {
// For text-only messages, first create a thread // ---- Text-only messages ----
const thread = await createThread(""); // 1. Generate a project name
const projectName = await generateThreadName(message);
// Then add the user message // 2. Create the project
// Assuming createProject gets the account_id from the logged-in user
const newProject = await createProject({
name: projectName,
description: "", // Or derive a description if desired
});
// 3. Create the thread using the new project ID
const thread = await createThread(newProject.id); // <-- Pass the actual project ID
// 4. Then add the user message
await addUserMessage(thread.thread_id, message); await addUserMessage(thread.thread_id, message);
// Start the agent on this thread with the options // 5. Start the agent on this thread with the options
await startAgent(thread.thread_id, options); await startAgent(thread.thread_id, options);
// Navigate to thread // 6. Navigate to thread
router.push(`/agents/${thread.thread_id}`); router.push(`/agents/${thread.thread_id}`);
} }
} catch (error: any) { } catch (error: any) {
// Log line 85 might be here if createThread or initiateAgent fails
console.error('Error creating thread or initiating agent:', error); console.error('Error creating thread or initiating agent:', error);
// Skip billing error checks in local development mode // Skip billing error checks in local development mode
@ -163,17 +176,18 @@ function DashboardContent() {
} }
// Don't rethrow - we've handled this error with the billing alert // Don't rethrow - we've handled this error with the billing alert
setIsSubmitting(false); setIsSubmitting(false); // Stop submission process on billing error
return; // Exit handleSubmit return; // Exit handleSubmit
} }
} }
// Handle other errors or rethrow // Handle other errors or rethrow
// The second log (line 174) might happen here if startAgent fails, for example
toast.error(error.message || "An error occurred"); toast.error(error.message || "An error occurred");
console.error("Error creating agent:", error); console.error("Error creating agent:", error);
setIsSubmitting(false); setIsSubmitting(false); // Reset submitting state on other errors too
} }
// Removed finally block as catch now handles resetting isSubmitting
}; };
// Check for pending prompt in localStorage on mount // Check for pending prompt in localStorage on mount