← Back to PRs

#16044: plugin-sdk: expose onAgentEvent + onSessionTranscriptUpdate via PluginRuntime.events

by scifantastic open 2026-02-14 06:26 View on GitHub →
channel: bluebubbles size: XS
Adds a new `events` namespace to `PluginRuntime` so extensions can subscribe to real-time agent events and transcript updates. This is needed for interfaces that want to show detailed status about what the agent is doing. ### Problem Extensions that need real-time streaming access to agent events (text deltas, tool calls, lifecycle) need a plugin supported way to access them. ### Solution Expose `onAgentEvent` and `onSessionTranscriptUpdate` through the established `PluginRuntime` interface, which is resolved at bundle time: ```typescript // Before (breaks on production installs): const { onAgentEvent } = require("../../../src/infra/agent-events.js"); // After (works everywhere): const unsub = api.runtime.events.onAgentEvent((evt) => { ... }); ``` ### Changes - **`src/plugins/runtime/types.ts`** — Add `OnAgentEvent` and `OnSessionTranscriptUpdate` type aliases; add `events: { onAgentEvent, onSessionTranscriptUpdate }` to `PluginRuntime` - **`src/plugins/runtime/index.ts`** — Import and wire the two functions into `createPluginRuntime()` ### Usage ```typescript register(api: OpenClawPluginApi) { const unsub = api.runtime.events.onAgentEvent((evt) => { // evt: { runId, seq, stream, ts, data, sessionKey? } if (evt.stream === "assistant") { /* text delta */ } if (evt.stream === "tool") { /* tool call/result */ } if (evt.stream === "lifecycle") { /* start/end */ } }); const unsubTranscript = api.runtime.events.onSessionTranscriptUpdate(({ sessionFile }) => { // Cross-channel message arrived, transcript file updated }); } ``` <!-- greptile_comment --> <h3>Greptile Summary</h3> Exposes `onAgentEvent` and `onSessionTranscriptUpdate` through a new `events` namespace on `PluginRuntime`, allowing extensions to subscribe to real-time agent events and transcript updates via the official plugin SDK rather than fragile internal `require()` paths. - Adds `OnAgentEvent` and `OnSessionTranscriptUpdate` type aliases to `types.ts` following the existing `typeof import(...)` convention - Wires the two functions into `createPluginRuntime()` in `index.ts` under the new `events` namespace - Purely additive change with no breaking modifications to existing APIs - Note: `emitSessionTranscriptUpdate` lacks try/catch around listener invocation (unlike `emitAgentEvent`), which becomes more relevant now that plugin authors can register listeners <h3>Confidence Score: 4/5</h3> - This PR is safe to merge; the one concern is a pre-existing missing error guard in transcript-events.ts that becomes more impactful with plugin exposure. - Purely additive change that re-exports two well-tested internal functions through the plugin SDK. Types and wiring follow established patterns exactly. The only concern is a pre-existing missing try/catch in emitSessionTranscriptUpdate that could now be triggered by third-party plugin code. - src/sessions/transcript-events.ts — missing try/catch around listener calls in emitSessionTranscriptUpdate <sub>Last reviewed commit: f01b6b2</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs