Skip to content

Commit eb417bc

Browse files
ai-hpcai-hpc
andauthored
fix(messages): preserve inbound audio for message-tool TTS
Preserve inbound-audio context for message-tool TTS across embedded reply runs, CLI MCP loopback, and queued follow-up paths. Thanks @ai-hpc. Co-authored-by: ai-hpc <[email protected]>
1 parent 5d6216a commit eb417bc

33 files changed

Lines changed: 225 additions & 48 deletions

‎src/agents/agent-tools.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ export function createOpenClawCodingTools(options?: {
453453
currentThreadTs?: string;
454454
/** Current inbound message id for action fallbacks (e.g. Telegram react). */
455455
currentMessageId?: string | number;
456+
/** True when the current inbound turn carried audio media. */
457+
currentInboundAudio?: boolean;
456458
/** Group id for channel-level tool policy resolution. */
457459
groupId?: string | null;
458460
/** Group channel label (e.g. #general) for channel-level tool policy resolution. */
@@ -1001,6 +1003,7 @@ export function createOpenClawCodingTools(options?: {
10011003
currentChannelId: options?.currentChannelId,
10021004
currentThreadTs: options?.currentThreadTs,
10031005
currentMessageId: options?.currentMessageId,
1006+
currentInboundAudio: options?.currentInboundAudio,
10041007
modelProvider: options?.modelProvider,
10051008
modelId: options?.modelId,
10061009
replyToMode: options?.replyToMode,

‎src/agents/cli-runner.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ export function buildRunClaudeCliAgentParams(params: RunClaudeCliAgentParams): R
888888
currentChannelId: params.currentChannelId,
889889
currentThreadTs: params.currentThreadTs,
890890
currentMessageId: params.currentMessageId,
891+
currentInboundAudio: params.currentInboundAudio,
891892
};
892893
}
893894

‎src/agents/cli-runner/prepare.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function createTestMcpLoopbackServerConfig(port: number) {
102102
"x-openclaw-current-channel-id": "${OPENCLAW_MCP_CURRENT_CHANNEL_ID}",
103103
"x-openclaw-current-thread-ts": "${OPENCLAW_MCP_CURRENT_THREAD_TS}",
104104
"x-openclaw-current-message-id": "${OPENCLAW_MCP_CURRENT_MESSAGE_ID}",
105+
"x-openclaw-current-inbound-audio": "${OPENCLAW_MCP_CURRENT_INBOUND_AUDIO}",
105106
"x-openclaw-inbound-event-kind": "${OPENCLAW_MCP_INBOUND_EVENT_KIND}",
106107
"x-openclaw-source-reply-delivery-mode": "${OPENCLAW_MCP_SOURCE_REPLY_DELIVERY_MODE}",
107108
},
@@ -1222,6 +1223,7 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
12221223
currentChannelId: undefined,
12231224
currentThreadTs: undefined,
12241225
currentMessageId: undefined,
1226+
currentInboundAudio: undefined,
12251227
accountId: undefined,
12261228
inboundEventKind: undefined,
12271229
sourceReplyDeliveryMode: undefined,
@@ -1367,6 +1369,7 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
13671369
currentChannelId: "telegram:-100123:topic:42",
13681370
currentThreadTs: "42",
13691371
currentMessageId: "reply-message-1",
1372+
currentInboundAudio: true,
13701373
sourceReplyDeliveryMode: "message_tool_only",
13711374
});
13721375

@@ -1375,6 +1378,7 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
13751378
OPENCLAW_MCP_CURRENT_CHANNEL_ID: "telegram:-100123:topic:42",
13761379
OPENCLAW_MCP_CURRENT_THREAD_TS: "42",
13771380
OPENCLAW_MCP_CURRENT_MESSAGE_ID: "reply-message-1",
1381+
OPENCLAW_MCP_CURRENT_INBOUND_AUDIO: "true",
13781382
OPENCLAW_MCP_INBOUND_EVENT_KIND: "room_event",
13791383
OPENCLAW_MCP_SOURCE_REPLY_DELIVERY_MODE: "message_tool_only",
13801384
});

