mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
fix(agent-tools): normalize childrensectionids handling and update tests for consistency
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user