@@ -52,9 +52,6 @@ type ScreenUpdateBody struct {
52
52
}
53
53
54
54
type Event struct {
55
- // Id's are monotonically increasing integers within a single subscription.
56
- // They are not globally unique.
57
- Id int
58
55
Type EventType
59
56
Payload any
60
57
}
@@ -64,7 +61,6 @@ type EventEmitter struct {
64
61
messages []st.ConversationMessage
65
62
status AgentStatus
66
63
chans map [int ]chan Event
67
- chanEventIdx map [int ]int
68
64
chanIdx int
69
65
subscriptionBufSize int
70
66
screen string
@@ -94,7 +90,6 @@ func NewEventEmitter(subscriptionBufSize int) *EventEmitter {
94
90
messages : make ([]st.ConversationMessage , 0 ),
95
91
status : AgentStatusRunning ,
96
92
chans : make (map [int ]chan Event ),
97
- chanEventIdx : make (map [int ]int ),
98
93
chanIdx : 0 ,
99
94
subscriptionBufSize : subscriptionBufSize ,
100
95
}
@@ -109,11 +104,9 @@ func (e *EventEmitter) notifyChannels(eventType EventType, payload any) {
109
104
for _ , chanId := range chanIds {
110
105
ch := e .chans [chanId ]
111
106
event := Event {
112
- Id : e .chanEventIdx [chanId ],
113
107
Type : eventType ,
114
108
Payload : payload ,
115
109
}
116
- e .chanEventIdx [chanId ]++
117
110
118
111
select {
119
112
case ch <- event :
@@ -182,20 +175,17 @@ func (e *EventEmitter) UpdateScreenAndEmitChanges(newScreen string) {
182
175
// Assumes the caller holds the lock.
183
176
func (e * EventEmitter ) currentStateAsEvents () []Event {
184
177
events := make ([]Event , 0 , len (e .messages )+ 2 )
185
- for i , msg := range e .messages {
178
+ for _ , msg := range e .messages {
186
179
events = append (events , Event {
187
- Id : i ,
188
180
Type : EventTypeMessageUpdate ,
189
181
Payload : MessageUpdateBody {Id : msg .Id , Role : msg .Role , Message : msg .Message , Time : msg .Time },
190
182
})
191
183
}
192
184
events = append (events , Event {
193
- Id : len (e .messages ),
194
185
Type : EventTypeStatusChange ,
195
186
Payload : StatusChangeBody {Status : e .status },
196
187
})
197
188
events = append (events , Event {
198
- Id : len (e .messages ) + 1 ,
199
189
Type : EventTypeScreenUpdate ,
200
190
Payload : ScreenUpdateBody {Screen : strings .TrimRight (e .screen , mf .WhiteSpaceChars )},
201
191
})
@@ -214,7 +204,6 @@ func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event) {
214
204
// Once a channel becomes full, it will be closed.
215
205
ch := make (chan Event , e .subscriptionBufSize )
216
206
e .chans [e .chanIdx ] = ch
217
- e .chanEventIdx [e .chanIdx ] = len (stateEvents )
218
207
e .chanIdx ++
219
208
return e .chanIdx - 1 , ch , stateEvents
220
209
}
@@ -223,7 +212,6 @@ func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event) {
223
212
func (e * EventEmitter ) unsubscribeInner (chanId int ) {
224
213
close (e .chans [chanId ])
225
214
delete (e .chans , chanId )
226
- delete (e .chanEventIdx , chanId )
227
215
}
228
216
229
217
func (e * EventEmitter ) Unsubscribe (chanId int ) {
0 commit comments