mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:11:24 +00:00
fix: avoid echoing prompts when rpc returns empty
This commit is contained in:
@@ -32,6 +32,7 @@ function stripRpcNoise(raw: string): string {
|
||||
const type = evt?.type;
|
||||
const msg = evt?.message ?? evt?.assistantMessageEvent;
|
||||
const msgType = msg?.type;
|
||||
const role = msg?.role;
|
||||
|
||||
// RPC streaming emits one message_update per delta; skip them to avoid flooding fallbacks.
|
||||
if (type === "message_update") continue;
|
||||
@@ -40,6 +41,11 @@ function stripRpcNoise(raw: string): string {
|
||||
if (type === "message_update" && msgType === "toolcall_delta") continue;
|
||||
if (type === "input_audio_buffer.append") continue;
|
||||
|
||||
// Keep only assistant/tool messages; drop agent_start/turn_start/user/etc.
|
||||
const isAssistant = role === "assistant";
|
||||
const isToolRole = typeof role === "string" && role.toLowerCase().includes("tool");
|
||||
if (!isAssistant && !isToolRole) continue;
|
||||
|
||||
// Ignore assistant messages that have no text content (pure toolcall scaffolding).
|
||||
if (msg?.role === "assistant" && Array.isArray(msg?.content)) {
|
||||
const hasText = msg.content.some(
|
||||
@@ -770,9 +776,15 @@ export async function runCommandReply(
|
||||
extractRpcAssistantText(trimmed) ??
|
||||
extractAssistantTextLoosely(trimmed) ??
|
||||
trimmed;
|
||||
if (replyItems.length === 0 && fallbackText && !hasParsedContent) {
|
||||
const promptEcho =
|
||||
fallbackText &&
|
||||
(fallbackText === (templatingCtx.Body ?? "") ||
|
||||
fallbackText === (templatingCtx.BodyStripped ?? ""));
|
||||
const safeFallbackText = promptEcho ? undefined : fallbackText;
|
||||
|
||||
if (replyItems.length === 0 && safeFallbackText && !hasParsedContent) {
|
||||
const { text: cleanedText, mediaUrls: mediaFound } =
|
||||
splitMediaFromOutput(fallbackText);
|
||||
splitMediaFromOutput(safeFallbackText);
|
||||
if (cleanedText || mediaFound?.length) {
|
||||
replyItems.push({
|
||||
text: cleanedText,
|
||||
|
||||
Reference in New Issue
Block a user