sim
sim copied to clipboard
improvement(router): add ports to router block
Summary
Add ports to router block
Type of Change
- [x] Improvement
Testing
Manual
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
Greptile Summary
Added port-based routing capability to the router block via new router_v2 block type. The new implementation allows users to define routes with descriptive text instead of relying on downstream block IDs, making routing logic more explicit and easier to understand.
Key Changes:
- Created
RouterV2Blockinapps/sim/blocks/blocks/router.tswithrouter-inputsubblock type - Implemented
executeV2()method in router handler to process route-based decisions using LLM - Extended
ConditionInputcomponent to support router mode with textarea-based route descriptions - Added per-route output handles in
WorkflowBlockcomponent for visual port-based connections - Updated DAG edge construction to handle
router-{routeId}handle prefixes - Legacy router block hidden from toolbar but remains functional for existing workflows
Implementation Quality:
- Clean separation between legacy and v2 router implementations
- Reused existing
ConditionInputcomponent with new mode parameter, avoiding code duplication - Proper type definitions and constants added across the codebase
- Consistent with existing condition block patterns for handle generation
Confidence Score: 5/5
- This PR is safe to merge with no blocking issues
- The implementation is well-structured with clear separation of concerns between legacy and v2 routers. All changes follow established patterns (similar to condition block implementation), include proper type definitions, and maintain backwards compatibility by keeping the legacy router functional.
- No files require special attention
Important Files Changed
| Filename | Overview |
|---|---|
| apps/sim/blocks/blocks/router.ts | Added RouterV2Block with port-based routing using route descriptions instead of downstream block IDs; refactored common helpers |
| apps/sim/executor/handlers/router/router-handler.ts | Added executeV2() method to handle router_v2 blocks with port-based routing logic and route selection |
| apps/sim/executor/dag/construction/edges.ts | Added router_v2 edge generation logic with port-based handle mapping for route connections |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/condition-input/condition-input.tsx | Extended ConditionInput to support router mode with textarea-based route descriptions and tag/env var support |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx | Added routerRows computation and rendering logic with per-route output handles for router_v2 blocks |
Sequence Diagram
sequenceDiagram
participant User
participant WorkflowBlock
participant SubBlock
participant ConditionInput
participant RouterHandler
participant EdgeConstructor
participant LLM
User->>WorkflowBlock: Add router_v2 block
WorkflowBlock->>SubBlock: Render router-input subblock
SubBlock->>ConditionInput: Render with mode='router'
User->>ConditionInput: Define routes with descriptions
ConditionInput->>ConditionInput: Store routes as JSON array
User->>WorkflowBlock: Connect routes to downstream blocks
WorkflowBlock->>WorkflowBlock: Render per-route output handles
Note over User,LLM: Workflow Execution Phase
User->>RouterHandler: Execute router_v2 block
RouterHandler->>RouterHandler: parseRoutes(inputs.routes)
RouterHandler->>RouterHandler: generateRouterV2Prompt(context, routes)
RouterHandler->>LLM: Send context + route descriptions
LLM-->>RouterHandler: Return selected route ID
RouterHandler->>RouterHandler: Find connection for route handle
RouterHandler->>EdgeConstructor: Route to connected block
EdgeConstructor->>EdgeConstructor: Generate edge with router-{routeId} handle
RouterHandler-->>User: Return selected route + path info