Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Jan 25, 2026

Summary

Workspace ID should be required for KBs moving forward.

Type of Change

  • Bug fix

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)

@vercel
Copy link

vercel bot commented Jan 25, 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 26, 2026 2:30am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 25, 2026

Greptile Overview

Greptile Summary

This PR enforces that workspaceId is required when creating knowledge bases, changing it from optional to mandatory across the API, service layer, and type definitions.

Key Changes:

  • API validation schema now requires workspaceId with clear error messaging
  • Service layer removed conditional null handling for workspaceId, always checking workspace permissions
  • Type definitions updated to reflect workspaceId as a required field
  • Copilot tool added validation to ensure workspaceId is provided
  • Schema documentation updated to clarify the requirement

Impact:
The change aligns with existing UI behavior (which already provides workspaceId) and database schema (which allows null but the application enforces workspace association). This improves data integrity by preventing orphaned knowledge bases without workspace context.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured and consistent across all layers (API, service, types). The existing UI already provides workspaceId, so this is a non-breaking change that enforces existing behavior. Permission checks are properly maintained, and the database schema supports the change.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/api/knowledge/route.ts Changed workspaceId from optional to required in validation schema with clear error message
apps/sim/lib/copilot/tools/server/knowledge/knowledge-base.ts Added validation check for workspaceId before creating knowledge base via copilot
apps/sim/lib/copilot/tools/shared/schemas.ts Updated JSDoc comment to clarify that workspaceId is required for create operation
apps/sim/lib/knowledge/service.ts Removed optional null handling for workspaceId, now always checking permissions and using the required value
apps/sim/lib/knowledge/types.ts Changed workspaceId from optional to required in CreateKnowledgeBaseData interface

Sequence Diagram

sequenceDiagram
    participant UI as CreateBaseModal
    participant API as POST /api/knowledge
    participant Service as createKnowledgeBase()
    participant Permissions as getUserEntityPermissions()
    participant DB as Database

    UI->>API: POST with name, description, workspaceId (required)
    API->>API: Validate schema (workspaceId required)
    alt workspaceId missing
        API-->>UI: 400 Error: Workspace ID is required
    end
    API->>Service: createKnowledgeBase(data, requestId)
    Service->>Permissions: Check user permissions for workspace
    alt No permission
        Permissions-->>Service: null
        Service-->>API: Error: No permission
        API-->>UI: 500 Error
    end
    Permissions-->>Service: Permission granted
    Service->>DB: Insert knowledge base with workspaceId
    DB-->>Service: Knowledge base created
    Service-->>API: Return knowledge base data
    API-->>UI: 200 Success with data
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.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 3790098 into staging Jan 27, 2026
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/kb-ws-id branch January 27, 2026 02:37
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