fix: use sync rate limiter for conversation routes

The distributed rate limiter (checkRateLimitDistributed) was causing
timeouts in production, likely due to @vercel/kv connection issues.
Switch to sync in-memory rate limiter (checkRateLimit) which works
reliably across all other endpoints.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2026-01-09 05:23:18 +10:00
parent 3612d12c90
commit 9b6a4a625e
3 changed files with 154 additions and 6 deletions

View file

@ -14,7 +14,7 @@ import type { AIProvider } from '@tpmjs/types/agent';
import { SendMessageSchema } from '@tpmjs/types/agent';
import type { LanguageModel, ModelMessage } from 'ai';
import { type NextRequest, NextResponse } from 'next/server';
import { type RateLimitConfig, checkRateLimitDistributed } from '~/lib/rate-limit';
import { type RateLimitConfig, checkRateLimit } from '~/lib/rate-limit';
/**
* Rate limit for chat messages: 30 requests per minute
@ -72,8 +72,8 @@ async function getProviderModel(
* Send a message and stream the AI response via SSE
*/
export async function POST(request: NextRequest, context: RouteContext): Promise<Response> {
// Check rate limit first to prevent expensive LLM calls (uses distributed KV when available)
const rateLimitResponse = await checkRateLimitDistributed(request, CHAT_RATE_LIMIT);
// Check rate limit first to prevent expensive LLM calls
const rateLimitResponse = checkRateLimit(request, CHAT_RATE_LIMIT);
if (rateLimitResponse) {
return rateLimitResponse;
}

View file

@ -14,7 +14,7 @@ import type { AIProvider } from '@tpmjs/types/agent';
import { SendMessageSchema } from '@tpmjs/types/agent';
import type { LanguageModel, ModelMessage } from 'ai';
import { type NextRequest, NextResponse } from 'next/server';
import { type RateLimitConfig, checkRateLimitDistributed } from '~/lib/rate-limit';
import { type RateLimitConfig, checkRateLimit } from '~/lib/rate-limit';
/**
* Rate limit for chat messages: 30 requests per minute
@ -85,8 +85,8 @@ async function getProviderModel(
* Send a message and stream the AI response via SSE
*/
export async function POST(request: NextRequest, context: RouteContext): Promise<Response> {
// Check rate limit first to prevent expensive LLM calls (uses distributed KV when available)
const rateLimitResponse = await checkRateLimitDistributed(request, CHAT_RATE_LIMIT);
// Check rate limit first to prevent expensive LLM calls
const rateLimitResponse = checkRateLimit(request, CHAT_RATE_LIMIT);
if (rateLimitResponse) {
return rateLimitResponse;
}