Add live agent views and improve Codex monitoring
This commit is contained in:
@@ -18,6 +18,7 @@ type EventsFilter struct {
|
||||
Limit int
|
||||
EventType string
|
||||
Framework string
|
||||
ClientID string
|
||||
}
|
||||
|
||||
func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow, error) {
|
||||
@@ -42,6 +43,11 @@ func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow,
|
||||
args = append(args, f.Framework)
|
||||
argN++
|
||||
}
|
||||
if f.ClientID != "" {
|
||||
query += fmt.Sprintf(" AND client_id = $%d", argN)
|
||||
args = append(args, f.ClientID)
|
||||
argN++
|
||||
}
|
||||
|
||||
query += fmt.Sprintf(" ORDER BY ts DESC LIMIT $%d", argN)
|
||||
args = append(args, f.Limit)
|
||||
@@ -62,3 +68,36 @@ func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow,
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (d *DB) ListAgentLiveEvents(ctx context.Context, framework, clientID string, limit int) ([]EventRow, error) {
|
||||
if limit <= 0 {
|
||||
limit = 200
|
||||
}
|
||||
if limit > 1000 {
|
||||
limit = 1000
|
||||
}
|
||||
|
||||
rows, err := d.sql.QueryContext(ctx, `
|
||||
SELECT event_id, ts, type, payload
|
||||
FROM events
|
||||
WHERE source_framework = $1
|
||||
AND client_id = $2
|
||||
AND type IN ('session.start', 'session.end', 'run.start', 'run.end', 'span.start', 'span.end', 'error')
|
||||
ORDER BY ts DESC
|
||||
LIMIT $3
|
||||
`, framework, clientID, limit)
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user