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.
24 lines
989 B
TypeScript
24 lines
989 B
TypeScript
import { isRecord } from "./record-type-guard"
|
|
|
|
function getStringField(record: Record<string, unknown> | undefined, key: string): string | undefined {
|
|
const value = record?.[key]
|
|
return typeof value === "string" && value.length > 0 ? value : undefined
|
|
}
|
|
|
|
export function resolveSessionEventID(properties: unknown): string | undefined {
|
|
const props = isRecord(properties) ? properties : undefined
|
|
const info = isRecord(props?.info) ? props.info : undefined
|
|
return getStringField(props, "sessionID")
|
|
?? getStringField(info, "sessionID")
|
|
?? getStringField(info, "id")
|
|
}
|
|
|
|
export function resolveMessageEventSessionID(properties: unknown): string | undefined {
|
|
const props = isRecord(properties) ? properties : undefined
|
|
const info = isRecord(props?.info) ? props.info : undefined
|
|
const part = isRecord(props?.part) ? props.part : undefined
|
|
return getStringField(props, "sessionID")
|
|
?? getStringField(info, "sessionID")
|
|
?? getStringField(part, "sessionID")
|
|
}
|