Files
agentmon/internal/store/postgres/query.go
T
William Valentin 3434db3c59 feat: complete agent monitoring - hook, UI, and backend filter
- Add event_type and framework filters to events query endpoint
- Add /agents SPA route to web-ui server
- Add Agents nav link and route in frontend
- Add agents page CSS (timeline, VM pills, stats panel)
- Build VM status strip, activity timeline, and real-time stats
- Add agentmon hook for OpenClaw (HOOK.md + handler.ts)
- Add docker-compose, Dockerfile, and supporting infra files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 00:26:42 -07:00

65 lines
1.2 KiB
Go

package postgres
import (
"context"
"encoding/json"
"fmt"
"time"
)
type EventRow struct {
EventID string `json:"event_id"`
TS time.Time `json:"ts"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
type EventsFilter struct {
Limit int
EventType string
Framework string
}
func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow, error) {
if f.Limit <= 0 {
f.Limit = 100
}
if f.Limit > 1000 {
f.Limit = 1000
}
query := "SELECT event_id, ts, type, payload FROM events WHERE 1=1"
args := []any{}
argN := 1
if f.EventType != "" {
query += fmt.Sprintf(" AND type = $%d", argN)
args = append(args, f.EventType)
argN++
}
if f.Framework != "" {
query += fmt.Sprintf(" AND source_framework = $%d", argN)
args = append(args, f.Framework)
argN++
}
query += fmt.Sprintf(" ORDER BY ts DESC LIMIT $%d", argN)
args = append(args, f.Limit)
rows, err := d.sql.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
var out []EventRow
for rows.Next() {
var r EventRow
if err := rows.Scan(&r.EventID, &r.TS, &r.Type, &r.Payload); err != nil {
return nil, err
}
out = append(out, r)
}
return out, rows.Err()
}