mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
fix(active-memory): keep search queries UTF-16 safe (#102621)
Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -5097,6 +5097,31 @@ describe("active-memory plugin", () => {
|
||||
expect(prompt).not.toContain("Recent conversation tail:");
|
||||
});
|
||||
|
||||
it("keeps a whole code point when the bounded search query crosses an emoji", async () => {
|
||||
api.pluginConfig = {
|
||||
agents: ["main"],
|
||||
queryMode: "message",
|
||||
};
|
||||
plugin.register(api as unknown as OpenClawPluginApi);
|
||||
const prefix = "a".repeat(479);
|
||||
|
||||
await hooks.before_prompt_build(
|
||||
{
|
||||
prompt: `${prefix}😀tail`,
|
||||
messages: [],
|
||||
},
|
||||
{
|
||||
agentId: "main",
|
||||
trigger: "user",
|
||||
sessionKey: "agent:main:main",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
const query = lastEmbeddedPrompt().match(/Bounded memory search query:\n([^\n]*)/u)?.[1];
|
||||
expect(query).toBe(prefix);
|
||||
});
|
||||
|
||||
it("sends a bounded latest-message query instead of channel metadata to memory search", async () => {
|
||||
api.pluginConfig = {
|
||||
agents: ["main"],
|
||||
|
||||
@@ -2711,7 +2711,7 @@ function normalizeSearchQueryText(text: string): string {
|
||||
function clampSearchQuery(text: string): string {
|
||||
const normalized = text.replace(/\s+/g, " ").trim();
|
||||
return normalized.length > MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS
|
||||
? normalized.slice(0, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
|
||||
? truncateUtf16Safe(normalized, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
|
||||
: normalized;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user