Allow slack bots to initiate conversations

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-03-25 22:58:59 +01:00
parent fa12dba7c2
commit fb20bbe5bf
2 changed files with 31 additions and 6 deletions

View File

@@ -41,6 +41,7 @@ type Agent struct {
mcpActions types.Actions
subscriberMutex sync.Mutex
newMessagesSubscribers []func(openai.ChatCompletionMessage)
}
@@ -118,7 +119,10 @@ func (a *Agent) startNewConversationsConsumer() {
return
case msg := <-a.newConversations:
for _, s := range a.newMessagesSubscribers {
a.subscriberMutex.Lock()
subs := a.newMessagesSubscribers
a.subscriberMutex.Unlock()
for _, s := range subs {
s(msg)
}
}
@@ -126,6 +130,12 @@ func (a *Agent) startNewConversationsConsumer() {
}()
}
func (a *Agent) AddSubscriber(f func(openai.ChatCompletionMessage)) {
a.subscriberMutex.Lock()
defer a.subscriberMutex.Unlock()
a.newMessagesSubscribers = append(a.newMessagesSubscribers, f)
}
// StopAction stops the current action
// if any. Can be called before adding a new job.
func (a *Agent) StopAction() {