fix: preserve subagent thread routing (#1241)
Thanks @gnarco. Co-authored-by: gnarco <gnarco@users.noreply.github.com>
This commit is contained in:
@@ -56,11 +56,13 @@ function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry {
|
||||
const sameDelivery =
|
||||
(entry.deliveryContext?.channel ?? undefined) === nextDelivery?.channel &&
|
||||
(entry.deliveryContext?.to ?? undefined) === nextDelivery?.to &&
|
||||
(entry.deliveryContext?.accountId ?? undefined) === nextDelivery?.accountId;
|
||||
(entry.deliveryContext?.accountId ?? undefined) === nextDelivery?.accountId &&
|
||||
(entry.deliveryContext?.threadId ?? undefined) === nextDelivery?.threadId;
|
||||
const sameLast =
|
||||
entry.lastChannel === normalized.lastChannel &&
|
||||
entry.lastTo === normalized.lastTo &&
|
||||
entry.lastAccountId === normalized.lastAccountId;
|
||||
entry.lastAccountId === normalized.lastAccountId &&
|
||||
entry.lastThreadId === normalized.lastThreadId;
|
||||
if (sameDelivery && sameLast) return entry;
|
||||
return {
|
||||
...entry,
|
||||
@@ -68,6 +70,7 @@ function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry {
|
||||
lastChannel: normalized.lastChannel,
|
||||
lastTo: normalized.lastTo,
|
||||
lastAccountId: normalized.lastAccountId,
|
||||
lastThreadId: normalized.lastThreadId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -379,11 +382,12 @@ export async function updateLastRoute(params: {
|
||||
channel?: SessionEntry["lastChannel"];
|
||||
to?: string;
|
||||
accountId?: string;
|
||||
threadId?: string | number;
|
||||
deliveryContext?: DeliveryContext;
|
||||
ctx?: MsgContext;
|
||||
groupResolution?: import("./types.js").GroupKeyResolution | null;
|
||||
}) {
|
||||
const { storePath, sessionKey, channel, to, accountId, ctx } = params;
|
||||
const { storePath, sessionKey, channel, to, accountId, threadId, ctx } = params;
|
||||
return await withSessionStoreLock(storePath, async () => {
|
||||
const store = loadSessionStore(storePath);
|
||||
const existing = store[sessionKey];
|
||||
@@ -393,6 +397,7 @@ export async function updateLastRoute(params: {
|
||||
channel,
|
||||
to,
|
||||
accountId,
|
||||
threadId,
|
||||
});
|
||||
const mergedInput = mergeDeliveryContext(explicitContext, inlineContext);
|
||||
const merged = mergeDeliveryContext(mergedInput, deliveryContextFromSession(existing));
|
||||
@@ -401,6 +406,7 @@ export async function updateLastRoute(params: {
|
||||
channel: merged?.channel,
|
||||
to: merged?.to,
|
||||
accountId: merged?.accountId,
|
||||
threadId: merged?.threadId,
|
||||
},
|
||||
});
|
||||
const metaPatch = ctx
|
||||
@@ -417,6 +423,7 @@ export async function updateLastRoute(params: {
|
||||
lastChannel: normalized.lastChannel,
|
||||
lastTo: normalized.lastTo,
|
||||
lastAccountId: normalized.lastAccountId,
|
||||
lastThreadId: normalized.lastThreadId,
|
||||
};
|
||||
const next = mergeSessionEntry(
|
||||
existing,
|
||||
|
||||
@@ -89,6 +89,7 @@ export type SessionEntry = {
|
||||
lastChannel?: SessionChannelId;
|
||||
lastTo?: string;
|
||||
lastAccountId?: string;
|
||||
lastThreadId?: string | number;
|
||||
skillsSnapshot?: SessionSkillSnapshot;
|
||||
systemPromptReport?: SessionSystemPromptReport;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user