mirror of https://github.com/kortix-ai/suna.git
commit
f6dd36d08a
|
@ -5,7 +5,8 @@ import { Skeleton } from "@/components/ui/skeleton";
|
|||
import { useRouter } from 'next/navigation';
|
||||
import { Menu } from "lucide-react";
|
||||
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 { useSidebar } from "@/components/ui/sidebar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
@ -32,7 +33,7 @@ function DashboardContent() {
|
|||
const chatInputRef = useRef<ChatInputHandles>(null);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -62,26 +63,38 @@ function DashboardContent() {
|
|||
|
||||
// Call initiateAgent API
|
||||
const result = await initiateAgent(formData);
|
||||
console.log('Agent initiated:', result);
|
||||
console.log('Agent initiated with files:', result);
|
||||
|
||||
// Navigate to the thread
|
||||
if (result.thread_id) {
|
||||
router.push(`/agents/${result.thread_id}`);
|
||||
}
|
||||
} else {
|
||||
// For text-only messages, first create a thread
|
||||
const thread = await createThread("");
|
||||
// ---- Text-only messages ----
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Navigate to thread
|
||||
// 6. Navigate to thread
|
||||
router.push(`/agents/${thread.thread_id}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Log line 85 might be here if createThread or initiateAgent fails
|
||||
console.error('Error creating thread or initiating agent:', error);
|
||||
|
||||
// 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
|
||||
setIsSubmitting(false);
|
||||
setIsSubmitting(false); // Stop submission process on billing error
|
||||
return; // Exit handleSubmit
|
||||
}
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue