-
Notifications
You must be signed in to change notification settings - Fork 0
Guardrails UI: add validators to config #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| NEXT_PUBLIC_BACKEND_URL= | ||
| NEXT_PUBLIC_GUARDRAILS_URL = | ||
|
|
||
| GUARDRAILS_TOKEN= | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||
| import { NextRequest, NextResponse } from 'next/server'; | ||||||
|
|
||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent default backend port. This file defaults to Proposed fix for consistency-const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
+const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8001';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| export async function GET(request: NextRequest) { | ||||||
| try { | ||||||
| // Get the API key from request headers | ||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||
| if (!apiKey) { | ||||||
| return NextResponse.json( | ||||||
| { error: 'Missing X-API-KEY header' }, | ||||||
| { status: 401 } | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| // Forward the request to the actual backend | ||||||
| const url = `${backendUrl}/api/v1/apikeys/verify`; | ||||||
|
|
||||||
| const response = await fetch(url, { | ||||||
| method: 'GET', | ||||||
| headers: { | ||||||
| 'X-API-KEY': apiKey, | ||||||
| 'Content-Type': 'application/json', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| // Handle empty responses (204 No Content, etc.) | ||||||
| const text = await response.text(); | ||||||
| const data = text ? JSON.parse(text) : {}; | ||||||
|
|
||||||
| // Return the response with the same status code | ||||||
| if (!response.ok) { | ||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } | ||||||
|
|
||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } catch (error: any) { | ||||||
| console.error('Proxy error:', error); | ||||||
| return NextResponse.json( | ||||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||||
| { status: 500 } | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,157 @@ | ||||
| import { NextResponse } from 'next/server'; | ||||
|
|
||||
| const backendUrl = process.env.NEXT_PUBLIC_GUARDRAILS_URL || 'http://localhost:8001'; | ||||
|
|
||||
| export async function GET( | ||||
| request: Request, | ||||
| { params }: { params: Promise<{ ban_list_id: string }> } | ||||
| ) { | ||||
| const { ban_list_id } = await params; | ||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||
|
|
||||
| if (!apiKey) { | ||||
| return NextResponse.json( | ||||
| { error: 'Missing X-API-KEY header' }, | ||||
| { status: 401 } | ||||
| ); | ||||
| } | ||||
|
|
||||
| try { | ||||
| const url = `${backendUrl}/api/v1/guardrails/ban_lists/${ban_list_id}`; | ||||
|
|
||||
| console.log('[GET /api/guardrails/ban_lists/[ban_list_id]] Forwarding to:', url); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent log paths within the same file. Line 22 uses Proposed fix: Standardize to plural formApply consistent naming across all log statements. For example: - console.log('[GET /api/guardrails/ban_list/[ban_list_id]] Backend response status:', response.status, response.statusText);
+ console.log('[GET /api/guardrails/ban_lists/[ban_list_id]] Backend response status:', response.status, response.statusText);Similar fixes needed for lines 37, 40, 74-76, 86, 88, 92, 95, 126, 136, 142, 145. 🤖 Prompt for AI Agents |
||||
|
|
||||
| const response = await fetch(url, { | ||||
| headers: { | ||||
| 'X-API-KEY': apiKey, | ||||
| 'Content-Type': 'application/json', | ||||
| }, | ||||
| }); | ||||
|
|
||||
| console.log('[GET /api/guardrails/ban_list/[ban_list_id]] Backend response status:', response.status, response.statusText); | ||||
|
|
||||
| // Handle empty responses (204 No Content, etc.) | ||||
| const text = await response.text(); | ||||
| const data = text ? JSON.parse(text) : {}; | ||||
|
|
||||
| console.log('[GET /api/guardrails/ban_list/[ban_list_id]] Backend response data:', JSON.stringify(data, null, 2)); | ||||
|
|
||||
| if (!response.ok) { | ||||
| console.error('[GET /api/guardrails/ban_list/[ban_list_id]] Backend error:', response.status, data); | ||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } | ||||
|
|
||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } catch (error: any) { | ||||
| console.error('Proxy error:', error); | ||||
| return NextResponse.json( | ||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||
| { status: 500 } | ||||
| ); | ||||
| } | ||||
| } | ||||
|
|
||||
| export async function PUT( | ||||
| request: Request, | ||||
| { params }: { params: Promise<{ ban_list_id: string }> } | ||||
| ) { | ||||
| const { ban_list_id } = await params; | ||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||
|
|
||||
| if (!apiKey) { | ||||
| return NextResponse.json( | ||||
| { error: 'Missing X-API-KEY header' }, | ||||
| { status: 401 } | ||||
| ); | ||||
| } | ||||
|
|
||||
| try { | ||||
| // Get the JSON body from the request | ||||
| const body = await request.json(); | ||||
|
|
||||
| const url = `${backendUrl}/api/v1/guardrails/ban_lists/${ban_list_id}`; | ||||
|
|
||||
| console.log('[PUT /api/guardrails/ban_list/[ban_list_id]] Forwarding to:', url); | ||||
| console.log('[PUT /api/guardrails/ban_list/[ban_list_id]] Body:', JSON.stringify(body, null, 2)); | ||||
|
|
||||
|
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging full request body in production. Same concern as other routes—logging complete request bodies could expose sensitive data in production logs. Proposed fix console.log('[PUT /api/guardrails/ban_lists/[ban_list_id]] Forwarding to:', url);
- console.log('[PUT /api/guardrails/ban_list/[ban_list_id]] Body:', JSON.stringify(body, null, 2));📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| const response = await fetch(url, { | ||||
| method: 'PUT', | ||||
| body: JSON.stringify(body), | ||||
| headers: { | ||||
| 'X-API-KEY': apiKey, | ||||
| 'Content-Type': 'application/json', | ||||
| }, | ||||
| }); | ||||
|
|
||||
| console.log('[PUT /api/guardrails/ban_list/[ban_list_id]] Backend response status:', response.status, response.statusText); | ||||
|
|
||||
| // Handle empty responses (204 No Content, etc.) | ||||
| const text = await response.text(); | ||||
| const data = text ? JSON.parse(text) : { success: true }; | ||||
|
|
||||
| console.log('[PUT /api/guardrails/ban_list/[ban_list_id]] Backend response data:', JSON.stringify(data, null, 2)); | ||||
|
|
||||
| if (!response.ok) { | ||||
| console.error('[PUT /api/guardrails/ban_list/[ban_list_id]] Backend error:', response.status, data); | ||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } | ||||
|
|
||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } catch (error: any) { | ||||
| console.error('Proxy error:', error); | ||||
| return NextResponse.json( | ||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||
| { status: 500 } | ||||
| ); | ||||
| } | ||||
| } | ||||
|
|
||||
| export async function DELETE( | ||||
| request: Request, | ||||
| { params }: { params: Promise<{ ban_list_id: string }> } | ||||
| ) { | ||||
| const { ban_list_id } = await params; | ||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||
|
|
||||
| if (!apiKey) { | ||||
| return NextResponse.json( | ||||
| { error: 'Missing X-API-KEY header' }, | ||||
| { status: 401 } | ||||
| ); | ||||
| } | ||||
|
|
||||
| try { | ||||
| const url = `${backendUrl}/api/v1/guardrails/ban_lists/${ban_list_id}`; | ||||
|
|
||||
| console.log('[DELETE /api/guardrails/ban_lists/[ban_list_id]] Forwarding to:', url); | ||||
|
|
||||
| const response = await fetch(url, { | ||||
| method: 'DELETE', | ||||
| headers: { | ||||
| 'X-API-KEY': apiKey, | ||||
| 'Content-Type': 'application/json', | ||||
| }, | ||||
| }); | ||||
|
|
||||
| console.log('[DELETE /api/guardrails/ban_list/[ban_list_id]] Backend response status:', response.status, response.statusText); | ||||
|
|
||||
| // Handle empty responses (204 No Content, etc.) | ||||
| const text = await response.text(); | ||||
| const data = text ? JSON.parse(text) : { success: true }; | ||||
|
|
||||
| console.log('[DELETE /api/guardrails/ban_list/[ban_list_id]] Backend response data:', JSON.stringify(data, null, 2)); | ||||
|
|
||||
| if (!response.ok) { | ||||
| console.error('[DELETE /api/guardrails/ban_list/[ban_list_id]] Backend error:', response.status, data); | ||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } | ||||
|
|
||||
| return NextResponse.json(data, { status: response.status }); | ||||
| } catch (error: any) { | ||||
| console.error('Proxy error:', error); | ||||
| return NextResponse.json( | ||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||
| { status: 500 } | ||||
| ); | ||||
| } | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||
| import { NextRequest, NextResponse } from 'next/server'; | ||||||
|
|
||||||
| const backendUrl = process.env.NEXT_PUBLIC_GUARDRAILS_URL || 'http://localhost:8001'; | ||||||
|
|
||||||
| export async function GET(request: NextRequest) { | ||||||
| try { | ||||||
| // Get the Kaapi API key from request headers | ||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||
| if (!apiKey) { | ||||||
| return NextResponse.json( | ||||||
| { error: 'Missing X-API-KEY header' }, | ||||||
| { status: 401 } | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| const url = `${backendUrl}/api/v1/guardrails/ban_lists`; | ||||||
|
|
||||||
| console.log('[GET /api/guardrails/ban_list] Forwarding to:', url); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent log path: singular vs plural. Log messages use Proposed fix: Use consistent plural naming- console.log('[GET /api/guardrails/ban_list] Forwarding to:', url);
+ console.log('[GET /api/guardrails/ban_lists] Forwarding to:', url);Apply similar fixes to other log statements in this file (lines 29, 35, 39, 69, 70, 82, 88, 92). 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| // Forward the request to the actual backend | ||||||
| const response = await fetch(url, { | ||||||
| method: 'GET', | ||||||
| headers: { | ||||||
| 'X-API-KEY': apiKey, | ||||||
| 'Content-Type': 'application/json', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| console.log('[GET /api/guardrails/ban_list] Backend response status:', response.status, response.statusText); | ||||||
|
|
||||||
| // Handle empty responses (204 No Content, etc.) | ||||||
| const text = await response.text(); | ||||||
| const data = text ? JSON.parse(text) : { data: [] }; | ||||||
|
|
||||||
| console.log('[GET /api/guardrails/ban_list] Backend response data:', JSON.stringify(data, null, 2)); | ||||||
|
|
||||||
| // Return the response with the same status code | ||||||
| if (!response.ok) { | ||||||
| console.error('[GET /api/guardrails/ban_list] Backend error:', response.status, data); | ||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } | ||||||
|
|
||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } catch (error: any) { | ||||||
| console.error('Proxy error:', error); | ||||||
| return NextResponse.json( | ||||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||||
| { status: 500 } | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| export async function POST(request: NextRequest) { | ||||||
| try { | ||||||
| // Get the Kaapi API key from request headers | ||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||
| if (!apiKey) { | ||||||
| return NextResponse.json( | ||||||
| { error: 'Missing X-API-KEY header' }, | ||||||
| { status: 401 } | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| // Get the JSON body from the request | ||||||
| const body = await request.json(); | ||||||
|
|
||||||
| const url = `${backendUrl}/api/v1/guardrails/ban_lists`; | ||||||
|
|
||||||
| console.log('[POST /api/guardrails/ban_list] Forwarding to:', url); | ||||||
| console.log('[POST /api/guardrails/ban_list] Body:', JSON.stringify(body, null, 2)); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging full request body in production. Same concern as the validators/configs route—logging complete request bodies could expose sensitive data. Proposed fix console.log('[POST /api/guardrails/ban_lists] Forwarding to:', url);
- console.log('[POST /api/guardrails/ban_list] Body:', JSON.stringify(body, null, 2));🤖 Prompt for AI Agents |
||||||
|
|
||||||
| // Forward the request to the actual backend | ||||||
| const response = await fetch(url, { | ||||||
| method: 'POST', | ||||||
| body: JSON.stringify(body), | ||||||
| headers: { | ||||||
| 'X-API-KEY': apiKey, | ||||||
| 'Content-Type': 'application/json', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| console.log('[POST /api/guardrails/ban_list] Backend response status:', response.status, response.statusText); | ||||||
|
|
||||||
| // Handle empty responses (204 No Content, etc.) | ||||||
| const text = await response.text(); | ||||||
| const data = text ? JSON.parse(text) : { success: true }; | ||||||
|
|
||||||
| console.log('[POST /api/guardrails/ban_list] Backend response data:', JSON.stringify(data, null, 2)); | ||||||
|
|
||||||
| // Return the response with the same status code | ||||||
| if (!response.ok) { | ||||||
| console.error('[POST /api/guardrails/ban_list] Backend error:', response.status, data); | ||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } | ||||||
|
|
||||||
| return NextResponse.json(data, { status: response.status }); | ||||||
| } catch (error: any) { | ||||||
| console.error('Proxy error:', error); | ||||||
| return NextResponse.json( | ||||||
| { error: 'Failed to forward request to backend', details: error.message }, | ||||||
| { status: 500 } | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
.env.exampleformatting issues.Static analysis flagged several formatting problems:
=sign (should beNEXT_PUBLIC_GUARDRAILS_URL=)Some environment variable parsers are sensitive to these formatting issues.
Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 1-1: [SpaceCharacter] The line has spaces around equal sign
(SpaceCharacter)
[warning] 1-1: [TrailingWhitespace] Trailing whitespace detected
(TrailingWhitespace)
[warning] 2-2: [SpaceCharacter] The line has spaces around equal sign
(SpaceCharacter)
[warning] 2-2: [TrailingWhitespace] Trailing whitespace detected
(TrailingWhitespace)
[warning] 4-4: [EndingBlankLine] No blank line at the end of the file
(EndingBlankLine)
🤖 Prompt for AI Agents