import type { IncomingMessage } from 'node:http'; import type { Duplex } from 'node:stream'; /** Handle the HTTP upgrade for `GET /v1/nodes/{id}/attach`. A-9 matches the * route, extracts `{id}`, and calls this with the raw upgrade triplet; this * owns the WS handshake (its own noServer `wss` above) AND the spec §5.3 * attach-implies-revive semantics. Never throws — every failure path either * refuses the upgrade (plain HTTP error + socket destroy) or, post-handshake, * closes the WS with a code. So A-9's upgrade router needs no try/catch around * this call beyond its own top-level safety net. * * Flow: * 1. Guard `isSafeNodeId` (→ 400) and existence (→ 404) BEFORE building any * fs path or reviving — an unsafe id must never reach `viewSocketPath`. * 2. Unless revive is opted out (`?revive=0` / `X-Crtr-Attach-Revive: 0`): * `reviveNode(id, { resume:true })` then * `waitForBrokerViewSocket` (bounded). Revive throw OR socket-not-listenable * → refuse 409, WS never opens. * 3. Revive opted out: a single connect probe. Dormant (socket refuses) → * refuse 409 (spec §5.3 asymmetry: a dead broker can't stream over WS). * 4. Only then upgrade and hand the live WS to {@link bridgeConnection}. */ export declare function handleAttachUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer, nodeId: string): Promise;