Skip to content

improvement(custom-tools): make them workspace scoped + ux to manage them - #1772

Merged
icecrasher321 merged 7 commits into
stagingfrom
improvement/sim-319
Oct 31, 2025
Merged

improvement(custom-tools): make them workspace scoped + ux to manage them#1772
icecrasher321 merged 7 commits into
stagingfrom
improvement/sim-319

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Usability improvements for custom tools for Agent blocks.

Type of Change

  • Other: Platform Improvement

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

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 31, 2025 0:18am

@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

Migrated custom tools from user-scoped to workspace-scoped with comprehensive database changes, API access control, and new settings UI for management.

Key Changes

- **Database**: Added `workspace_id` column to `custom_tools` table, made `user_id` nullable for backward compatibility with legacy tools - **Access Control**: Implemented workspace-based permissions (read/write/admin) for all custom tool operations - **State Management**: Refactored store from localStorage persistence to server-backed with async operations - **UI**: New settings section for managing custom tools with search, CRUD operations, and inline editing - **Duplicate Prevention**: Added validation to prevent tools with duplicate names in same workspace - **Backward Compatibility**: Legacy user-scoped tools (without `workspace_id`) still supported

Architecture

Custom tools now follow workspace isolation model consistent with other workspace-scoped resources (API keys, env vars). The migration preserves existing user-scoped tools while new tools are workspace-scoped.

Issues Found

- Race condition in `store.ts` `createTool()` when finding newly created tool by title after refetch

Confidence Score: 4/5

  • Safe to merge with one race condition that needs addressing in the custom tools store
  • Well-structured migration with proper access control, backward compatibility, and duplicate prevention. The race condition in createTool is a real bug that could cause failures when finding the newly created tool by title. All other changes follow established patterns and include proper error handling.
  • Pay close attention to apps/sim/stores/custom-tools/store.ts - the race condition in createTool needs to be fixed before merge

Important Files Changed

File Analysis

FilenameScoreOverview
packages/db/schema.ts5/5Updated schema to include workspace_id with cascade delete, made user_id optional with set null on delete, added workspace index
apps/sim/stores/custom-tools/store.ts3/5Converted from local persistence to server-backed store with workspace scoping; removed localStorage sync; potential race condition in createTool
apps/sim/app/api/tools/custom/route.ts4/5Added workspace-based access control, duplicate name validation, and backward compatibility for user-scoped tools
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/tool-input/components/custom-tool-modal/custom-tool-modal.tsx4/5Updated modal to use async store methods with workspace context; improved error handling for duplicate names
apps/sim/lib/workflows/custom-tools-persistence.ts4/5Added workspace context for custom tool persistence; skip legacy user-scoped tools; workspace members can update tools

Sequence Diagram

sequenceDiagram
participant User
participant UI as Settings UI
participant Store as Custom Tools Store
participant API as /api/tools/custom
participant DB as Database
participant Perms as Permission Service
Note over User,DB: Create Custom Tool Flow
User->>UI: Click "Add Tool"
User->>UI: Fill tool details
User->>UI: Click "Save Tool"
UI->>Store: createTool(workspaceId, tool)
Store->>API: POST /api/tools/custom
API->>Perms: getUserEntityPermissions(userId, workspace)
Perms-->>API: write permission
API->>DB: Check for duplicate tool name
alt Tool name already exists
DB-->>API: Duplicate found
API-->>Store: Error: "tool already exists"
Store-->>UI: Throw error
UI->>UI: Display schema error
else Tool name unique
DB-->>API: No duplicate
API->>DB: INSERT custom_tool (workspaceId, userId, title, schema, code)
DB-->>API: Success
API-->>Store: {success: true}
Store->>API: GET /api/tools/custom?workspaceId=X
API->>DB: SELECT custom_tools WHERE workspaceId OR userId
DB-->>API: Tool list
API-->>Store: {data: [tools]}
Store->>Store: Find tool by title
Store-->>UI: Return created tool
UI->>User: Show success
end
Note over User,DB: Fetch Tools Flow
UI->>Store: fetchTools(workspaceId)
Store->>API: GET /api/tools/custom?workspaceId=X
API->>Perms: getUserEntityPermissions(userId, workspace)
Perms-->>API: read permission
API->>DB: SELECT WHERE workspaceId=X OR (workspaceId IS NULL AND userId=Y)
DB-->>API: Tools list
API-->>Store: {data: [tools]}
Store-->>UI: Update tools state
Note over User,DB: Delete Tool Flow
User->>UI: Click "Delete"
UI->>Store: deleteTool(workspaceId, toolId)
Store->>API: DELETE /api/tools/custom?id=X&workspaceId=Y
API->>DB: SELECT tool WHERE id=X
DB-->>API: Tool data
alt Workspace-scoped tool
API->>Perms: getUserEntityPermissions(userId, workspace)
Perms-->>API: write permission
API->>DB: Verify tool.workspaceId matches
else User-scoped tool (legacy)
API->>API: Verify tool.userId matches
end
API->>DB: DELETE FROM custom_tools WHERE id=X
DB-->>API: Success
API-->>Store: {success: true}
Store-->>UI: Update local state
UI->>User: Tool deleted
Loading

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/stores/custom-tools/store.ts
@icecrasher321
icecrasher321 merged commit a072e6d into stagingOct 31, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/sim-319 branch November 7, 2025 20:18
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
…them (#1772)
* improvement(custom-tools): make them workspace scoped
* fix auth check
* remove comments
* add dup check
* fix dup error message display
* fix tests
* fix on app loading of custom tools
@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

@icecrasher321