Skip to content

Commit

Permalink
feat: Add afterSendMessage hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Jul 18, 2024
1 parent 9205a66 commit 7d54491
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/looking_glass/stray-cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class StrayCat {
log.warn(`No websocket connection is open for "${this.userId}". Queuing the message...`)
this.wsQueue.push(msg)
}
madHatter.executeHook('afterSendMessage', msg, this)
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/mad_hatter/core_plugin/plugin-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CatHook.add('beforeReadMessage', msg => msg)

CatHook.add('beforeSendMessage', msg => msg)

CatHook.add('afterSendMessage', msg => msg)

CatHook.add('beforeStoreEpisodicMemory', doc => doc)

CatHook.add('beforeRecallMemories', configs => configs)
Expand Down
3 changes: 2 additions & 1 deletion src/mad_hatter/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { EmbedderSettings, LLMSettings } from '@factory'
import type { VectorMemoryCollection } from '@memory'
import type { FileParsers, WebParser } from '@rh'
import type { AgentFastReply, ContextInput, InstantToolTrigger } from '@dto/agent.ts'
import type { MemoryMessage, MemoryRecallConfigs, Message } from '@/dtos/message.ts'
import type { MemoryMessage, MemoryRecallConfigs, Message, WSMessage } from '@dto/message.ts'

export interface HookTypes {
// Cheshire Cat hooks
Expand All @@ -28,6 +28,7 @@ export interface HookTypes {
recallQuery: (query: string, stray: StrayCat) => MaybePromise<string>
beforeReadMessage: (msg: Message, stray: StrayCat) => MaybePromise<Message>
beforeSendMessage: (msg: MemoryMessage, stray: StrayCat) => MaybePromise<MemoryMessage>
afterSendMessage: (msg: WSMessage, stray: StrayCat) => MaybePromise<WSMessage>
beforeStoreEpisodicMemory: (doc: Document, stray: StrayCat) => MaybePromise<Document>
beforeRecallMemories: (configs: MemoryRecallConfigs, stray: StrayCat) => MaybePromise<MemoryRecallConfigs>
afterRecallMemories: (stray: StrayCat) => MaybePromise<void>
Expand Down

0 comments on commit 7d54491

Please sign in to comment.