@@ -2,34 +2,45 @@ use serde::Deserialize;
2
2
use serde:: Serialize ;
3
3
use ts_rs:: TS ;
4
4
5
- /// Top-level events emitted on the Codex Exec thread stream.
5
+ /// Top-level JSONL events emitted by codex exec
6
6
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
7
7
#[ serde( tag = "type" ) ]
8
8
pub enum ThreadEvent {
9
+ /// Emitted when a new thread is started as the first event.
9
10
#[ serde( rename = "thread.started" ) ]
10
11
ThreadStarted ( ThreadStartedEvent ) ,
12
+ /// Emitted when a turn is started by sending a new prompt to the model.
13
+ /// A turn encompasses all events that happen while agent is processing the prompt.
11
14
#[ serde( rename = "turn.started" ) ]
12
15
TurnStarted ( TurnStartedEvent ) ,
16
+ /// Emitted when a turn is completed. Typically right after the assistant's response.
13
17
#[ serde( rename = "turn.completed" ) ]
14
18
TurnCompleted ( TurnCompletedEvent ) ,
19
+ /// Indicates that a turn failed with an error.
15
20
#[ serde( rename = "turn.failed" ) ]
16
21
TurnFailed ( TurnFailedEvent ) ,
22
+ /// Emitted when a new item is added to the thread. Typically the item will be in an "in progress" state.
17
23
#[ serde( rename = "item.started" ) ]
18
24
ItemStarted ( ItemStartedEvent ) ,
25
+ /// Emitted when an item is updated.
19
26
#[ serde( rename = "item.updated" ) ]
20
27
ItemUpdated ( ItemUpdatedEvent ) ,
28
+ /// Signals that an item has reached a terminal state—either success or failure.
21
29
#[ serde( rename = "item.completed" ) ]
22
30
ItemCompleted ( ItemCompletedEvent ) ,
31
+ /// Represents an unrecoverable error emitted directly by the event stream.
23
32
#[ serde( rename = "error" ) ]
24
33
Error ( ThreadErrorEvent ) ,
25
34
}
26
35
27
36
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
28
37
pub struct ThreadStartedEvent {
38
+ /// The identified of the new thread. Can be used to resume the thread later.
29
39
pub thread_id : String ,
30
40
}
31
41
32
42
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS , Default ) ]
43
+
33
44
pub struct TurnStartedEvent { }
34
45
35
46
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
@@ -42,11 +53,14 @@ pub struct TurnFailedEvent {
42
53
pub error : ThreadErrorEvent ,
43
54
}
44
55
45
- /// Minimal usage summary for a turn.
56
+ /// Describes the usage of tokens during a turn.
46
57
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS , Default ) ]
47
58
pub struct Usage {
59
+ /// The number of input tokens used during the turn.
48
60
pub input_tokens : u64 ,
61
+ /// The number of cached input tokens used during the turn.
49
62
pub cached_input_tokens : u64 ,
63
+ /// The number of output tokens used during the turn.
50
64
pub output_tokens : u64 ,
51
65
}
52
66
@@ -83,34 +97,44 @@ pub struct ThreadItem {
83
97
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
84
98
#[ serde( tag = "item_type" , rename_all = "snake_case" ) ]
85
99
pub enum ThreadItemDetails {
100
+ /// Response from the agent.
101
+ /// Either a natural-language response or a JSON string when structured output is requested.
86
102
AssistantMessage ( AssistantMessageItem ) ,
103
+ /// Agent's reasoning summary.
87
104
Reasoning ( ReasoningItem ) ,
105
+ /// Tracks a command executed by the agent. The item starts when the command is
106
+ /// spawned, and completes when the process exits with an exit code.
88
107
CommandExecution ( CommandExecutionItem ) ,
108
+ /// Represents a set of file changes by the agent. The item is emitted only as a
109
+ /// completed event once the patch succeeds or fails.
89
110
FileChange ( FileChangeItem ) ,
111
+ /// Represents a call to an MCP tool. The item starts when the invocation is
112
+ /// dispatched and completes when the MCP server reports success or failure.
90
113
McpToolCall ( McpToolCallItem ) ,
114
+ /// Captures a web search request. It starts when the search is kicked off
115
+ /// and completes when results are returned to the agent.
91
116
WebSearch ( WebSearchItem ) ,
117
+ /// Tracks the agent's running to-do list. It starts when the plan is first
118
+ /// issued, updates as steps change state, and completes when the turn ends.
92
119
TodoList ( TodoListItem ) ,
120
+ /// Describes a non-fatal error surfaced as an item.
93
121
Error ( ErrorItem ) ,
94
122
}
95
123
96
- /// Session metadata.
97
- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
98
- pub struct SessionItem {
99
- pub session_id : String ,
100
- }
101
-
102
- /// Assistant message payload.
124
+ /// Response from the agent.
125
+ /// Either a natural-language response or a JSON string when structured output is requested.
103
126
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
104
127
pub struct AssistantMessageItem {
105
128
pub text : String ,
106
129
}
107
130
108
- /// Model reasoning summary payload .
131
+ /// Agent's reasoning summary.
109
132
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
110
133
pub struct ReasoningItem {
111
134
pub text : String ,
112
135
}
113
136
137
+ /// The status of a command execution.
114
138
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , Default , TS ) ]
115
139
#[ serde( rename_all = "snake_case" ) ]
116
140
pub enum CommandExecutionStatus {
@@ -120,7 +144,7 @@ pub enum CommandExecutionStatus {
120
144
Failed ,
121
145
}
122
146
123
- /// Local shell command execution payload .
147
+ /// A command executed by the agent .
124
148
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
125
149
pub struct CommandExecutionItem {
126
150
pub command : String ,
@@ -130,28 +154,29 @@ pub struct CommandExecutionItem {
130
154
pub status : CommandExecutionStatus ,
131
155
}
132
156
133
- /// Single file change summary for a patch .
157
+ /// A set of file changes by the agent .
134
158
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
135
159
pub struct FileUpdateChange {
136
160
pub path : String ,
137
161
pub kind : PatchChangeKind ,
138
162
}
139
163
164
+ /// The status of a file change.
140
165
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
141
166
#[ serde( rename_all = "snake_case" ) ]
142
167
pub enum PatchApplyStatus {
143
168
Completed ,
144
169
Failed ,
145
170
}
146
171
147
- /// Patch application payload .
172
+ /// A set of file changes by the agent .
148
173
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
149
174
pub struct FileChangeItem {
150
175
pub changes : Vec < FileUpdateChange > ,
151
176
pub status : PatchApplyStatus ,
152
177
}
153
178
154
- /// Known change kinds for a patch .
179
+ /// Indicates the type of the file change .
155
180
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
156
181
#[ serde( rename_all = "snake_case" ) ]
157
182
pub enum PatchChangeKind {
@@ -160,6 +185,7 @@ pub enum PatchChangeKind {
160
185
Update ,
161
186
}
162
187
188
+ /// The status of an MCP tool call.
163
189
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , Default , TS ) ]
164
190
#[ serde( rename_all = "snake_case" ) ]
165
191
pub enum McpToolCallStatus {
@@ -169,23 +195,27 @@ pub enum McpToolCallStatus {
169
195
Failed ,
170
196
}
171
197
198
+ /// A call to an MCP tool.
172
199
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
173
200
pub struct McpToolCallItem {
174
201
pub server : String ,
175
202
pub tool : String ,
176
203
pub status : McpToolCallStatus ,
177
204
}
178
205
206
+ /// A web search request.
179
207
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
180
208
pub struct WebSearchItem {
181
209
pub query : String ,
182
210
}
183
211
212
+ /// An error notification.
184
213
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
185
214
pub struct ErrorItem {
186
215
pub message : String ,
187
216
}
188
217
218
+ /// An item in agent's to-do list.
189
219
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , TS ) ]
190
220
pub struct TodoItem {
191
221
pub text : String ,
0 commit comments