const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./CmQc_KsG2.js","./Y-eU8Aa32.js","./DrKWWDpL.js","./DsQIgu-4.js","./Ouh6Dj2I2.js","./Dg_1c8FK2.js","./DTkg6Mnx.js","./DYP3EJMY.js","./bG-fsHMS.js","./DeO5NWhN.js","./DgZn9uJn.js","./CbGRcr-D.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","./-TjUTcZv2.js","./CG84LPq-.js","./2PQNgpBd.js","./DsanjglN.js","./BmWTAsFW.js","./B5XQZRTz.js","./CVwAhlPZ.js","./BVC3q6GM.js","./B8PRMiR2.js","./BDDiPmhF.js","./BYJC6_MM.js","./Cx_-1PHK2.js","./B_DA9RKE2.js","./DOPTvi6T.js","./CvaH7m0y.js","./O2P-f9sv.js","./BQ9wXJVQ2.js","./OnYyYdSr2.js","./ImGf_A8f.js","./Dn7LRnjg2.js","./C8ICldoB2.js","./BlapV1mo.js","./DOhdLuUP.js","./C5cNeu21.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{t as i}from"./DTkg6Mnx.js";var a=e(r(),1);t();function o(e){a.isMainThread||({}.CLEO_DIR=(0,a.join)(e,`.cleo`))}async function s(e){switch(o(e.projectRoot),e.kind){case`observe`:return c(e);case`decision`:return l(e);case`learning`:return u(e);case`plasticity_event`:return d(e);case`weight_update`:return f(e);case`dialectic`:return p(e);default:throw Error(`Unknown BrainWriteOp kind: ${JSON.stringify(e)}`)}}async function c(e){let{observeBrain:t}=await n(async()=>{let{observeBrain:e}=await import(`./CmQc_KsG2.js`);return{observeBrain: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,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]),import.meta.url);return{kind:`observe`,result:await t(e.projectRoot,{...e.params,_skipQueue:!0})}}async function l(e){let{getBrainAccessor:t}=await n(async()=>{let{getBrainAccessor:e}=await import(`./C8ICldoB2.js`);return{getBrainAccessor:e}},__vite__mapDeps([44,43,27,11,8,2,3,6,7,9,10,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url);return{kind:`decision`,id:(await(await t(e.projectRoot)).addDecision(e.row)).id}}async function u(e){let{getBrainAccessor:t}=await n(async()=>{let{getBrainAccessor:e}=await import(`./C8ICldoB2.js`);return{getBrainAccessor:e}},__vite__mapDeps([44,43,27,11,8,2,3,6,7,9,10,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url);return{kind:`learning`,id:(await(await t(e.projectRoot)).addLearning(e.row)).id}}async function d(e){let{getBrainDb:t,getBrainNativeDb:r}=await n(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__vite__mapDeps([45,8,2,3,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url);await t(e.projectRoot);let i=r();if(!i)throw Error(`brain native DB unavailable for plasticity_event op`);let a=i.prepare(`INSERT INTO brain_plasticity_events
       (source_node, target_node, delta_w, kind, timestamp,
        session_id, retrieval_log_id, weight_before, weight_after, delta_t_ms)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(e.sourceNode,e.targetNode,e.deltaW,e.eventKind,e.timestamp,e.sessionId,e.retrievalLogId,e.weightBefore,e.weightAfter,e.deltaTms);return{kind:`plasticity_event`,lastInsertRowid:typeof a.lastInsertRowid==`bigint`?Number(a.lastInsertRowid):typeof a.lastInsertRowid==`number`?a.lastInsertRowid:null}}async function f(e){let{getBrainDb:t,getBrainNativeDb:r}=await n(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__vite__mapDeps([45,8,2,3,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url);await t(e.projectRoot);let i=r();if(!i)throw Error(`brain native DB unavailable for weight_update op`);try{i.prepare(`SELECT 1 FROM brain_weight_history LIMIT 1`).get()}catch{return{kind:`weight_update`,ok:!0}}return i.prepare(`INSERT INTO brain_weight_history
       (edge_from_id, edge_to_id, edge_type, weight_before, weight_after,
        delta_weight, event_kind, source_plasticity_event_id, retrieval_log_id,
        reward_signal, changed_at)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(e.edgeFromId,e.edgeToId,e.edgeType,e.weightBefore,e.weightAfter,e.deltaWeight,e.eventKind,e.sourcePlasticityEventId,e.retrievalLogId,e.rewardSignal,e.changedAt),{kind:`weight_update`,ok:!0}}async function p(e){let t=i(`brain-writer`),r=`dialectic:${e.sessionId}`;for(let i of e.insights.peerInsights)try{let{observeBrain:t}=await n(async()=>{let{observeBrain:e}=await import(`./CmQc_KsG2.js`);return{observeBrain: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,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]),import.meta.url);await t(e.projectRoot,{text:`[${i.key}] ${i.value}`,title:i.key,sourceSessionId:e.sessionId,sourceType:`agent`,agent:e.activePeerId,sourceConfidence:i.confidence>=.8?`task-outcome`:`agent`,_skipQueue:!0})}catch(e){t.warn({err:e,sourceTag:r,key:i.key},`dialectic peer insight write failed`)}if(e.insights.sessionNarrativeDelta)try{let{appendNarrativeDelta:t}=await n(async()=>{let{appendNarrativeDelta:e}=await import(`./DOhdLuUP.js`);return{appendNarrativeDelta:e}},__vite__mapDeps([46,47,4,3,2,8,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url);await t(e.sessionId,e.insights.sessionNarrativeDelta,e.projectRoot)}catch(e){t.warn({err:e,sourceTag:r},`dialectic narrative delta write failed`)}return{kind:`dialectic`,ok:!0}}export{s as handleWriteOp};