fix(plugin): normalize event session ids
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.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user