/** * March Agent SDK - Memory Helper * Port of Python march_agent/memory.py */ import { MemoryClient } from './memory-client.js' import type { MemoryMessage, MemorySearchResult, UserSummary } from './types.js' /** * Helper class for accessing long-term memory. * Provides convenient methods for storing and searching memories. */ export class Memory { readonly userId: string readonly conversationId: string private readonly client: MemoryClient constructor( userId: string, conversationId: string, client: MemoryClient ) { this.userId = userId this.conversationId = conversationId this.client = client } /** * Add messages to memory. */ async addMessages(messages: MemoryMessage[]): Promise { const result = await this.client.addMessages( this.userId, this.conversationId, messages ) return result.added } /** * Add a single message to memory. */ async addMessage(role: 'user' | 'assistant', content: string): Promise { await this.addMessages([{ role, content }]) } /** * Search memory for relevant content. */ async search(query: string, limit: number = 10): Promise { return this.client.search(query, { userId: this.userId, conversationId: this.conversationId, limit, }) } /** * Get user summary. */ async getSummary(): Promise { return this.client.getUserSummary(this.userId) } /** * Clear all memories for this user. */ async clear(): Promise { const result = await this.client.clearMemory(this.userId) return result.shortTermDeleted } }