@@ -635,6 +635,14 @@ function stringifyToolOutput(output: unknown): string {
635635 return YAML . stringify ( output === undefined ? EMPTY_HANDLER_RESPONSE_ERROR : output ) ;
636636}
637637
638+ function attachDurationMs ( output : unknown , durationMs : number ) : unknown {
639+ if ( output !== null && typeof output === 'object' && ! Array . isArray ( output ) ) {
640+ return { ...output , durationMs } ;
641+ }
642+
643+ return { result : output , durationMs } ;
644+ }
645+
638646export function prepareApiBasedTools (
639647 adminforth : IAdminForth ,
640648 hiddenResourceIds : Iterable < string > = [ ] ,
@@ -666,11 +674,13 @@ export function prepareApiBasedTools(
666674 input_schema : schema . request_schema ,
667675 agent : schema . agent ,
668676 call : async ( { adminUser, adminuser, abortSignal, inputs, userTimeZone, acceptLanguage } = { } ) => {
677+ const startedAt = Date . now ( ) ;
678+
669679 if ( isHiddenResourceCall ( hiddenResourceIdSet , inputs ) ) {
670- return stringifyToolOutput ( {
680+ return stringifyToolOutput ( attachDurationMs ( {
671681 error : 'RESOURCE_NOT_AVAILABLE' ,
672682 message : 'This resource is not available to the agent.' ,
673- } ) ;
683+ } , Date . now ( ) - startedAt ) ) ;
674684 }
675685
676686 const output = await callOpenApiSchema ( {
@@ -693,7 +703,7 @@ export function prepareApiBasedTools(
693703 userTimeZone,
694704 } ) ;
695705
696- return stringifyToolOutput ( processedOutput ) ;
706+ return stringifyToolOutput ( attachDurationMs ( processedOutput , Date . now ( ) - startedAt ) ) ;
697707 } ,
698708 } ;
699709 }
0 commit comments