feat: 新增 Agent OS 管理与运行时能力
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { AdminAuthTokenRequestSchema } from '@/lib/agent-os/schemas'
|
||||
import { issueAdminToken, isValidAdminKey } from '@/lib/agent-os/admin-auth'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const validation = AdminAuthTokenRequestSchema.safeParse(body)
|
||||
|
||||
if (!validation.success) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Validation error',
|
||||
details: validation.error.errors,
|
||||
},
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const { adminKey, operator } = validation.data
|
||||
|
||||
if (!isValidAdminKey(adminKey)) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Unauthorized',
|
||||
details: ['Invalid admin key'],
|
||||
},
|
||||
{ status: 401 }
|
||||
)
|
||||
}
|
||||
|
||||
const token = issueAdminToken(operator || 'admin-console')
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
token: token.token,
|
||||
operator: token.operator,
|
||||
expiresAt: new Date(token.expiresAt).toISOString(),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('[AdminAuth] Failed to issue token:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user