import{AN as zj,At as m,GP as Hj,Iz as I,PA as Y,PF as P,QA as O,QF as s,RA as Z,SA as $,TA as _,Tk as A,UA as y,Uk as W,Vk as u,WA as c,cL as B,dL as o,dM as C,iL as k,kM as wj,lx as f,mN as R,mx as n,ow as U,qw as a,sw as X,tw as r,uL as e,vw as b,wL as d,ww as x,xL as t,zt as N}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import"./cli-0.5.4-mn22gk7g.mjs";import"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import{X3 as D,Y3 as g}from"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import"./cli-0.5.4-w8ttefr5.mjs";import"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{B6 as h,J6 as p}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import"./cli-0.5.4-e822fzaq.mjs";import"./cli-0.5.4-09dvrzcr.mjs";import"./cli-0.5.4-end8wj9r.mjs";import"./cli-0.5.4-4x206j04.mjs";import"./cli-0.5.4-yd3rd9qt.mjs";import{Ega as v,Nga as E}from"./cli-0.5.4-sgcaw17t.mjs";import{ima as i,uja as T}from"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import{Zma as M}from"./cli-0.5.4-aacw1src.mjs";async function jj(q,j,H,w){j.onCompactProgress?.({type:"hooks_start",hookType:"pre_compact"}),j.setSDKStatus?.("compacting");try{let[z,J]=await Promise.all([I({trigger:"manual",customInstructions:H||null},j.abortController.signal),l(j,q)]),Q=_(H,z.newCustomInstructions);j.setStreamMode?.("requesting"),j.setResponseLength?.(()=>0),j.onCompactProgress?.({type:"compact_start"});let K=await w.reactiveCompactOnPromptTooLong(q,J,{customInstructions:Q,trigger:"manual"});if(!K.ok)switch(K.reason){case"too_few_groups":throw Error(Y);case"aborted":throw Error(O);case"exhausted":case"error":case"media_unstrippable":throw Error(Z)}k(void 0);let F=$(K.result);B(void 0,F,j.contentReplacementState),X(),W.cache.clear?.();let V=[z.userDisplayMessage,K.result.userDisplayMessage].filter(Boolean).join(`
`)||void 0;return{type:"compact",compactionResult:{...K.result,userDisplayMessage:V},displayText:L(j,V)}}finally{j.setStreamMode?.("requesting"),j.setResponseLength?.(()=>0),j.onCompactProgress?.({type:"compact_end"}),j.setSDKStatus?.(null)}}function L(q,j){let H=f("tip"),w=N("app:toggleTranscript","Global","ctrl+o"),z=[...q.options.verbose?[]:[`(${w} to see full summary)`],...j?[j]:[],...H?[H]:[]];return D.dim("Compacted "+z.join(`
`))}async function l(q,j){let H=q.getAppState(),w=await C(q.options.tools,q.options.mainLoopModel,Array.from(H.toolPermissionContext.additionalWorkingDirectories.keys()),q.options.mcpClients),z=P({mainThreadAgentDefinition:void 0,toolUseContext:q,customSystemPrompt:q.options.customSystemPrompt,defaultSystemPrompt:w,appendSystemPrompt:q.options.appendSystemPrompt}),[J,Q]=await Promise.all([W(),A()]);return{systemPrompt:z,userContext:J,systemContext:Q,toolUseContext:q,forkContextMessages:j}}var G=null,Aj=async(q,j)=>{let{abortController:H}=j,{messages:w}=j;if(w=R(w),w.length===0)throw Error("No messages to compact");let z=q.trim();try{if(!z){let V=await d(w,j.agentId);if(V){W.cache.clear?.();let S=$(V);return B(void 0,S,j.contentReplacementState),U(j.options.querySource??"compact",j.agentId),T(),X(),{type:"compact",compactionResult:V,displayText:L(j)}}}if(G?.isReactiveOnlyMode())return await jj(w,j,z,G);let Q=(await b(w,j)).messages,K=await y(Q,j,await l(j,Q),!1,z,!1);k(void 0),X(),W.cache.clear?.();let F=$(K);return B(void 0,F,j.contentReplacementState),{type:"compact",compactionResult:K,displayText:L(j,K.userDisplayMessage)}}catch(J){if(H.signal.aborted)throw Error("Compaction canceled.");else if(v(J,Y))throw Error(Y);else if(v(J,Z))throw Error(Z);else throw h(J),Error(`Error during compaction: ${J}`)}};var qj=M(()=>{g();i();wj();u();m();a();c();r();x();o();t();e();E();Hj();p();zj();n();s()});qj();export{Aj as call};
