// @bun
import{Ij as k}from"./chunk-e39gegdb.js";import{Jj as m,Lj as G}from"./chunk-gmt7f7kk.js";import{Sk as g}from"./chunk-qysx0asq.js";import{Sn as R}from"./chunk-2szzt9yn.js";import O from"os";import d from"path";function f(t){if(!t||typeof t!=="object"||Array.isArray(t))return{};return{...t}}function w(t){return{input:Object.assign(Object.create(null),t.input),metadata:Object.assign(Object.create(null),t.meta),frame:t}}function D(t){return{input:Object.assign(Object.create(null),t.input),metadata:Object.assign(Object.create(null),t.meta),patterns:t.patterns}}function l(t){return typeof t==="string"?t:""}function P(t){if(typeof t!=="number"||!Number.isFinite(t))return;return t}function p(t){if(!Array.isArray(t))return[];return t}function S(t,o=[]){let e=Object.entries(t).filter(([n,r])=>{if(o.includes(n))return!1;return typeof r==="string"||typeof r==="number"||typeof r==="boolean"});if(e.length===0)return"";return`[${e.map(([n,r])=>`${n}=${String(r)}`).join(", ")}]`}function T(t){let o=f(t.time),e=P(o.start),n=P(o.end);if(e===void 0||n===void 0||n<=e)return"";return G(n-e)}function $(t){let o=j(t);if(o)return`\u2716 ${t.name} failed: ${o}`;return`\u2716 ${t.name} failed`}function j(t){if(t.error)return t.error;let o=l(t.state.error).trim();if(o)return o;return t.raw.trim()}function W(t){let o=S(t.input);if(!o)return`\u2699 ${t.name}`;return`\u2699 ${t.name} ${o}`}function F(t){if(t.status==="error")return $(t);if(t.status&&t.status!=="completed")return t.raw.trim();let o=T(t.state);if(!o)return`${t.name} completed`;return`${t.name} completed \xB7 ${o}`}function s(t,o={}){if(!t)return"";let e=process.cwd(),n=O.homedir(),r=d.isAbsolute(t)?t:d.resolve(e,t),i=d.relative(e,r);if(!i)return".";if(!i.startsWith(".."))return i.replaceAll("\\","/");if(o.home&&n&&(r===n||r.startsWith(n+d.sep)))return r.replace(n,"~").replaceAll("\\","/");return r.replaceAll("\\","/")}function L(t){let o=l(t.state.title)||(Object.keys(t.input).length>0?JSON.stringify(t.input):"Unknown");return{icon:"\u2699",title:`${t.name} ${o}`}}function B(t,o){return`${t} ${o}${t===1?"":"es"}`}function Q(t){let o=t.input.path??"",e=`Glob "${t.input.pattern??""}"`,n=o?`in ${s(o)}`:"",r=t.metadata.count,i=r===void 0?n:`${n}${n?" \xB7 ":""}${B(r,"match")}`;return{icon:"\u2731",title:e,...i&&{description:i}}}function C(t){let o=t.input.path??"",e=`Grep "${t.input.pattern??""}"`,n=o?`in ${s(o)}`:"",r=t.metadata.matches,i=r===void 0?n:`${n}${n?" \xB7 ":""}${B(r,"match")}`;return{icon:"\u2731",title:e,...i&&{description:i}}}function N(t){let o=l(f(t.input).path);return{icon:"\u2192",title:o?`List ${s(o)}`:"List"}}function M(t){let o=s(t.input.filePath),e=S(t.frame.input,["filePath"])||void 0;return{icon:"\u2192",title:`Read ${o}`,...e&&{description:e}}}function U(t){return{icon:"\u2190",title:`Write ${s(t.input.filePath)}`,mode:"block",body:t.frame.status==="completed"?l(t.frame.state.output):void 0}}function V(t){let o=t.input.url??"";return{icon:"%",title:o?`WebFetch ${o}`:"WebFetch"}}function K(t){return{icon:"\u2190",title:`Edit ${s(t.input.filePath)}`,mode:"block",body:t.metadata.diff}}function J(t){let o=g(t.metadata.provider);return{icon:"\u25C8",title:t.input.query?`${o} "${t.input.query}"`:o}}function X(t){let o=m(t.input.subagent_type||"unknown"),e=t.input.description;return{icon:t.frame.status==="error"?"\u2717":t.frame.status==="running"?"\u2022":"\u2713",title:e||`${o} Task`,description:e?`${o} Agent`:void 0}}function z(t){return{icon:"#",title:"Todos",mode:"block",body:p(t.frame.input.todos).flatMap((o)=>{let e=typeof o?.content==="string"?o.content:"";if(!e)return[];return[`${o.status==="completed"?"[\u2713]":o.status==="in_progress"?"[\u2022]":"[ ]"} ${e}`]}).join(`
`)}}function H(t){return{icon:"\u2192",title:`Skill "${t.input.name??""}"`}}function Y(t){let o=t.metadata.files?.length??0;if(o===0)return{icon:"%",title:"Patch"};return{icon:"%",title:`Patch ${o} file${o===1?"":"s"}`}}function Z(t){let o=p(t.frame.input.questions).length;return{icon:"\u2192",title:`Asked ${o} question${o===1?"":"s"}`}}function tt(t){return{icon:"\u2717",title:l(t.frame.state.title)||"Invalid Tool",mode:"block",body:t.frame.status==="completed"?l(t.frame.state.output):void 0}}function ot(t){let o=p(f(t.input).tool_calls).length;return{icon:"#",title:l(t.frame.state.title)||(o>0?`Batch ${o} tool${o===1?"":"s"}`:"Batch"),mode:"block",body:t.frame.status==="completed"?l(t.frame.state.output):void 0}}function I(t,o={}){let e=t.operation||"request",n=t.filePath?s(t.filePath,o):"",r=typeof t.line==="number"?t.line:void 0,i=typeof t.character==="number"?t.character:void 0,a=r!==void 0&&i!==void 0?`:${r}:${i}`:"";if(!n)return`LSP ${e}`;return`LSP ${e} ${n}${a}`}function et(t){return{icon:"\u2192",title:l(t.frame.state.title)||I(t.input)}}function nt(t){return{icon:"\u2192",title:l(t.frame.state.title)||"Switching to build agent",mode:"block",body:t.frame.status==="completed"?l(t.frame.state.output):void 0}}function rt(t){let{relativePath:o,filePath:e}=t;if(t.type==="add")return`# Created ${o||s(e)}`;if(t.type==="delete")return`# Deleted ${o||s(e)}`;if(t.type==="move")return`# Moved ${s(e)} -> ${o||s(t.movePath)}`;return`# Patched ${o||s(e)}`}function it(t){let o=t.input.filePath||"",e=t.input.content||"";if(!o&&!e)return;return{kind:"code",title:`# Wrote ${s(o)}`,content:e,file:o}}function st(t){let o=t.input.filePath||"",e=t.metadata.diff||"";if(!o||!e.trim())return;return{kind:"diff",items:[{title:`# Edited ${s(o)}`,diff:e,file:o}]}}function lt(t){let o=p(t.frame.meta.files);if(o.length===0)return;let e=o.flatMap((n)=>{if(!n||typeof n!=="object")return[];let r=typeof n.patch==="string"?n.patch:"";if(!r.trim())return[];let i=n.movePath||n.filePath||n.relativePath;return[{title:rt(n),diff:r,file:i,deletions:typeof n.deletions==="number"?n.deletions:0}]});if(e.length===0)return;return{kind:"diff",items:e}}function at(t){let o=m(t.input.subagent_type||"general"),e=t.input.description,n=l(t.frame.state.title),r=[e||n].filter((i)=>Boolean(i));return{kind:"task",title:`# ${o} Task`,rows:r,tail:""}}function ut(t){return{kind:"todo",items:p(t.frame.input.todos).flatMap((e)=>{let n=typeof e?.content==="string"?e.content:"";if(!n)return[];return[{status:typeof e.status==="string"?e.status:"",content:n}]}),tail:""}}function ft(t){let o=p(t.frame.meta.answers);return{kind:"question",items:p(t.frame.input.questions).map((n,r)=>{let i=p(o[r]).filter((a)=>typeof a==="string");return{question:n.question||`Question ${r+1}`,answer:i.length>0?i.join(", "):"(no answer)"}}),tail:""}}function pt(t){let o=t.input.command??"",e=t.input.description||"Shell",n=t.input.workdir??"",r=n&&n!=="."?s(n):"";if(o&&e==="Shell"&&!r)return`$ ${o}`;let i=r&&!e.includes(r)?`${e} in ${r}`:e;if(!o)return`# ${i}`;return`# ${i}
$ ${o}`}function ct(t){let o=k(t.frame.raw),e=(t.input.command??"").trim(),n=(x)=>{let v=x.replace(/^\n+/,"").replace(/\n+$/,"");return v?`
${v}`:""};if(!e)return o.replace(/\n+$/,"");let r=(t.input.workdir??"").trim(),i=r?s(r):"",a=o.split(`
`),u=(a[0]||"").trim(),y=(a[1]||"").trim();if(i&&(u===i||u===r)&&y===e)return n(a.slice(2).join(`
`));if(u===e||u===`$ ${e}`)return n(a.slice(1).join(`
`));if(i&&(u===`${i} ${e}`||u===`${r} ${e}`))return n(a.slice(1).join(`
`));return n(o)}function dt(t){let o=t.metadata.exit??P(t.frame.meta.exitCode)??P(t.frame.meta.exit_code),e=T(t.frame.state);if(o===void 0){if(!e)return"bash completed";return`bash completed \xB7 ${e}`}return`bash completed (exit ${o})${e?` \xB7 ${e}`:""}`}function mt(t){let o=s(t.input.filePath),e=S(t.frame.input,["filePath"]),n=e?` ${e}`:"";return`\u2192 Read ${o}${n}`.trim()}function Tt(t){return""}function ht(t){return""}function yt(t){return""}function E(t){let{type:o,relativePath:e,filePath:n}=t;if(o==="add")return`+ Created ${e||s(n)}`;if(o==="delete")return`- Deleted ${e||s(n)}`;if(o==="move")return`\u2192 Moved ${s(n)} \u2192 ${e||s(t.movePath)}`;return`~ Patched ${e||s(n)}`}function Pt(t){if(t.frame.status==="error")return $(t.frame);let o=p(t.frame.meta.files);if(o.length===0){let i=T(t.frame.state);if(!i)return"patch";return`patch \xB7 ${i}`}let e=!o.some((i)=>i?.type&&i.type!=="update"),n=o.filter((i)=>e||i.type!=="update"),r=n.slice(0,6).map(E);if(n.length>6)r.push(`... and ${n.length-6} more`);if(r.length>0)return r.join(`
`);return E(o[0])}function gt(t){return""}function $t(t){if(!t.trim())return;let o=t.match(/<task_result>\s*([\s\S]*?)\s*<\/task_result>/);if(o)return o[1].trim()||void 0;return t.split(`
`).filter((n)=>!n.startsWith("task_id:")).join(`
`).trim()||void 0}function bt(t){if(t.frame.status==="error")return $(t.frame);let o=m(t.input.subagent_type||"general"),e=t.input.description||l(t.frame.state.title);if(!e)return`# ${o} Task`;return`# ${o} Task
${e}`}function kt(t){return""}function wt(t){let o=p(t.input.todos),e=T(t.frame.state);if(o.length===0){if(!e)return"0 todos";return`0 todos \xB7 ${e}`}let n=o.filter((u)=>u.status==="completed").length,r=o.filter((u)=>u.status==="in_progress").length,i=o.length-n-r,a=[`${o.length} total`];if(n>0)a.push(`${n} done`);if(r>0)a.push(`${r} active`);if(i>0)a.push(`${i} pending`);if(e)a.push(e);return a.join(" \xB7 ")}function St(t){return""}function It(t){let o=t.input.questions??[],e=t.metadata.answers??[],n=T(t.frame.state);if(o.length===0){if(!n)return"0 questions";return`0 questions \xB7 ${n}`}let r=[];for(let[i,a]of o.slice(0,4).entries()){let u=a.question,y=e[i]??[];r.push(`? ${u||`Question ${i+1}`}`),r.push(`  ${y.length>0?y.join(", "):"(no answer)"}`)}if(o.length>4)r.push(`... and ${o.length-4} more`);return r.join(`
`)}function vt(t){return`\u2192 ${I(t.input)}`}function Wt(t){return`\u2192 Skill "${t.input.name??""}"`}function Ft(t){let o=t.input.pattern??"",e=o?`\u2731 Glob "${o}"`:"\u2731 Glob",n=t.input.path??"";if(!n)return e;return`${e} in ${s(n)}`}function Lt(t){return j(t.frame)||$(t.frame)}function Et(t){let o=t.input.pattern??"",e=o?`\u2731 Grep "${o}"`:"\u2731 Grep",n=t.input.path??"";if(!n)return e;return`${e} in ${s(n)}`}function Rt(t){let o=l(f(t.input).path);if(!o)return"\u2192 List";return`\u2192 List ${s(o)}`}function Gt(t){let o=t.input.url??"";if(!o)return"% WebFetch";return`% WebFetch ${o}`}function jt(t){let o=g(t.metadata.provider),e=t.input.query??"";if(!e)return`\u25C8 ${o}`;return`\u25C8 ${o} "${e}"`}function Bt(t){let o=t.input,e=o.filePath||o.filepath||t.patterns[0]||"";return{icon:"\u2192",title:`Edit ${s(e,{home:!0})}`,lines:[],diff:t.metadata.diff??o.diff,file:e}}function _t(t){let o=t.input.filePath||t.patterns[0]||"";return{icon:"\u2192",title:`Read ${s(o,{home:!0})}`,lines:o?[`Path: ${s(o,{home:!0})}`]:[]}}function qt(t){let o=t.input.pattern||t.patterns[0]||"";return{icon:"\u2731",title:`Glob "${o}"`,lines:o?[`Pattern: ${o}`]:[]}}function At(t){let o=t.input.pattern||t.patterns[0]||"";return{icon:"\u2731",title:`Grep "${o}"`,lines:o?[`Pattern: ${o}`]:[]}}function xt(t){let o=l(f(t.input).path)||t.patterns[0]||"";return{icon:"\u2192",title:`List ${s(o,{home:!0})}`,lines:o?[`Path: ${s(o,{home:!0})}`]:[]}}function Ot(t){let o=t.input.description||"Shell command",e=t.input.command||"";return{icon:"#",title:o,lines:e?[`$ ${e}`]:t.patterns.map((n)=>`- ${n}`)}}function Dt(t){let o=t.input.subagent_type||"general",e=t.input.description;return{icon:"#",title:`${m(o)} Task`,lines:e?[`\u25C9 ${e}`]:[]}}function Qt(t){let o=t.input.url||"";return{icon:"%",title:`WebFetch ${o}`,lines:o?[`URL: ${o}`]:[]}}function Ct(t){let o=t.input.query||"",e=g(t.metadata.provider);return{icon:"\u25C8",title:o?`${e} "${o}"`:e,lines:o?[`Query: ${o}`]:[]}}function Nt(t){let o=t.input.filePath||"",e=typeof t.input.line==="number"?t.input.line:void 0,n=typeof t.input.character==="number"?t.input.character:void 0,r=e!==void 0&&n!==void 0?`${e}:${n}`:void 0;return{icon:"\u2192",title:I(t.input,{home:!0}),lines:[...t.input.operation?[`Operation: ${t.input.operation}`]:[],...o?[`Path: ${s(o,{home:!0})}`]:[],...r?[`Position: ${r}`]:[]]}}var _={invalid:{view:{output:!0,final:!1},run:tt,scroll:{start:()=>""}},bash:{view:{output:!0,final:!1},run:Vt,scroll:{start:pt,progress:ct,final:dt},permission:Ot},write:{view:{output:!1,final:!0,snap:"code"},run:U,snap:it,scroll:{start:Tt}},edit:{view:{output:!1,final:!0,snap:"diff"},run:K,snap:st,scroll:{start:ht},permission:Bt},apply_patch:{view:{output:!1,final:!0,snap:"diff"},run:Y,snap:lt,scroll:{start:yt,final:Pt}},batch:{view:{output:!0,final:!1},run:ot,scroll:{start:()=>""}},task:{view:{output:!1,final:!0,snap:"structured"},run:X,snap:at,scroll:{start:gt,final:bt},permission:Dt},todowrite:{view:{output:!1,final:!0,snap:"structured"},run:z,snap:ut,scroll:{start:kt,final:wt}},question:{view:{output:!1,final:!0,snap:"structured"},run:Z,snap:ft,scroll:{start:St,final:It}},read:{view:{output:!1,final:!1},run:M,scroll:{start:mt},permission:_t},glob:{view:{output:!1,final:!1},run:Q,scroll:{start:Ft,final:Lt},permission:qt},grep:{view:{output:!1,final:!1},run:C,scroll:{start:Et},permission:At},list:{view:{output:!1,final:!1},run:N,scroll:{start:Rt},permission:xt},lsp:{view:{output:!1,final:!1},run:et,scroll:{start:vt},permission:Nt},webfetch:{view:{output:!1,final:!1},run:V,scroll:{start:Gt},permission:Qt},websearch:{view:{output:!1,final:!1},run:J,scroll:{start:jt},permission:Ct},skill:{view:{output:!1,final:!1},run:H,scroll:{start:Wt}},plan_exit:{view:{output:!0,final:!1},run:nt,scroll:{start:()=>""}}};function Mt(t){return Object.prototype.hasOwnProperty.call(_,t)}function h(t){if(!t||!Mt(t))return;return _[t]}function Ut(t){let o=f(t.state);return{raw:"",name:t.tool,input:f(o.input),meta:"metadata"in t.state?f(t.state.metadata):{},state:o,status:l(o.status),error:l(o.error)}}function q(t,o){let e=f(t.part?.state);return{raw:o,name:t.tool||t.part?.tool||"tool",input:f(e.input),meta:t.part?.state&&"metadata"in t.part.state?f(t.part.state.metadata):{},state:e,status:t.toolState??l(e.status),error:(t.toolError??"").trim()}}function Vt(t){return{icon:"$",title:t.input.command||"",mode:"block",body:t.frame.status==="completed"?l(t.frame.state.output).trim():void 0}}function A(t){return h(t)?.view??{output:!0,final:!0}}function Kt(t){let o=t.toolState??t.part?.state.status;return t.kind==="tool"&&t.phase==="final"&&o==="completed"&&Boolean(A(t.tool??t.part?.tool).snap)}function ro(t){let o=Ut(t),e=h(o.name)?.run;try{if(e)return e(w(o))}catch{return L(o)}return L(o)}function b(t,o){let e=h(o.name)?.scroll?.[t];try{if(e)return e(w(o))}catch{if(t==="start")return W(o);if(t==="progress")return o.raw;return F(o)}if(t==="start")return W(o);if(t==="progress")return o.raw;return F(o)}function io(t,o,e,n){let r=h(t)?.permission;if(!r)return;try{return r(D({input:o,meta:e,patterns:n}))}catch{return}}function Jt(t,o){let e=q(t,o),n=h(e.name)?.snap;if(!n)return;try{return n(w(e))}catch{return}}function c(t){if(!t)return;return{type:"text",content:t}}function Xt(t){if(!t)return;return{type:"markdown",content:t}}function zt(t,o){let e=Jt(t,o);if(!e)return;return{type:"structured",snapshot:e}}function Ht(t,o){let e=k(o).replace(/^\n+/,"").replace(/\n+$/,"");if(!e)return;if(!t)return e;return`
${e}`}function so(t,o){if(t.shell){if(t.phase==="start")return c(`$ ${t.shell.command}`);if(t.phase==="progress")return c(Ht(t.shell.command,o)??"");return}let e=q(t,o),n=A(e.name);if(e.name==="task"){if(t.phase==="start")return;if(t.phase==="final"&&e.status==="completed"){let r=$t(l(e.state.output));if(r)return Xt(r)}}if(t.phase==="progress"&&!n.output)return;if(t.phase==="final"){if(e.status==="error")return c(b("final",e));if(!n.final)return;if(e.status&&e.status!=="completed")return c(e.raw.trim());if(Kt(t))return zt(t,o)??c(b("final",e))}return c(b(t.phase,e))}function lo(t){if(!t)return;let o=d.extname(t),e=R[o];if(["typescriptreact","javascriptreact","javascript"].includes(e))return"typescript";return e}
export{s as Rf,q as Sf,A as Tf,Kt as Uf,ro as Vf,b as Wf,io as Xf,Jt as Yf,so as Zf,lo as _f};
