fix(agent-tools): normalize childrensectionids handling and update tests for consistency

This commit is contained in:
2026-04-22 12:22:35 +05:30
parent 3649718b77
commit 204b12d5f7
2 changed files with 14 additions and 13 deletions
+10 -8
View File
@@ -113,19 +113,25 @@ export function createGetSectionContentTool(table: Table) {
for (const result of sortedResults) {
const typedResult = result as {
text?: string;
childrensectionids?: string[];
childrensectionids?: unknown;
sectiontitle?: string;
partindex?: number;
totalparts?: number;
};
// Normalize childrensectionids: LanceDB may return an Apache Arrow Vector
// which is iterable but not a plain JS array.
const childrenIds = typedResult.childrensectionids
? Array.from(typedResult.childrensectionids as Iterable<string>)
: undefined;
// Get or create section data
let section = sectionsData.get(currentId);
if (!section) {
section = {
content: [],
title: typedResult.sectiontitle,
childrenSectionIds: typedResult.childrensectionids,
childrenSectionIds: childrenIds,
};
sectionsData.set(currentId, section);
}
@@ -135,12 +141,8 @@ export function createGetSectionContentTool(table: Table) {
}
// Add children to queue for recursive fetching only if recursive is true
if (
recursive &&
typedResult.childrensectionids &&
Array.isArray(typedResult.childrensectionids)
) {
queue.push(...typedResult.childrensectionids);
if (recursive && childrenIds && childrenIds.length > 0) {
queue.push(...childrenIds);
}
}
}
+4 -5
View File
@@ -81,16 +81,15 @@ describe("getSectionContent", () => {
expect(result.sections.length).toBe(0);
});
test("should include partIndex and totalParts when available", async () => {
test("should include childrensectionids when available", async () => {
const result = await getContentTool({
sectionIds: ["sec-try-statement"],
sectionIds: ["sec-catch-clause"],
recursive: false,
});
const section = result.sections[0];
if (section.found && section.partIndex !== undefined) {
expect(section.partIndex).toBeNumber();
expect(section.totalParts).toBeNumber();
if (section.found && section.childrensectionids !== undefined) {
expect(section.childrensectionids).toBeArray();
}
});