Files
openclaw/src/plugins/runtime/runtime-system.ts
M1a0 7847e67f8a plugin-runtime: expose runHeartbeatOnce in system API (#40299)
* plugin-runtime: expose runHeartbeatOnce in system API

Plugins that enqueue system events and need the agent to deliver
responses to the originating channel currently have no way to
override the default `heartbeat.target: "none"` behaviour.

Expose `runHeartbeatOnce` in the plugin runtime `system` namespace
so plugins can trigger a single heartbeat cycle with an explicit
`heartbeat: { target: "last" }` override — the same pattern the
cron service already uses (see #28508).

Changes:
- Add `RunHeartbeatOnceOptions` type and `runHeartbeatOnce` to
  `PluginRuntimeCore.system` (types-core.ts)
- Wire the function through a thin wrapper in runtime-system.ts
- Update the test-utils plugin-runtime mock

Made-with: Cursor

* feat(plugins): expose runHeartbeatOnce in system API (#40299) (thanks @loveyana)

---------

Co-authored-by: George Zhang <georgezhangtj97@gmail.com>
2026-03-25 10:47:01 -07:00

27 lines
1.0 KiB
TypeScript

import { runHeartbeatOnce as runHeartbeatOnceInternal } from "../../infra/heartbeat-runner.js";
import { requestHeartbeatNow } from "../../infra/heartbeat-wake.js";
import { enqueueSystemEvent } from "../../infra/system-events.js";
import { runCommandWithTimeout } from "../../process/exec.js";
import { formatNativeDependencyHint } from "./native-deps.js";
import type { RunHeartbeatOnceOptions } from "./types-core.js";
import type { PluginRuntime } from "./types.js";
export function createRuntimeSystem(): PluginRuntime["system"] {
return {
enqueueSystemEvent,
requestHeartbeatNow,
runHeartbeatOnce: (opts?: RunHeartbeatOnceOptions) => {
// Destructure to forward only the plugin-safe subset; prevent cfg/deps injection at runtime.
const { reason, agentId, sessionKey, heartbeat } = opts ?? {};
return runHeartbeatOnceInternal({
reason,
agentId,
sessionKey,
heartbeat: heartbeat ? { target: heartbeat.target } : undefined,
});
},
runCommandWithTimeout,
formatNativeDependencyHint,
};
}