( request: SDKControlRequest, handlers: ServerControlRequestHandlers, )
| 333 | * collaborators as params so both cores can use it. |
| 334 | */ |
| 335 | export function handleServerControlRequest( |
| 336 | request: SDKControlRequest, |
| 337 | handlers: ServerControlRequestHandlers, |
| 338 | ): void { |
| 339 | const { |
| 340 | transport, |
| 341 | sessionId, |
| 342 | outboundOnly, |
| 343 | onInterrupt, |
| 344 | onSetModel, |
| 345 | onSetMaxThinkingTokens, |
| 346 | onSetPermissionMode, |
| 347 | } = handlers |
| 348 | if (!transport) { |
| 349 | logForDebugging( |
| 350 | '[bridge:repl] Cannot respond to control_request: transport not configured', |
| 351 | ) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | let response: SDKControlResponse |
| 356 | |
| 357 | // Outbound-only: reply error for mutable requests so claude.ai doesn't show |
| 358 | // false success. initialize must still succeed (server kills the connection |
| 359 | // if it doesn't — see comment above). |
| 360 | const req = request.request as { |
| 361 | subtype: string |
| 362 | model?: string |
| 363 | max_thinking_tokens?: number | null |
| 364 | mode?: string |
| 365 | [key: string]: unknown |
| 366 | } |
| 367 | if (outboundOnly && req.subtype !== 'initialize') { |
| 368 | response = { |
| 369 | type: 'control_response', |
| 370 | response: { |
| 371 | subtype: 'error', |
| 372 | request_id: request.request_id, |
| 373 | error: OUTBOUND_ONLY_ERROR, |
| 374 | }, |
| 375 | } |
| 376 | const event = { ...response, session_id: sessionId } |
| 377 | void transport.write(event) |
| 378 | logForDebugging( |
| 379 | `[bridge:repl] Rejected ${req.subtype} (outbound-only) request_id=${request.request_id}`, |
| 380 | ) |
| 381 | return |
| 382 | } |
| 383 | |
| 384 | switch (req.subtype) { |
| 385 | case 'initialize': |
| 386 | // Respond with minimal capabilities — the REPL handles |
| 387 | // commands, models, and account info itself. |
| 388 | response = { |
| 389 | type: 'control_response', |
| 390 | response: { |
| 391 | subtype: 'success', |
| 392 | request_id: request.request_id, |
no test coverage detected