(token: string, session: Session)
| 173 | private metadataLock = new AsyncLock() |
| 174 | |
| 175 | constructor(token: string, session: Session) { |
| 176 | super() |
| 177 | this.token = token |
| 178 | this.sessionId = session.id |
| 179 | this.metadata = session.metadata |
| 180 | this.metadataVersion = session.metadataVersion |
| 181 | this.agentState = session.agentState |
| 182 | this.agentStateVersion = session.agentStateVersion |
| 183 | |
| 184 | this.rpcHandlerManager = new RpcHandlerManager({ |
| 185 | scopePrefix: this.sessionId, |
| 186 | logger: (msg, data) => logger.debug(msg, data) |
| 187 | }) |
| 188 | |
| 189 | if (this.metadata?.path) { |
| 190 | registerCommonHandlers(this.rpcHandlerManager, this.metadata.path) |
| 191 | } |
| 192 | |
| 193 | this.socket = io(`${configuration.apiUrl}/cli`, { |
| 194 | auth: { |
| 195 | token: this.token, |
| 196 | clientType: 'session-scoped' as const, |
| 197 | sessionId: this.sessionId |
| 198 | }, |
| 199 | path: '/socket.io/', |
| 200 | reconnection: true, |
| 201 | reconnectionAttempts: Infinity, |
| 202 | reconnectionDelay: 1000, |
| 203 | reconnectionDelayMax: 5000, |
| 204 | transports: ['websocket'], |
| 205 | autoConnect: false, |
| 206 | ...buildSocketIoExtraHeaderOptions() |
| 207 | }) |
| 208 | |
| 209 | this.terminalManager = new TerminalManager({ |
| 210 | sessionId: this.sessionId, |
| 211 | getSessionPath: () => this.metadata?.path ?? null, |
| 212 | onReady: (payload) => this.socket.emit('terminal:ready', payload), |
| 213 | onOutput: (payload) => this.socket.emit('terminal:output', payload), |
| 214 | onExit: (payload) => this.socket.emit('terminal:exit', payload), |
| 215 | onError: (payload) => this.socket.emit('terminal:error', payload) |
| 216 | }) |
| 217 | |
| 218 | this.socket.on('connect', () => { |
| 219 | logger.debug('Socket connected successfully') |
| 220 | this.rpcHandlerManager.onSocketConnect(this.socket) |
| 221 | if (this.hasConnectedOnce) { |
| 222 | this.needsBackfill = true |
| 223 | } |
| 224 | void this.backfillIfNeeded() |
| 225 | this.hasConnectedOnce = true |
| 226 | this.socket.emit('session-alive', { |
| 227 | sid: this.sessionId, |
| 228 | time: Date.now(), |
| 229 | thinking: false |
| 230 | }) |
| 231 | }) |
| 232 |
nothing calls this directly
no test coverage detected