fix(background-agent): forward session stream activity
This commit is contained in:
@@ -35,6 +35,23 @@ describe("createBackgroundNotificationHook", () => {
|
||||
expect(handleEvent).toHaveBeenCalledWith(event)
|
||||
})
|
||||
|
||||
test("#given session.next stream event #when event handler runs #then it forwards to manager", async () => {
|
||||
//#given
|
||||
const handleEvent = mock(() => {})
|
||||
const hook = createBackgroundNotificationHook({
|
||||
handleEvent,
|
||||
injectPendingNotificationsIntoChatMessage: () => {},
|
||||
} as never)
|
||||
|
||||
const event = { type: "session.next.text.delta", properties: { sessionID: "ses-1", delta: "x" } }
|
||||
|
||||
//#when
|
||||
await hook.event({ event })
|
||||
|
||||
//#then
|
||||
expect(handleEvent).toHaveBeenCalledWith(event)
|
||||
})
|
||||
|
||||
test("#given todo.updated event #when event handler runs #then it forwards to manager", async () => {
|
||||
//#given
|
||||
const handleEvent = mock(() => {})
|
||||
|
||||
@@ -28,9 +28,16 @@ const FORWARDED_EVENT_TYPES = new Set([
|
||||
"session.status",
|
||||
])
|
||||
|
||||
const FORWARDED_EVENT_PREFIXES = ["session.next."]
|
||||
|
||||
function shouldForwardEvent(type: string): boolean {
|
||||
return FORWARDED_EVENT_TYPES.has(type)
|
||||
|| FORWARDED_EVENT_PREFIXES.some((prefix) => type.startsWith(prefix))
|
||||
}
|
||||
|
||||
export function createBackgroundNotificationHook(manager: BackgroundManager) {
|
||||
const eventHandler = async ({ event }: EventInput) => {
|
||||
if (!FORWARDED_EVENT_TYPES.has(event.type)) return
|
||||
if (!shouldForwardEvent(event.type)) return
|
||||
manager.handleEvent(event)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user