Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(utils): add truncateText utility function

Steven Enamakel9bbcc23b2def
diff --git a/app/src/utils/truncateText.ts b/app/src/utils/truncateText.ts
new file mode 100644
index 0000000000..4dc6a5a688
--- /dev/null
+++ b/app/src/utils/truncateText.ts
@@ -0,0 +1,12 @@
+/**
+ * Truncate `text` to at most `max` characters, appending an ellipsis (`…`)
+ * when it was cut. The ellipsis itself counts against `max`, so the result
+ * is never longer than `max` characters.
+ *
+ * Pass `trim: true` to trim whitespace before measuring/truncating (useful
+ * for freeform text pulled from tool output or user input).
+ */
+export function truncateText(text: string, max: number, options?: { trim?: boolean }): string {
+ const value = options?.trim ? text.trim() : text;
+ return value.length > max ? `${value.slice(0, Math.max(0, max - 1))}…` : value;
+}