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 +
|
* If `to` is omitted, use the session's default reply routing (channel +
|
||||||
* thread the conversation is in) — the agent replies in place.
|
* thread the conversation is in) — the agent replies in place.
|
||||||
*
|
*
|
||||||
* If `to` is specified, look up the named destination; thread_id is null
|
* If `to` is specified, look up the named destination. If it resolves to
|
||||||
* because a cross-destination send starts a new conversation elsewhere.
|
* 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(
|
function resolveRouting(
|
||||||
to: string | undefined,
|
to: string | undefined,
|
||||||
@@ -75,10 +77,17 @@ function resolveRouting(
|
|||||||
const dest = findByName(to);
|
const dest = findByName(to);
|
||||||
if (!dest) return { error: `Unknown destination "${to}". Known: ${destinationList()}` };
|
if (!dest) return { error: `Unknown destination "${to}". Known: ${destinationList()}` };
|
||||||
if (dest.type === 'channel') {
|
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 {
|
return {
|
||||||
channel_type: dest.channelType!,
|
channel_type: dest.channelType!,
|
||||||
platform_id: dest.platformId!,
|
platform_id: dest.platformId!,
|
||||||
thread_id: null,
|
thread_id: threadId,
|
||||||
resolvedName: to,
|
resolvedName: to,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user