mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-12 18:11:51 +08:00
fix(agent-runner): preserve thread_id when sending to current channel
send_file and send_message with an explicit `to` parameter were always setting thread_id to null, causing files and messages to land in the Discord channel root instead of the thread the session is bound to. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -42,8 +42,10 @@ function destinationList(): string {
|
||||
* If `to` is omitted, use the session's default reply routing (channel +
|
||||
* thread the conversation is in) — the agent replies in place.
|
||||
*
|
||||
* If `to` is specified, look up the named destination; thread_id is null
|
||||
* because a cross-destination send starts a new conversation elsewhere.
|
||||
* If `to` is specified, look up the named destination. If it resolves to
|
||||
* the same channel the session is bound to, the session's thread_id is
|
||||
* preserved so replies land in the correct thread. Otherwise thread_id
|
||||
* is null (a cross-destination send starts a new conversation).
|
||||
*/
|
||||
function resolveRouting(
|
||||
to: string | undefined,
|
||||
@@ -75,10 +77,17 @@ function resolveRouting(
|
||||
const dest = findByName(to);
|
||||
if (!dest) return { error: `Unknown destination "${to}". Known: ${destinationList()}` };
|
||||
if (dest.type === 'channel') {
|
||||
// If the destination is the same channel the session is bound to,
|
||||
// preserve the thread_id so replies land in the correct thread.
|
||||
const session = getSessionRouting();
|
||||
const threadId =
|
||||
session.channel_type === dest.channelType && session.platform_id === dest.platformId
|
||||
? session.thread_id
|
||||
: null;
|
||||
return {
|
||||
channel_type: dest.channelType!,
|
||||
platform_id: dest.platformId!,
|
||||
thread_id: null,
|
||||
thread_id: threadId,
|
||||
resolvedName: to,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user