MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / POST

Function POST

web/src/app/api/admin/relabel-for-user/route.ts:93–150  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

91}
92
93export async function POST(req: NextRequest) {
94 const authResult = await checkAdminAuth()
95 if (authResult instanceof NextResponse) {
96 return authResult
97 }
98
99 const userId = req.nextUrl.searchParams.get('userId')
100 if (!userId) {
101 return NextResponse.json(
102 { error: 'Missing required parameter: userId' },
103 { status: 400 },
104 )
105 }
106
107 const { limit: requestedLimit } = await req.json().catch(() => ({}))
108 const limit =
109 typeof requestedLimit === 'number' && requestedLimit > 0
110 ? requestedLimit
111 : DEFAULT_RELABEL_LIMIT
112
113 // Require API key from Authorization header - user must provide their own key
114 const apiKey = getApiKeyFromRequest(req)
115 if (!apiKey) {
116 return NextResponse.json(
117 {
118 error: 'API key required',
119 details:
120 'Provide your API key via Authorization header (Bearer token).',
121 hint: 'Visit /usage in the web app to create an API key.',
122 },
123 { status: 401 },
124 )
125 }
126
127 try {
128 await ensureBigQuery()
129 const results = await relabelUserTraces({
130 userId,
131 limit,
132 promptContext: buildPromptContext(apiKey),
133 })
134
135 return NextResponse.json({
136 success: true,
137 message: 'Traces relabeled successfully',
138 data: results,
139 })
140 } catch (error) {
141 logger.error(
142 { error, userId },
143 'Error relabeling traces for admin endpoint',
144 )
145 return NextResponse.json(
146 { error: 'Failed to relabel traces' },
147 { status: 500 },
148 )
149 }
150}

Callers

nothing calls this directly

Calls 6

checkAdminAuthFunction · 0.90
getApiKeyFromRequestFunction · 0.85
ensureBigQueryFunction · 0.85
relabelUserTracesFunction · 0.85
buildPromptContextFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected