diff --git a/src/features/audit/AuditLogViewer.tsx b/src/features/audit/AuditLogViewer.tsx new file mode 100644 index 0000000..93653d4 --- /dev/null +++ b/src/features/audit/AuditLogViewer.tsx @@ -0,0 +1,165 @@ +'use client'; + +import React, { useState, useMemo } from 'react'; +import { AuditLogEntry } from '@/types/audit'; + +const MOCK_AUDIT_LOGS: AuditLogEntry[] = [ + { + id: 'log-1', + agentId: 'agent-stellar-treasury-01', + agentName: 'Treasury Guardian', + actionType: 'payment', + status: 'success', + cryptographicHash: '0x8f9c...3b21', + timestamp: '2026-08-31T10:15:00Z', + metadata: { recipient: 'GBC7...XYZ', amount: '500 XLM', asset: 'USDC', memo: 'Monthly contractor disbursement' }, + }, + { + id: 'log-2', + agentId: 'agent-risk-eval-04', + agentName: 'Policy Sentinel', + actionType: 'policy_check', + status: 'warning', + cryptographicHash: '0x4a12...9e88', + timestamp: '2026-08-31T09:42:10Z', + metadata: { ruleId: 'RULE-LIMIT-02', evaluatedLimit: '10,000 XLM', requestedValue: '12,500 XLM', verdict: 'flagged_for_review' }, + }, + { + id: 'log-3', + agentId: 'agent-key-manager-99', + agentName: 'Auth Rotator', + actionType: 'key_rotation', + status: 'success', + cryptographicHash: '0x1c34...ff09', + timestamp: '2026-08-30T22:00:00Z', + metadata: { keyId: 'KEY-ENV-PROD-02', provider: 'Nvidia NIM', reason: 'Scheduled rotation cycle' }, + }, +]; + +export function AuditLogViewer() { + const [searchQuery, setSearchQuery] = useState(''); + const [selectedActionType, setSelectedActionType] = useState('all'); + const [expandedRowId, setExpandedRowId] = useState(null); + + const filteredLogs = useMemo(() => { + return MOCK_AUDIT_LOGS.filter((log) => { + const matchesSearch = + log.agentId.toLowerCase().includes(searchQuery.toLowerCase()) || + log.agentName.toLowerCase().includes(searchQuery.toLowerCase()) || + log.cryptographicHash.toLowerCase().includes(searchQuery.toLowerCase()); + + const matchesType = selectedActionType === 'all' || log.actionType === selectedActionType; + + return matchesSearch && matchesType; + }); + }, [searchQuery, selectedActionType]); + + const toggleRow = (id: string) => { + setExpandedRowId(expandedRowId === id ? null : id); + }; + + return ( +
+
+
+

AI Agent Audit Logs

+

Track immutable agent decisions, compliance records, and Stellar operations.

+
+ +
+ setSearchQuery(e.target.value)} + className="px-3 py-2 bg-slate-900 border border-slate-700 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-violet-500" + aria-label="Search audit logs" + /> + + +
+
+ +
+ + + + + + + + + + + + + {filteredLogs.length === 0 ? ( + + + + ) : ( + filteredLogs.map((log) => ( + + + + + + + + + + {expandedRowId === log.id && ( + + + + )} + + )) + )} + +
AgentAction TypeStatusCrypto HashTimestampDetails
+ No matching audit records found. +
+
{log.agentName}
+
{log.agentId}
+
+ + {log.actionType} + + + + {log.status} + + {log.cryptographicHash}{new Date(log.timestamp).toLocaleString()} + +
+
+
{JSON.stringify(log.metadata, null, 2)}
+
+
+
+
+ ); +} diff --git a/src/types/audit.ts b/src/types/audit.ts index 95ec430..006cec1 100644 --- a/src/types/audit.ts +++ b/src/types/audit.ts @@ -1,36 +1,12 @@ -export type AuditEventType = - | 'action' - | 'policy_change' - | 'approval' - | 'signature' - | 'key_rotation' - | 'budget_cap'; +export type AuditActionType = 'payment' | 'policy_check' | 'key_rotation' | 'model_invoke'; -export type AuditLogLevel = 'info' | 'success' | 'warning' | 'error'; - -export interface AuditEvent { +export interface AuditLogEntry { id: string; + agentId: string; + agentName: string; + actionType: AuditActionType; + status: 'success' | 'failed' | 'warning'; + cryptographicHash: string; timestamp: string; - eventType: AuditEventType; - level: AuditLogLevel; - actorId: string; - actorName: string; - actorType: 'agent' | 'user' | 'system'; - summary: string; - details: string; - project?: string; - amount?: number; - asset?: string; - xdrHash?: string; - rawPayload: Record; -} - -export type AuditTimeRange = 'all' | '24h' | '7d' | '30d'; - -export interface AuditFilters { - searchQuery: string; - eventType: AuditEventType | 'all'; - logLevel: AuditLogLevel | 'all'; - timeRange: AuditTimeRange; - actorId: string | 'all'; + metadata: Record; }