import { Memory } from "../../src/memory"; async function testUndefinedFix() { console.log("šŸ”§ Testing Undefined/Null Property Fixes"); console.log("=" .repeat(50)); const memory = new Memory({ llm: { provider: "openai", config: { model: "gpt-4o-mini", }, }, }); try { // Add some test data console.log("\nšŸ“ Adding test messages..."); await memory.add( [ { role: "user", content: "Hello, my name is Caroline" }, { role: "assistant", content: "Nice to meet you, Caroline!" }, ], { userId: "test-user" } ); // Test search that might return results with undefined properties console.log("\nšŸ” Testing search with filtering..."); const searchResult = await memory.search("Caroline", { userId: "test-user", limit: 5 }); console.log(`āœ… Search completed: ${searchResult.results.length} results`); // Test chat that uses filtering internally console.log("\nšŸ’¬ Testing chat with filtering..."); const chatResult = await memory.chat("Who is Caroline?", { userId: "test-user", responseCustomInstructions: "Be brief and direct", useSearchAgents: true, enableMultihop: true }); console.log(`āœ… Chat completed: ${chatResult.response.length} chars response`); console.log(`šŸ“Š Sources found: ${chatResult.sources.length}`); console.log("\nšŸŽÆ All undefined/null fixes are working correctly!"); } catch (error) { if (error instanceof Error && error.message.includes("substring")) { console.error("āŒ Substring error still exists:", error.message); console.error(" This indicates a missed null/undefined check"); } else { console.error("āŒ Other error occurred:", error); } } finally { await memory.reset(); } } // Run the test if (require.main === module) { testUndefinedFix().catch(console.error); } export { testUndefinedFix };