events.go RawHistoryFolder
1package core
2
3import (
4 "encoding/json"
5
6 "github.com/patriceckhart/zot/internal/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
22type EvUserMessage struct {
23 Message provider.Message
24}
25
26func (EvUserMessage) Type() string { return "user_message" }
27
28type EvAssistantStart struct{}
29
30func (EvAssistantStart) Type() string { return "assistant_start" }
31
32type EvTextDelta struct {
33 Delta string
34}
35
36func (EvTextDelta) Type() string { return "text_delta" }
37
38type EvToolCall struct {
39 ID string
40 Name string
41 Args json.RawMessage
42}
43
44func (EvToolCall) Type() string { return "tool_call" }
45
46// EvToolUseStart fires the moment the provider announces a new
47// tool_use block during streaming, before any arg JSON has
48// arrived. Gives UIs a hook to pre-render a live "tool is being
49// composed" panel so the user sees the model typing the call in
50// real time. Name is already final at this point; Args is empty.
51type EvToolUseStart struct {
52 ID string
53 Name string
54}
55
56func (EvToolUseStart) Type() string { return "tool_use_start" }
57
58// EvToolUseArgs fires for each delta fragment of the tool_use
59// block's argument JSON. Concatenating every delta for a given
60// ID produces the full JSON string; during streaming it's likely
61// truncated mid-value. UIs can extract partial string fields
62// (e.g. the `content` arg of `write`) with an escape-aware scan.
63type EvToolUseArgs struct {
64 ID string
65 Delta string
66}
67
68func (EvToolUseArgs) Type() string { return "tool_use_args" }
69
70// EvToolUseEnd fires when the provider marks the tool_use block
71// complete. At this point the full args JSON is known; a separate
72// EvToolCall follows once the assistant message is assembled,
73// carrying the parsed block that actually runs.
74type EvToolUseEnd struct {
75 ID string
76}
77
78func (EvToolUseEnd) Type() string { return "tool_use_end" }
79
80type EvToolProgress struct {
81 ID string
82 Text string
83}
84
85func (EvToolProgress) Type() string { return "tool_progress" }
86
87type EvToolResult struct {
88 ID string
89 Result ToolResult
90}
91
92func (EvToolResult) Type() string { return "tool_result" }
93
94type EvUsage struct {
95 Usage provider.Usage
96 Cumulative provider.Usage
97}
98
99func (EvUsage) Type() string { return "usage" }
100
101type EvAssistantMessage struct {
102 Message provider.Message
103}
104
105func (EvAssistantMessage) Type() string { return "assistant_message" }
106
107type EvTurnEnd struct {
108 Stop provider.StopReason
109 Err error
110}
111
112func (EvTurnEnd) Type() string { return "turn_end" }
113
114type EvDone struct{}
115
116func (EvDone) Type() string { return "done" }
117
118type EvError struct {
119 Err error
120}
121
122func (EvError) Type() string { return "error" }