@@ -33,35 +33,67 @@ export function getToolDisplayInfo(toolName: string): {
3333 name : string
3434 type : string
3535} {
36- const toolNameMap : Record < string , string > = {
37- write_file : 'File Writer' ,
38- str_replace : 'File Editor' ,
39- read_files : 'File Reader' ,
40- code_search : 'Code Search' ,
41- run_terminal_command : 'Terminal' ,
42- browser_logs : 'Browser' ,
43- run_file_change_hooks : 'File Hooks' ,
44- web_search : 'Web Search' ,
45- read_docs : 'Doc Reader' ,
46- spawn_agents : 'Agent Spawner' ,
36+ const capitalizeWords = ( str : string ) => {
37+ return str . replace ( / _ / g, ' ' ) . replace ( / \b \w / g, ( l ) => l . toUpperCase ( ) )
4738 }
4839
4940 return {
50- name :
51- toolNameMap [ toolName ] ||
52- toolName . replace ( / _ / g, ' ' ) . replace ( / \b \w / g, ( l ) => l . toUpperCase ( ) ) ,
41+ name : capitalizeWords ( toolName ) ,
5342 type : 'tool' ,
5443 }
5544}
5645
46+ function toYaml ( obj : any , indent = 0 ) : string {
47+ const spaces = ' ' . repeat ( indent )
48+
49+ if ( obj === null || obj === undefined ) {
50+ return 'null'
51+ }
52+
53+ if ( typeof obj === 'string' ) {
54+ if ( obj . includes ( '\n' ) ) {
55+ const lines = obj . split ( '\n' )
56+ return '|\n' + lines . map ( line => ' ' . repeat ( indent + 1 ) + line ) . join ( '\n' )
57+ }
58+ return obj . includes ( ':' ) || obj . includes ( '#' ) ? `"${ obj } "` : obj
59+ }
60+
61+ if ( typeof obj === 'number' || typeof obj === 'boolean' ) {
62+ return String ( obj )
63+ }
64+
65+ if ( Array . isArray ( obj ) ) {
66+ if ( obj . length === 0 ) return '[]'
67+ return '\n' + obj . map ( item => spaces + '- ' + toYaml ( item , indent + 1 ) . trimStart ( ) ) . join ( '\n' )
68+ }
69+
70+ if ( typeof obj === 'object' ) {
71+ const entries = Object . entries ( obj )
72+ if ( entries . length === 0 ) return '{}'
73+
74+ return entries . map ( ( [ key , value ] ) => {
75+ const yamlValue = toYaml ( value , indent + 1 )
76+ if ( typeof value === 'object' && value !== null && ! Array . isArray ( value ) && Object . keys ( value ) . length > 0 ) {
77+ return `${ spaces } ${ key } :\n${ yamlValue } `
78+ }
79+ if ( typeof value === 'string' && value . includes ( '\n' ) ) {
80+ return `${ spaces } ${ key } : ${ yamlValue } `
81+ }
82+ return `${ spaces } ${ key } : ${ yamlValue } `
83+ } ) . join ( '\n' )
84+ }
85+
86+ return String ( obj )
87+ }
88+
5789export function formatToolOutput ( output : unknown ) : string {
5890 if ( ! output ) return ''
5991
6092 if ( Array . isArray ( output ) ) {
6193 return output
6294 . map ( ( item ) => {
6395 if ( item . type === 'json' ) {
64- return JSON . stringify ( item . value , null , 2 )
96+ return toYaml ( item . value )
6597 }
6698 if ( item . type === 'text' ) {
6799 return item . text || ''
@@ -75,5 +107,5 @@ export function formatToolOutput(output: unknown): string {
75107 return output
76108 }
77109
78- return JSON . stringify ( output , null , 2 )
110+ return toYaml ( output )
79111}
0 commit comments