-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(kb): fix mistral parse and kb uploads, include userId in internal auth #1767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this 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()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
… 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
Summary
Type of Change
Testing
Tested extensively manually
Checklist