sim
sim copied to clipboard
feat(copilot): show inline prompt to increase usage limit or upgrade plan
Summary
Brief description of what this PR does and why.
Fixes #(issue)
Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation
- [ ] Other: ___________
Testing
How has this been tested? What should reviewers focus on?
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)
Screenshots/Videos
The latest updates on your projects. Learn more about Vercel for GitHub.
Greptile Summary
This PR adds inline prompts to help users when they hit their copilot usage limits. When a 402 status code is returned, users can now either increase their usage limit directly (for Pro/Team plans) or navigate to upgrade their subscription (for Free plans).
Key changes:
- Added
UsageLimitActionscomponent that displays action buttons when usage limit is exceeded - Extended the copilot store to track
errorTypeon messages for specific HTTP error codes (401, 402, 403, 426, 429) - Added
errorTypefield toCopilotMessageinterface - The component automatically retries the last user message after successfully updating the limit
Implementation notes:
- Uses existing
useSubscriptionDataanduseUpdateUsageLimithooks for subscription management - Uses established
open-settingscustom event pattern for navigation to settings modal - Follows the existing component patterns in the copilot-message components directory
Confidence Score: 4/5
- This PR is safe to merge - it adds a self-contained feature with proper error handling and follows established patterns.
- The implementation follows existing codebase patterns, uses established hooks and events, and includes proper error handling with rollback on failure. The code is well-structured and the changes are focused on the feature scope.
- usage-limit-actions.tsx could benefit from minor improvements like a Props interface and memoization for larger components.
Important Files Changed
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/components/usage-limit-actions.tsx | New component providing inline usage limit actions - allows users to increase limits or upgrade plan after hitting usage limits. Follows established patterns. |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/copilot-message.tsx | Integrated UsageLimitActions component, conditionally rendered when message has usage_limit errorType. |
| apps/sim/stores/panel/copilot/store.ts | Extended createErrorMessage function and error handling to track errorType for specific HTTP status codes (401, 402, 403, 426, 429). |
| apps/sim/stores/panel/copilot/types.ts | Added optional errorType field to CopilotMessage interface for tracking error categories. |
Sequence Diagram
sequenceDiagram
participant User
participant CopilotMessage
participant UsageLimitActions
participant CopilotStore
participant API
User->>CopilotStore: sendMessage()
CopilotStore->>API: POST /api/copilot
API-->>CopilotStore: 402 Usage Limit Exceeded
CopilotStore->>CopilotStore: createErrorMessage(errorType: 'usage_limit')
CopilotStore->>CopilotMessage: render with errorType
CopilotMessage->>UsageLimitActions: render actions
alt User can edit limit (Pro/Team)
User->>UsageLimitActions: click $50/$100/$150 button
UsageLimitActions->>API: PUT /api/usage
API-->>UsageLimitActions: success
UsageLimitActions->>CopilotStore: filter error messages
UsageLimitActions->>CopilotStore: sendMessage() retry
CopilotStore->>API: POST /api/copilot
API-->>CopilotStore: success
else User cannot edit limit (Free)
User->>UsageLimitActions: click "Upgrade Plan"
UsageLimitActions->>UsageLimitActions: dispatch 'open-settings' event
Note over UsageLimitActions: Settings modal opens to subscription tab
end