MCPcopy
hub / github.com/CodebuffAI/codebuff / POST

Function POST

web/src/app/api/agents/publish/route.ts:40–356  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

38}
39
40export async function POST(request: NextRequest) {
41 try {
42 // Parse request body
43 const body = await request.json()
44 const parseResult = publishAgentsRequestSchema.safeParse(body)
45 if (!parseResult.success) {
46 const errorMessages = parseResult.error.issues.map((issue) => {
47 const path = issue.path.length > 0 ? `${issue.path.join('.')}: ` : ''
48 return `${path}${issue.message}`
49 })
50
51 return NextResponse.json(
52 {
53 error: 'Invalid request body',
54 details: errorMessages.join('; '),
55 validationErrors: parseResult.error.issues,
56 },
57 { status: 400 },
58 )
59 }
60
61 // DEPRECATED: authToken in body is for backwards compatibility with older CLI versions.
62 // New clients should use the Authorization header instead.
63 const {
64 data,
65 authToken: bodyAuthToken,
66 allLocalAgentIds,
67 } = parseResult.data
68 const agentDefinitions = data
69
70 // Prefer Authorization header, fall back to body authToken for backwards compatibility
71 const authToken = extractApiKeyFromHeader(request) ?? bodyAuthToken
72
73 // First use validateAgents to convert to DynamicAgentTemplate types
74 const agentMap = agentDefinitions.reduce(
75 (acc: Record<string, any>, agent: any) => {
76 acc[agent.id] = agent
77 return acc
78 },
79 {} as Record<string, any>,
80 )
81
82 const { validationErrors, dynamicTemplates } =
83 await validateAgentsWithSpawnableAgents({
84 agentTemplates: agentMap,
85 allLocalAgentIds,
86 logger,
87 })
88 const agents = Object.values(dynamicTemplates)
89
90 if (validationErrors.length > 0) {
91 const errorDetails = validationErrors.map((err) => err.message).join('\n')
92
93 return NextResponse.json(
94 {
95 error: 'Agent config validation failed',
96 details: errorDetails,
97 validationErrors,

Callers

nothing calls this directly

Calls 10

extractApiKeyFromHeaderFunction · 0.90
getUserInfoFromApiKeyFunction · 0.90
determineNextVersionFunction · 0.90
versionExistsFunction · 0.90
stringifyVersionFunction · 0.90
getPublishedAgentIdsFunction · 0.85
fromMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected