import { p as ptyManager } from './pty-manager-BsHXoNks.js';
import { r as resolveAccess } from './share-auth-BS7JuiHf.js';
import { t as toErrorMessage } from './error-DDXB3duW.js';
import { j as json } from './index-lhTMmBNn.js';
import 'child_process';
import 'crypto';
import 'fs';
import 'path';
import 'url';
import './qwen-reader-DGfUbKaJ.js';
import 'os';
import './guest-registry-Dxvd7p-g.js';
import './super-session-handler-DPyxFgmz.js';
import './registry-D4J_CuzW.js';
import 'better-sqlite3';
import './coordinator-DMU_ADXf.js';
import 'net';
import 'node:module';
import './shooter-home-4f_HkdGI.js';
import './auth-DuunT7Cg.js';
import './shared-server-DaWdgxVh.js';
import './share-store-B9jMpVg0.js';

const POST = async ({ params, request }) => {
  const access = resolveAccess(request, params.id);
  if (!access) {
    return json({ error: "Unauthorized" }, { status: 401 });
  }
  if (access.level === "guest" && access.mode !== "control") {
    return json({ error: "View-only access" }, { status: 403 });
  }
  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-C3rA9AOZ.js.map
