const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./vDOh_fWF.js","./DFB29SWc.js","./DrKWWDpL.js","./DsQIgu-4.js","./Ouh6Dj2I2.js","./C0bVU7gr2.js","./Dn7LRnjg2.js","./DsanjglN.js","./CbGRcr-D.js","./bG-fsHMS.js","./DTkg6Mnx.js","./DYP3EJMY.js","./DeO5NWhN.js","./DgZn9uJn.js","./CudpqN6Z.js","./CX8DOZuw2.js","./DOqzs8kl2.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./CxlOpib82.js","./Czb-RtcG.js","./C0nwgWmB.js","./D-eE9s2f.js","./CWxOfblT.js","./DlZwu-Y7.js","./CvFbqtf9.js","./Dg_1c8FK2.js"])))=>i.map(i=>d[i]);
import{s as e}from"./DrKWWDpL.js";import{n as t,t as n}from"./DsQIgu-4.js";import{t as r}from"./DYP3EJMY.js";import{n as i}from"./Dn7LRnjg2.js";import{r as a}from"./Dg_1c8FK2.js";import{r as o}from"./-TjUTcZv2.js";import{n as s,t as c}from"./2yUiEINB.js";var l=e(r(),1);t();function u(){return`L-${(0,l.randomBytes)(4).toString(`hex`)}`}async function d(e,t){if(!t.insight?.trim())throw Error(`Insight text is required`);if(!t.source?.trim())throw Error(`Source is required`);if(t.confidence<0||t.confidence>1)throw Error(`Confidence must be between 0.0 and 1.0`);if(!t._skipGate){let{verifyCandidate:r}=await n(async()=>{let{verifyCandidate:e}=await import(`./vDOh_fWF.js`);return{verifyCandidate:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]),import.meta.url),a=t.source.includes(`manual`)||t.source.includes(`owner`),o=t.source.includes(`transcript:ses_`),s=a?`owner`:o?`speculative`:`agent`,c=await r(e,{text:t.insight.trim(),memoryType:`semantic`,tier:a?`medium`:`short`,confidence:t.confidence,source:a?`manual`:`transcript`,sourceConfidence:s,trusted:a});if(c.action!==`stored`){let n=c.id?await(await i(e)).getLearning(c.id).catch(()=>null):null;return n?{...n,applicableTypes:JSON.parse(n.applicableTypesJson||`[]`)}:{id:c.id??``,insight:t.insight.trim(),source:t.source,confidence:t.confidence,actionable:t.actionable??!1,application:t.application??null,applicableTypesJson:`[]`,applicableTypes:[],qualityScore:0,memoryTier:`short`,memoryType:`semantic`,sourceConfidence:s,verified:!1,contentHash:``,createdAt:new Date().toISOString().replace(`T`,` `).slice(0,19),updatedAt:null,tierPromotedAt:null,tierPromotionReason:null,invalidAt:null,pruneCandidateAt:null,citationCount:0,pruneCandidate:!1}}}let r=await i(e),d=await r.findLearnings(),f=t.insight.trim().toLowerCase(),p=d.find(e=>e.insight.trim().toLowerCase()===f);if(p){let n=Math.max(p.confidence,t.confidence);await r.updateLearning(p.id,{confidence:n});let i=await r.getLearning(p.id);return a(e,`learning:${p.id}`,`learning`,p.insight.substring(0,200),p.qualityScore??.5,p.insight+(p.application??``),{source:p.source,confidence:n,actionable:p.actionable}).catch(()=>{}),{...i,applicableTypes:JSON.parse(i.applicableTypesJson||`[]`)}}let m=t.source.includes(`manual`)||t.source.includes(`owner`),h=t.source.includes(`transcript:ses_`),g=m?`owner`:h?`speculative`:`agent`,_=m?`medium`:`short`,v=h?`episodic`:`semantic`,y=m,b=o({confidence:t.confidence,actionable:t.actionable??!1,insight:t.insight.trim(),application:t.application??null,sourceConfidence:g,memoryTier:_}),x=(0,l.createHash)(`sha256`).update(t.insight.trim().toLowerCase()).digest(`hex`).slice(0,16),S={id:u(),insight:t.insight.trim(),source:t.source.trim(),confidence:t.confidence,actionable:t.actionable??!1,application:t.application??null,applicableTypesJson:t.applicableTypes?JSON.stringify(t.applicableTypes):`[]`,qualityScore:b,memoryTier:_,memoryType:v,sourceConfidence:g,verified:y,contentHash:x},C=await r.addLearning(S);return a(e,`learning:${C.id}`,`learning`,C.insight.substring(0,200),b,C.insight+(C.application??``),{source:C.source,confidence:C.confidence,actionable:C.actionable}).catch(()=>{}),(g===`owner`||g===`task-outcome`)&&c(e,{id:C.id,text:C.insight,createdAt:C.createdAt??new Date().toISOString().replace(`T`,` `).slice(0,19)}).then(t=>{for(let n of t)s(e,n.existingId,C.id,`auto:learning-supersedes — high overlap detected at store time`).catch(()=>{})}).catch(()=>{}),{...C,applicableTypes:JSON.parse(C.applicableTypesJson||`[]`)}}export{d as t};