fix: preserve subagent thread routing (#1241)
Thanks @gnarco. Co-authored-by: gnarco <gnarco@users.noreply.github.com>
This commit is contained in:
@@ -407,6 +407,8 @@ export async function agentCommand(
|
||||
sessionKey,
|
||||
messageChannel,
|
||||
agentAccountId: runContext.accountId,
|
||||
messageTo: opts.replyTo ?? opts.to,
|
||||
messageThreadId: opts.threadId,
|
||||
currentChannelId: runContext.currentChannelId,
|
||||
currentThreadTs: runContext.currentThreadTs,
|
||||
replyToMode: runContext.replyToMode,
|
||||
|
||||
@@ -61,6 +61,7 @@ export async function deliverAgentCommandResult(params: {
|
||||
sessionEntry,
|
||||
requestedChannel: opts.replyChannel ?? opts.channel,
|
||||
explicitTo: opts.replyTo ?? opts.to,
|
||||
explicitThreadId: opts.threadId,
|
||||
accountId: opts.replyAccountId ?? opts.accountId,
|
||||
wantsDelivery: deliver,
|
||||
});
|
||||
@@ -93,6 +94,10 @@ export async function deliverAgentCommandResult(params: {
|
||||
};
|
||||
const resolvedTarget = resolved.resolvedTarget;
|
||||
const deliveryTarget = resolved.resolvedTo;
|
||||
const resolvedThreadId = deliveryPlan.resolvedThreadId ?? opts.threadId;
|
||||
const resolvedReplyToId =
|
||||
deliveryChannel === "slack" && resolvedThreadId != null ? String(resolvedThreadId) : undefined;
|
||||
const resolvedThreadTarget = deliveryChannel === "slack" ? undefined : resolvedThreadId;
|
||||
|
||||
const logDeliveryError = (err: unknown) => {
|
||||
const message = `Delivery failed (${deliveryChannel}${deliveryTarget ? ` to ${deliveryTarget}` : ""}): ${String(err)}`;
|
||||
@@ -153,6 +158,8 @@ export async function deliverAgentCommandResult(params: {
|
||||
to: deliveryTarget,
|
||||
accountId: resolvedAccountId,
|
||||
payloads: deliveryPayloads,
|
||||
replyToId: resolvedReplyToId ?? null,
|
||||
threadId: resolvedThreadTarget ?? null,
|
||||
bestEffort: bestEffortDeliver,
|
||||
onError: (err) => logDeliveryError(err),
|
||||
onPayload: logPayload,
|
||||
|
||||
@@ -14,5 +14,14 @@ export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext
|
||||
const normalizedAccountId = normalizeAccountId(merged.accountId ?? opts.accountId);
|
||||
if (normalizedAccountId) merged.accountId = normalizedAccountId;
|
||||
|
||||
if (
|
||||
merged.currentThreadTs == null &&
|
||||
opts.threadId != null &&
|
||||
opts.threadId !== "" &&
|
||||
opts.threadId !== null
|
||||
) {
|
||||
merged.currentThreadTs = String(opts.threadId);
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ export type AgentCommandOpts = {
|
||||
replyChannel?: string;
|
||||
/** Override delivery account id (separate from session routing). */
|
||||
replyAccountId?: string;
|
||||
/** Override delivery thread/topic id (separate from session routing). */
|
||||
threadId?: string | number;
|
||||
/** Message channel context (webchat|voicewake|whatsapp|...). */
|
||||
messageChannel?: string;
|
||||
channel?: string; // delivery channel (whatsapp|telegram|...)
|
||||
|
||||
Reference in New Issue
Block a user