-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevents.go
More file actions
66 lines (58 loc) · 1.61 KB
/
events.go
File metadata and controls
66 lines (58 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package trusera
import (
"crypto/rand"
"encoding/hex"
"time"
)
// EventType defines the type of agent event
type EventType string
const (
EventToolCall EventType = "tool_call"
EventLLMInvoke EventType = "llm_invoke"
EventDataAccess EventType = "data_access"
EventAPICall EventType = "api_call"
EventFileWrite EventType = "file_write"
EventDecision EventType = "decision"
)
// Event represents an agent action tracked by Trusera
type Event struct {
ID string `json:"id"`
Type EventType `json:"type"`
Name string `json:"name"`
Payload map[string]any `json:"payload"`
Metadata map[string]any `json:"metadata,omitempty"`
Timestamp string `json:"timestamp"`
}
// generateID creates a random hex ID
func generateID() string {
b := make([]byte, 16)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}
// NewEvent creates a new event with generated ID and timestamp
func NewEvent(eventType EventType, name string) Event {
return Event{
ID: generateID(),
Type: eventType,
Name: name,
Payload: make(map[string]any),
Metadata: make(map[string]any),
Timestamp: time.Now().UTC().Format(time.RFC3339),
}
}
// WithPayload adds payload data to the event (builder pattern)
func (e Event) WithPayload(key string, value any) Event {
if e.Payload == nil {
e.Payload = make(map[string]any)
}
e.Payload[key] = value
return e
}
// WithMetadata adds metadata to the event (builder pattern)
func (e Event) WithMetadata(key string, value any) Event {
if e.Metadata == nil {
e.Metadata = make(map[string]any)
}
e.Metadata[key] = value
return e
}