function summarizeToolArgs(e,t=80){if(e==null)return``;if(typeof e!=`object`)return truncate(formatScalar(e),t);if(Array.isArray(e))return truncate(`[${e.length}]`,t);let n=Object.entries(e);if(n.length===0)return``;let r=[];for(let[e,t]of n)r.push(`${e}=${formatInlineValue(t)}`);return truncate(r.join(`  `),t)}function summarizeToolResult(e,t=80){if(e==null)return``;if(typeof e==`string`)return truncate((e.split(`
`).find(e=>e.trim().length>0)??``).trim(),t);if(typeof e!=`object`)return truncate(formatScalar(e),t);if(Array.isArray(e))return truncate(`${e.length} ${e.length===1?`item`:`items`}`,t);let n=e;for(let e of[`result`,`text`,`message`,`summary`,`value`,`output`]){let r=n[e];if(r!==void 0&&typeof r!=`object`)return truncate(`${formatScalar(r)}`,t)}let r=Object.keys(n);if(r.length===0)return`{}`;let i=r.slice(0,3).map(e=>`${e}=${formatInlineValue(n[e])}`).join(`  `);return truncate(r.length>3?`${i}  …`:i,t)}function formatValuePretty(e){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)??String(e)}catch{return String(e)}}function formatInlineValue(e){return e===void 0?`undefined`:e===null?`null`:typeof e==`string`?`"${truncate(e,32)}"`:typeof e==`object`?Array.isArray(e)?`[${e.length}]`:`{…}`:formatScalar(e)}function formatScalar(e){return typeof e==`string`?e:String(e)}function truncate(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`}export{formatValuePretty,summarizeToolArgs,summarizeToolResult,truncate};