@@ -67,8 +67,36 @@ class cbws {
6767 const agentTask = process . env . agentTask ? `&agentTask=${ process . env . agentTask } ` : '' ;
6868 const socketPort = process . env . SOCKET_PORT || '12345' ;
6969 const serverUrl = process . env . CODEBOLT_SERVER_URL || 'localhost' ;
70+ const threadToken = process . env . threadToken || null
71+
72+ console . log ( '[WebSocket] Logging all relevant variables:' ) ;
73+ console . log ( 'uniqueConnectionId:' , uniqueConnectionId ) ;
74+ console . log ( 'initialMessage:' , initialMessage ) ;
75+ console . log ( 'agentIdParam:' , agentIdParam ) ;
76+ console . log ( 'parentIdParam:' , parentIdParam ) ;
77+ console . log ( 'parentAgentInstanceIdParam:' , parentAgentInstanceIdParam ) ;
78+ console . log ( 'agentTask:' , agentTask ) ;
79+ console . log ( 'socketPort:' , socketPort ) ;
80+ console . log ( 'serverUrl:' , serverUrl ) ;
81+ console . log ( 'threadToken:' , threadToken ) ;
82+ console . log ( '[WebSocket] Environment variables check:' ) ;
83+ console . log ( 'process.env.agentId:' , process . env . agentId ) ;
84+ console . log ( 'process.env.threadToken:' , process . env . threadToken ) ;
85+ console . log ( 'process.env.parentId:' , process . env . parentId ) ;
86+ console . log ( 'process.env.agentTask:' , process . env . agentTask ) ;
7087
71- const wsUrl = `ws://${ serverUrl } :${ socketPort } /codebolt?id=${ uniqueConnectionId } ${ agentIdParam } ${ parentIdParam } ${ parentAgentInstanceIdParam } ${ agentTask } ${ process . env . Is_Dev ? '&dev=true' : '' } ` ;
88+ const threadTokenParam = threadToken ? `&threadToken=${ encodeURIComponent ( threadToken ) } ` : '' ;
89+
90+ // Add all custom environment variables as URL parameters
91+ const knownEnvVars = [ 'SOCKET_PORT' , 'CODEBOLT_SERVER_URL' , 'agentId' , 'parentId' , 'parentAgentInstanceId' , 'agentTask' , 'threadToken' , 'Is_Dev' , 'PATH' , 'NODE_ENV' , 'HOME' , 'USER' , 'SHELL' ] ;
92+ let customParams = '' ;
93+ for ( const [ key , value ] of Object . entries ( process . env ) ) {
94+ if ( ! knownEnvVars . includes ( key ) && value && ! key . startsWith ( 'npm_' ) && ! key . startsWith ( '_' ) ) {
95+ customParams += `&${ encodeURIComponent ( key ) } =${ encodeURIComponent ( value ) } ` ;
96+ }
97+ }
98+
99+ const wsUrl = `ws://${ serverUrl } :${ socketPort } /codebolt?id=${ uniqueConnectionId } ${ agentIdParam } ${ parentIdParam } ${ parentAgentInstanceIdParam } ${ agentTask } ${ threadTokenParam } ${ customParams } ${ process . env . Is_Dev ? '&dev=true' : '' } ` ;
72100 console . log ( '[WebSocket] Connecting to:' , wsUrl ) ;
73101
74102 this . websocket = new WebSocket ( wsUrl ) ;
0 commit comments