MCPcopy Create free account
hub / github.com/coder/agentapi / currentStateAsEvents

Method currentStateAsEvents

lib/httpapi/events.go:240–266  ·  view source on GitHub ↗

Assumes the caller holds the lock.

()

Source from the content-addressed store, hash-verified

238
239// Assumes the caller holds the lock.
240func (e *EventEmitter) currentStateAsEvents() []Event {
241 events := make([]Event, 0, len(e.messages)+2)
242 for _, msg := range e.messages {
243 events = append(events, Event{
244 Type: EventTypeMessageUpdate,
245 Payload: MessageUpdateBody{Id: msg.Id, Role: msg.Role, Message: msg.Message, Time: msg.Time},
246 })
247 }
248 events = append(events, Event{
249 Type: EventTypeStatusChange,
250 Payload: StatusChangeBody{Status: e.status, AgentType: e.agentType},
251 })
252 events = append(events, Event{
253 Type: EventTypeScreenUpdate,
254 Payload: ScreenUpdateBody{Screen: strings.TrimRight(e.screen, mf.WhiteSpaceChars)},
255 })
256
257 // Include all error events
258 for _, err := range e.errors {
259 events = append(events, Event{
260 Type: EventTypeError,
261 Payload: err,
262 })
263 }
264
265 return events
266}
267
268// Subscribe returns:
269// - a subscription ID that can be used to unsubscribe.

Callers 1

SubscribeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected