Merge b2e648d9c0 into da71eaebd2
This commit is contained in:
commit
cee3d65827
@ -108,6 +108,27 @@ describe("initSessionState thread forking", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("initSessionState RawBody", () => {
|
describe("initSessionState RawBody", () => {
|
||||||
|
it("canonicalizes main session aliases for explicit SessionKey", async () => {
|
||||||
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-alias-"));
|
||||||
|
const storePath = path.join(root, "sessions.json");
|
||||||
|
const cfg = {
|
||||||
|
session: { store: storePath, mainKey: "work" },
|
||||||
|
agents: { list: [{ id: "ops", default: true }] },
|
||||||
|
} as OpenClawConfig;
|
||||||
|
|
||||||
|
const result = await initSessionState({
|
||||||
|
ctx: {
|
||||||
|
Body: "Hello",
|
||||||
|
SessionKey: "main",
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
commandAuthorized: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.sessionKey).toBe("agent:ops:work");
|
||||||
|
expect(result.sessionCtx.SessionKey).toBe("agent:ops:work");
|
||||||
|
});
|
||||||
|
|
||||||
it("triggerBodyNormalized correctly extracts commands when Body contains context but RawBody is clean", async () => {
|
it("triggerBodyNormalized correctly extracts commands when Body contains context but RawBody is clean", async () => {
|
||||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-rawbody-"));
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-rawbody-"));
|
||||||
const storePath = path.join(root, "sessions.json");
|
const storePath = path.join(root, "sessions.json");
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import type { OpenClawConfig } from "../../config/config.js";
|
|||||||
import type { TtsAutoMode } from "../../config/types.tts.js";
|
import type { TtsAutoMode } from "../../config/types.tts.js";
|
||||||
import {
|
import {
|
||||||
DEFAULT_RESET_TRIGGERS,
|
DEFAULT_RESET_TRIGGERS,
|
||||||
|
canonicalizeMainSessionAlias,
|
||||||
deriveSessionMetaPatch,
|
deriveSessionMetaPatch,
|
||||||
evaluateSessionFreshness,
|
evaluateSessionFreshness,
|
||||||
type GroupKeyResolution,
|
type GroupKeyResolution,
|
||||||
@ -187,6 +188,7 @@ export async function initSessionState(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessionKey = resolveSessionKey(sessionScope, sessionCtxForState, mainKey);
|
sessionKey = resolveSessionKey(sessionScope, sessionCtxForState, mainKey);
|
||||||
|
sessionKey = canonicalizeMainSessionAlias({ cfg, agentId, sessionKey });
|
||||||
const entry = sessionStore[sessionKey];
|
const entry = sessionStore[sessionKey];
|
||||||
const previousSessionEntry = resetTriggered && entry ? { ...entry } : undefined;
|
const previousSessionEntry = resetTriggered && entry ? { ...entry } : undefined;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@ -337,6 +339,7 @@ export async function initSessionState(params: {
|
|||||||
|
|
||||||
const sessionCtx: TemplateContext = {
|
const sessionCtx: TemplateContext = {
|
||||||
...ctx,
|
...ctx,
|
||||||
|
SessionKey: sessionKey,
|
||||||
// Keep BodyStripped aligned with Body (best default for agent prompts).
|
// Keep BodyStripped aligned with Body (best default for agent prompts).
|
||||||
// RawBody is reserved for command/directive parsing and may omit context.
|
// RawBody is reserved for command/directive parsing and may omit context.
|
||||||
BodyStripped: formatInboundBodyWithSenderMeta({
|
BodyStripped: formatInboundBodyWithSenderMeta({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user