Skip to content

Commit ec13ad2

Browse files
authored
Add rate limits (#1034)
* Add rate limits * Lint
1 parent 2009901 commit ec13ad2

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

apps/sim/app/api/copilot/chat/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ export async function POST(req: NextRequest) {
474474
})
475475

476476
if (!simAgentResponse.ok) {
477-
if (simAgentResponse.status === 401 || simAgentResponse.status === 402) {
477+
if (
478+
simAgentResponse.status === 401 ||
479+
simAgentResponse.status === 402 ||
480+
simAgentResponse.status === 429
481+
) {
478482
// Rethrow status only; client will render appropriate assistant message
479483
return new NextResponse(null, { status: simAgentResponse.status })
480484
}

apps/sim/lib/copilot/tools/client-tools/get-oauth-credentials.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ export class GetOAuthCredentialsClientTool extends BaseTool {
6262
}),
6363
})
6464

65-
logger.info('Methods route response received', { status: response.status })
66-
6765
if (!response.ok) {
6866
const errorData = await response.json().catch(() => ({}))
6967
options?.onStateChange?.('errored')

apps/sim/lib/copilot/tools/client-tools/get-workflow-console.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ export class GetWorkflowConsoleClientTool extends BaseTool {
7575
if (activeWorkflowId) workflowId = activeWorkflowId
7676
}
7777

78-
logger.info('get_workflow_console: prepared params', {
79-
toolCallId: toolCall.id,
80-
hasWorkflowId: !!workflowId,
81-
})
82-
8378
if (!workflowId) {
8479
options?.onStateChange?.('errored')
8580
return { success: false, error: 'workflowId is required' }
@@ -102,7 +97,6 @@ export class GetWorkflowConsoleClientTool extends BaseTool {
10297
credentials: 'include',
10398
body: JSON.stringify(body),
10499
})
105-
logger.info('Methods route response', { ok: response.ok, status: response.status })
106100
if (!response.ok) {
107101
const e = await response.json().catch(() => ({}))
108102
options?.onStateChange?.('errored')

apps/sim/stores/copilot/store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,7 @@ const COPILOT_AUTH_REQUIRED_MESSAGE =
18651865
'*Authorization failed. An API key must be configured in order to use the copilot. You can configure an API key at [sim.ai](https://sim.ai).*'
18661866
const COPILOT_USAGE_EXCEEDED_MESSAGE =
18671867
'*Usage limit exceeded, please upgrade your plan or top up credits at [sim.ai](https://sim.ai) to continue using the copilot*'
1868+
const COPILOT_RATE_LIMIT_EXCEEDED_MESSAGE = '*Too many requests, please try again later*'
18681869

18691870
/**
18701871
* Copilot store using the new unified API
@@ -2320,6 +2321,8 @@ export const useCopilotStore = create<CopilotStore>()(
23202321
displayError = COPILOT_AUTH_REQUIRED_MESSAGE
23212322
} else if (result.status === 402) {
23222323
displayError = COPILOT_USAGE_EXCEEDED_MESSAGE
2324+
} else if (result.status === 429) {
2325+
displayError = COPILOT_RATE_LIMIT_EXCEEDED_MESSAGE
23232326
}
23242327

23252328
const errorMessage = createErrorMessage(streamingMessage.id, displayError)

0 commit comments

Comments
 (0)