import { r as requireApiToken } from '../../../chunks/apiAuth_DcNSM7D5.mjs';
import { i as isAdminAuthenticated } from '../../../chunks/adminAuth_CY4OwU1a.mjs';
import { r as runTassAgent } from '../../../chunks/tassAgent_jxZgSz7r.mjs';
export { renderers } from '../../../renderers.mjs';

const POST = async (context) => {
  if (!isAdminAuthenticated(context)) {
    const unauthorized = requireApiToken(context);
    if (unauthorized) {
      return unauthorized;
    }
  }
  try {
    const contentType = context.request.headers.get("content-type") ?? "";
    const payload = contentType.includes("application/json") ? await context.request.json() : {};
    const limit = Math.min(Math.max(Number(payload.limit ?? 3), 1), 10);
    const result = await runTassAgent(limit);
    return new Response(JSON.stringify({ ok: true, ...result }), {
      headers: { "content-type": "application/json; charset=utf-8" }
    });
  } catch (error) {
    return new Response(JSON.stringify({ ok: false, error: error instanceof Error ? error.message : "Agent failed" }), {
      status: 500,
      headers: { "content-type": "application/json; charset=utf-8" }
    });
  }
};

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  POST
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
