Files
openclaw/src/commands/agent/run-context.ts
Clawdbot a13efbe2b5 fix: pass threadId/to/accountId from parent to subagent gateway call
When spawning a subagent, the requesterOrigin's threadId, to, and
accountId were not forwarded to the callGateway({method:'agent'}) params.
This meant the subagent's runContext had no currentThreadTs or
currentChannelId, so resolveTelegramAutoThreadId could not auto-inject
the forum topic thread ID when the subagent used the message tool.

Changes:
- sessions-spawn-tool: pass to, accountId, threadId from requesterOrigin
- run-context: populate currentChannelId from opts.to as fallback

Fixes subagent messages landing in General Topic instead of the correct
Telegram DM topic thread.
2026-02-06 00:23:04 +05:30

56 lines
1.6 KiB
TypeScript

import type { AgentCommandOpts, AgentRunContext } from "./types.js";
import { normalizeAccountId } from "../../utils/account-id.js";
import { resolveMessageChannel } from "../../utils/message-channel.js";
export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext {
const merged: AgentRunContext = opts.runContext ? { ...opts.runContext } : {};
const normalizedChannel = resolveMessageChannel(
merged.messageChannel ?? opts.messageChannel,
opts.replyChannel ?? opts.channel,
);
if (normalizedChannel) {
merged.messageChannel = normalizedChannel;
}
const normalizedAccountId = normalizeAccountId(merged.accountId ?? opts.accountId);
if (normalizedAccountId) {
merged.accountId = normalizedAccountId;
}
const groupId = (merged.groupId ?? opts.groupId)?.toString().trim();
if (groupId) {
merged.groupId = groupId;
}
const groupChannel = (merged.groupChannel ?? opts.groupChannel)?.toString().trim();
if (groupChannel) {
merged.groupChannel = groupChannel;
}
const groupSpace = (merged.groupSpace ?? opts.groupSpace)?.toString().trim();
if (groupSpace) {
merged.groupSpace = groupSpace;
}
if (
merged.currentThreadTs == null &&
opts.threadId != null &&
opts.threadId !== "" &&
opts.threadId !== null
) {
merged.currentThreadTs = String(opts.threadId);
}
// Populate currentChannelId from the outbound target so that
// resolveTelegramAutoThreadId can match the originating chat.
if (!merged.currentChannelId && opts.to) {
const trimmedTo = opts.to.trim();
if (trimmedTo) {
merged.currentChannelId = trimmedTo;
}
}
return merged;
}