Skip to content

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

feat(conversations): render flat object arrays as data tables in tool views

Steven Enamakel90182b56cb74
diff --git a/app/src/features/conversations/tools/ToolDataView.tsx b/app/src/features/conversations/tools/ToolDataView.tsx
index eb5832d384..aa5a0e095c 100644
--- a/app/src/features/conversations/tools/ToolDataView.tsx
+++ b/app/src/features/conversations/tools/ToolDataView.tsx
@@ -1,11 +1,43 @@
+import { DataTable, type DataTableColumn } from '../../../components/assistant-ui/elements/data-table';
import { BubbleMarkdown } from '../components/AgentMessageBubble';
/**
* Generic, readable rendering of a tool's input or output: JSON objects as a
- * definition list, arrays as a list, strings as markdown. The fallback body
- * for any tool without a dedicated renderer.
+ * definition list, arrays of flat, uniform objects as the vendored
+ * `data-table` element, any other array as a list, strings as markdown. The
+ * fallback body for any tool without a dedicated renderer.
*/
+type FlatRow = Record<string, string | number | boolean | null>;
+
+/**
+ * `true` only for a non-empty array of plain objects that all share the same
+ * key set and hold only primitive values — a genuinely tabular result. A
+ * single mixed or nested item falls back to the generic list rendering
+ * below, which handles nesting fine.
+ */
+function isFlatObjectArray(value: unknown[]): value is FlatRow[] {
+ if (value.length === 0) return false;
+ const isFlatRow = (row: unknown): row is FlatRow =>
+ !!row &&
+ typeof row === 'object' &&
+ !Array.isArray(row) &&
+ Object.values(row as object).every(
+ v => v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean'
+ );
+ if (!value.every(isFlatRow)) return false;
+ const keys = Object.keys(value[0] as FlatRow).sort().join('\u0000');
+ return value.every(row => Object.keys(row).sort().join('\u0000') === keys);
+}
+
+function flatRowColumns(rows: FlatRow[]): DataTableColumn<FlatRow>[] {
+ return Object.keys(rows[0]).map(key => ({
+ key,
+ header: friendlyLabel(key),
+ cell: row => (row[key] === null || row[key] === undefined ? '—' : String(row[key])),
+ }));
+}
+
function friendlyLabel(key: string): string {
return key
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')