





















@@ -58,6 +58,7 @@ function collectSessionIdMatchesForRequest(opts: {
5858storePath: string;
5959storeAgentId?: string;
6060sessionId: string;
61+searchOtherAgentStores: boolean;
6162}): SessionIdMatchSet {
6263const matches: Array<[string, SessionEntry]> = [];
6364const primaryStoreMatches: Array<[string, SessionEntry]> = [];
@@ -85,6 +86,10 @@ function collectSessionIdMatchesForRequest(opts: {
8586};
86878788addMatches(opts.sessionStore, opts.storePath, { primary: true });
89+if (!opts.searchOtherAgentStores) {
90+return { matches, primaryStoreMatches, storeByKey };
91+}
92+8893for (const agentId of listAgentIds(opts.cfg)) {
8994if (agentId === opts.storeAgentId) {
9095continue;
@@ -137,13 +142,19 @@ export function resolveSessionKeyForRequest(opts: {
137142const sessionCfg = opts.cfg.session;
138143const scope = sessionCfg?.scope ?? "per-sender";
139144const mainKey = normalizeMainKey(sessionCfg?.mainKey);
145+const requestedAgentId = opts.agentId?.trim() ? normalizeAgentId(opts.agentId) : undefined;
146+const requestedSessionId = opts.sessionId?.trim() || undefined;
140147const explicitSessionKey =
141148opts.sessionKey?.trim() ||
142-resolveExplicitAgentSessionKey({
143-cfg: opts.cfg,
144-agentId: opts.agentId,
145-});
146-const storeAgentId = resolveAgentIdFromSessionKey(explicitSessionKey);
149+(!requestedSessionId
150+ ? resolveExplicitAgentSessionKey({
151+cfg: opts.cfg,
152+agentId: requestedAgentId,
153+})
154+ : undefined);
155+const storeAgentId = explicitSessionKey
156+ ? resolveAgentIdFromSessionKey(explicitSessionKey)
157+ : (requestedAgentId ?? normalizeAgentId(undefined));
147158const storePath = resolveStorePath(sessionCfg?.store, {
148159agentId: storeAgentId,
149160});
@@ -158,22 +169,23 @@ export function resolveSessionKeyForRequest(opts: {
158169// by the shared gateway/session resolver helpers instead of whichever store happens to be scanned
159170// first.
160171if (
161-opts.sessionId &&
172+requestedSessionId &&
162173!explicitSessionKey &&
163-(!sessionKey || sessionStore[sessionKey]?.sessionId !== opts.sessionId)
174+(!sessionKey || sessionStore[sessionKey]?.sessionId !== requestedSessionId)
164175) {
165176const { matches, primaryStoreMatches, storeByKey } = collectSessionIdMatchesForRequest({
166177cfg: opts.cfg,
167178 sessionStore,
168179 storePath,
169180 storeAgentId,
170-sessionId: opts.sessionId,
181+sessionId: requestedSessionId,
182+searchOtherAgentStores: requestedAgentId === undefined,
171183});
172-const preferredSelection = resolveSessionIdMatchSelection(matches, opts.sessionId);
184+const preferredSelection = resolveSessionIdMatchSelection(matches, requestedSessionId);
173185const currentStoreSelection =
174186preferredSelection.kind === "selected"
175187 ? preferredSelection
176- : resolveSessionIdMatchSelection(primaryStoreMatches, opts.sessionId);
188+ : resolveSessionIdMatchSelection(primaryStoreMatches, requestedSessionId);
177189if (currentStoreSelection.kind === "selected") {
178190const preferred = storeByKey.get(currentStoreSelection.sessionKey);
179191if (preferred) {
@@ -183,9 +195,9 @@ export function resolveSessionKeyForRequest(opts: {
183195}
184196}
185197186-if (opts.sessionId && !sessionKey) {
198+if (requestedSessionId && !sessionKey) {
187199sessionKey = buildExplicitSessionIdSessionKey({
188-sessionId: opts.sessionId,
200+sessionId: requestedSessionId,
189201agentId: opts.agentId,
190202});
191203}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。