/** * SFTP-over-frame — structured file RPC over the shell binary channel. * Mirrors `edge-client/src/session/sftp.rs`. * * A frame type `FrameType::Sftp = 6` carries a JSON request/response payload * on the existing 17-byte shell frame. The relay is a dumb byte-pump: * it forwards Sftp frames verbatim; ALL filesystem logic lives here. * Under the hood this is JSON RPC over `node:fs` — we do NOT shell out * to `sftp` (the edge-client already runs as the Standard User with full * filesystem access). * * ## Protocol * Request (browser → edge, Sftp frame payload = UTF-8 JSON): * ```json * {"op":"list|read|write|delete|stat","path":"/abs/path"[,"content":"..."],"reqId":1} * ``` * Response (edge → browser): * ```json * {"reqId":1,"ok":true,"data":{...}} * {"reqId":1,"ok":false,"error":"..."} * ``` * * ## P1-a / R-MED-2 — per-session SFTP chroot * When the relay sends an `SftpRoot` control frame (frame type 7) on shell * session open, the edge stores the supplied root path in a per-session map. * Every subsequent Sftp op for that session is resolved under the root. * A `null` root (or absent) means "no chroot" (default). * * ## E-H2 — max file size for read/write ops * Files larger than 32 MiB are refused to prevent browser OOM. */ interface SftpRequest { op: string; path: string; content?: string; reqId?: number; } interface SftpResponse { reqId: number; ok: boolean; data?: Record; error?: string; } declare function setSessionRoot(sessionId: string, payload: Buffer): void; declare function resolveSftpPath(sessionId: string, userPath: string): string; declare function dispatch(sessionId: string, req: SftpRequest): SftpResponse; export type FrameHandler = (sessionId: string, frameType: number, payload: Buffer) => void; export declare class SftpForwarder { private readonly emitter; /** * Handle an inbound Sftp frame. Mirrors Rust `handle_sftp_request`. * Parses the JSON request, dispatches the file op, and emits the response * frame (to be sent back to the relay/browser). */ handleFrame(sessionId: string, frameType: number, payload: Buffer): void; /** * Register a handler for outbound Sftp response frames. * The handler receives (sessionId, frameType, payloadBytes). */ onFrame(handler: FrameHandler): void; } /** Clear all session roots (for tests only). */ export declare function clearSessionRoots(): void; export { setSessionRoot, resolveSftpPath, dispatch };