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) { for (const result of sortedResults) {
const typedResult = result as { const typedResult = result as {
text?: string; text?: string;
childrensectionids?: string[]; childrensectionids?: unknown;
sectiontitle?: string; sectiontitle?: string;
partindex?: number; partindex?: number;
totalparts?: 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 // Get or create section data
let section = sectionsData.get(currentId); let section = sectionsData.get(currentId);
if (!section) { if (!section) {
section = { section = {
content: [], content: [],
title: typedResult.sectiontitle, title: typedResult.sectiontitle,
childrenSectionIds: typedResult.childrensectionids, childrenSectionIds: childrenIds,
}; };
sectionsData.set(currentId, section); 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 // Add children to queue for recursive fetching only if recursive is true
if ( if (recursive && childrenIds && childrenIds.length > 0) {
recursive && queue.push(...childrenIds);
typedResult.childrensectionids &&
Array.isArray(typedResult.childrensectionids)
) {
queue.push(...typedResult.childrensectionids);
} }
} }
} }
+4 -5
View File
@@ -81,16 +81,15 @@ describe("getSectionContent", () => {
expect(result.sections.length).toBe(0); 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({ const result = await getContentTool({
sectionIds: ["sec-try-statement"], sectionIds: ["sec-catch-clause"],
recursive: false, recursive: false,
}); });
const section = result.sections[0]; const section = result.sections[0];
if (section.found && section.partIndex !== undefined) { if (section.found && section.childrensectionids !== undefined) {
expect(section.partIndex).toBeNumber(); expect(section.childrensectionids).toBeArray();
expect(section.totalParts).toBeNumber();
} }
}); });