fix(runtime-events): honor OpenCode progress shapes

This commit is contained in:
YeonGyu-Kim
2026-05-19 13:48:45 +09:00
parent 38462aa9d2
commit 44ef5dec1d
6 changed files with 93 additions and 7 deletions
+3 -2
View File
@@ -101,11 +101,12 @@ export function createContextWindowMonitorHook(
sessionID?: string
providerID?: string
modelID?: string
finish?: boolean
finish?: unknown
tokens?: TokenInfo
} | undefined
if (!info || info.role !== "assistant" || !info.finish) return
const finish = info?.finish
if (!info || info.role !== "assistant" || !finish) return
if (isCompactionAgent(info.agent)) return
const sessionID = resolveMessageEventSessionID(props)
if (!sessionID || !info.providerID || !info.tokens) return
+3 -2
View File
@@ -76,13 +76,14 @@ export function createPreemptiveCompactionHook(
sessionID?: string
providerID?: string
modelID?: string
finish?: boolean
finish?: unknown
tokens?: TokenInfo
parts?: unknown
} | undefined
const sessionID = resolveMessageEventSessionID(props)
if (!info || info.role !== "assistant" || !info.finish || !sessionID) return
const finish = info?.finish
if (!info || info.role !== "assistant" || !finish || !sessionID) return
if (isCompactionAgent(info.agent)) return
if (info.providerID && info.tokens) {
@@ -277,6 +277,18 @@ describe("observeEventForWatchdog", () => {
expect(calls.progress).toEqual([sessionID])
})
it.each(assistantProgressParts)("#given a message.part.updated event whose part is type=%s #when observed #then onAssistantProgress is called", (_label: string, part: { readonly type: string; readonly text?: string; readonly id?: string; readonly name?: string; readonly tool_use_id?: string }) => {
const calls = freshCalls()
observeEventForWatchdog(
{
type: "message.part.updated",
properties: { sessionID, part },
},
createRecordingWatchdog(calls),
)
expect(calls.progress).toEqual([sessionID])
})
it("#given a message.updated assistant event with parts: [] and no error/finish #when observed #then no progress is signalled (no activity yet)", () => {
const calls = freshCalls()
observeEventForWatchdog(
@@ -46,6 +46,18 @@ export function observeEventForWatchdog(
const props = event.properties as Record<string, unknown> | undefined
if (!props) return
if (event.type === "message.part.updated" || event.type === "message.part.delta") {
const sessionID = props.sessionID as string | undefined
const part = props.part as Record<string, unknown> | undefined
const partType = typeof part?.type === "string"
? part.type
: typeof props.type === "string" ? props.type : undefined
if (sessionID && partType) {
watchdog.onAssistantProgress(sessionID)
}
return
}
if (event.type === "message.updated") {
const info = props.info as Record<string, unknown> | undefined
const sessionID = info?.sessionID as string | undefined