add onstart event

This commit is contained in:
Wlad Paiva
2023-10-17 11:39:51 -03:00
parent bd68230b1f
commit 41aea69835
2 changed files with 27 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'aibitat': patch
---
added `onStart` event
+22 -1
View File
@@ -318,6 +318,17 @@ export class AIbitat {
return this
}
/**
* Triggered when a chat is interrupted by a node.
*
* @param listener
* @returns
*/
public onStart(listener: (chat: ChatState) => void) {
this.emitter.on('start', listener)
return this
}
/**
* Start a new chat.
*
@@ -332,6 +343,7 @@ export class AIbitat {
// register the message in the chat history
this.newMessage(message)
this.emitter.emit('start', message)
// ask the node to reply
await this.chat({
@@ -611,10 +623,19 @@ ${this.getHistory({to})
}
if (feedback) {
await this.start({
const message = {
from,
to,
content: feedback,
}
// register the message in the chat history
this.newMessage(message)
// ask the node to reply
await this.chat({
to: message.from,
from: message.to,
})
} else {
await this.chat({from, to})