@@ -21,7 +21,7 @@ export async function useVSCLMT(
2121 arguments : removeClosingTag ( "arguments" , toolArgs ) ,
2222 } )
2323
24- await cline . ask ( "tool" , partialMessage , toolUse . partial ) . catch ( ( ) => { } )
24+ await cline . ask ( "tool" , partialMessage , toolUse . partial ) . catch ( ( ) => { } )
2525 return
2626 }
2727
@@ -85,17 +85,59 @@ export async function useVSCLMT(
8585 const result = await vsclmtService . invokeTool ( tool_name , parsedArgs )
8686
8787 // Format the result for display
88+ const extractText = ( obj : unknown ) : string => {
89+ if ( typeof obj === "string" ) return obj
90+ if ( ! obj || typeof obj !== "object" ) return ""
91+ const asRecord = obj as Record < string , unknown >
92+ if ( "text" in asRecord && typeof asRecord . text === "string" ) return asRecord . text
93+ if ( "value" in asRecord && typeof asRecord . value === "string" ) return asRecord . value
94+ // Special handling for PromptTsx node structure
95+ if ( "node" in asRecord && asRecord . node && typeof asRecord . node === "object" ) {
96+ const node = asRecord . node as Record < string , unknown >
97+ if ( "children" in node && Array . isArray ( node . children ) ) {
98+ return node . children . map ( ( child : unknown ) => extractText ( child ) ) . join ( "" )
99+ }
100+ }
101+ if ( Array . isArray ( obj ) ) return obj . map ( ( item ) => extractText ( item ) ) . join ( "" )
102+ return Object . values ( asRecord )
103+ . map ( ( v ) => extractText ( v ) )
104+ . join ( "" )
105+ }
106+
88107 const resultText = result . content
89- . map ( part =>
90- typeof part === 'object' && part !== null && 'value' in part && typeof part . value === 'string' ?
91- ( part as { value : string } ) . value :
92- String ( part )
93- )
94- . join ( '\n\n' )
108+ . map ( ( part ) : string => {
109+ if ( typeof part === "object" && part !== null ) {
110+ // Handle MarkdownString specifically
111+ if ( part instanceof vscode . MarkdownString ) {
112+ return part . value
113+ }
114+ // Handle objects with value property
115+ if ( "value" in part ) {
116+ const value = part . value
117+ if ( value instanceof vscode . MarkdownString ) {
118+ return value . value
119+ }
120+ if ( typeof value === "string" ) {
121+ return value
122+ }
123+ // Handle LanguageModelPromptTsxPart or complex nested structures
124+ if ( value && typeof value === "object" ) {
125+ return extractText ( value )
126+ }
127+ }
128+ return JSON . stringify ( part , null , 2 )
129+ }
130+ return String ( part )
131+ } )
132+ . join ( "\n\n" )
95133
96134 pushToolResult ( resultText )
97135 } catch ( error ) {
98136 await handleError ( "VS Code LM tool invocation" , error )
99- pushToolResult ( formatResponse . toolError ( `Failed to invoke VS Code LM tool '${ tool_name } ': ${ error . stack || error . message } ` ) )
137+ pushToolResult (
138+ formatResponse . toolError (
139+ `Failed to invoke VS Code LM tool '${ tool_name } ': ${ error . stack || error . message } ` ,
140+ ) ,
141+ )
100142 }
101143}
0 commit comments