diff --git a/src/agent-tools/getSectionContent.ts b/src/agent-tools/getSectionContent.ts index e5d8a71..8f0beaf 100644 --- a/src/agent-tools/getSectionContent.ts +++ b/src/agent-tools/getSectionContent.ts @@ -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) + : 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); } } } diff --git a/src/test/getSectionContent.test.ts b/src/test/getSectionContent.test.ts index 4119258..583ed59 100644 --- a/src/test/getSectionContent.test.ts +++ b/src/test/getSectionContent.test.ts @@ -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(); } });