MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / flattenTree

Function flattenTree

packages/react/src/components/tool-tree.tsx:197–226  ·  view source on GitHub ↗
(
  node: TreeNode,
  depth: number,
  openSet: ReadonlySet<string>,
  acc: Row[],
)

Source from the content-addressed store, hash-verified

195};
196
197const flattenTree = (
198 node: TreeNode,
199 depth: number,
200 openSet: ReadonlySet<string>,
201 acc: Row[],
202): void => {
203 const sorted = [...node.children.values()].sort((a, b) => a.segment.localeCompare(b.segment));
204 for (const child of sorted) {
205 const hasChildren = child.children.size > 0;
206 const isLeaf = !!child.tool && !hasChildren;
207
208 if (isLeaf) {
209 acc.push({ kind: "leaf", depth, path: child.path, tool: child.tool! });
210 continue;
211 }
212
213 const open = openSet.has(child.path);
214 acc.push({
215 kind: "group",
216 depth,
217 path: child.path,
218 segment: child.segment,
219 count: countLeaves(child),
220 open,
221 });
222 if (open) {
223 flattenTree(child, depth + 1, openSet, acc);
224 }
225 }
226};
227
228// ---------------------------------------------------------------------------
229// Highlight

Callers 1

ToolTreeBodyFunction · 0.85

Calls 3

countLeavesFunction · 0.85
valuesMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected