mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 23:17:59 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7573fadb1 | ||
|
|
8016af60f4 | ||
|
|
8fccd5c20d | ||
|
|
8de06b63d1 |
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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}:`, {
|
||||
|
||||
Reference in New Issue
Block a user