Merge pull request #1768 from kubet/fix/show-attached-files-in-tools

fix: show attached files in tools
This commit is contained in:
kubet 2025-10-01 22:32:54 +02:00 committed by GitHub
commit ed912fcebf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 60 additions and 34 deletions

View File

@ -59,20 +59,46 @@ function preprocessTextOnlyTools(content: string): string {
return content || ''; return content || '';
} }
// Handle new function calls format for text-only tools - extract text parameter content // For ask/complete tools, we need to preserve them if they have attachments
// Complete XML format // Only strip them if they don't have attachments parameter
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'); // 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'); 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 // 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, '$1'); content = content.replace(/<function_calls>\s*<invoke name="ask">\s*<parameter name="text">([\s\S]*?)$/gi, (match) => {
content = content.replace(/<function_calls>\s*<invoke name="complete">\s*<parameter name="text">([\s\S]*?)$/gi, '$1'); 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'); 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 // Also handle old format - only strip if no attachments attribute
content = content.replace(/<ask[^>]*>([\s\S]*?)<\/ask>/gi, '$1'); content = content.replace(/<ask[^>]*>([\s\S]*?)<\/ask>/gi, (match) => {
content = content.replace(/<complete[^>]*>([\s\S]*?)<\/complete>/gi, '$1'); 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'); content = content.replace(/<present_presentation[^>]*>([\s\S]*?)<\/present_presentation>/gi, '$1');
return content; return content;
} }