mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 18:52:54 +00:00
fix: preserve threaded delivery lookup
This commit is contained in:
@@ -115,6 +115,30 @@ describe("extractDeliveryInfo", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves generic thread session keys through the stored base row", () => {
|
||||
const env = setStateDir();
|
||||
const sessionKey = "agent:main:webchat:dm:user-123";
|
||||
upsertSessionEntry({
|
||||
agentId: "main",
|
||||
env,
|
||||
sessionKey,
|
||||
entry: buildEntry({
|
||||
channel: "webchat",
|
||||
to: "webchat:user-123",
|
||||
accountId: "default",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(extractDeliveryInfo(`${sessionKey}:thread:66`)).toEqual({
|
||||
deliveryContext: {
|
||||
channel: "webchat",
|
||||
to: "webchat:user-123",
|
||||
accountId: "default",
|
||||
},
|
||||
threadId: "66",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns empty delivery info when the session row is missing", () => {
|
||||
setStateDir();
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { DEFAULT_AGENT_ID, resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
|
||||
import {
|
||||
DEFAULT_AGENT_ID,
|
||||
parseThreadSessionSuffix,
|
||||
resolveAgentIdFromSessionKey,
|
||||
} from "../../routing/session-key.js";
|
||||
import { deliveryContextFromSession } from "../../utils/delivery-context.shared.js";
|
||||
import type { DeliveryContext } from "../../utils/delivery-context.types.js";
|
||||
import { normalizeSessionRowKey } from "./store-entry.js";
|
||||
@@ -56,10 +60,7 @@ function readDeliverySessionEntry(sessionKey: string): SessionEntry | undefined
|
||||
}
|
||||
|
||||
export function parseSessionThreadInfo(sessionKey: string | undefined): ParsedSessionThreadInfo {
|
||||
return {
|
||||
baseSessionKey: sessionKey,
|
||||
threadId: undefined,
|
||||
};
|
||||
return parseThreadSessionSuffix(sessionKey);
|
||||
}
|
||||
|
||||
export function extractDeliveryInfo(sessionKey: string | undefined): {
|
||||
@@ -70,14 +71,18 @@ export function extractDeliveryInfo(sessionKey: string | undefined): {
|
||||
return { deliveryContext: undefined, threadId: undefined };
|
||||
}
|
||||
|
||||
const { baseSessionKey, threadId } = parseSessionThreadInfo(sessionKey);
|
||||
const lookupKey = baseSessionKey ?? sessionKey;
|
||||
try {
|
||||
const entry = readDeliverySessionEntry(sessionKey);
|
||||
const entry =
|
||||
readDeliverySessionEntry(lookupKey) ??
|
||||
(lookupKey === sessionKey ? undefined : readDeliverySessionEntry(sessionKey));
|
||||
const deliveryContext = toExtractedDeliveryContext(entry);
|
||||
return {
|
||||
deliveryContext,
|
||||
threadId: deliveryContext?.threadId,
|
||||
threadId: deliveryContext?.threadId ?? threadId,
|
||||
};
|
||||
} catch {
|
||||
return { deliveryContext: undefined, threadId: undefined };
|
||||
return { deliveryContext: undefined, threadId };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user