-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(settings): add rate limit control for Profile configuration #1785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(settings): add rate limit control for Profile configuration #1785
Conversation
Introduce a new RateLimitControl component to manage per-profile rate limiting. The API configuration now includes a rateLimitSeconds option, allowing users to set a custom rate limit. This change also updates the AdvancedSettings and ApiOptions components to integrate the new rate limit functionality. Add translations for the new rate limit settings in multiple languages.
|
|
I think we should do the migration for the current value into all profiles. And are there more places to remove references to the global state? |
Add support for migrating global rate limit settings to individual API profiles. Introduce a migrations object to track migration status and apply rate limits during configuration saves. New tests ensure correct migration behavior for existing and new profiles.
Added mock global state to prevent rate limit errors during tests. Updated assertions to verify rate limit values in stored configurations. This ensures that the ConfigManager behaves correctly when handling rate limits in various scenarios.
|
I think everything looks good now; the migration of the previous value is already in place @mrubens |
|
|
||
| // If no global rate limit, use default value of 5 seconds | ||
| if (rateLimitSeconds === undefined) { | ||
| rateLimitSeconds = 5 // Default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default should be 0
| // Apply rate limit migration if needed | ||
| if (!config.migrations.rateLimitMigrated) { | ||
| await this.migrateRateLimit(config) | ||
| config.migrations.rateLimitMigrated = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clear out the global state rate limit too right?
| // If this is a new config or doesn't have rate limit, try to apply the global rate limit | ||
| if (!existingConfig || config.rateLimitSeconds === undefined) { | ||
| // Apply rate limit if not specified explicitly in the config being saved | ||
| if (config.rateLimitSeconds === undefined) { | ||
| let globalRateLimit: number | undefined | ||
|
|
||
| // First check if we have an existing migrated config to copy from | ||
| const anyExistingConfig = Object.values(currentConfig.apiConfigs)[0] | ||
| if (anyExistingConfig?.rateLimitSeconds !== undefined) { | ||
| globalRateLimit = anyExistingConfig.rateLimitSeconds | ||
| console.log( | ||
| `[RateLimitMigration] Using existing profile's rate limit value: ${globalRateLimit}s`, | ||
| ) | ||
| } else { | ||
| // Otherwise check global state | ||
| try { | ||
| globalRateLimit = await this.context.globalState.get<number>("rateLimitSeconds") | ||
| console.log( | ||
| `[RateLimitMigration] Using global rate limit for new profile: ${globalRateLimit}s`, | ||
| ) | ||
| } catch (error) { | ||
| console.error( | ||
| "[RateLimitMigration] Error getting global rate limit for new profile:", | ||
| error, | ||
| ) | ||
| } | ||
|
|
||
| // Use default if not found | ||
| if (globalRateLimit === undefined) { | ||
| globalRateLimit = 5 // Default value | ||
| console.log( | ||
| `[RateLimitMigration] Using default rate limit value for new profile: ${globalRateLimit}s`, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Apply the rate limit to the new config | ||
| config.rateLimitSeconds = globalRateLimit | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need this code. After we do the migration, we should just remove the idea of a global rate limit.
|
|
||
| <Section> | ||
| <div> | ||
| <div className="flex flex-col gap-2"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just an empty section now? Can we get rid of it?
| useDebounce(() => onChange(inputValue), 50, [onChange, inputValue]) | ||
| // Sync internal state with prop changes when switching profiles | ||
| useEffect(() => { | ||
| const hasCustomRateLimit = value !== undefined && value !== null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checkbox doesn't seem to be serializing correctly
Screen.Recording.2025-03-24.at.3.10.38.PM.mov
|
Completed in #2376. Thanks for pushing for this! |
Introduce a new RateLimitControl component to manage per-profile rate limiting. The API configuration now includes a rateLimitSeconds option, allowing users to set a custom rate limit. This change also updates the AdvancedSettings and ApiOptions components to integrate the new rate limit functionality.
Add translations for the new rate limit settings in multiple languages.
Important
Adds rate limit control to API configurations with a new
RateLimitControlcomponent and updates translations across multiple languages.rateLimitSecondsoption toApiHandlerOptionsinapi.tsfor per-profile rate limiting.API_CONFIG_KEYSinapi.tsto includerateLimitSeconds.AdvancedSettings.tsx.RateLimitControlinApiOptions.tsx.RateLimitControlcomponent inRateLimitControl.tsxfor managing rate limits.ca/settings.json,de/settings.json,en/settings.json,es/settings.json,fr/settings.json,hi/settings.json,it/settings.json,ja/settings.json,ko/settings.json,pl/settings.json,pt-BR/settings.json,tr/settings.json,vi/settings.json,zh-CN/settings.json,zh-TW/settings.json.This description was created by
for 9efc90d. It will automatically update as commits are pushed.