Skip to content

Commit bb8d527

Browse files
committed
workign trace graph v2
1 parent d48bde7 commit bb8d527

File tree

7 files changed

+36
-32
lines changed

7 files changed

+36
-32
lines changed

ell-studio/src/components/DependencyGraphPane.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {DependencyGraph} from './depgraph/DependencyGraph';
66
// When changing pages we need to rerender this component (or create a new graph)
77
const DependencyGraphPane = ({ lmp, uses }) => {
88
const lmps = [lmp, ...uses];
9-
console.log(lmps);
9+
1010
return (
1111
<DependencyGraph lmps={lmps} />
1212
);

ell-studio/src/components/HierarchicalTable.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ const TableRow = ({ item, schema, level = 0, onRowClick, columnWidths, updateWid
8080
}
8181
}, [isNew]);
8282

83-
const rowRef = useRef(null);
83+
const primaryColumnRef = useRef(null);
8484

8585
useEffect(() => {
86-
if (!rowRef.current) return;
86+
if (!primaryColumnRef.current) return;
8787

8888
const updatePosition = () => {
89-
const tableRect = rowRef.current.closest('table').getBoundingClientRect();
90-
const rowRect = rowRef.current.getBoundingClientRect();
89+
const tableRect = primaryColumnRef.current.closest('table').getBoundingClientRect();
90+
const rowRect = primaryColumnRef.current.getBoundingClientRect();
9191
const relativeX = rowRect.left - tableRect.left;
9292
const relativeY = rowRect.top - tableRect.top + rowRect.height / 2;
9393
setRowRef(item.id, { id: item.id, x: relativeX, y: relativeY, visible: true });
@@ -100,16 +100,15 @@ const TableRow = ({ item, schema, level = 0, onRowClick, columnWidths, updateWid
100100
const resizeObserver = new ResizeObserver(updatePosition);
101101

102102
// Observe both the row and the table
103-
resizeObserver.observe(rowRef.current);
104-
resizeObserver.observe(rowRef.current.closest('table'));
103+
resizeObserver.observe(primaryColumnRef.current);
104+
resizeObserver.observe(primaryColumnRef.current.closest('table'));
105105

106106
// Clean up
107107
return () => {
108108
setRowRef(item.id, {visible: false});
109109
resizeObserver.disconnect();
110110
};
111-
}, [item.id, setRowRef, sortedData.length, expandedRows]);
112-
111+
}, [item.id, setRowRef, sortedData.length, expandedRows, linkColumn]);
113112

114113
return (
115114
<React.Fragment>
@@ -158,10 +157,10 @@ const TableRow = ({ item, schema, level = 0, onRowClick, columnWidths, updateWid
158157
title={typeof content === 'string' ? content : ''}
159158
>
160159
<div style={{
161-
marginLeft: column.key === linkColumn ? `${level * 20 + 16}px` : 0,
162-
width: column.key === linkColumn ? '100%' : 'auto'
160+
marginLeft: column.key === 'name' ? `${level * 20 + 16}px` : 0,
161+
width: column.key === 'name' ? '100%' : 'auto'
163162
}}>
164-
<div ref={column.key === linkColumn ? rowRef : null}>
163+
<div ref={column.key === linkColumn ? primaryColumnRef : null}>
165164
{content}
166165
</div>
167166
</div>
@@ -299,7 +298,7 @@ const PaginationControls = ({ currentPage, totalPages, onPageChange, pageSize, t
299298
);
300299
};
301300

302-
const HierarchicalTable = ({ schema, data, onRowClick, onSelectionChange, initialSortConfig, rowClassName, currentPage, onPageChange, pageSize, totalItems, omitColumns, expandAll, links, linkColumn }) => {
301+
const HierarchicalTable = ({ schema, data, onRowClick, onSelectionChange, initialSortConfig, rowClassName, currentPage, onPageChange, pageSize, totalItems, omitColumns, expandAll, links, expandedLinkColumn, collapsedLinkColumn }) => {
303302
const [columnWidths, setColumnWidths] = useState({});
304303
const [isExpanded, setIsExpanded] = useState(false);
305304
const [rowRefs, setRowRefs] = useState({});
@@ -352,6 +351,8 @@ const HierarchicalTable = ({ schema, data, onRowClick, onSelectionChange, initia
352351
return schema;
353352
}, [schema, omitColumns, isExpanded]);
354353

354+
const linkColumn = !isExpanded && omitColumns ? collapsedLinkColumn : expandedLinkColumn;
355+
355356

356357
return (
357358
<HierarchicalTableProvider
@@ -446,7 +447,7 @@ const LinkLines = ({ links, rowRefs, tableOffset }) => {
446447
if (startRow && endRow && startRow?.visible && endRow?.visible) {
447448
const isHighlighted = hoveredRow === link.from ||
448449
hoveredRow === link.to;
449-
const offset = (groupedLinks[link.from].indexOf(link)+ 2) * 5; // Multiply by 20 for spacing
450+
const offset = (groupedLinks[link.from].indexOf(link)+ 4) * 3; // Multiply by 20 for spacing
450451
const color = isHighlighted
451452
? (hoveredRow === link.from ? '#f97316' : '#3b82f6') // Orange if going from, Blue if coming to
452453
: '#4a5568';

ell-studio/src/components/invocations/InvocationsTable.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,9 @@ const InvocationsTable = ({ invocations, currentPage, setCurrentPage, pageSize,
7575
links.push(...invocation.consumes.map(c => ({
7676
to: invocation.id,
7777
from: c
78-
})));
78+
})).filter(link => link.from !== invocation.id));
7979
}
8080

81-
// Recursively add links for child invocations
82-
if (invocation.uses) {
83-
invocation.uses.forEach(child => {
84-
links.push(...generateLinks(child));
85-
});
86-
}
8781

8882
return links;
8983
};
@@ -175,13 +169,15 @@ const InvocationsTable = ({ invocations, currentPage, setCurrentPage, pageSize,
175169

176170
if (isLoading) return <div>Loading...</div>;
177171

172+
178173
return (
179174
<HierarchicalTable
180175
schema={{
181176
columns: defaultColumns
182177
}}
183178
links={links}
184-
linkColumn={omitColumns.includes('name') ? 'version' : 'name'}
179+
expandedLinkColumn={'name'}
180+
collapsedLinkColumn={'version'}
185181
expandAll={expandAll}
186182
omitColumns={omitColumns}
187183
data={invocationTableData}

ell-studio/src/components/source/DiffRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function DiffRenderer({
2727
})
2828

2929
const diff = diffLines(previousCode, code);
30-
console.log("DIFF", diff)
30+
3131

3232
let oldLineNumber = startingLineNumber;
3333
let newLineNumber = startingLineNumber;

ell-studio/src/hooks/useBackend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const useLMPs = (name, id) => {
5858
});
5959
};
6060

61-
export const useInvocationsFromLMP = (name, id, page = 0, pageSize = 50) => {
61+
export const useInvocationsFromLMP = (name, id, page = 0, pageSize = 50, hierarchical = false) => {
6262
return useQuery({
6363
queryKey: ['invocations', name, id, page, pageSize],
6464
queryFn: async () => {
@@ -67,7 +67,7 @@ export const useInvocationsFromLMP = (name, id, page = 0, pageSize = 50) => {
6767
if (name) params.append('lmp_name', name);
6868
if (id) params.append('lmp_id', id);
6969
params.append('skip', skip);
70-
params.append('hierarchical', false);
70+
params.append('hierarchical', hierarchical);
7171
params.append('limit', pageSize);
7272
const response = await axios.get(`${API_BASE_URL}/api/invocations?${params.toString()}`);
7373

ell-studio/src/pages/LMP.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function LMP() {
5252
name,
5353
id,
5454
currentPage,
55-
pageSize
55+
pageSize,
56+
true // dangerous hierarchical query that will not scale to unique invocations
5657
);
5758
const { data: uses } = useMultipleLMPs(lmp?.uses);
5859

src/ell/stores/sql.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ def get_lmps(self, skip: int = 0, limit: int = 10, subquery=None, **filters: Opt
159159

160160
def get_invocations(self, lmp_filters: Dict[str, Any], skip: int = 0, limit: int = 10, filters: Optional[Dict[str, Any]] = None, hierarchical: bool = False) -> List[Dict[str, Any]]:
161161
with Session(self.engine) as session:
162-
def fetch_invocation(inv_id, depth=0):
163-
if depth > 10: # Prevent infinite recursion
164-
return None
165-
162+
def fetch_invocation(inv_id):
166163
query = (
167164
select(Invocation, SerializedLStr, SerializedLMP)
168165
.join(SerializedLMP)
@@ -185,9 +182,8 @@ def fetch_invocation(inv_id, depth=0):
185182

186183
inv_dict['consumes'] = [r for r in session.exec(consumes_query).all()]
187184
inv_dict['consumed_by'] = [r for r in session.exec(consumed_by_query).all()]
185+
inv_dict['uses'] = list([d.id for d in inv.uses])
188186

189-
if hierarchical:
190-
inv_dict['uses'] = [fetch_invocation(used.id, depth + 1) for used in inv.uses if used]
191187

192188
return inv_dict
193189

@@ -209,6 +205,16 @@ def fetch_invocation(inv_id, depth=0):
209205

210206
invocations = [fetch_invocation(inv_id) for inv_id in invocation_ids if inv_id]
211207

208+
if hierarchical:
209+
# Fetch all related "uses" invocations
210+
used_ids = set()
211+
for inv in invocations:
212+
213+
used_ids.update(inv['uses'])
214+
215+
used_invocations = [fetch_invocation(inv_id) for inv_id in used_ids if inv_id not in invocation_ids]
216+
invocations.extend(used_invocations)
217+
212218
return invocations
213219

214220
def get_traces(self):

0 commit comments

Comments
 (0)