#16044: plugin-sdk: expose onAgentEvent + onSessionTranscriptUpdate via PluginRuntime.events
channel: bluebubbles
size: XS
Cluster:
Plugin Enhancements and Fixes
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
#19464: feat(plugins): expose requestHeartbeatNow on plugin runtime
by AustinEral · 2026-02-17
76.3%
#22283: Plugins: expose resolveMainSessionKey in runtime system
by MegaPhoenix92 · 2026-02-21
74.2%
#14873: [Feature]: Extend before_agent_start hook context with Model, Tools...
by akv2011 · 2026-02-12
74.0%
#22733: feat(plugin): add runner-extensions extension
by cintia09 · 2026-02-21
71.7%
#16867: plugin-sdk: export PluginLogger type for plugin use
by fsdwen · 2026-02-15
70.6%
#19565: feat: add agent lifecycle hook events (session, message, error)
by tag-assistant · 2026-02-17
70.4%
#11732: feat(plugins): add injectMessages to before_agent_start hook
by antra-tess · 2026-02-08
70.2%
#15577: feat(hooks): add message:preprocessed hook event
by heybeaux · 2026-02-13
70.0%
#11124: feat(plugins): add before_llm_request hook for custom LLM headers
by johnlanni · 2026-02-07
69.8%
#2556: fix(plugin-install): handle existing plugins and filter workspace deps
by longmaba · 2026-01-27
69.5%