feat(platform): add document_list agent tool#713
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Add a new document_list tool that allows the AI agent to browse, filter, and paginate through documents in the knowledge base. Supports filtering by folder path, file extension, team, date range, and title search. Includes cursor-based pagination, configurable sorting, and team-based access control. Refs #658
- Fix cursor pagination bug when sorting by name (restrict cursor to createdAt sort only since cursor is timestamp-based) - Fix dateTo end-of-day: add 24h-1ms so documents created during the target day are included - Simplify extension filter (merge two identical branches into one) - Simplify extractSize (remove redundant isRecord check) - Deduplicate types (re-export from canonical source) - Simplify internal query handler using spread Refs #658
…rden edge cases Replace timestamp-based cursor with offset-based pagination to fix duplicate-skipping issues with identical createdAt values. Add _id tiebreaker for deterministic sort, validate date format with regex, fix date/folder filters for edge cases (0, NaN, "/"), and use null instead of -1 for unknown totalCount.
Validate dates (reject invalid YYYY-MM-DD), cursor (non-negative int), and extension (no leading dot) at the schema level. Surface a warning field when the scan limit is hit so agents know to narrow filters. Clamp negative cursors, isolate folder-path resolution errors, and add comprehensive tests for all new behaviors.
Add metadata.name fallback for document titles, auto-strip leading dots from extension filter, return early with warning when dateFrom > dateTo, and improve scan limit warning messages with match counts.
…ve sort - Extract shared getDocumentTitle() to eliminate 3x duplicated title resolution with inconsistent fallbacks (sort used '', display used 'Untitled') - Make name sort case-insensitive with precomputed lowercase keys for performance - Title search now uses getDocumentTitle, making "untitled" searchable for docs without titles (matches displayed value)
…and breadcrumb errors - Return descriptive warning when teamId filter is not in user's teams (H3) - Return warning with case-sensitivity hint when folder path not found (H4) - Add console.warn when buildBreadcrumb fails for orphaned folders (M4) - Update folderPath description to note case-sensitive exact match
- Reject empty extension and teamId with .min(1) - Auto-normalize extension to lowercase - Add .max(500) on folderPath, .max(200) on query - Update extension description to reflect auto-normalization
Add round-trip validation in toTimestamp() to catch dates like 2026-02-30 that silently roll over to the next month.
…esult directly Delete single-line re-export file and update consumers to import from the source module.
…mment - Add .int().min(1).max(50) on limit for better LLM error feedback - Add comment documenting buildQuery index selection priority
091ed97 to
b2baf5f
Compare
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR implements a new Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Summary
document_listagent tool that allows AI agents to browse and list documents by team, folder, date range, and search query with offset-based paginationlist_documents_for_agentConvex query with robust validation, case-insensitive sorting, breadcrumb paths, and structured warnings for unauthorized teams or missing foldersTest plan
document_list_tool(parameter validation, pagination, formatting)list_documents_for_agent(filtering, sorting, edge cases, authorization, date validation)document_listand confirm it can list documents🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests