mirror of
https://github.com/Mintplex-Labs/abitat.git
synced 2026-07-01 10:05:27 -04:00
add onstart event
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'aibitat': patch
|
||||
---
|
||||
|
||||
added `onStart` event
|
||||
+22
-1
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user