import{a as e,n as t}from"./jsx-runtime-CutOxEx1.js";import{r as n}from"./taskStore-B6nkxJKo.js";import{s as r}from"./ToolSidebarNav-Py6lZOex.js";import{n as i,r as a}from"./conversationMemoryStore-C3CPcvQ5.js";var o=e(t(),1),s=e=>i(e),c=(e,t)=>{a(e,t);try{let a=String(t?.runState||``).trim();if(!a)return;let o=a===`partial`?`running`:a;if(o===`running`||o===`done`||o===`failed`||o===`cancelled`){let t=i(e)||{},a=r(e),s=t?.billing,c=typeof s?.pointsCharged==`number`?s.pointsCharged:typeof t?.pointsCharged==`number`?t.pointsCharged:null;n({tool:e,label:a.label,path:a.path,status:o,title:String(t?.fileName||t?.focus||t?.jobTitle||t?.okMsg||a.label).slice(0,40),ts:t?._ts,pointsCharged:c,error:o===`failed`?String(t?.err||t?.msg||`任务失败`):void 0})}}catch{}};function l({tool:e,onRestore:t,syncEntries:n,onRunState:r,shouldStop:i=e=>e!==`running`&&e!==`partial`,intervalMs:a=600}){let c=(0,o.useRef)(null),l=(0,o.useRef)(t),u=(0,o.useRef)(n),d=(0,o.useRef)(r),f=(0,o.useRef)(i);l.current=t,u.current=n,d.current=r,f.current=i,(0,o.useEffect)(()=>{let t=s(e);if(t&&typeof t==`object`){l.current?.(t);let e=String(t.runState||``).trim(),n=Number(t?._ts||0),r=(e===`running`||e===`partial`)&&Number.isFinite(n)&&n>0&&Date.now()-n>45e3;d.current?.(r?`idle`:e,t,`restore`)}let n=new Map;return c.current=window.setInterval(()=>{let t=s(e);if(!t||typeof t!=`object`)return;for(let e of u.current){let r=e.signature(t);n.get(e.key)!==r&&(n.set(e.key,r),e.apply(t))}let r=String(t.runState||``).trim();if(d.current?.(r,t,`tick`),f.current?.(r)){try{c.current&&window.clearInterval(c.current)}catch{}c.current=null}},a),()=>{try{c.current&&window.clearInterval(c.current)}catch{}c.current=null}},[a,e])}export{l as n,c as r,s as t};