mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:24:31 +00:00
refactor(heartbeat): share reply payload picker
This commit is contained in:
22
src/auto-reply/heartbeat-reply-payload.ts
Normal file
22
src/auto-reply/heartbeat-reply-payload.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import type { ReplyPayload } from "./types.js";
|
||||||
|
|
||||||
|
export function resolveHeartbeatReplyPayload(
|
||||||
|
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
||||||
|
): ReplyPayload | undefined {
|
||||||
|
if (!replyResult) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!Array.isArray(replyResult)) {
|
||||||
|
return replyResult;
|
||||||
|
}
|
||||||
|
for (let idx = replyResult.length - 1; idx >= 0; idx -= 1) {
|
||||||
|
const payload = replyResult[idx];
|
||||||
|
if (!payload) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (payload.text || payload.mediaUrl || (payload.mediaUrls && payload.mediaUrls.length > 0)) {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import { appendCronStyleCurrentTimeLine } from "../agents/current-time.js";
|
import { appendCronStyleCurrentTimeLine } from "../agents/current-time.js";
|
||||||
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||||
import { DEFAULT_HEARTBEAT_FILENAME } from "../agents/workspace.js";
|
import { DEFAULT_HEARTBEAT_FILENAME } from "../agents/workspace.js";
|
||||||
|
import { resolveHeartbeatReplyPayload } from "../auto-reply/heartbeat-reply-payload.js";
|
||||||
import {
|
import {
|
||||||
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
||||||
DEFAULT_HEARTBEAT_EVERY,
|
DEFAULT_HEARTBEAT_EVERY,
|
||||||
@@ -308,27 +309,6 @@ function resolveHeartbeatSession(
|
|||||||
return { sessionKey: mainSessionKey, storePath, store, entry: mainEntry };
|
return { sessionKey: mainSessionKey, storePath, store, entry: mainEntry };
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveHeartbeatReplyPayload(
|
|
||||||
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
|
||||||
): ReplyPayload | undefined {
|
|
||||||
if (!replyResult) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (!Array.isArray(replyResult)) {
|
|
||||||
return replyResult;
|
|
||||||
}
|
|
||||||
for (let idx = replyResult.length - 1; idx >= 0; idx -= 1) {
|
|
||||||
const payload = replyResult[idx];
|
|
||||||
if (!payload) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (payload.text || payload.mediaUrl || (payload.mediaUrls && payload.mediaUrls.length > 0)) {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveHeartbeatReasoningPayloads(
|
function resolveHeartbeatReasoningPayloads(
|
||||||
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
||||||
): ReplyPayload[] {
|
): ReplyPayload[] {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
|
||||||
import { appendCronStyleCurrentTimeLine } from "../../agents/current-time.js";
|
import { appendCronStyleCurrentTimeLine } from "../../agents/current-time.js";
|
||||||
|
import { resolveHeartbeatReplyPayload } from "../../auto-reply/heartbeat-reply-payload.js";
|
||||||
import {
|
import {
|
||||||
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
||||||
resolveHeartbeatPrompt,
|
resolveHeartbeatPrompt,
|
||||||
@@ -26,27 +26,6 @@ import { whatsappHeartbeatLog } from "./loggers.js";
|
|||||||
import { getSessionSnapshot } from "./session-snapshot.js";
|
import { getSessionSnapshot } from "./session-snapshot.js";
|
||||||
import { elide } from "./util.js";
|
import { elide } from "./util.js";
|
||||||
|
|
||||||
function resolveHeartbeatReplyPayload(
|
|
||||||
replyResult: ReplyPayload | ReplyPayload[] | undefined,
|
|
||||||
): ReplyPayload | undefined {
|
|
||||||
if (!replyResult) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (!Array.isArray(replyResult)) {
|
|
||||||
return replyResult;
|
|
||||||
}
|
|
||||||
for (let idx = replyResult.length - 1; idx >= 0; idx -= 1) {
|
|
||||||
const payload = replyResult[idx];
|
|
||||||
if (!payload) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (payload.text || payload.mediaUrl || (payload.mediaUrls && payload.mediaUrls.length > 0)) {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function runWebHeartbeatOnce(opts: {
|
export async function runWebHeartbeatOnce(opts: {
|
||||||
cfg?: ReturnType<typeof loadConfig>;
|
cfg?: ReturnType<typeof loadConfig>;
|
||||||
to: string;
|
to: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user