diff --git a/apps/web/src/app/api/admin/make-agents-public/route.ts b/apps/web/src/app/api/admin/make-agents-public/route.ts new file mode 100644 index 0000000..3c895a8 --- /dev/null +++ b/apps/web/src/app/api/admin/make-agents-public/route.ts @@ -0,0 +1,42 @@ +import { prisma } from '@tpmjs/db'; +import { type NextRequest, NextResponse } from 'next/server'; + +export const runtime = 'nodejs'; +export const dynamic = 'force-dynamic'; + +/** + * POST /api/admin/make-agents-public + * One-off endpoint to update all existing agents to be public. + * Protected by CRON_SECRET. + */ +export async function POST(request: NextRequest): Promise { + // Verify authorization + const authHeader = request.headers.get('authorization'); + const cronSecret = process.env.CRON_SECRET; + + if (!cronSecret || authHeader !== `Bearer ${cronSecret}`) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + + try { + // Update all agents to be public + const result = await prisma.agent.updateMany({ + where: { isPublic: false }, + data: { isPublic: true }, + }); + + // Get all agents for verification + const agents = await prisma.agent.findMany({ + select: { id: true, name: true, isPublic: true }, + }); + + return NextResponse.json({ + success: true, + updated: result.count, + agents: agents.map((a) => ({ name: a.name, isPublic: a.isPublic })), + }); + } catch (error) { + console.error('Failed to update agents:', error); + return NextResponse.json({ success: false, error: 'Failed to update agents' }, { status: 500 }); + } +} diff --git a/packages/db/prisma/make-agents-public.ts b/packages/db/prisma/make-agents-public.ts new file mode 100644 index 0000000..0f19f6d --- /dev/null +++ b/packages/db/prisma/make-agents-public.ts @@ -0,0 +1,34 @@ +/** + * One-off script to update all existing agents to be public. + * Run with: pnpm --filter=@tpmjs/db exec tsx prisma/make-agents-public.ts + */ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +async function main() { + console.log('Updating all agents to be public...'); + + const result = await prisma.agent.updateMany({ + where: { isPublic: false }, + data: { isPublic: true }, + }); + + console.log(`Updated ${result.count} agents to isPublic=true`); + + // Show all agents now + const agents = await prisma.agent.findMany({ + select: { id: true, name: true, isPublic: true }, + }); + console.log('\nAll agents:'); + for (const agent of agents) { + console.log(` - ${agent.name} (isPublic: ${agent.isPublic})`); + } +} + +main() + .catch((e) => { + console.error('Error:', e); + process.exit(1); + }) + .finally(() => prisma.$disconnect());