Files
oh-my-opencode/src/plugin/build-team-idle-wake-hint-client.ts
T
YeonGyu-Kim a43215f24e fix(plugin/event): bind team-idle-wake-hint client methods to SDK Session
The team-mode wiring at `createEventHandler` extracted
`pluginContext.client.session.promptAsync` and `.status` into a fresh
wrapper object. The methods were copied by reference, so the prompt-async
gate's `session.promptAsync.bind(session)` was binding to that plain
wrapper rather than the underlying SDK `Session` instance. The opencode
SDK's `promptAsync` reads `this._client.post(...)`, so production calls
threw `TypeError: undefined is not an object (evaluating 'this._client')`
on the very first dispatch — fingerprinted in /tmp/oh-my-opencode.log as
688 `background-agent-parent-wake`, 47 `model-suggestion-retry`, and 4
`team-idle-wake-hint` failures over the past three days.

Move the wrapper construction into `buildTeamIdleWakeHintClient`, which
preserves the narrow factory contract while binding both methods back to
the SDK `Session` so `_client` survives the dispatch. Cover the contract
with four BDD-style tests including the historical destructure-only
failure mode so any future regression is caught at unit-test time.
2026-05-17 02:06:52 +09:00

26 lines
766 B
TypeScript

import type { PluginInput } from "@opencode-ai/plugin"
type SdkSession = PluginInput["client"]["session"]
type SdkPromptAsync = SdkSession["promptAsync"]
type SdkStatus = SdkSession["status"]
export type TeamIdleWakeHintNarrowClient = {
session: {
promptAsync?: SdkPromptAsync
status?: SdkStatus
}
}
export function buildTeamIdleWakeHintClient(client: PluginInput["client"]): TeamIdleWakeHintNarrowClient {
const session = client.session
const promptAsync = typeof session.promptAsync === "function"
? session.promptAsync.bind(session) as SdkPromptAsync
: undefined
const status = typeof session.status === "function"
? session.status.bind(session) as SdkStatus
: undefined
return {
session: { promptAsync, status },
}
}