Skip to content

Commit 7a577fc

Browse files
committed
feat: add truncation logic for visible text and HTML content responses
1 parent f60509d commit 7a577fc

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/tools/browser/visiblePage.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ export class VisibleTextTool extends BrowserToolBase {
5050
}
5151
return text.trim();
5252
});
53-
return createSuccessResponse(`Visible text content:\n${visibleText}`);
53+
// Truncate logic
54+
const maxLength = typeof args.maxLength === 'number' ? args.maxLength : 20000;
55+
let output = visibleText;
56+
let truncated = false;
57+
if (output.length > maxLength) {
58+
output = output.slice(0, maxLength) + '\n[Output truncated due to size limits]';
59+
truncated = true;
60+
}
61+
return createSuccessResponse(`Visible text content:\n${output}`);
5462
} catch (error) {
5563
return createErrorResponse(`Failed to get visible text content: ${(error as Error).message}`);
5664
}
@@ -170,7 +178,13 @@ export class VisibleHtmlTool extends BrowserToolBase {
170178
);
171179
}
172180

173-
return createSuccessResponse(`HTML content:\n${htmlContent}`);
181+
// Truncate logic
182+
const maxLength = typeof args.maxLength === 'number' ? args.maxLength : 20000;
183+
let output = htmlContent;
184+
if (output.length > maxLength) {
185+
output = output.slice(0, maxLength) + '\n<!-- Output truncated due to size limits -->';
186+
}
187+
return createSuccessResponse(`HTML content:\n${output}`);
174188
} catch (error) {
175189
return createErrorResponse(`Failed to get visible HTML content: ${(error as Error).message}`);
176190
}

0 commit comments

Comments
 (0)