diff --git a/apps/sim/app/workspace/providers/socket-provider.tsx b/apps/sim/app/workspace/providers/socket-provider.tsx index a637fa1b2..0b4c5d017 100644 --- a/apps/sim/app/workspace/providers/socket-provider.tsx +++ b/apps/sim/app/workspace/providers/socket-provider.tsx @@ -368,11 +368,7 @@ export function SocketProvider({ children, user }: SocketProviderProps) { eventHandlers.current.workflowReverted?.(data) }) - const rehydrateWorkflowStores = async ( - workflowId: string, - workflowState: any, - source: 'copilot' | 'workflow-state' - ) => { + const rehydrateWorkflowStores = async (workflowId: string, workflowState: any) => { const [ { useOperationQueueStore }, { useWorkflowRegistry }, @@ -397,7 +393,7 @@ export function SocketProvider({ children, user }: SocketProviderProps) { .getState() .operations.some((op: any) => op.workflowId === workflowId && op.status !== 'confirmed') if (hasPending) { - logger.info(`Skipping ${source} rehydration due to pending operations in queue`) + logger.info('Skipping rehydration due to pending operations in queue') return false } @@ -426,32 +422,10 @@ export function SocketProvider({ children, user }: SocketProviderProps) { }, })) - logger.info(`Successfully rehydrated stores from ${source}`) + logger.info('Successfully rehydrated workflow stores') return true } - socketInstance.on('copilot-workflow-edit', async (data) => { - logger.info( - `Copilot edited workflow ${data.workflowId} - rehydrating stores from database` - ) - - try { - const response = await fetch(`/api/workflows/${data.workflowId}`) - if (response.ok) { - const responseData = await response.json() - const workflowData = responseData.data - - if (workflowData?.state) { - await rehydrateWorkflowStores(data.workflowId, workflowData.state, 'copilot') - } - } else { - logger.error('Failed to fetch fresh workflow state:', response.statusText) - } - } catch (error) { - logger.error('Failed to rehydrate stores after copilot edit:', error) - } - }) - socketInstance.on('operation-confirmed', (data) => { logger.debug('Operation confirmed', { operationId: data.operationId }) eventHandlers.current.operationConfirmed?.(data) @@ -522,7 +496,7 @@ export function SocketProvider({ children, user }: SocketProviderProps) { if (workflowData?.state) { try { - await rehydrateWorkflowStores(workflowData.id, workflowData.state, 'workflow-state') + await rehydrateWorkflowStores(workflowData.id, workflowData.state) } catch (error) { logger.error('Error rehydrating workflow state:', error) } diff --git a/apps/sim/socket/rooms/memory-manager.ts b/apps/sim/socket/rooms/memory-manager.ts index 0aaf253bf..4633bc775 100644 --- a/apps/sim/socket/rooms/memory-manager.ts +++ b/apps/sim/socket/rooms/memory-manager.ts @@ -234,27 +234,4 @@ export class MemoryRoomManager implements IRoomManager { logger.info(`Notified ${room.users.size} users about workflow update: ${workflowId}`) } - - async handleCopilotWorkflowEdit(workflowId: string, description?: string): Promise { - logger.info(`Handling copilot workflow edit notification for ${workflowId}`) - - const room = this.workflowRooms.get(workflowId) - if (!room) { - logger.debug(`No active room found for copilot workflow edit ${workflowId}`) - return - } - - const timestamp = Date.now() - - this._io.to(workflowId).emit('copilot-workflow-edit', { - workflowId, - description, - message: 'Copilot has edited the workflow - rehydrating from database', - timestamp, - }) - - room.lastModified = timestamp - - logger.info(`Notified ${room.users.size} users about copilot workflow edit: ${workflowId}`) - } } diff --git a/apps/sim/socket/rooms/redis-manager.ts b/apps/sim/socket/rooms/redis-manager.ts index 51b22819b..38dde216f 100644 --- a/apps/sim/socket/rooms/redis-manager.ts +++ b/apps/sim/socket/rooms/redis-manager.ts @@ -407,28 +407,4 @@ export class RedisRoomManager implements IRoomManager { const userCount = await this.getUniqueUserCount(workflowId) logger.info(`Notified ${userCount} users about workflow update: ${workflowId}`) } - - async handleCopilotWorkflowEdit(workflowId: string, description?: string): Promise { - logger.info(`Handling copilot workflow edit notification for ${workflowId}`) - - const hasRoom = await this.hasWorkflowRoom(workflowId) - if (!hasRoom) { - logger.debug(`No active room found for copilot workflow edit ${workflowId}`) - return - } - - const timestamp = Date.now() - - this._io.to(workflowId).emit('copilot-workflow-edit', { - workflowId, - description, - message: 'Copilot has edited the workflow - rehydrating from database', - timestamp, - }) - - await this.updateRoomLastModified(workflowId) - - const userCount = await this.getUniqueUserCount(workflowId) - logger.info(`Notified ${userCount} users about copilot workflow edit: ${workflowId}`) - } } diff --git a/apps/sim/socket/rooms/types.ts b/apps/sim/socket/rooms/types.ts index 6a5edb5e6..4e3fc56b9 100644 --- a/apps/sim/socket/rooms/types.ts +++ b/apps/sim/socket/rooms/types.ts @@ -132,9 +132,4 @@ export interface IRoomManager { * Handle workflow update - notify users */ handleWorkflowUpdate(workflowId: string): Promise - - /** - * Handle copilot workflow edit - notify users to rehydrate - */ - handleCopilotWorkflowEdit(workflowId: string, description?: string): Promise } diff --git a/apps/sim/socket/routes/http.ts b/apps/sim/socket/routes/http.ts index b068b94ab..afd5946c5 100644 --- a/apps/sim/socket/routes/http.ts +++ b/apps/sim/socket/routes/http.ts @@ -115,20 +115,6 @@ export function createHttpHandler(roomManager: IRoomManager, logger: Logger) { return } - // Handle copilot workflow edit notifications from the main API - if (req.method === 'POST' && req.url === '/api/copilot-workflow-edit') { - try { - const body = await readRequestBody(req) - const { workflowId, description } = JSON.parse(body) - await roomManager.handleCopilotWorkflowEdit(workflowId, description) - sendSuccess(res) - } catch (error) { - logger.error('Error handling copilot workflow edit notification:', error) - sendError(res, 'Failed to process copilot edit notification') - } - return - } - // Handle workflow revert notifications from the main API if (req.method === 'POST' && req.url === '/api/workflow-reverted') { try { diff --git a/docker-compose.local.yml b/docker-compose.local.yml index a2f768c30..f47643ad0 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -14,11 +14,15 @@ services: - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio} - BETTER_AUTH_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here} - - ENCRYPTION_KEY=${ENCRYPTION_KEY:-your_encryption_key_here} + - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-dev-secret-at-least-32-characters-long} + - ENCRYPTION_KEY=${ENCRYPTION_KEY:-dev-encryption-key-at-least-32-chars} + - API_ENCRYPTION_KEY=${API_ENCRYPTION_KEY:-} + - INTERNAL_API_SECRET=${INTERNAL_API_SECRET:-dev-internal-api-secret-min-32-chars} + - REDIS_URL=${REDIS_URL:-} - COPILOT_API_KEY=${COPILOT_API_KEY} - SIM_AGENT_API_URL=${SIM_AGENT_API_URL} - OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434} + - SOCKET_SERVER_URL=${SOCKET_SERVER_URL:-http://realtime:3002} - NEXT_PUBLIC_SOCKET_URL=${NEXT_PUBLIC_SOCKET_URL:-http://localhost:3002} depends_on: db: @@ -39,10 +43,13 @@ services: context: . dockerfile: docker/realtime.Dockerfile environment: + - NODE_ENV=development - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - BETTER_AUTH_URL=${BETTER_AUTH_URL:-http://localhost:3000} - - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here} + - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-dev-secret-at-least-32-characters-long} + - INTERNAL_API_SECRET=${INTERNAL_API_SECRET:-dev-internal-api-secret-min-32-chars} + - REDIS_URL=${REDIS_URL:-} depends_on: db: condition: service_healthy diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 74bdd67f8..527c8d86b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -13,12 +13,15 @@ services: - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio} - BETTER_AUTH_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here} - - ENCRYPTION_KEY=${ENCRYPTION_KEY:-your_encryption_key_here} + - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} + - ENCRYPTION_KEY=${ENCRYPTION_KEY} + - API_ENCRYPTION_KEY=${API_ENCRYPTION_KEY:-} + - INTERNAL_API_SECRET=${INTERNAL_API_SECRET} + - REDIS_URL=${REDIS_URL:-} - COPILOT_API_KEY=${COPILOT_API_KEY} - SIM_AGENT_API_URL=${SIM_AGENT_API_URL} - OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434} - - SOCKET_SERVER_URL=${SOCKET_SERVER_URL:-http://localhost:3002} + - SOCKET_SERVER_URL=${SOCKET_SERVER_URL:-http://realtime:3002} - NEXT_PUBLIC_SOCKET_URL=${NEXT_PUBLIC_SOCKET_URL:-http://localhost:3002} depends_on: db: @@ -44,10 +47,13 @@ services: limits: memory: 1G environment: + - NODE_ENV=production - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000} - BETTER_AUTH_URL=${BETTER_AUTH_URL:-http://localhost:3000} - - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here} + - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} + - INTERNAL_API_SECRET=${INTERNAL_API_SECRET} + - REDIS_URL=${REDIS_URL:-} depends_on: db: condition: service_healthy