fix: validate memory search min score · openclaw/openclaw@4ac6bb1
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/memory-core/src
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import { stringEnum } from "openclaw/plugin-sdk/channel-actions"; |
| 1 | +import { optionalFiniteNumberSchema, stringEnum } from "openclaw/plugin-sdk/channel-actions"; |
2 | 2 | import { |
3 | 3 | listMemoryCorpusSupplements, |
4 | 4 | resolveMemorySearchConfig, |
@@ -31,7 +31,7 @@ export async function loadMemoryToolRuntime(): Promise<MemoryToolRuntime> {
|
31 | 31 | export const MemorySearchSchema = Type.Object({ |
32 | 32 | query: Type.String(), |
33 | 33 | maxResults: Type.Optional(Type.Integer({ minimum: 1 })), |
34 | | -minScore: Type.Optional(Type.Number()), |
| 34 | +minScore: optionalFiniteNumberSchema(), |
35 | 35 | corpus: Type.Optional(stringEnum(["memory", "wiki", "all", "sessions"])), |
36 | 36 | }); |
37 | 37 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,35 @@ describe("memory_search unavailable payloads", () => {
|
71 | 71 | expect(getMemorySearchManagerMockCalls()).toBe(0); |
72 | 72 | }); |
73 | 73 | |
| 74 | +it("rejects malformed minScore before searching", async () => { |
| 75 | +const tool = createMemorySearchToolOrThrow(); |
| 76 | + |
| 77 | +await expect( |
| 78 | +tool.execute("malformed-min-score", { |
| 79 | +query: "hello", |
| 80 | +minScore: "0.8junk", |
| 81 | +}), |
| 82 | +).rejects.toThrow("minScore must be a finite number"); |
| 83 | + |
| 84 | +expect(getMemorySearchManagerMockCalls()).toBe(0); |
| 85 | +}); |
| 86 | + |
| 87 | +it("passes string minScore through to memory search", async () => { |
| 88 | +let seenMinScore: number | undefined; |
| 89 | +setMemorySearchImpl(async (opts) => { |
| 90 | +seenMinScore = opts?.minScore; |
| 91 | +return []; |
| 92 | +}); |
| 93 | +const tool = createMemorySearchToolOrThrow(); |
| 94 | + |
| 95 | +await tool.execute("string-min-score", { |
| 96 | +query: "hello", |
| 97 | +minScore: "0.8", |
| 98 | +}); |
| 99 | + |
| 100 | +expect(seenMinScore).toBe(0.8); |
| 101 | +}); |
| 102 | + |
74 | 103 | it("returns explicit unavailable metadata for quota failures", async () => { |
75 | 104 | setMemorySearchImpl(async () => { |
76 | 105 | throw new Error("openai embeddings failed: 429 insufficient_quota"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import type { MemorySource } from "openclaw/plugin-sdk/memory-core-host-engine-s
|
3 | 3 | import { |
4 | 4 | asToolParamsRecord, |
5 | 5 | jsonResult, |
6 | | -readNumberParam, |
| 6 | +readFiniteNumberParam, |
7 | 7 | readPositiveIntegerParam, |
8 | 8 | readStringParam, |
9 | 9 | type MemoryCorpusSearchResult, |
@@ -257,7 +257,7 @@ export function createMemorySearchTool(options: {
|
257 | 257 | const rawParams = asToolParamsRecord(params); |
258 | 258 | const query = readStringParam(rawParams, "query", { required: true }); |
259 | 259 | const maxResults = readPositiveIntegerParam(rawParams, "maxResults"); |
260 | | -const minScore = readNumberParam(rawParams, "minScore"); |
| 260 | +const minScore = readFiniteNumberParam(rawParams, "minScore"); |
261 | 261 | const requestedCorpus = readStringParam(rawParams, "corpus") as |
262 | 262 | | "memory" |
263 | 263 | | "wiki" |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ export {
|
7 | 7 | export { |
8 | 8 | asToolParamsRecord, |
9 | 9 | jsonResult, |
| 10 | +readFiniteNumberParam, |
10 | 11 | readNumberParam, |
11 | 12 | readPositiveIntegerParam, |
12 | 13 | readStringParam, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。