Compare commits

...

4 Commits

Author SHA1 Message Date
Waleed Latif
f7573fadb1 v0.3.24: api block fixes 2025-08-12 20:35:07 -07:00
Waleed Latif
8016af60f4 fix(api): fix api block (#951) 2025-08-12 20:31:41 -07:00
Vikhyath Mondreti
8fccd5c20d Merge pull request #948 from simstudioai/staging
v0.3.24: revert redis session management change
2025-08-12 17:56:16 -05:00
Vikhyath Mondreti
8de06b63d1 Revert "improvement(performance): use redis for session data (#934)" (#947)
This reverts commit 3c7b3e1a4b.
2025-08-12 17:30:21 -05:00
4 changed files with 8 additions and 48 deletions

View File

@@ -25,7 +25,6 @@ import { quickValidateEmail } from '@/lib/email/validation'
import { env, isTruthy } from '@/lib/env'
import { isBillingEnabled, isProd } from '@/lib/environment'
import { createLogger } from '@/lib/logs/console/logger'
import { getRedisClient } from '@/lib/redis'
import { getEmailDomain } from '@/lib/urls/utils'
import { db } from '@/db'
import * as schema from '@/db/schema'
@@ -73,55 +72,14 @@ export const auth = betterAuth({
provider: 'pg',
schema,
}),
// Conditionally use Redis for session storage only if Redis is available
...(env.REDIS_URL
? {
secondaryStorage: {
get: async (key: string) => {
try {
const redis = getRedisClient()
if (!redis) return null
const value = await redis.get(`auth:${key}`)
return value || null
} catch (error) {
logger.error('Redis get error:', error)
return null
}
},
set: async (key: string, value: string, ttl?: number) => {
try {
const redis = getRedisClient()
if (!redis) return
if (ttl) {
await redis.setex(`auth:${key}`, ttl, value)
} else {
await redis.set(`auth:${key}`, value)
}
} catch (error) {
logger.error('Redis set error:', error)
}
},
delete: async (key: string) => {
try {
const redis = getRedisClient()
if (!redis) return
await redis.del(`auth:${key}`)
} catch (error) {
logger.error('Redis delete error:', error)
}
},
},
}
: {}),
session: {
cookieCache: {
enabled: true,
// Use shorter cache with Redis (5 min), longer without (1 hour)
maxAge: env.REDIS_URL ? 5 * 60 : 60 * 60,
maxAge: 24 * 60 * 60, // 24 hours in seconds
},
expiresIn: 30 * 24 * 60 * 60, // 30 days (how long a session can last overall)
updateAge: 24 * 60 * 60, // 24 hours (how often to refresh the expiry)
freshAge: env.REDIS_URL ? 0 : 6 * 60 * 60, // 0 with Redis, 6 hours without Redis
freshAge: 60 * 60, // 1 hour (or set to 0 to disable completely)
},
databaseHooks: {
session: {

View File

@@ -29,7 +29,7 @@ export const env = createEnv({
// Database & Storage
POSTGRES_URL: z.string().url().optional(), // Alternative PostgreSQL connection string
REDIS_URL: z.string().url().optional(), // Redis connection string for caching/sessions (optional - improves performance)
REDIS_URL: z.string().url().optional(), // Redis connection string for caching/sessions
// Payment & Billing
BILLING_ENABLED: z.boolean().optional(), // Enable billing enforcement and usage tracking

View File

@@ -171,7 +171,8 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
try {
data = await (contentType.includes('application/json') ? response.json() : response.text())
} catch (error) {
data = await response.text()
// If response body reading fails, we can't retry reading - just use error message
data = `Failed to parse response: ${error instanceof Error ? error.message : String(error)}`
}
return {

View File

@@ -399,8 +399,9 @@ async function handleInternalRequest(
const response = await fetch(fullUrl, requestOptions)
// Clone the response for error checking while preserving original for transformResponse
// Clone the response immediately before any body consumption
const responseForErrorCheck = response.clone()
const responseForTransform = response.clone()
// Parse response data for error checking
let responseData
@@ -468,7 +469,7 @@ async function handleInternalRequest(
// Success case: use transformResponse if available
if (tool.transformResponse) {
try {
const data = await tool.transformResponse(response, params)
const data = await tool.transformResponse(responseForTransform, params)
return data
} catch (transformError) {
logger.error(`[${requestId}] Transform response error for ${toolId}:`, {