Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • fix mistral parse and kb uploads by including userId in knowledge-base context upload to workspace_files
  • include userId in internal auth for enhanced security posture
  • increment updated_at when inserting doc via knowledge block

Type of Change

  • Bug fix

Testing

Tested extensively 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)

@vercel
Copy link

vercel bot commented Oct 30, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 30, 2025 6:16am

@waleedlatif1 waleedlatif1 merged commit 47913f8 into staging Oct 30, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/kb branch October 30, 2025 06:18
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.

Greptile Overview

Greptile Summary

This PR enhances the internal authentication system and fixes knowledge base document uploads by propagating user context through the entire processing pipeline.

Key Changes

  • Internal Auth Enhancement: Modified generateInternalToken() and verifyInternalToken() to support optional userId in JWT payload, changing verification from returning a boolean to returning an object with {valid, userId?}
  • KB Upload Fix: Added userId and workspaceId parameters throughout the document processing pipeline (processDocument, parseDocument, handleFileForOCR, etc.) to ensure proper metadata tracking when uploading files to storage
  • Mistral Parser Fix: Fixed URL validation bug by converting relative paths to absolute URLs before validation, and included userId when generating internal tokens for API calls
  • Updated Timestamp: Knowledge base updatedAt field now increments when documents are added via the knowledge block

Impact

All workflow routes now properly handle the new verification response structure, and knowledge base uploads will correctly track user and workspace ownership for files uploaded to cloud storage.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured and consistent throughout the codebase. The auth signature change is backwards-compatible (boolean to object with .valid property), all call sites have been updated, and the parameter threading through document processing maintains proper typing
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/lib/auth/internal.ts 5/5 Enhanced JWT token generation and verification to include optional userId in payload for improved auth context
apps/sim/lib/auth/hybrid.ts 5/5 Updated hybrid auth to extract and use userId from internal JWT token payload, with fallback to query params and request body
apps/sim/lib/knowledge/documents/document-processor.ts 5/5 Added userId and workspaceId parameters throughout document processing pipeline to enable proper file metadata tracking
apps/sim/lib/knowledge/documents/service.ts 5/5 Updated knowledge base operations to increment updatedAt timestamp when documents are added, and pass user context to document processor
apps/sim/tools/mistral/parser.ts 5/5 Fixed URL validation by converting relative paths to absolute URLs before validation

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as API Route
    participant Auth as Internal Auth
    participant DocProcessor as Document Processor
    participant Mistral as Mistral Parser
    participant Storage as Storage Service
    
    Note over Client,Storage: Enhanced Internal Auth Flow
    
    Client->>API: Request with Bearer token
    API->>Auth: Verify internal token
    Auth-->>API: Return validation result
    Note over API: Extract user from token payload
    
    Note over Client,Storage: Knowledge Base Upload Flow
    
    Client->>API: Upload document to KB
    API->>DocProcessor: Process with context parameters
    DocProcessor->>Storage: Upload file with metadata
    Note over Storage: Store metadata with context
    Storage-->>DocProcessor: Upload successful
    
    DocProcessor->>Mistral: Parse PDF if needed
    Note over Mistral: Detect internal route
    Mistral->>Auth: Request new token
    Auth-->>Mistral: Provide token
    Mistral->>Mistral: Call internal API
    Note over Mistral: Context preserved in chain
    Mistral-->>DocProcessor: Return parsed content
    
    DocProcessor-->>API: Processing complete
    API-->>Client: Success
Loading

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

waleedlatif1 added a commit that referenced this pull request Nov 12, 2025
… auth (#1767)

* fix(kb): fix mistral parse and kb uploads, include userId in internal auth

* update updated_at for kb when adding a new doc via knowledge block

* update tests
@waleedlatif1 waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
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