Files
agent-bounty-protocol/apps/web/src/app/api/a2a/growth/kit/route.ts
OG T 745ff300b5
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
feat: harden A2A funnel and paid proposal intake
2026-06-11 11:28:08 +08:00

60 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { buildAgentGrowthKit, sanitizeAgentId } from "@/lib/a2a-growth";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const agentId = sanitizeAgentId(searchParams.get("agent_id"));
const campaign = searchParams.get("campaign") || "a2a-agent-referral";
const source = searchParams.get("source") || "growth-kit";
const shouldRegister = searchParams.get("register") === "true";
if (!agentId) {
return NextResponse.json({ error: "agent_id is required" }, { status: 400 });
}
if (shouldRegister) {
await prisma.agentProfile.upsert({
where: { agent_id: agentId },
update: {
discovery_source: "A2A_GROWTH_KIT",
},
create: {
agent_id: agentId,
type: "SCOUT",
status: "PENDING",
discovery_source: "A2A_GROWTH_KIT",
capabilities: {
growth_referral: true,
channels: [source],
},
},
});
}
const kit = buildAgentGrowthKit({ agentId, campaign, source });
await prisma.auditEvent.create({
data: {
actorType: "AGENT",
actorId: agentId,
action: "A2A_GROWTH_KIT_ISSUED",
entityType: "SYSTEM",
entityId: "a2a-growth-kit",
metadata: {
campaign,
source,
registered_pending_agent: shouldRegister,
referral_url: kit.referral_url,
},
},
});
return NextResponse.json({
success: true,
kit,
});
}