audit

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditRow

type AuditRow struct {
	RequestID       string `json:"request_id"`
	AgentID         string `json:"agent_id"`
	BackendID       string `json:"backend_id"`
	ToolName        string `json:"tool_name"`
	Arguments       string `json:"arguments"`
	ACLResult       string `json:"acl_result"`
	RateLimitResult string `json:"rate_limit_result"`
	ApprovalResult  string `json:"approval_result"`
	QueuePosition   int    `json:"queue_position"`
	QueueWaitMs     int64  `json:"queue_wait_ms"`
	ExecStatus      string `json:"exec_status"`
	ExecDurationMs  int64  `json:"exec_duration_ms"`
	ErrorMessage    string `json:"error_message"`
	CreatedAt       string `json:"created_at"`
}

AuditRow represents a row from the audit log for API queries.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger writes audit entries and rate limit records to SQLite.

func NewLogger

func NewLogger(dbPath string) (*Logger, error)

NewLogger opens (or creates) the SQLite database at dbPath.

func (*Logger) Close

func (l *Logger) Close() error

Close stops the purge loop and closes the database. Safe to call multiple times.

func (*Logger) CountCalls

func (l *Logger) CountCalls(agentID, toolName string, since time.Time) (int, error)

CountCalls returns the number of calls by an agent for a tool since the given time. Returns an error if the DB query fails (callers should fail-closed).

func (*Logger) CountCallsGlobal

func (l *Logger) CountCallsGlobal(toolName string, since time.Time) (int, error)

CountCallsGlobal returns the number of calls for a tool across all agents since the given time. Returns an error if the DB query fails (callers should fail-closed).

func (*Logger) Log

func (l *Logger) Log(e *model.AuditEntry)

Log writes an audit entry.

func (*Logger) Purge

func (l *Logger) Purge(days int) (int64, error)

Purge deletes audit entries older than the given number of days.

func (*Logger) Query

func (l *Logger) Query(limit, offset int) ([]AuditRow, error)

Query returns recent audit log rows.

func (*Logger) RecordCall

func (l *Logger) RecordCall(agentID, toolName string)

RecordCall records a tool call for rate limiting.

func (*Logger) StartPurgeLoop

func (l *Logger) StartPurgeLoop(retentionDays int)

StartPurgeLoop starts a background goroutine that purges old entries daily.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL