(trace: AgentStep[])
| 6 | * - run_terminal_command/code_search: Truncate stdout to 500 chars |
| 7 | */ |
| 8 | export function truncateTrace(trace: AgentStep[]): AgentStep[] { |
| 9 | return trace.map((step) => { |
| 10 | if (step.type === 'tool_result') { |
| 11 | const output = Array.isArray(step.output) ? step.output : [step.output] |
| 12 | |
| 13 | if (step.toolName === 'read_files') { |
| 14 | const truncatedOutput = output.map((item: any) => { |
| 15 | if (item.type === 'json' && Array.isArray(item.value)) { |
| 16 | return { |
| 17 | ...item, |
| 18 | value: item.value.map((file: any) => |
| 19 | file.path && file.content |
| 20 | ? { |
| 21 | path: file.path, |
| 22 | content: '[TRUNCATED - file was read]', |
| 23 | referencedBy: file.referencedBy, |
| 24 | } |
| 25 | : file, |
| 26 | ), |
| 27 | } |
| 28 | } |
| 29 | return item |
| 30 | }) |
| 31 | return { ...step, output: truncatedOutput } |
| 32 | } |
| 33 | |
| 34 | if ( |
| 35 | step.toolName === 'run_terminal_command' || |
| 36 | step.toolName === 'code_search' |
| 37 | ) { |
| 38 | const truncatedOutput = output.map((item: any) => { |
| 39 | if (item.type === 'json' && item.value?.stdout) { |
| 40 | return { |
| 41 | ...item, |
| 42 | value: { |
| 43 | ...item.value, |
| 44 | stdout: |
| 45 | item.value.stdout.length > 500 |
| 46 | ? item.value.stdout.slice(0, 500) + '... [TRUNCATED]' |
| 47 | : item.value.stdout, |
| 48 | }, |
| 49 | } |
| 50 | } |
| 51 | return item |
| 52 | }) |
| 53 | return { ...step, output: truncatedOutput } |
| 54 | } |
| 55 | } |
| 56 | return step |
| 57 | }) |
| 58 | } |
no outgoing calls
no test coverage detected