import { v as validateAuth } from './auth-DuunT7Cg.js';
import { s as sosCoordinator } from './coordinator-DMU_ADXf.js';
import { i as isValidSessionKey, a as isValidProvider } from './super-session-handler-DPyxFgmz.js';
import { j as json } from './index-lhTMmBNn.js';
import './shared-server-DaWdgxVh.js';
import 'crypto';
import 'better-sqlite3';
import 'fs';
import 'os';
import 'path';
import './registry-D4J_CuzW.js';
import './qwen-reader-DGfUbKaJ.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 });
  }
  if (typeof body !== "object" || body === null) {
    return json({ error: "Invalid JSON in request body" }, { status: 400 });
  }
  const payload = body;
  if (typeof payload.sessionKey !== "string" || !isValidSessionKey(payload.sessionKey)) {
    return json({ error: "sessionKey must be a session id or a path under home" }, { status: 400 });
  }
  if (typeof payload.provider !== "string" || !isValidProvider(payload.provider)) {
    return json({ error: "provider must be a known session source" }, { status: 400 });
  }
  const member = sosCoordinator.addMember(params.id ?? "", {
    capability: typeof payload.capability === "string" ? payload.capability : void 0,
    provider: payload.provider,
    sessionKey: payload.sessionKey,
    terminalId: typeof payload.terminalId === "string" ? payload.terminalId : null
  });
  if (!member) {
    return json({ error: "Super-session not found" }, { status: 404 });
  }
  return json(member, { status: 201 });
};

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