// @bun
var m=Object.defineProperty;var s=(t)=>t;function y(t,e){this[t]=s.bind(null,e)}var u=(t,e)=>{for(var i in e)m(t,i,{get:e[i],enumerable:!0,configurable:!0,set:y.bind(e,i)})};var l=(t,e)=>()=>(t&&(e=t(t=0)),e);var x=import.meta.require;import{randomUUID as n}from"crypto";function d(t){let e=t.content;if(typeof e==="string")return e;if(Array.isArray(e))return e.map((i)=>{if(typeof i==="string")return i;if("text"in i&&typeof i.text==="string")return i.text;return""}).filter(Boolean).join("");return""}function A(t){let e=t.content;if(typeof e==="string")return e;if(Array.isArray(e))return e.map((i)=>{if(typeof i==="string")return i;if("text"in i&&typeof i.text==="string")return i.text;return""}).filter(Boolean).join("");return""}function M(t){switch(t){case"assistant":return"assistant";case"system":return"system";case"tool":return"tool";case"user":default:return"user"}}class o{async append(t,e){let i=await this.load(t.sessionId)??this.bootstrapMemory(t),r={id:n(),createdAt:e.createdAt??new Date,...e};return i.memory.entries.push(r),await this.save(i),i}async summarize(t){return}async prune(t){}bootstrapMemory(t){return{session:t,memory:{entries:t.messages.map((e)=>({id:n(),createdAt:new Date,type:M(e.role),content:d(e)}))}}}}function f(t,e,i){if(!t)return;t.append(e,{type:i.role,content:A(i),metadata:i.metadata})}class h extends o{ttlMs;maxEntries;store=new Map;constructor(t){super();this.ttlMs=(t?.ttlMinutes??60)*60*1000,this.maxEntries=t?.maxEntries??250}async load(t){this.evictExpired();let e=this.store.get(t);if(!e)return null;return e.data.session.updatedAt=new Date,e.expiresAt=Date.now()+this.ttlMs,e.data}async save(t){this.trim(t.memory.entries),this.store.set(t.session.sessionId,{data:t,expiresAt:Date.now()+this.ttlMs})}async summarize(t){let e=await this.load(t.sessionId)??this.bootstrapMemory(t),i=e.memory.entries.slice(-10).map((r)=>`- ${r.type}: ${r.content}`).join(`
`);return e.memory.summary=i,e.memory.lastSummarizedAt=new Date,await this.save(e),e.memory}trim(t){if(t.length<=this.maxEntries)return;t.splice(0,t.length-this.maxEntries)}evictExpired(){let t=Date.now();for(let[e,i]of this.store.entries())if(i.expiresAt<=t)this.store.delete(e)}}export{f as trackMessageInMemory,h as InMemoryAgentMemory,o as BaseAgentMemoryManager};
