import {
  proxyWorker,
  requireOwnedJob,
  routeJobId,
} from '@/lib/agent-worker-proxy';

export const POST = async (
  request: Request,
  context: { params: Promise<{ jobId: string; interactionId: string }> },
) => {
  const params = await context.params;
  const jobId = await routeJobId({ params });
  const owned = await requireOwnedJob(jobId);
  if (!owned.ok) return owned.response;
  return await proxyWorker(
    jobId,
    `interactions/${encodeURIComponent(params.interactionId)}/reply`,
    {
      method: 'POST',
      body: await request.text(),
    },
  );
};
