fix: log dashboard chat requests; add view-logs button on keys page
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { api } from '../lib/api'
|
||||
import type { VirtualKey } from '../lib/types'
|
||||
|
||||
@@ -86,6 +87,7 @@ function Modal({ onClose, onCreate }: { onClose: () => void; onCreate: (key: str
|
||||
}
|
||||
|
||||
export default function ApiKeys() {
|
||||
const navigate = useNavigate()
|
||||
const [keys, setKeys] = useState<VirtualKey[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [showModal, setShowModal] = useState(false)
|
||||
@@ -102,7 +104,7 @@ export default function ApiKeys() {
|
||||
load()
|
||||
}
|
||||
|
||||
const cols = '162px 1fr 110px 110px 80px 130px 60px'
|
||||
const cols = '162px 1fr 110px 110px 80px 130px 64px'
|
||||
|
||||
return (
|
||||
<div className="animate-fade-up">
|
||||
@@ -143,6 +145,12 @@ export default function ApiKeys() {
|
||||
{k.allow_all_models ? 'all models' : 'restricted'}
|
||||
</span>
|
||||
<div style={{ display: 'flex', gap: 5, justifyContent: 'flex-end' }}>
|
||||
<button onClick={() => navigate(`/logs?key=${k.prefix}`)} title="View logs"
|
||||
style={{ width: 27, height: 27, borderRadius: 5, border: '1px solid rgba(255,255,255,0.08)', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}>
|
||||
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" stroke="rgba(237,237,240,0.42)" strokeWidth="1.6" strokeLinecap="round">
|
||||
<line x1="2" y1="4" x2="14" y2="4"/><line x1="2" y1="8" x2="11" y2="8"/><line x1="2" y1="12" x2="14" y2="12"/>
|
||||
</svg>
|
||||
</button>
|
||||
{!k.revoked_at && (
|
||||
<button onClick={() => revoke(k.id)} title="Revoke" style={{ width: 27, height: 27, borderRadius: 5, border: '1px solid rgba(255,255,255,0.08)', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}>
|
||||
<svg width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="rgba(237,237,240,0.42)" strokeWidth="1.6" strokeLinecap="round">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import { api } from '../lib/api'
|
||||
import type { RequestLog } from '../lib/types'
|
||||
|
||||
@@ -53,10 +54,11 @@ function ContentDrawer({ log }: { log: RequestLog }) {
|
||||
}
|
||||
|
||||
export default function Logs() {
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const [logs, setLogs] = useState<RequestLog[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [rangeIdx, setRangeIdx] = useState(1)
|
||||
const [search, setSearch] = useState('')
|
||||
const [search, setSearch] = useState(() => searchParams.get('key') ?? '')
|
||||
const [expanded, setExpanded] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -66,6 +68,12 @@ export default function Logs() {
|
||||
.finally(() => setLoading(false))
|
||||
}, [rangeIdx])
|
||||
|
||||
// Sync search → URL param so links from ApiKeys page work.
|
||||
useEffect(() => {
|
||||
if (search) setSearchParams({ key: search }, { replace: true })
|
||||
else setSearchParams({}, { replace: true })
|
||||
}, [search])
|
||||
|
||||
const visible = logs.filter(l =>
|
||||
!search ||
|
||||
l.ModelName.includes(search) ||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
chimw "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.govekar.net/LovroG05/localmodelroutex/internal/billing"
|
||||
"git.govekar.net/LovroG05/localmodelroutex/internal/catalog"
|
||||
@@ -176,8 +177,11 @@ func (a *API) logRequest(r *http.Request, key *store.VirtualKey, entry *catalog.
|
||||
ClientIP: clientIP(r),
|
||||
}
|
||||
if key != nil {
|
||||
rec.VirtualKeyID = &key.ID
|
||||
rec.KeyPrefix = key.KeyPrefix
|
||||
// Only set VirtualKeyID for real keys — synthetic dashboard keys have a nil UUID.
|
||||
if key.ID != uuid.Nil {
|
||||
rec.VirtualKeyID = &key.ID
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user