MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / pty_connect

Function pty_connect

crates/opencode-server/src/routes.rs:3463–3486  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
3463async 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
3488async fn handle_pty_websocket(mut socket: WebSocket, sub: PtySubscription, cursor_param: i64) {
3489 // --- Phase 1: Replay buffered output ---

Callers

nothing calls this directly

Calls 5

get_pty_managerFunction · 0.85
handle_pty_websocketFunction · 0.85
into_responseMethod · 0.80
subscribeMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected