fix(background-agent): forward session stream activity

This commit is contained in:
YeonGyu-Kim
2026-05-21 15:49:58 +09:00
parent 90c38d16b4
commit bd1a6e3d3b
5 changed files with 93 additions and 1 deletions
@@ -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(() => {})
+8 -1
View File
@@ -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)
}