Skip to content

fix(kb): fix mistral parse and kb uploads, include userId in internal auth - #1767

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/kb
Oct 30, 2025
Merged

fix(kb): fix mistral parse and kb uploads, include userId in internal auth#1767
waleedlatif1 merged 3 commits into
stagingfrom
fix/kb

Conversation

@waleedlatif1

Copy link
Copy Markdown
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

vercelBot commented Oct 30, 2025

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedOct 30, 2025 6:16am

@waleedlatif1
waleedlatif1 merged commit 47913f8 into stagingOct 30, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/kb branch October 30, 2025 06:18

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

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

FilenameScoreOverview
apps/sim/lib/auth/internal.ts5/5Enhanced JWT token generation and verification to include optional userId in payload for improved auth context
apps/sim/lib/auth/hybrid.ts5/5Updated 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.ts5/5Added userId and workspaceId parameters throughout document processing pipeline to enable proper file metadata tracking
apps/sim/lib/knowledge/documents/service.ts5/5Updated knowledge base operations to increment updatedAt timestamp when documents are added, and pass user context to document processor
apps/sim/tools/mistral/parser.ts5/5Fixed 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
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto 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.

1 participant

@waleedlatif1