mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:24:31 +00:00
fix: derive citations chat type via session parser
This commit is contained in:
committed by
Vignesh
parent
d0b98c75e5
commit
edd6289f26
@@ -84,4 +84,40 @@ describe("memory search citations", () => {
|
|||||||
const details = result.details as { results: Array<{ snippet: string; citation?: string }> };
|
const details = result.details as { results: Array<{ snippet: string; citation?: string }> };
|
||||||
expect(details.results[0]?.snippet.length).toBeLessThanOrEqual(20);
|
expect(details.results[0]?.snippet.length).toBeLessThanOrEqual(20);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("honors auto mode for direct chats", async () => {
|
||||||
|
backend = "builtin";
|
||||||
|
const cfg = {
|
||||||
|
memory: { citations: "auto" },
|
||||||
|
agents: { list: [{ id: "main", default: true }] },
|
||||||
|
};
|
||||||
|
const tool = createMemorySearchTool({
|
||||||
|
config: cfg,
|
||||||
|
agentSessionKey: "agent:main:discord:dm:u123",
|
||||||
|
});
|
||||||
|
if (!tool) {
|
||||||
|
throw new Error("tool missing");
|
||||||
|
}
|
||||||
|
const result = await tool.execute("auto_mode_direct", { query: "notes" });
|
||||||
|
const details = result.details as { results: Array<{ snippet: string }> };
|
||||||
|
expect(details.results[0]?.snippet).toMatch(/Source:/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("suppresses citations for auto mode in group chats", async () => {
|
||||||
|
backend = "builtin";
|
||||||
|
const cfg = {
|
||||||
|
memory: { citations: "auto" },
|
||||||
|
agents: { list: [{ id: "main", default: true }] },
|
||||||
|
};
|
||||||
|
const tool = createMemorySearchTool({
|
||||||
|
config: cfg,
|
||||||
|
agentSessionKey: "agent:main:discord:group:c123",
|
||||||
|
});
|
||||||
|
if (!tool) {
|
||||||
|
throw new Error("tool missing");
|
||||||
|
}
|
||||||
|
const result = await tool.execute("auto_mode_group", { query: "notes" });
|
||||||
|
const details = result.details as { results: Array<{ snippet: string }> };
|
||||||
|
expect(details.results[0]?.snippet).not.toMatch(/Source:/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { MemoryCitationsMode } from "../../config/types.memory.js";
|
|||||||
import { resolveMemoryBackendConfig } from "../../memory/backend-config.js";
|
import { resolveMemoryBackendConfig } from "../../memory/backend-config.js";
|
||||||
import { getMemorySearchManager } from "../../memory/index.js";
|
import { getMemorySearchManager } from "../../memory/index.js";
|
||||||
import type { MemorySearchResult } from "../../memory/types.js";
|
import type { MemorySearchResult } from "../../memory/types.js";
|
||||||
|
import { parseAgentSessionKey } from "../../routing/session-key.js";
|
||||||
import { resolveSessionAgentId } from "../agent-scope.js";
|
import { resolveSessionAgentId } from "../agent-scope.js";
|
||||||
import { resolveMemorySearchConfig } from "../memory-search.js";
|
import { resolveMemorySearchConfig } from "../memory-search.js";
|
||||||
import type { AnyAgentTool } from "./common.js";
|
import type { AnyAgentTool } from "./common.js";
|
||||||
@@ -195,14 +196,19 @@ function shouldIncludeCitations(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deriveChatTypeFromSessionKey(sessionKey?: string): "direct" | "group" | "channel" {
|
function deriveChatTypeFromSessionKey(sessionKey?: string): "direct" | "group" | "channel" {
|
||||||
if (!sessionKey) {
|
const parsed = parseAgentSessionKey(sessionKey);
|
||||||
|
if (!parsed?.rest) {
|
||||||
return "direct";
|
return "direct";
|
||||||
}
|
}
|
||||||
if (sessionKey.includes(":group:")) {
|
const tokens = parsed.rest
|
||||||
return "group";
|
.toLowerCase()
|
||||||
}
|
.split(":")
|
||||||
if (sessionKey.includes(":channel:")) {
|
.filter(Boolean);
|
||||||
|
if (tokens.includes("channel")) {
|
||||||
return "channel";
|
return "channel";
|
||||||
}
|
}
|
||||||
|
if (tokens.includes("group")) {
|
||||||
|
return "group";
|
||||||
|
}
|
||||||
return "direct";
|
return "direct";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user