(parentId: string | null, depth = 0)
| 81 | // Recursively fetch all items in the knowledge base (with pagination) |
| 82 | const allItems: any[] = []; |
| 83 | async function fetchItems(parentId: string | null, depth = 0) { |
| 84 | const PAGE_SIZE = 100; |
| 85 | let offset = 0; |
| 86 | let hasMore = true; |
| 87 | |
| 88 | while (hasMore) { |
| 89 | const query: any = { knowledgeBaseId: id, limit: PAGE_SIZE, offset, parentId }; |
| 90 | const result = await client.file.getKnowledgeItems.query(query); |
| 91 | const list = Array.isArray(result) ? result : ((result as any).items ?? []); |
| 92 | hasMore = Array.isArray(result) ? false : ((result as any).hasMore ?? false); |
| 93 | offset += list.length; |
| 94 | |
| 95 | // Collect folders for parallel recursive fetch |
| 96 | const folders: any[] = []; |
| 97 | for (const item of list) { |
| 98 | allItems.push({ ...item, _depth: depth }); |
| 99 | if (item.fileType === 'custom/folder') { |
| 100 | folders.push(item); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Fetch all sub-folders in parallel |
| 105 | if (folders.length > 0) { |
| 106 | await Promise.all(folders.map((f) => fetchItems(f.id, depth + 1))); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | await fetchItems(null); |
| 111 | |
| 112 | if (options.json !== undefined) { |
no test coverage detected