mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:41:23 +00:00
fix(core): unify session-key normalization and plugin boundary checks
This commit is contained in:
@@ -4,7 +4,11 @@ import {
|
||||
getSubagentDepth,
|
||||
isCronSessionKey,
|
||||
} from "../sessions/session-key-utils.js";
|
||||
import { classifySessionKeyShape } from "./session-key.js";
|
||||
import {
|
||||
classifySessionKeyShape,
|
||||
parseAgentSessionKey,
|
||||
toAgentStoreSessionKey,
|
||||
} from "./session-key.js";
|
||||
|
||||
describe("classifySessionKeyShape", () => {
|
||||
it("classifies empty keys as missing", () => {
|
||||
@@ -93,3 +97,21 @@ describe("deriveSessionChatType", () => {
|
||||
expect(deriveSessionChatType("")).toBe("unknown");
|
||||
});
|
||||
});
|
||||
|
||||
describe("session key canonicalization", () => {
|
||||
it("parses agent keys case-insensitively and returns lowercase tokens", () => {
|
||||
expect(parseAgentSessionKey("AGENT:Main:Hook:Webhook:42")).toEqual({
|
||||
agentId: "main",
|
||||
rest: "hook:webhook:42",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not double-prefix already-qualified agent keys", () => {
|
||||
expect(
|
||||
toAgentStoreSessionKey({
|
||||
agentId: "main",
|
||||
requestKey: "agent:main:main",
|
||||
}),
|
||||
).toBe("agent:main:main");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,16 +49,17 @@ export function toAgentStoreSessionKey(params: {
|
||||
mainKey?: string | undefined;
|
||||
}): string {
|
||||
const raw = (params.requestKey ?? "").trim();
|
||||
if (!raw || raw === DEFAULT_MAIN_KEY) {
|
||||
if (!raw || raw.toLowerCase() === DEFAULT_MAIN_KEY) {
|
||||
return buildAgentMainSessionKey({ agentId: params.agentId, mainKey: params.mainKey });
|
||||
}
|
||||
const parsed = parseAgentSessionKey(raw);
|
||||
if (parsed) {
|
||||
return `agent:${parsed.agentId}:${parsed.rest}`;
|
||||
}
|
||||
const lowered = raw.toLowerCase();
|
||||
if (lowered.startsWith("agent:")) {
|
||||
return lowered;
|
||||
}
|
||||
if (lowered.startsWith("subagent:")) {
|
||||
return `agent:${normalizeAgentId(params.agentId)}:${lowered}`;
|
||||
}
|
||||
return `agent:${normalizeAgentId(params.agentId)}:${lowered}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user