
























@@ -1,11 +1,14 @@
1+// Structured heartbeat response tool payload helpers.
12import { isRecord } from "@openclaw/normalization-core/record-coerce";
23import { normalizeOptionalString as readString } from "@openclaw/normalization-core/string-coerce";
34import type { ReplyPayload } from "./reply-payload.js";
45import { HEARTBEAT_TOKEN } from "./tokens.js";
567+/** Tool name used by heartbeat runs to report visible or silent progress. */
68export const HEARTBEAT_RESPONSE_TOOL_NAME = "heartbeat_respond";
79const HEARTBEAT_RESPONSE_CHANNEL_DATA_KEY = "openclawHeartbeatResponse";
81011+/** Allowed heartbeat response outcomes. */
912export const HEARTBEAT_TOOL_OUTCOMES = [
1013"no_change",
1114"progress",
@@ -15,9 +18,11 @@ export const HEARTBEAT_TOOL_OUTCOMES = [
1518] as const;
1619type HeartbeatToolOutcome = (typeof HEARTBEAT_TOOL_OUTCOMES)[number];
172021+/** Allowed heartbeat notification priorities. */
1822export const HEARTBEAT_TOOL_PRIORITIES = ["low", "normal", "high"] as const;
1923type HeartbeatToolPriority = (typeof HEARTBEAT_TOOL_PRIORITIES)[number];
202425+/** Normalized response emitted by the heartbeat response tool. */
2126export type HeartbeatToolResponse = {
2227outcome: HeartbeatToolOutcome;
2328notify: boolean;
@@ -51,6 +56,7 @@ function readBooleanAlias(record: Record<string, unknown>, ...keys: string[]) {
5156return undefined;
5257}
535859+/** Validate and normalize unknown heartbeat tool output. */
5460export function normalizeHeartbeatToolResponse(value: unknown): HeartbeatToolResponse | undefined {
5561if (!isRecord(value)) {
5662return undefined;
@@ -79,10 +85,12 @@ export function normalizeHeartbeatToolResponse(value: unknown): HeartbeatToolRes
7985};
8086}
818788+/** Resolve the user-visible notification text for a heartbeat response. */
8289export function getHeartbeatToolNotificationText(response: HeartbeatToolResponse): string {
8390return response.notify ? (response.notificationText ?? response.summary).trim() : "";
8491}
859293+/** Store a heartbeat tool response in reply channel data for later extraction. */
8694export function createHeartbeatToolResponsePayload(response: HeartbeatToolResponse): ReplyPayload {
8795return {
8896text: response.notify ? getHeartbeatToolNotificationText(response) : HEARTBEAT_TOKEN,
@@ -100,6 +108,7 @@ function getHeartbeatToolResponseFromPayload(
100108);
101109}
102110111+/** Find the last heartbeat tool response embedded in a reply result. */
103112export function resolveHeartbeatToolResponseFromReplyResult(
104113replyResult: ReplyPayload | ReplyPayload[] | undefined,
105114): HeartbeatToolResponse | undefined {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。