‎src/agents/cli-runner/prepare.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export async function prepareCliRunContext(
287287
OPENCLAW_MCP_CURRENT_THREAD_TS: params.currentThreadTs ?? "",
288288
OPENCLAW_MCP_CURRENT_MESSAGE_ID:
289289
params.currentMessageId != null ? String(params.currentMessageId) : "",
290+
OPENCLAW_MCP_CURRENT_INBOUND_AUDIO: params.currentInboundAudio === true ? "true" : "",
290291
OPENCLAW_MCP_INBOUND_EVENT_KIND: params.currentInboundEventKind ?? "",
291292
OPENCLAW_MCP_SOURCE_REPLY_DELIVERY_MODE: params.sourceReplyDeliveryMode ?? "",
292293
}
@@ -364,6 +365,7 @@ export async function prepareCliRunContext(
364365
currentChannelId: params.currentChannelId,
365366
currentThreadTs: params.currentThreadTs,
366367
currentMessageId: params.currentMessageId,
368+
currentInboundAudio: params.currentInboundAudio,
367369
accountId: params.agentAccountId,
368370
inboundEventKind: params.currentInboundEventKind,
369371
sourceReplyDeliveryMode: params.sourceReplyDeliveryMode,

‎src/agents/cli-runner/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type RunCliAgentParams = {
8080
currentChannelId?: string;
8181
currentThreadTs?: string;
8282
currentMessageId?: string | number;
83+
currentInboundAudio?: boolean;
8384
agentAccountId?: string;
8485
/** Trusted sender identity bit for channel action auth. */
8586
senderIsOwner?: boolean;

‎src/agents/command/attempt-execution.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ export function runAgentAttempt(params: {
590590
messageChannel: params.messageChannel,
591591
streamParams: params.opts.streamParams,
592592
messageProvider: params.opts.messageProvider ?? params.messageChannel,
593+
currentChannelId: params.runContext.currentChannelId,
594+
currentThreadTs: params.runContext.currentThreadTs,
595+
currentInboundAudio: params.runContext.currentInboundAudio,
593596
agentAccountId: params.runContext.accountId,
594597
senderIsOwner: params.opts.senderIsOwner,
595598
toolsAllow: params.opts.toolsAllow,
@@ -657,6 +660,7 @@ export function runAgentAttempt(params: {
657660
spawnedBy: params.spawnedBy,
658661
currentChannelId: params.runContext.currentChannelId,
659662
currentThreadTs: params.runContext.currentThreadTs,
663+
currentInboundAudio: params.runContext.currentInboundAudio,
660664
replyToMode: params.runContext.replyToMode,
661665
hasRepliedRef: params.runContext.hasRepliedRef,
662666
senderIsOwner: params.opts.senderIsOwner,

‎src/agents/command/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type AgentRunContext = {
3434
groupSpace?: string | null;
3535
currentChannelId?: string;
3636
currentThreadTs?: string;
37+
currentInboundAudio?: boolean;
3738
replyToMode?: "off" | "first" | "all" | "batched";
3839
hasRepliedRef?: { value: boolean };
3940
};

‎src/agents/embedded-agent-runner/run.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,7 @@ export async function runEmbeddedAgent(
15671567
currentChannelId: params.currentChannelId,
15681568
currentThreadTs: params.currentThreadTs,
15691569
currentMessageId: params.currentMessageId,
1570+
currentInboundAudio: params.currentInboundAudio,
15701571
replyToMode: params.replyToMode,
15711572
hasRepliedRef: params.hasRepliedRef,
15721573
sessionFile: activeSessionFile,

‎src/agents/embedded-agent-runner/run/attempt.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ export async function runEmbeddedAttempt(
12121212
currentChannelId: params.currentChannelId,
12131213
currentThreadTs: params.currentThreadTs,
12141214
currentMessageId: params.currentMessageId,
1215+
currentInboundAudio: params.currentInboundAudio,
12151216
includeCoreTools: toolConstructionPlan.includeCoreTools,
12161217
includeToolSearchControls: toolSearchControlsEnabledForRun,
12171218
toolSearchCatalogExecutor: (toolParams) => {

‎src/agents/embedded-agent-runner/run/params.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export type RunEmbeddedAgentParams = {
8282
currentThreadTs?: string;
8383
/** Current inbound message id for action fallbacks (e.g. Telegram react). */
8484
currentMessageId?: string | number;
85+
/** True when the current inbound turn carried audio media. */
86+
currentInboundAudio?: boolean;
8587
/** Reply-to mode for Slack auto-threading. */
8688
replyToMode?: "off" | "first" | "all" | "batched";
8789
/** Mutable ref to track if a reply was sent (for "first" mode). */

0 commit comments

Comments
 (0)