import{r as e}from"./ToolConversationPersistence-DHdCZcA8.js";function t(e){try{e.current&&window.clearTimeout(e.current)}catch{}e.current=null}function n(e,t,n=16e3){let r=String(e||``).trim(),i=String(t||``).trim();if(!i)return r;if(!r)return i.length<=n?i:`…\n${i.slice(-n)}`;if(r===i||r.includes(i))return r;if(i.includes(r))return i.length<=n?i:`…\n${i.slice(-n)}`;let a=`${r}\n\n${i}`;return a.length<=n?a:`…\n${a.slice(-n)}`}function r(e,t){let n=String(t||``).trim();if(!n)return e;let r=e[e.length-1];return r?.tool===n&&r?.status===`running`?e:[...e,{tool:n,status:`running`}]}function i(e,t){let n=String(t||``).trim();if(!n)return e;let r=!1,i=e.map(e=>!r&&e.tool===n&&e.status===`running`?(r=!0,{...e,status:`done`}):e);return r?i:e}function a({timerRef:e,rawRef:t,flush:n,delayMs:r=80}){e.current||=window.setTimeout(()=>{e.current=null,n(String(t.current||``))},r)}function o({timerRef:e,rawRef:n,flush:r}){t(e),r(String(n.current||``))}function s({setStreamText:e,setStreamThinking:n,setStreamStage:r,setStreamActor:i,streamTextRawRef:a,streamThinkingRawRef:o,streamTextFlushTimerRef:s,streamThinkingFlushTimerRef:c}){e(``),n(``),r(``),i(``),a.current=``,o.current=``,t(s),t(c)}function c({tool:t,runSeqRef:n,abortRef:r,setBusy:i,onCancelled:a,snapshotPatch:o}){n.current+=1;try{r.current?.abort()}catch{}try{i(!1)}catch{}try{a?.()}catch{}e(t,{...o||{},runState:`cancelled`})}function l({tool:t,runSeq:n,runSeqRef:r,stage:i,agentLabel:s,skillLabel:c,setStreamStage:l,setStreamActor:u,setStreamText:d,setStreamThinking:f,buildPlainStreamPreview:p,sanitizeThinking:m,streamTextRawRef:h,streamThinkingRawRef:g,streamTextFlushTimerRef:_,streamThinkingFlushTimerRef:v,hideModelMeta:y}){let b=``,x=n=>{let r=p(n);d(r||``),e(t,{runState:`running`,streamText:r||``})},S=n=>{let r=m(n);f(r||`思考中…`),e(t,{runState:`running`,streamThinking:r||`思考中…`})};return{getRequestId:()=>b,onMeta:n=>{if(n?.type!==`start`)return;b=String(n?.requestId||``).trim();let r=String(n?.provider||``).trim(),a=String(n?.model||``).trim(),o=[!y&&(r||a)?`Model: ${[r,a].filter(Boolean).join(`/`)}`:``,s,c].filter(Boolean).join(` · `);l(i),u(o),e(t,{runState:`running`,streamStage:i,streamActor:o})},onText:e=>{n===r.current&&(h.current=String(e||``),a({timerRef:_,rawRef:h,flush:x}))},onThinking:e=>{n===r.current&&(g.current=String(e||``),a({timerRef:v,rawRef:g,flush:S}))},flushPending:()=>{o({timerRef:_,rawRef:h,flush:x}),o({timerRef:v,rawRef:g,flush:S})}}}export{r as a,n as i,l as n,s as o,i as r,c as t};