4da48555ee
Handle OpenCode session events that carry the session ID under properties.info.id or properties.info.sessionID so background tasks and continuation hooks do not miss idle/error/delete events. Add regression coverage for nested session.idle events completing background tasks and waking continuation hooks.
25 lines
672 B
TypeScript
25 lines
672 B
TypeScript
import { resolveSessionEventID } from "../shared/event-session-id"
|
|
|
|
type EventInput = { event: { type: string; properties?: Record<string, unknown> } }
|
|
type SessionStatus = { type: string }
|
|
|
|
export function normalizeSessionStatusToIdle(input: EventInput): EventInput | null {
|
|
if (input.event.type !== "session.status") return null
|
|
|
|
const props = input.event.properties
|
|
if (!props) return null
|
|
|
|
const status = props.status as SessionStatus | undefined
|
|
if (!status || status.type !== "idle") return null
|
|
|
|
const sessionID = resolveSessionEventID(props)
|
|
if (!sessionID) return null
|
|
|
|
return {
|
|
event: {
|
|
type: "session.idle",
|
|
properties: { sessionID },
|
|
},
|
|
}
|
|
}
|