fix(kb): fix mistral parse and kb uploads, include userId in internal auth#1767
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
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()andverifyInternalToken()to support optionaluserIdin JWT payload, changing verification from returning a boolean to returning an object with{valid, userId?} - KB Upload Fix: Added
userIdandworkspaceIdparameters 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
userIdwhen generating internal tokens for API calls - Updated Timestamp: Knowledge base
updatedAtfield 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
7 files reviewed, no comments
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of Change
Testing
Tested extensively manually
Checklist