events.go RawHistoryFolder
1package core
2
3import (
4 "encoding/json"
5
6 "github.com/patriceckhart/zot/packages/provider"
7)
8
9// AgentEvent is the superset of events emitted by an Agent run.
10// Consumers discriminate via a type switch. Each concrete type has a
11// Type() method for JSON serialization.
12type AgentEvent interface {
13 Type() string
14}
15
16type EvTurnStart struct {
17 Step int
18}
19
20func (EvTurnStart) Type() string { return "turn_start" }
21
22// EvPromptSubmit observes accepted model input before it is appended or queued.
23// Queued input can subsequently be withdrawn without reaching the model.
24type EvPromptSubmit struct {
25 Text string
26 Queued bool
27 ImageCount int
28}
29
30func (EvPromptSubmit) Type() string { return "user_prompt_submit" }
31
32type EvUserMessage struct {
33 Message provider.Message
34}
35
36func (EvUserMessage) Type() string { return "user_message" }
37
38type EvAssistantStart struct{}
39
40func (EvAssistantStart) Type() string { return "assistant_start" }
41
42type EvTextDelta struct {
43 Delta string
44}
45
46func (EvTextDelta) Type() string { return "text_delta" }
47
48type EvToolCall struct {
49 ID string
50 Name string
51 Args json.RawMessage
52}
53
54func (EvToolCall) Type() string { return "tool_call" }
55
56// EvToolUseStart fires the moment the provider announces a new
57// tool_use block during streaming, before any arg JSON has
58// arrived. Gives UIs a hook to pre-render a live "tool is being
59// composed" panel so the user sees the model typing the call in
60// real time. Name is already final at this point; Args is empty.
61type EvToolUseStart struct {
62 ID string
63 Name string
64}
65
66func (EvToolUseStart) Type() string { return "tool_use_start" }
67
68// EvToolUseArgs fires for each delta fragment of the tool_use
69// block's argument JSON. Concatenating every delta for a given
70// ID produces the full JSON string; during streaming it's likely
71// truncated mid-value. UIs can extract partial string fields
72// (e.g. the `content` arg of `write`) with an escape-aware scan.
73type EvToolUseArgs struct {
74 ID string
75 Delta string
76}
77
78func (EvToolUseArgs) Type() string { return "tool_use_args" }
79
80// EvToolUseEnd fires when the provider marks the tool_use block
81// complete. At this point the full args JSON is known; a separate
82// EvToolCall follows once the assistant message is assembled,
83// carrying the parsed block that actually runs.
84type EvToolUseEnd struct {
85 ID string
86}
87
88func (EvToolUseEnd) Type() string { return "tool_use_end" }
89
90type EvToolProgress struct {
91 ID string
92 Text string
93}
94
95func (EvToolProgress) Type() string { return "tool_progress" }
96
97type EvToolResult struct {
98 ID string
99 Name string
100 Args json.RawMessage // effective arguments, or last proposed arguments if blocked
101 Status string // completed, failed, blocked, cancelled, timed_out
102 Executed bool // whether Tool.Execute was entered
103 Result ToolResult
104}
105
106func (EvToolResult) Type() string { return "tool_result" }
107
108// EvCompact brackets a compaction attempt, including failed and cancelled attempts.
109// TokenEstimate is a rough text estimate, not provider token usage.
110type EvCompact struct {
111 Phase string
112 ID string
113 MessageCount int
114 TokenEstimate int
115 Status string
116 Err error
117}
118
119func (e EvCompact) Type() string { return e.Phase + "_compact" }
120
121type EvUsage struct {
122 Usage provider.Usage
123 Cumulative provider.Usage
124}
125
126func (EvUsage) Type() string { return "usage" }
127
128type EvAssistantMessage struct {
129 Message provider.Message
130}
131
132func (EvAssistantMessage) Type() string { return "assistant_message" }
133
134type EvTurnEnd struct {
135 Stop provider.StopReason
136 Err error
137}
138
139func (EvTurnEnd) Type() string { return "turn_end" }
140
141type EvDone struct{}
142
143func (EvDone) Type() string { return "done" }
144
145type EvError struct {
146 Err error
147}
148
149func (EvError) Type() string { return "error" }