mirror of https://github.com/kortix-ai/suna.git
Merge pull request #1768 from kubet/fix/show-attached-files-in-tools
fix: show attached files in tools
This commit is contained in:
commit
ed912fcebf
|
@ -59,20 +59,46 @@ function preprocessTextOnlyTools(content: string): string {
|
|||
return content || '';
|
||||
}
|
||||
|
||||
// Handle new function calls format for text-only tools - extract text parameter content
|
||||
// Complete XML format
|
||||
content = content.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)<\/parameter>[\s\S]*?<\/invoke>\s*<\/function_calls>/gi, '$1');
|
||||
content = content.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)<\/parameter>[\s\S]*?<\/invoke>\s*<\/function_calls>/gi, '$1');
|
||||
// For ask/complete tools, we need to preserve them if they have attachments
|
||||
// Only strip them if they don't have attachments parameter
|
||||
|
||||
// Handle new function calls format - only strip if no attachments
|
||||
content = content.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)<\/parameter>\s*<\/invoke>\s*<\/function_calls>/gi, (match) => {
|
||||
if (match.includes('<parameter name="attachments"')) return match;
|
||||
return match.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)<\/parameter>\s*<\/invoke>\s*<\/function_calls>/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)<\/parameter>\s*<\/invoke>\s*<\/function_calls>/gi, (match) => {
|
||||
if (match.includes('<parameter name="attachments"')) return match;
|
||||
return match.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)<\/parameter>\s*<\/invoke>\s*<\/function_calls>/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<function_calls>\s*<invoke name="present_presentation">[\s\S]*?<parameter name="text">([\s\S]*?)<\/parameter>[\s\S]*?<\/invoke>\s*<\/function_calls>/gi, '$1');
|
||||
|
||||
// Handle streaming/partial XML for message tools - extract text parameter content even if incomplete
|
||||
content = content.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)$/gi, '$1');
|
||||
content = content.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)$/gi, '$1');
|
||||
// Handle streaming/partial XML for message tools - only strip if no attachments visible yet
|
||||
content = content.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)$/gi, (match) => {
|
||||
if (match.includes('<parameter name="attachments"')) return match;
|
||||
return match.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)$/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)$/gi, (match) => {
|
||||
if (match.includes('<parameter name="attachments"')) return match;
|
||||
return match.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)$/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<function_calls>\s*<invoke name="present_presentation">[\s\S]*?<parameter name="text">([\s\S]*?)$/gi, '$1');
|
||||
|
||||
// Also handle old format for backward compatibility
|
||||
content = content.replace(/<ask[^>]*>([\s\S]*?)<\/ask>/gi, '$1');
|
||||
content = content.replace(/<complete[^>]*>([\s\S]*?)<\/complete>/gi, '$1');
|
||||
// Also handle old format - only strip if no attachments attribute
|
||||
content = content.replace(/<ask[^>]*>([\s\S]*?)<\/ask>/gi, (match) => {
|
||||
if (match.match(/<ask[^>]*attachments=/i)) return match;
|
||||
return match.replace(/<ask[^>]*>([\s\S]*?)<\/ask>/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<complete[^>]*>([\s\S]*?)<\/complete>/gi, (match) => {
|
||||
if (match.match(/<complete[^>]*attachments=/i)) return match;
|
||||
return match.replace(/<complete[^>]*>([\s\S]*?)<\/complete>/gi, '$1');
|
||||
});
|
||||
|
||||
content = content.replace(/<present_presentation[^>]*>([\s\S]*?)<\/present_presentation>/gi, '$1');
|
||||
return content;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue