Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • migrate manual fetches in kb module to use reactquery
    • better aligns with query patterns, avoids manual state management

Type of Change

  • Improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Jan 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 20, 2026 1:24am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 20, 2026

Greptile Summary

  • Migrates manual fetch operations in the knowledge base (KB) module to React Query mutations for better state management and alignment with established query patterns
  • Adds comprehensive React Query CRUD operations in hooks/queries/knowledge.ts with proper error handling, query invalidation, and type safety
  • Removes manual loading states and error handling from 10+ components, replacing them with React Query's built-in isPending and mutation states

Important Files Changed

Filename Overview
apps/sim/hooks/queries/knowledge.ts Added 13 new React Query mutation hooks for all KB CRUD operations; centralizes data operations with proper caching and invalidation
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx Major refactor introducing optimistic updates for document operations; replaced manual fetch with mutation hooks
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/document.tsx Complete migration from manual state management to React Query mutations for chunk and document operations

Confidence score: 4/5

  • This PR is safe to merge with good architectural improvements that align with established patterns
  • Score reflects comprehensive migration with proper error handling and optimistic updates throughout the KB module
  • Pay close attention to hooks/queries/knowledge.ts for the new mutation implementations and ensure all invalidation patterns are correct

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateBaseModal
    participant KnowledgeUpload
    participant PresignedAPI
    participant S3
    participant KnowledgeAPI
    participant QueryClient
    participant ProcessingService

    User->>CreateBaseModal: "Click Create Knowledge Base"
    CreateBaseModal->>CreateBaseModal: "Open modal with form"
    User->>CreateBaseModal: "Fill form (name, chunking config)"
    User->>CreateBaseModal: "Add documents (optional)"
    User->>CreateBaseModal: "Click Create"
    
    CreateBaseModal->>KnowledgeAPI: "createKnowledgeBase(params)"
    KnowledgeAPI-->>CreateBaseModal: "Return knowledge base"
    
    alt Files selected
        CreateBaseModal->>KnowledgeUpload: "uploadFiles(files, kbId, config)"
        
        loop For each file
            KnowledgeUpload->>PresignedAPI: "POST /api/files/presigned"
            PresignedAPI-->>KnowledgeUpload: "Return presigned URL"
            KnowledgeUpload->>S3: "Upload file to S3"
            S3-->>KnowledgeUpload: "Upload complete"
        end
        
        KnowledgeUpload->>KnowledgeAPI: "POST documents with file URLs"
        KnowledgeAPI-->>KnowledgeUpload: "Return document records"
        KnowledgeAPI->>ProcessingService: "Queue document processing"
        KnowledgeUpload-->>CreateBaseModal: "Upload complete"
        
        ProcessingService->>ProcessingService: "Process documents into chunks"
    end
    
    CreateBaseModal->>QueryClient: "invalidateQueries(knowledgeBases)"
    CreateBaseModal->>User: "Close modal, navigate to KB"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@waleedlatif1 waleedlatif1 merged commit 69614d2 into staging Jan 20, 2026
7 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/kb branch January 20, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants