WebSocket endpoint that bridges a client to a PTY session, matching the TS `Pty.connect` protocol: 1. On connect: replay buffered output from the requested cursor, then send a binary metadata frame (`0x00` + JSON `{"cursor": }`) so the client knows the current position. 2. Forward live PTY output to the client as binary frames. 3. Forward text/binary messages from the client into the PTY as inpu
(
Path(id): Path<String>,
Query(query): Query<PtyConnectQuery>,
ws: WebSocketUpgrade,
)
| 3461 | /// 2. Forward live PTY output to the client as binary frames. |
| 3462 | /// 3. Forward text/binary messages from the client into the PTY as input. |
| 3463 | async fn pty_connect( |
| 3464 | Path(id): Path<String>, |
| 3465 | Query(query): Query<PtyConnectQuery>, |
| 3466 | ws: WebSocketUpgrade, |
| 3467 | ) -> impl IntoResponse { |
| 3468 | let manager = get_pty_manager(); |
| 3469 | |
| 3470 | // Validate the session exists before upgrading. |
| 3471 | let subscription = match manager.subscribe(&id).await { |
| 3472 | Ok(sub) => sub, |
| 3473 | Err(_) => { |
| 3474 | return axum::response::Response::builder() |
| 3475 | .status(404) |
| 3476 | .body(axum::body::Body::from("PTY session not found")) |
| 3477 | .unwrap() |
| 3478 | .into_response(); |
| 3479 | } |
| 3480 | }; |
| 3481 | |
| 3482 | let cursor_param = query.cursor.unwrap_or(0); |
| 3483 | |
| 3484 | ws.on_upgrade(move |socket| handle_pty_websocket(socket, subscription, cursor_param)) |
| 3485 | .into_response() |
| 3486 | } |
| 3487 | |
| 3488 | async fn handle_pty_websocket(mut socket: WebSocket, sub: PtySubscription, cursor_param: i64) { |
| 3489 | // --- Phase 1: Replay buffered output --- |
nothing calls this directly
no test coverage detected