@@ -52,9 +52,6 @@ type ScreenUpdateBody struct {
5252}
5353
5454type Event struct {
55- // Id's are monotonically increasing integers within a single subscription.
56- // They are not globally unique.
57- Id int
5855 Type EventType
5956 Payload any
6057}
@@ -64,7 +61,6 @@ type EventEmitter struct {
6461 messages []st.ConversationMessage
6562 status AgentStatus
6663 chans map [int ]chan Event
67- chanEventIdx map [int ]int
6864 chanIdx int
6965 subscriptionBufSize int
7066 screen string
@@ -94,7 +90,6 @@ func NewEventEmitter(subscriptionBufSize int) *EventEmitter {
9490 messages : make ([]st.ConversationMessage , 0 ),
9591 status : AgentStatusRunning ,
9692 chans : make (map [int ]chan Event ),
97- chanEventIdx : make (map [int ]int ),
9893 chanIdx : 0 ,
9994 subscriptionBufSize : subscriptionBufSize ,
10095 }
@@ -109,11 +104,9 @@ func (e *EventEmitter) notifyChannels(eventType EventType, payload any) {
109104 for _ , chanId := range chanIds {
110105 ch := e .chans [chanId ]
111106 event := Event {
112- Id : e .chanEventIdx [chanId ],
113107 Type : eventType ,
114108 Payload : payload ,
115109 }
116- e .chanEventIdx [chanId ]++
117110
118111 select {
119112 case ch <- event :
@@ -182,20 +175,17 @@ func (e *EventEmitter) UpdateScreenAndEmitChanges(newScreen string) {
182175// Assumes the caller holds the lock.
183176func (e * EventEmitter ) currentStateAsEvents () []Event {
184177 events := make ([]Event , 0 , len (e .messages )+ 2 )
185- for i , msg := range e .messages {
178+ for _ , msg := range e .messages {
186179 events = append (events , Event {
187- Id : i ,
188180 Type : EventTypeMessageUpdate ,
189181 Payload : MessageUpdateBody {Id : msg .Id , Role : msg .Role , Message : msg .Message , Time : msg .Time },
190182 })
191183 }
192184 events = append (events , Event {
193- Id : len (e .messages ),
194185 Type : EventTypeStatusChange ,
195186 Payload : StatusChangeBody {Status : e .status },
196187 })
197188 events = append (events , Event {
198- Id : len (e .messages ) + 1 ,
199189 Type : EventTypeScreenUpdate ,
200190 Payload : ScreenUpdateBody {Screen : strings .TrimRight (e .screen , mf .WhiteSpaceChars )},
201191 })
@@ -214,7 +204,6 @@ func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event) {
214204 // Once a channel becomes full, it will be closed.
215205 ch := make (chan Event , e .subscriptionBufSize )
216206 e .chans [e .chanIdx ] = ch
217- e .chanEventIdx [e .chanIdx ] = len (stateEvents )
218207 e .chanIdx ++
219208 return e .chanIdx - 1 , ch , stateEvents
220209}
@@ -223,7 +212,6 @@ func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event) {
223212func (e * EventEmitter ) unsubscribeInner (chanId int ) {
224213 close (e .chans [chanId ])
225214 delete (e .chans , chanId )
226- delete (e .chanEventIdx , chanId )
227215}
228216
229217func (e * EventEmitter ) Unsubscribe (chanId int ) {
0 commit comments