mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-01 21:35:53 +00:00
fix: validate memory get ranges
This commit is contained in:
@@ -74,8 +74,8 @@ const MemoryGetSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
path: { type: "string" },
|
||||
from: { type: "number" },
|
||||
lines: { type: "number" },
|
||||
from: { type: "integer", minimum: 1 },
|
||||
lines: { type: "integer", minimum: 1 },
|
||||
corpus: { type: "string", enum: ["memory", "wiki", "all"] },
|
||||
},
|
||||
required: ["path"],
|
||||
|
||||
@@ -207,6 +207,21 @@ describe("memory tools", () => {
|
||||
expect(getMemorySearchManagerMockCalls()).toBe(0);
|
||||
});
|
||||
|
||||
it("rejects fractional memory_get ranges before reading files", async () => {
|
||||
setMemoryBackend("builtin");
|
||||
const tool = createMemoryGetToolOrThrow();
|
||||
|
||||
await expect(
|
||||
tool.execute("call_fractional_range", {
|
||||
path: "memory/2026-02-19.md",
|
||||
from: 1.5,
|
||||
lines: 2,
|
||||
}),
|
||||
).rejects.toThrow("from must be a positive integer");
|
||||
expect(getReadAgentMemoryFileMockCalls()).toBe(0);
|
||||
expect(getMemorySearchManagerMockCalls()).toBe(0);
|
||||
});
|
||||
|
||||
it("returns truncation metadata and a continuation notice for partial memory_get results", async () => {
|
||||
setMemoryBackend("builtin");
|
||||
setMemoryReadFileImpl(async (params: MemoryReadParams) => ({
|
||||
|
||||
@@ -37,8 +37,8 @@ export const MemorySearchSchema = Type.Object({
|
||||
|
||||
export const MemoryGetSchema = Type.Object({
|
||||
path: Type.String(),
|
||||
from: Type.Optional(Type.Number()),
|
||||
lines: Type.Optional(Type.Number()),
|
||||
from: Type.Optional(Type.Integer()),
|
||||
lines: Type.Optional(Type.Integer()),
|
||||
corpus: Type.Optional(stringEnum(["memory", "wiki", "all"])),
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
asToolParamsRecord,
|
||||
jsonResult,
|
||||
readNumberParam,
|
||||
readPositiveIntegerParam,
|
||||
readStringParam,
|
||||
type MemoryCorpusSearchResult,
|
||||
type OpenClawConfig,
|
||||
@@ -443,8 +444,8 @@ export function createMemoryGetTool(options: {
|
||||
async (_toolCallId, params) => {
|
||||
const rawParams = asToolParamsRecord(params);
|
||||
const relPath = readStringParam(rawParams, "path", { required: true });
|
||||
const from = readNumberParam(rawParams, "from", { integer: true });
|
||||
const lines = readNumberParam(rawParams, "lines", { integer: true });
|
||||
const from = readPositiveIntegerParam(rawParams, "from");
|
||||
const lines = readPositiveIntegerParam(rawParams, "lines");
|
||||
const requestedCorpus = readStringParam(rawParams, "corpus") as
|
||||
| "memory"
|
||||
| "wiki"
|
||||
|
||||
@@ -8,6 +8,7 @@ export {
|
||||
asToolParamsRecord,
|
||||
jsonResult,
|
||||
readNumberParam,
|
||||
readPositiveIntegerParam,
|
||||
readStringParam,
|
||||
type AnyAgentTool,
|
||||
} from "../agents/tools/common.js";
|
||||
|
||||
Reference in New Issue
Block a user