mirror of https://github.com/kortix-ai/suna.git
Merge pull request #664 from escapade-mckv/content-length-fix
Content length fix
This commit is contained in:
commit
4c1905aef0
|
@ -1706,12 +1706,12 @@ class ResponseProcessor:
|
|||
"output": output, # Now properly structured for frontend
|
||||
"error": getattr(result, 'error', None) if hasattr(result, 'error') else None
|
||||
},
|
||||
"execution_details": {
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"parsing_details": parsing_details
|
||||
}
|
||||
# "execution_details": {
|
||||
# "timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
# "parsing_details": parsing_details
|
||||
# }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# STRUCTURED_OUTPUT_TOOLS = {
|
||||
# "str_replace",
|
||||
|
@ -1737,22 +1737,21 @@ class ResponseProcessor:
|
|||
summary_output = result.output if hasattr(result, 'output') else str(result)
|
||||
success_status = structured_result_v1["tool_execution"]["result"]["success"]
|
||||
|
||||
# Create a more comprehensive summary for the LLM
|
||||
if xml_tag_name:
|
||||
status = "completed successfully" if structured_result_v1["tool_execution"]["result"]["success"] else "failed"
|
||||
summary = f"Tool '{xml_tag_name}' {status}. Output: {summary_output}"
|
||||
else:
|
||||
status = "completed successfully" if structured_result_v1["tool_execution"]["result"]["success"] else "failed"
|
||||
summary = f"Function '{function_name}' {status}. Output: {summary_output}"
|
||||
# # Create a more comprehensive summary for the LLM
|
||||
# if xml_tag_name:
|
||||
# status = "completed successfully" if structured_result_v1["tool_execution"]["result"]["success"] else "failed"
|
||||
# summary = f"Tool '{xml_tag_name}' {status}. Output: {summary_output}"
|
||||
# else:
|
||||
# status = "completed successfully" if structured_result_v1["tool_execution"]["result"]["success"] else "failed"
|
||||
# summary = f"Function '{function_name}' {status}. Output: {summary_output}"
|
||||
|
||||
if self.is_agent_builder:
|
||||
return summary
|
||||
elif function_name == "get_data_provider_endpoints":
|
||||
logger.info(f"Returning sumnary for data provider call: {summary}")
|
||||
return summary
|
||||
# if self.is_agent_builder:
|
||||
# return summary
|
||||
# elif function_name == "get_data_provider_endpoints":
|
||||
# logger.info(f"Returning sumnary for data provider call: {summary}")
|
||||
# return summary
|
||||
|
||||
else:
|
||||
return structured_result_v1
|
||||
return structured_result_v1
|
||||
|
||||
def _format_xml_tool_result(self, tool_call: Dict[str, Any], result: ToolResult) -> str:
|
||||
"""Format a tool result wrapped in a <tool_result> tag.
|
||||
|
|
|
@ -13,9 +13,9 @@ import {
|
|||
createProject,
|
||||
createThread,
|
||||
addUserMessage,
|
||||
startAgent,
|
||||
BillingError,
|
||||
} from '@/lib/api';
|
||||
import { useStartAgentMutation } from '@/hooks/react-query/threads/use-agent-run';
|
||||
import { generateThreadName } from '@/lib/actions/threads';
|
||||
import GoogleSignIn from '@/components/GoogleSignIn';
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
@ -59,6 +59,7 @@ export function HeroSection() {
|
|||
const { data: accounts } = useAccounts();
|
||||
const personalAccount = accounts?.find((account) => account.personal_account);
|
||||
const { onOpen } = useModal();
|
||||
const startAgentMutation = useStartAgentMutation();
|
||||
|
||||
// Auth dialog state
|
||||
const [authDialogOpen, setAuthDialogOpen] = useState(false);
|
||||
|
@ -123,32 +124,23 @@ export function HeroSection() {
|
|||
description: '',
|
||||
});
|
||||
|
||||
// 2. Create a new thread for this project
|
||||
const thread = await createThread(newAgent.id);
|
||||
|
||||
// 3. Add the user message to the thread
|
||||
await addUserMessage(thread.thread_id, inputValue.trim());
|
||||
|
||||
// 4. Start the agent with the thread ID
|
||||
await startAgent(thread.thread_id, {
|
||||
stream: true,
|
||||
await startAgentMutation.mutateAsync({
|
||||
threadId: thread.thread_id,
|
||||
options: {
|
||||
model_name: 'openrouter/deepseek/deepseek-chat',
|
||||
stream: true,
|
||||
},
|
||||
});
|
||||
|
||||
// 5. Navigate to the new agent's thread page
|
||||
router.push(`/agents/${thread.thread_id}`);
|
||||
// Clear input on success
|
||||
router.push(`/projects/${newAgent.id}/thread/${thread.thread_id}`);
|
||||
setInputValue('');
|
||||
} catch (error: any) {
|
||||
console.error('Error creating agent:', error);
|
||||
|
||||
// Check specifically for BillingError (402)
|
||||
if (error instanceof BillingError) {
|
||||
console.log('Handling BillingError from hero section:', error.detail);
|
||||
// Open the payment required dialog modal instead of showing the alert
|
||||
onOpen("paymentRequiredDialog");
|
||||
// Don't show toast for billing errors
|
||||
} else {
|
||||
// Handle other errors (e.g., network, other API errors)
|
||||
const isConnectionError =
|
||||
error instanceof TypeError &&
|
||||
error.message.includes('Failed to fetch');
|
||||
|
|
|
@ -50,30 +50,30 @@ export function CompleteToolView({
|
|||
const [completeData, setCompleteData] = useState<CompleteContent>({});
|
||||
const [progress, setProgress] = useState(0);
|
||||
|
||||
// Extract completion summary and attachments from assistant content
|
||||
useEffect(() => {
|
||||
if (assistantContent) {
|
||||
try {
|
||||
const contentStr = normalizeContentToString(assistantContent);
|
||||
|
||||
// Try to extract content from <complete> tag
|
||||
const completeMatch = contentStr.match(/<complete[^>]*>([^<]*)<\/complete>/);
|
||||
let cleanContent = contentStr
|
||||
.replace(/<function_calls>[\s\S]*?<\/function_calls>/g, '')
|
||||
.replace(/<invoke name="complete"[\s\S]*?<\/invoke>/g, '')
|
||||
.trim();
|
||||
|
||||
const completeMatch = cleanContent.match(/<complete[^>]*>([^<]*)<\/complete>/);
|
||||
if (completeMatch) {
|
||||
setCompleteData(prev => ({ ...prev, summary: completeMatch[1].trim() }));
|
||||
} else {
|
||||
// Fallback: use the whole content as summary
|
||||
setCompleteData(prev => ({ ...prev, summary: contentStr }));
|
||||
} else if (cleanContent) {
|
||||
setCompleteData(prev => ({ ...prev, summary: cleanContent }));
|
||||
}
|
||||
|
||||
// Extract attachments if present
|
||||
const attachmentsMatch = contentStr.match(/attachments=["']([^"']*)["']/i);
|
||||
if (attachmentsMatch) {
|
||||
const attachments = attachmentsMatch[1].split(',').map(a => a.trim()).filter(a => a.length > 0);
|
||||
setCompleteData(prev => ({ ...prev, attachments }));
|
||||
}
|
||||
|
||||
// Try to extract any task list items
|
||||
const taskMatches = contentStr.match(/- ([^\n]+)/g);
|
||||
const taskMatches = cleanContent.match(/- ([^\n]+)/g);
|
||||
if (taskMatches) {
|
||||
const tasks = taskMatches.map(task => task.replace('- ', '').trim());
|
||||
setCompleteData(prev => ({ ...prev, tasksCompleted: tasks }));
|
||||
|
@ -84,18 +84,14 @@ export function CompleteToolView({
|
|||
}
|
||||
}, [assistantContent]);
|
||||
|
||||
// Extract result from tool content
|
||||
useEffect(() => {
|
||||
if (toolContent && !isStreaming) {
|
||||
try {
|
||||
const contentStr = normalizeContentToString(toolContent);
|
||||
|
||||
// Try to extract from ToolResult pattern
|
||||
const toolResultMatch = contentStr.match(/ToolResult\([^)]*output=['"]([^'"]+)['"]/);
|
||||
if (toolResultMatch) {
|
||||
setCompleteData(prev => ({ ...prev, result: toolResultMatch[1] }));
|
||||
} else {
|
||||
// Fallback: use the content directly
|
||||
setCompleteData(prev => ({ ...prev, result: contentStr }));
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -104,7 +100,6 @@ export function CompleteToolView({
|
|||
}
|
||||
}, [toolContent, isStreaming]);
|
||||
|
||||
// Simulate progress when streaming
|
||||
useEffect(() => {
|
||||
if (isStreaming) {
|
||||
const timer = setInterval(() => {
|
||||
|
|
Loading…
Reference in New Issue