fix(ts-oss): return attributedTo from get/search/getAll (#5675)
This commit is contained in:
@@ -1189,7 +1189,13 @@ export class Memory {
|
||||
}
|
||||
}
|
||||
|
||||
const result = { ...memoryItem, ...filters };
|
||||
const result = {
|
||||
...memoryItem,
|
||||
...filters,
|
||||
...(memory.payload.attributedTo && {
|
||||
attributedTo: memory.payload.attributedTo,
|
||||
}),
|
||||
};
|
||||
await this._displayFirstRunNotice("get");
|
||||
return result;
|
||||
}
|
||||
@@ -1453,6 +1459,7 @@ export class Memory {
|
||||
...(payload.user_id && { user_id: payload.user_id }),
|
||||
...(payload.agent_id && { agent_id: payload.agent_id }),
|
||||
...(payload.run_id && { run_id: payload.run_id }),
|
||||
...(payload.attributedTo && { attributedTo: payload.attributedTo }),
|
||||
...(scored.scoreDetails && { score_details: scored.scoreDetails }),
|
||||
};
|
||||
});
|
||||
@@ -1687,6 +1694,9 @@ export class Memory {
|
||||
...(mem.payload.user_id && { user_id: mem.payload.user_id }),
|
||||
...(mem.payload.agent_id && { agent_id: mem.payload.agent_id }),
|
||||
...(mem.payload.run_id && { run_id: mem.payload.run_id }),
|
||||
...(mem.payload.attributedTo && {
|
||||
attributedTo: mem.payload.attributedTo,
|
||||
}),
|
||||
}));
|
||||
|
||||
const result = { results };
|
||||
|
||||
@@ -82,6 +82,7 @@ export interface MemoryItem {
|
||||
updatedAt?: string;
|
||||
score?: number;
|
||||
metadata?: Record<string, any>;
|
||||
attributedTo?: string;
|
||||
}
|
||||
|
||||
export interface SearchFilters {
|
||||
|
||||
@@ -361,6 +361,45 @@ describe("Memory - search()", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── attributedTo (#5666) ────────────────────────────────
|
||||
|
||||
describe("Memory - attributedTo round-trip (#5666)", () => {
|
||||
let memory: Memory;
|
||||
const userId = `attributed_test_${Date.now()}`;
|
||||
let id: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
memory = createMemory();
|
||||
// The mocked LLM tags every extracted fact with attributed_to: "user".
|
||||
const addResult: SearchResult = await memory.add("I love AI", { userId });
|
||||
id = addResult.results[0].id;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await memory.reset();
|
||||
});
|
||||
|
||||
test("get() surfaces attributedTo", async () => {
|
||||
const item: MemoryItem | null = await memory.get(id);
|
||||
expect(item!.attributedTo).toBe("user");
|
||||
});
|
||||
|
||||
test("getAll() surfaces attributedTo", async () => {
|
||||
const result: SearchResult = await memory.getAll({
|
||||
filters: { user_id: userId },
|
||||
});
|
||||
expect(result.results[0].attributedTo).toBe("user");
|
||||
});
|
||||
|
||||
test("search() surfaces attributedTo", async () => {
|
||||
const result: SearchResult = await memory.search("AI", {
|
||||
filters: { user_id: userId },
|
||||
});
|
||||
expect(result.results.length).toBeGreaterThan(0);
|
||||
expect(result.results[0].attributedTo).toBe("user");
|
||||
});
|
||||
});
|
||||
|
||||
// ─── history() ───────────────────────────────────────────
|
||||
|
||||
describe("Memory - history()", () => {
|
||||
|
||||
Reference in New Issue
Block a user