Skip to content

Commit 040ad64

Browse files
committed
fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 066301a commit 040ad64

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

core/services/agentpool/agent_config_distributed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ func (b *distributedAgentConfigBackend) GetObservables(userID, name string) (any
138138
}
139139

140140
// ClearObservables clears observables from the PostgreSQL table.
141-
func (b *distributedAgentConfigBackend) ClearObservables(_, name string) error {
142-
return b.store.ClearObservables(name)
141+
func (b *distributedAgentConfigBackend) ClearObservables(userID, name string) error {
142+
return b.store.ClearObservables(agents.AgentKey(userID, name))
143143
}
144144

145145
func (b *distributedAgentConfigBackend) ListAllGrouped() map[string][]UserAgentInfo {

core/services/agents/dispatcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (d *NATSDispatcher) buildNATSCallbacks(evt AgentChatEvent) Callbacks {
417417
ActionResult: result,
418418
}
419419
if d.eventBridge != nil {
420-
d.eventBridge.PersistObservable(evt.AgentName, "tool_result", obs)
420+
d.eventBridge.PersistObservable(evt.AgentName, evt.UserID, "tool_result", obs)
421421
}
422422
}
423423
},
@@ -446,7 +446,7 @@ func (d *NATSDispatcher) buildNATSCallbacks(evt AgentChatEvent) Callbacks {
446446
},
447447
}
448448
}
449-
d.eventBridge.PersistObservable(evt.AgentName, "chat", rootObs)
449+
d.eventBridge.PersistObservable(evt.AgentName, evt.UserID, "chat", rootObs)
450450
}
451451
},
452452
}

core/services/agents/events.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,28 @@ func (b *EventBridge) PublishEvent(agentName, userID string, evt AgentEvent) err
6060
return b.nats.Publish(subject, evt)
6161
}
6262

63-
// PersistObservable writes a structured observable record to the database.
63+
// PersistObservable writes a structured observable record to the database
64+
// and publishes an observable_update SSE event for real-time UI updates.
6465
// The obs should be a coreTypes.Observable or compatible struct.
65-
func (b *EventBridge) PersistObservable(agentName, eventType string, obs any) {
66+
func (b *EventBridge) PersistObservable(agentName, userID, eventType string, obs any) {
6667
if b.store == nil {
6768
return
6869
}
70+
payload := mustJSON(obs)
6971
b.store.AppendObservable(&AgentObservableRecord{
7072
ID: uuid.New().String(),
71-
AgentName: agentName,
73+
AgentName: AgentKey(userID, agentName),
7274
EventType: eventType,
73-
PayloadJSON: mustJSON(obs),
75+
PayloadJSON: payload,
7476
CreatedAt: time.Now(),
7577
})
78+
// Publish real-time SSE update (uses plain agentName for NATS subject routing)
79+
b.PublishEvent(agentName, userID, AgentEvent{
80+
AgentName: agentName,
81+
UserID: userID,
82+
EventType: "observable_update",
83+
Metadata: payload,
84+
})
7685
}
7786

7887
// PublishMessage publishes a chat message event via NATS for SSE bridging.
@@ -240,7 +249,7 @@ func (b *EventBridge) handleSSEInternal(c echo.Context, agentName, userID string
240249
if evt.Metadata != "" {
241250
writeSSE(evt.EventType, evt.Metadata)
242251
}
243-
case "stream_event":
252+
case "stream_event", "observable_update":
244253
// Send the metadata JSON directly — React UI expects {type, content, ...}
245254
if evt.Metadata != "" {
246255
writeSSE(evt.EventType, evt.Metadata)

0 commit comments

Comments
 (0)