/**
 * Handler for terminal_stdin messages.
 *
 * Writes data to a PTY process identified by terminalId.
 */
import { ErrorCode } from "@pocketcoder/shared/constants";
import { writeTerminal } from "../services/terminal-manager.js";
import { logger } from "../utils/logger.js";
export async function handleTerminalStdin(message, send) {
    const msg = message;
    const { requestId, payload } = msg;
    const { terminalId, data } = payload;
    try {
        writeTerminal(terminalId, data);
    }
    catch (err) {
        const errMsg = err instanceof Error ? err.message : String(err);
        logger.error(`terminal_stdin failed: ${errMsg}`);
        send({
            type: "terminal_stdin",
            requestId,
            error: {
                code: ErrorCode.TERMINAL_NOT_FOUND,
                message: `Terminal not found: ${terminalId}`,
            },
        });
    }
}
//# sourceMappingURL=terminal-stdin.js.map