MCPcopy
hub / github.com/simstudioai/sim / setupOperationsHandlers

Function setupOperationsHandlers

apps/realtime/src/handlers/operations.ts:23–654  ·  view source on GitHub ↗
(socket: AuthenticatedSocket, roomManager: IRoomManager)

Source from the content-addressed store, hash-verified

21const logger = createLogger('OperationsHandlers')
22
23export function setupOperationsHandlers(socket: AuthenticatedSocket, roomManager: IRoomManager) {
24 socket.on('workflow-operation', async (data) => {
25 const emitOperationError = (
26 forbidden: { type: string; message: string; operation?: string; target?: string },
27 failed?: { error: string; retryable?: boolean }
28 ) => {
29 socket.emit('operation-forbidden', forbidden)
30 if (failed && data?.operationId) {
31 socket.emit('operation-failed', { operationId: data.operationId, ...failed })
32 }
33 }
34
35 if (!roomManager.isReady()) {
36 emitOperationError(
37 { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' },
38 { error: 'Realtime unavailable', retryable: true }
39 )
40 return
41 }
42
43 let workflowId: string | null = null
44 let session: UserSession | null = null
45
46 try {
47 workflowId = await roomManager.getWorkflowIdForSocket(socket.id)
48 session = await roomManager.getUserSession(socket.id)
49 } catch (error) {
50 logger.error('Error loading session for workflow operation:', error)
51 emitOperationError(
52 { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' },
53 { error: 'Realtime unavailable', retryable: true }
54 )
55 return
56 }
57
58 if (!workflowId || !session) {
59 emitOperationError(
60 { type: 'SESSION_ERROR', message: 'Session expired, please rejoin workflow' },
61 { error: 'Session expired' }
62 )
63 return
64 }
65
66 let hasRoom = false
67 try {
68 hasRoom = await roomManager.hasWorkflowRoom(workflowId)
69 } catch (error) {
70 logger.error('Error checking workflow room:', error)
71 emitOperationError(
72 { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' },
73 { error: 'Realtime unavailable', retryable: true }
74 )
75 return
76 }
77 if (!hasRoom) {
78 emitOperationError(
79 { type: 'ROOM_NOT_FOUND', message: 'Workflow room not found' },
80 { error: 'Workflow room not found' }

Callers 1

setupAllHandlersFunction · 0.90

Calls 15

assertWorkflowMutableFunction · 0.90
generateIdFunction · 0.90
persistWorkflowOperationFunction · 0.90
getErrorMessageFunction · 0.90
emitOperationErrorFunction · 0.85
onMethod · 0.80
errorMethod · 0.80
parseMethod · 0.80
isReadyMethod · 0.65
getUserSessionMethod · 0.65

Tested by

no test coverage detected