Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge pull request #5837 from Afloat16/fix/data-sql-truncation-receipts

milind-soni7f9a36b71c87
diff --cc server/data/tools.ts
index ffb75ceea2,17e9f30c1b..f5a7fe5779
--- a/server/data/tools.ts
+++ b/server/data/tools.ts
@@@ -326,8 -326,12 +326,12 @@@ const CELL_CHARS_MAX = 2000
export function boundRows(rows: RunResult["rows"], maxRows: number, maxBytes: number): { rows: RunResult["rows"]; truncated: boolean } {
let truncated = rows.length > maxRows;
- let kept = rows.slice(0, maxRows).map((row) => row.map((cell) => (typeof cell === "string" && cell.length > CELL_CHARS_MAX ? `${cell.slice(0, CELL_CHARS_MAX)}…` : cell)));
+ let kept = rows.slice(0, maxRows).map((row) => row.map((cell) => {
+ if (typeof cell !== "string" || cell.length <= CELL_CHARS_MAX) return cell;
+ truncated = true;
+ return `${cell.slice(0, CELL_CHARS_MAX)}…`;
+ }));
- while (kept.length && JSON.stringify(kept).length > maxBytes) {
+ while (kept.length && Buffer.byteLength(JSON.stringify(kept)) > maxBytes) {
kept = kept.slice(0, Math.max(0, kept.length - Math.max(1, Math.ceil(kept.length / 10))));
truncated = true;
}