UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

2 lines 1.71 kB
import{stripTerminalControls}from"./terminal-text.js";function summarizeToolArgs(t,n=80){if(t==null)return``;if(typeof t!=`object`)return truncate(formatScalar(t),n);if(Array.isArray(t))return truncate(`[${t.length}]`,n);let r=Object.entries(t);if(r.length===0)return``;let i=[];for(let[t,n]of r)i.push(`${stripTerminalControls(t)}=${formatInlineValue(n)}`);return truncate(i.join(` `),n)}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(t){if(typeof t==`string`)return stripTerminalControls(t);try{return stripTerminalControls(JSON.stringify(t,null,2)??String(t))}catch{return stripTerminalControls(String(t))}}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(t){return stripTerminalControls(typeof t==`string`?t:String(t))}function truncate(t,n){let r=stripTerminalControls(t).replace(/\s+/g,` `).trim();return r.length<=n?r:`${r.slice(0,Math.max(0,n-1)).trimEnd()}…`}export{formatValuePretty,summarizeToolArgs,summarizeToolResult,truncate};