mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 09:38:33 +00:00
fix: validate memory search result counts
This commit is contained in:
@@ -62,7 +62,7 @@ const MemorySearchSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
query: { type: "string" },
|
||||
maxResults: { type: "number" },
|
||||
maxResults: { type: "integer", minimum: 1 },
|
||||
minScore: { type: "number" },
|
||||
corpus: { type: "string", enum: ["memory", "wiki", "all", "sessions"] },
|
||||
},
|
||||
|
||||
@@ -30,7 +30,7 @@ export async function loadMemoryToolRuntime(): Promise<MemoryToolRuntime> {
|
||||
|
||||
export const MemorySearchSchema = Type.Object({
|
||||
query: Type.String(),
|
||||
maxResults: Type.Optional(Type.Number()),
|
||||
maxResults: Type.Optional(Type.Integer({ minimum: 1 })),
|
||||
minScore: Type.Optional(Type.Number()),
|
||||
corpus: Type.Optional(stringEnum(["memory", "wiki", "all", "sessions"])),
|
||||
});
|
||||
|
||||
@@ -58,6 +58,19 @@ describe("memory_search unavailable payloads", () => {
|
||||
resetMemoryToolMockState({ searchImpl: async () => [] });
|
||||
});
|
||||
|
||||
it("rejects fractional maxResults before searching", async () => {
|
||||
const tool = createMemorySearchToolOrThrow();
|
||||
|
||||
await expect(
|
||||
tool.execute("fractional-max-results", {
|
||||
query: "hello",
|
||||
maxResults: 1.5,
|
||||
}),
|
||||
).rejects.toThrow("maxResults must be a positive integer");
|
||||
|
||||
expect(getMemorySearchManagerMockCalls()).toBe(0);
|
||||
});
|
||||
|
||||
it("returns explicit unavailable metadata for quota failures", async () => {
|
||||
setMemorySearchImpl(async () => {
|
||||
throw new Error("openai embeddings failed: 429 insufficient_quota");
|
||||
|
||||
@@ -256,7 +256,7 @@ export function createMemorySearchTool(options: {
|
||||
async (_toolCallId, params) => {
|
||||
const rawParams = asToolParamsRecord(params);
|
||||
const query = readStringParam(rawParams, "query", { required: true });
|
||||
const maxResults = readNumberParam(rawParams, "maxResults");
|
||||
const maxResults = readPositiveIntegerParam(rawParams, "maxResults");
|
||||
const minScore = readNumberParam(rawParams, "minScore");
|
||||
const requestedCorpus = readStringParam(rawParams, "corpus") as
|
||||
| "memory"
|
||||
|
||||
Reference in New Issue
Block a user