mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
refactor(core): Centralize tool response formatting (#743)
This commit is contained in:
@@ -138,12 +138,7 @@ describe('DiscoveredMCPTool', () => {
|
||||
const stringifiedResponseContent = JSON.stringify(
|
||||
mockToolSuccessResultObject,
|
||||
);
|
||||
// getStringifiedResultForDisplay joins text parts, then wraps the array of processed parts in JSON
|
||||
const expectedDisplayOutput =
|
||||
'```json\n' +
|
||||
JSON.stringify([stringifiedResponseContent], null, 2) +
|
||||
'\n```';
|
||||
expect(toolResult.returnDisplay).toBe(expectedDisplayOutput);
|
||||
expect(toolResult.returnDisplay).toBe(stringifiedResponseContent);
|
||||
});
|
||||
|
||||
it('should handle empty result from getStringifiedResultForDisplay', async () => {
|
||||
|
||||
@@ -149,6 +149,13 @@ function getStringifiedResultForDisplay(result: Part[]) {
|
||||
return part; // Fallback for unexpected structure or non-FunctionResponsePart
|
||||
};
|
||||
|
||||
const processedResults = result.map(processFunctionResponse);
|
||||
const processedResults =
|
||||
result.length === 1
|
||||
? processFunctionResponse(result[0])
|
||||
: result.map(processFunctionResponse);
|
||||
if (typeof processedResults === 'string') {
|
||||
return processedResults;
|
||||
}
|
||||
|
||||
return '```json\n' + JSON.stringify(processedResults, null, 2) + '\n```';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user