import { v as validateAuth } from './auth-DuunT7Cg.js';
import { p as ptyManager } from './pty-manager-TyMUpDA9.js';
import { t as toErrorMessage } from './error-DDXB3duW.js';
import { j as json } from './index-CoD1IJuy.js';
import './shared-server-DaWdgxVh.js';
import 'crypto';
import 'child_process';
import 'fs';
import 'path';
import 'url';
import './events-handler-Dm1mNPQP.js';
import 'net';
import 'better-sqlite3';
import './opencode-db-path-DcfhJtJy.js';

const POST = async ({ params, request }) => {
  const authError = validateAuth(request);
  if (authError) {
    return authError;
  }
  let body;
  try {
    body = await request.json();
  } catch {
    return json({ error: "Invalid JSON in request body" }, { status: 400 });
  }
  try {
    const { cols, rows } = body;
    if (cols === void 0 || rows === void 0) {
      return json({ error: "cols and rows are required" }, { status: 400 });
    }
    if (typeof cols !== "number" || cols < 1) {
      return json({ error: "cols must be a positive number" }, { status: 400 });
    }
    if (typeof rows !== "number" || rows < 1) {
      return json({ error: "rows must be a positive number" }, { status: 400 });
    }
    if (cols > 500 || rows > 200) {
      return json({ error: "cols must be <= 500 and rows must be <= 200" }, { status: 400 });
    }
    const terminal = ptyManager.get(params.id);
    if (!terminal) {
      return json({ error: "Terminal not found" }, { status: 404 });
    }
    if (terminal.status === "exited") {
      return json({ error: "Terminal already exited" }, { status: 409 });
    }
    ptyManager.resize(params.id, cols, rows);
    console.log(`[terminals] Resized terminal ${params.id} to ${cols}x${rows}`);
    return json({
      success: true,
      timestamp: (/* @__PURE__ */ new Date()).toISOString()
    });
  } catch (error) {
    console.error("[terminals] Failed to resize terminal:", toErrorMessage(error));
    return json({ error: "Failed to resize terminal" }, { status: 500 });
  }
};

export { POST };
//# sourceMappingURL=_server.ts-BuYyCrnF.js.map
